Author: mladen.turk(a)jboss.com
Date: 2007-09-26 07:57:11 -0400 (Wed, 26 Sep 2007)
New Revision: 1044
Modified:
trunk/sight/native/os/linux/service.c
Log:
Remove parsing the script files. Use predefined list of known service names
Modified: trunk/sight/native/os/linux/service.c
===================================================================
--- trunk/sight/native/os/linux/service.c 2007-09-25 05:55:25 UTC (rev 1043)
+++ trunk/sight/native/os/linux/service.c 2007-09-26 11:57:11 UTC (rev 1044)
@@ -131,64 +131,65 @@
sight_unload_class(_E, &_clazzn);
}
-#define SCC_DESC "# description:"
-#define SCC_PNAM "# processname:"
-#define SCC_PIDF "# pidfile:"
+static const struct {
+ const char *script;
+ const char *name;
+ const char *description;
+} known_services[] = {
+ { "acpid"
+ "Power Management",
+ "Listen and dispatch ACPI events from the kernel"
+ },
+ { "anacron"
+ "Actions scheduler",
+ "Run cron jobs that were left out due to downtime"
+ },
+ { "atd"
+ "Actions scheduler",
+ "Runs commands scheduled by the at command at the time "
+ "specified when at was run, and runs batch commands when the load "
+ "average is low enough."
+ },
+ { "auditd"
+ "Auditing System Daemon",
+ "Linux Auditing System Daemon"
+ },
+ { "autofs"
+ "Automount",
+ "Automounts filesystems on demand"
+ },
+ { "avahi-daemon"
+ "Avahi Daemon",
+ "This is a daemon which runs on client machines to perform "
+ "Zeroconf service discovery on a network. avahi-daemon must be "
+ "running on systems that use Avahi for service discovery. "
+ "Avahi-daemon should not be running otherwise."
+ },
+ { "avahi-dnsconfd"
+ "Avahi dns configuration daemon",
+ "Connects to a running avahi-daemon and runs the script "
+ "/etc/avahi/dnsconf.action for each unicast DNS server that is announced
"
+ "on the local LAN. This is useful for configuring unicast DNS servers in
"
+ "a DHCP-like fashion with mDNS."
+ },
-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);
- }
+ { NULL,
+ NULL,
+ NULL
+ }
+};
+
+int find_service_desc(const char *name)
+{
+ int i = 0;
+ while (known_services[i].script) {
+ if (!strcmp(known_services[i].script, name)) {
+ return i;
}
- }
-
- fclose(file);
+ i++;
+ }
+ return -1;
}
@@ -225,7 +226,7 @@
struct dirent *sent, sbuf;
int found = 0;
int state = SIGHT_SS_UNKNOWN;
- while (!readdir_r(rd, &sbuf, &sent)) {
+ while (!readdir_r(rd, &sbuf, &sent)) {
char sname[PATH_MAX];
char smatch[PATH_MAX];
struct stat sb;
@@ -237,29 +238,20 @@
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);
+ int snix = find_service_desc(J2S(name));
+
SET_IFIELD_S(0001, thiz, sname);
- SET_IFIELD_S(0003, thiz, sent->d_name);
- if (pn[0])
- SET_IFIELD_S(0004, thiz, pn);
- else
+ if (snix >= 0) {
+ SET_IFIELD_S(0004, thiz, known_services[snix].name);
+ SET_IFIELD_S(0005, thiz, known_services[snix].description);
+ }
+ 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;
}
+
+ /* TODO: Launch script with status param
+ * to figure out the state.
+ */
found = 1;
break;
}
@@ -267,10 +259,10 @@
closedir(rd);
if (found) {
/* Populate the fields */
- CALL_METHOD1(0000, thiz, state);
+ CALL_METHOD1(0000, thiz, state);
}
else {
- CALL_METHOD1(0000, thiz, SIGHT_SS_DISABLED);
+ CALL_METHOD1(0000, thiz, SIGHT_SS_DISABLED);
}
}
SIGHT_FREE_CSTRING(name);