Author: mladen.turk(a)jboss.com
Date: 2007-09-20 07:18:58 -0400 (Thu, 20 Sep 2007)
New Revision: 1035
Modified:
trunk/sight/examples/org/jboss/sight/ListServices.java
trunk/sight/native/os/linux/service.c
Log:
Parse service descriptions from script files
Modified: trunk/sight/examples/org/jboss/sight/ListServices.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/ListServices.java 2007-09-20 08:39:38 UTC (rev
1034)
+++ trunk/sight/examples/org/jboss/sight/ListServices.java 2007-09-20 11:18:58 UTC (rev
1035)
@@ -45,7 +45,7 @@
for (Service s : scm.getServices()) {
System.out.println("Service\t[" + s.Name + "] \t" +
- s.DisplayName );
+ s.DisplayName + " \t" + s.Description);
}
System.out.println();
for (Service s : scm.getDrivers()) {
Modified: trunk/sight/native/os/linux/service.c
===================================================================
--- trunk/sight/native/os/linux/service.c 2007-09-20 08:39:38 UTC (rev 1034)
+++ trunk/sight/native/os/linux/service.c 2007-09-20 11:18:58 UTC (rev 1035)
@@ -131,6 +131,67 @@
sight_unload_class(_E, &_clazzn);
}
+#define SCC_DESC "# description:"
+#define SCC_PNAM "# processname:"
+#define SCC_PIDF "# pidfile:"
+
+static void parse_service_script(const char *fname, char *description,
+ char *procname, char *pidfile)
+{
+ FILE *file;
+ char buf[8192];
+ int mdesc = 0;
+
+ if (!(file = fopen(fname, "r")))
+ return;
+ while (fgets(&buf[0], 8192, file)) {
+ char *pline = sight_trim(&buf[0]);
+ /* Skip empty lines */
+ if (pline) {
+ if (*pline != '#')
+ break;
+ if (mdesc) {
+ mdesc = 0;
+ if (buf[0] == '#' && buf[1] == ' ') {
+ pline = sight_trim(&buf[1]);
+ if (pline) {
+ if (strlen(description) + strlen(pline) < SIGHT_MBUFFER_LEN)
{
+ strcat(description, pline);
+ if (description[strlen(description) - 1] == '\\') {
+ /* We have multi-line description */
+ description[strlen(description) - 1] = '\0';
+ mdesc = 1;
+ }
+ }
+ }
+ }
+ if (!mdesc)
+ continue;
+ }
+ if (!strncmp(pline, SCC_DESC, sizeof(SCC_DESC) - 1)) {
+ apr_cpystrn(description, pline + sizeof(SCC_DESC),
+ SIGHT_MBUFFER_SIZ);
+ if (description[strlen(description) - 1] == '\\') {
+ /* We have multi-line description */
+ description[strlen(description) - 1] = '\0';
+ mdesc = 1;
+ }
+ }
+ else if (!strncmp(pline, SCC_PNAM, sizeof(SCC_PNAM) - 1)) {
+ apr_cpystrn(procname, pline + sizeof(SCC_PNAM),
+ SIGHT_SBUFFER_SIZ);
+ }
+ else if (!strncmp(pline, SCC_PIDF, sizeof(SCC_PIDF) - 1)) {
+ apr_cpystrn(pidfile, pline + sizeof(SCC_PIDF),
+ SIGHT_SBUFFER_SIZ);
+ }
+ }
+ }
+
+ fclose(file);
+}
+
+
SIGHT_EXPORT_DECLARE(jint, Service, open0)(SIGHT_STDARGS,
jobject thiz,
jlong instance,
@@ -175,9 +236,18 @@
strcat(smatch, J2S(name));
/* Match the SnnName */
if (!sight_wmatch(sname, smatch)) {
+ char pn[SIGHT_SBUFFER_SIZ] = "";
+ char pf[SIGHT_SBUFFER_SIZ] = "";
+ char dn[SIGHT_MBUFFER_SIZ] = "";
+ parse_service_script(sname, dn, pn, pf);
SET_IFIELD_S(0001, thiz, sname);
SET_IFIELD_S(0003, thiz, sent->d_name);
- SET_IFIELD_S(0004, thiz, sent->d_name);
+ if (pn[0])
+ SET_IFIELD_S(0004, thiz, pn);
+ else
+ SET_IFIELD_S(0004, thiz, sent->d_name);
+ SET_IFIELD_S(0005, thiz, dn);
+
found = 1;
break;
}