[jbossnative-commits] JBoss Native SVN: r1036 - in trunk/sight: native/os/linux and 1 other directory.

jbossnative-commits at lists.jboss.org jbossnative-commits at lists.jboss.org
Thu Sep 20 07:34:03 EDT 2007


Author: mladen.turk at jboss.com
Date: 2007-09-20 07:34:03 -0400 (Thu, 20 Sep 2007)
New Revision: 1036

Modified:
   trunk/sight/examples/org/jboss/sight/ListServices.java
   trunk/sight/native/os/linux/service.c
Log:
Figure out the ServiceState from pidfile

Modified: trunk/sight/examples/org/jboss/sight/ListServices.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListServices.java	2007-09-20 11:18:58 UTC (rev 1035)
+++ trunk/sight/examples/org/jboss/sight/ListServices.java	2007-09-20 11:34:03 UTC (rev 1036)
@@ -44,7 +44,8 @@
             scm.open(null, EnumSet.of(GenericAccessRights.READ));
 
             for (Service s : scm.getServices()) {
-                System.out.println("Service\t[" + s.Name + "] \t" +
+                System.out.println("Service " + s.State + "\t[" +
+                                   s.Name + "] \t" +
                                    s.DisplayName + " \t" + s.Description);
             }
             System.out.println();

Modified: trunk/sight/native/os/linux/service.c
===================================================================
--- trunk/sight/native/os/linux/service.c	2007-09-20 11:18:58 UTC (rev 1035)
+++ trunk/sight/native/os/linux/service.c	2007-09-20 11:34:03 UTC (rev 1036)
@@ -224,6 +224,7 @@
     if ((rd = opendir(rlpath))) {
         struct dirent *sent, sbuf;
         int found = 0;
+        int state = SIGHT_SS_UNKNOWN;
         while (!readdir_r(rd, &sbuf, &sent)) {            
             char sname[PATH_MAX];
             char smatch[PATH_MAX];
@@ -247,7 +248,18 @@
                 else
                     SET_IFIELD_S(0004, thiz, sent->d_name);
                 SET_IFIELD_S(0005, thiz, dn);
-
+                
+                if (pf[0]) {
+                    struct stat sb;
+                    if (stat(pf, &sb) >= 0) {
+                        /* If there is a pidfile the service
+                         * is probably running
+                         */
+                        state = SIGHT_SS_RUNNING;
+                    }
+                    else
+                        state = SIGHT_SS_STOPPED;
+                }
                 found = 1;
                 break;
             }
@@ -255,7 +267,7 @@
         closedir(rd);
         if (found) {
             /* Populate the fields */
-            CALL_METHOD1(0000, thiz, SIGHT_SS_UNKNOWN);            
+            CALL_METHOD1(0000, thiz, state);            
         }
         else {
             CALL_METHOD1(0000, thiz, SIGHT_SS_DISABLED);            




More information about the jbossnative-commits mailing list