[systemd-commits] 2 commits - fixme src/service.c

Lennart Poettering lennart at kemper.freedesktop.org
Tue Sep 28 09:30:51 PDT 2010


 fixme         |    6 +
 src/service.c |  188 ++++++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 131 insertions(+), 63 deletions(-)

New commits:
commit 0b5d26f95dd0aceb051f334c109a90e356b38c90
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Sep 28 18:30:32 2010 +0200

    service: filter out empty LSB description strings

diff --git a/src/service.c b/src/service.c
index cf5edd2..6a230e5 100644
--- a/src/service.c
+++ b/src/service.c
@@ -432,6 +432,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                 LSB,
                 LSB_DESCRIPTION
         } state = NORMAL;
+        char *short_description = NULL, *long_description = NULL, *chkconfig_description = NULL, *description;
 
         assert(s);
         assert(path);
@@ -522,24 +523,27 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                         s->sysv_runlevels = d;
                                 }
 
-                        } else if (startswith_no_case(t, "description:") &&
-                                   !u->meta.description) {
+                        } else if (startswith_no_case(t, "description:")) {
 
                                 size_t k = strlen(t);
                                 char *d;
+                                const char *j;
 
                                 if (t[k-1] == '\\') {
                                         state = DESCRIPTION;
                                         t[k-1] = 0;
                                 }
 
-                                if (!(d = strappend("LSB: ", strstrip(t+12)))) {
-                                        r = -ENOMEM;
-                                        goto finish;
-                                }
+                                if ((j = strstrip(t+12)) && *j) {
+                                        if (!(d = strdup(j))) {
+                                                r = -ENOMEM;
+                                                goto finish;
+                                        }
+                                } else
+                                        d = NULL;
 
-                                free(u->meta.description);
-                                u->meta.description = d;
+                                free(chkconfig_description);
+                                chkconfig_description = d;
 
                         } else if (startswith_no_case(t, "pidfile:")) {
 
@@ -568,21 +572,29 @@ static int service_load_sysv_path(Service *s, const char *path) {
                          * continuation */
 
                         size_t k = strlen(t);
-                        char *d;
+                        char *j;
 
                         if (t[k-1] == '\\')
                                 t[k-1] = 0;
                         else
                                 state = NORMAL;
 
-                        assert(u->meta.description);
-                        if (asprintf(&d, "%s %s", u->meta.description, strstrip(t)) < 0) {
-                                r = -ENOMEM;
-                                goto finish;
-                        }
+                        if ((j = strstrip(t)) && *j) {
+                                char *d = NULL;
+
+                                if (chkconfig_description)
+                                        asprintf(&d, "%s %s", chkconfig_description, j);
+                                else
+                                        d = strdup(j);
+
+                                if (!d) {
+                                        r = -ENOMEM;
+                                        goto finish;
+                                }
 
-                        free(u->meta.description);
-                        u->meta.description = d;
+                                free(chkconfig_description);
+                                chkconfig_description = d;
+                        }
 
                 } else if (state == LSB || state == LSB_DESCRIPTION) {
 
@@ -688,35 +700,37 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                         s->sysv_runlevels = d;
                                 }
 
-                        } else if (startswith_no_case(t, "Description:") &&
-                                   !u->meta.description) {
-                                char *d;
-
-                                /* We use the long description only if
-                                 * no short description is set. */
+                        } else if (startswith_no_case(t, "Description:")) {
+                                char *d, *j;
 
                                 state = LSB_DESCRIPTION;
 
-                                if (!(d = strappend("LSB: ", strstrip(t+12)))) {
-                                        r = -ENOMEM;
-                                        goto finish;
-                                }
+                                if ((j = strstrip(t+12)) && *j) {
+                                        if (!(d = strdup(j))) {
+                                                r = -ENOMEM;
+                                                goto finish;
+                                        }
+                                } else
+                                        d = NULL;
 
-                                free(u->meta.description);
-                                u->meta.description = d;
+                                free(long_description);
+                                long_description = d;
 
                         } else if (startswith_no_case(t, "Short-Description:")) {
-                                char *d;
+                                char *d, *j;
 
                                 state = LSB;
 
-                                if (!(d = strappend("LSB: ", strstrip(t+18)))) {
-                                        r = -ENOMEM;
-                                        goto finish;
-                                }
+                                if ((j = strstrip(t+18)) && *j) {
+                                        if (!(d = strdup(j))) {
+                                                r = -ENOMEM;
+                                                goto finish;
+                                        }
+                                } else
+                                        d = NULL;
 
-                                free(u->meta.description);
-                                u->meta.description = d;
+                                free(short_description);
+                                short_description = d;
 
                         } else if (startswith_no_case(t, "X-Interactive:")) {
                                 int b;
@@ -734,16 +748,25 @@ static int service_load_sysv_path(Service *s, const char *path) {
                         } else if (state == LSB_DESCRIPTION) {
 
                                 if (startswith(l, "#\t") || startswith(l, "#  ")) {
-                                        char *d;
+                                        char *j;
 
-                                        assert(u->meta.description);
-                                        if (asprintf(&d, "%s %s", u->meta.description, t) < 0) {
-                                                r = -ENOMEM;
-                                                goto finish;
+                                        if ((j = strstrip(t)) && *j) {
+                                                char *d = NULL;
+
+                                                if (long_description)
+                                                        asprintf(&d, "%s %s", long_description, t);
+                                                else
+                                                        d = strdup(j);
+
+                                                if (!d) {
+                                                        r = -ENOMEM;
+                                                        goto finish;
+                                                }
+
+                                                free(long_description);
+                                                long_description = d;
                                         }
 
-                                        free(u->meta.description);
-                                        u->meta.description = d;
                                 } else
                                         state = LSB;
                         }
@@ -775,6 +798,29 @@ static int service_load_sysv_path(Service *s, const char *path) {
                 ? EXEC_OUTPUT_TTY : EXEC_OUTPUT_NULL;
         s->exec_context.kill_mode = KILL_PROCESS_GROUP;
 
+        /* We use the long description only if
+         * no short description is set. */
+
+        if (short_description)
+                description = short_description;
+        else if (chkconfig_description)
+                description = chkconfig_description;
+        else if (long_description)
+                description = long_description;
+        else
+                description = NULL;
+
+        if (description) {
+                char *d;
+
+                if (!(d = strappend("LSB: ", description))) {
+                        r = -ENOMEM;
+                        goto finish;
+                }
+
+                u->meta.description = d;
+        }
+
         u->meta.load_state = UNIT_LOADED;
         r = 0;
 
@@ -783,6 +829,10 @@ finish:
         if (f)
                 fclose(f);
 
+        free(short_description);
+        free(long_description);
+        free(chkconfig_description);
+
         return r;
 }
 
commit a7d3cc26f9694053712458615006ea79cd7a7cb4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Sep 28 18:30:02 2010 +0200

    service: when resolving sysv names drop leading $

diff --git a/fixme b/fixme
index 9e283f5..623a1d0 100644
--- a/fixme
+++ b/fixme
@@ -97,7 +97,11 @@
 
 * LSB provides should only create targets, never aliases
 
-* s/tempfiles/volatile-files/
+* stability promise must say that #ifdef TARGET_XXX style distro compatibility will go away one day
+
+* drop empty assignments for parse_env_file
+
+* #include "fanotify.h"
 
 External:
 
diff --git a/src/service.c b/src/service.c
index 021bc86..cf5edd2 100644
--- a/src/service.c
+++ b/src/service.c
@@ -252,48 +252,62 @@ static char *sysv_translate_name(const char *name) {
 
 static int sysv_translate_facility(const char *name, char **_r) {
 
+        /* We silently ignore the $ prefix here. According to the LSB
+         * spec it simply indicates whether something is a
+         * standardized name or a distribution-specific one. Since we
+         * just follow what already exists and do not introduce new
+         * uses or names we don't care who introduced a new name. */
+
         static const char * const table[] = {
                 /* LSB defined facilities */
-                "$local_fs",  SPECIAL_LOCAL_FS_TARGET,
-                "$network",   SPECIAL_NETWORK_TARGET,
-                "$named",     SPECIAL_NSS_LOOKUP_TARGET,
-                "$portmap",   SPECIAL_RPCBIND_TARGET,
-                "$remote_fs", SPECIAL_REMOTE_FS_TARGET,
-                "$syslog",    SPECIAL_SYSLOG_TARGET,
-                "$time",      SPECIAL_RTC_SET_TARGET,
+                "local_fs",             SPECIAL_LOCAL_FS_TARGET,
+                "network",              SPECIAL_NETWORK_TARGET,
+                "named",                SPECIAL_NSS_LOOKUP_TARGET,
+                "portmap",              SPECIAL_RPCBIND_TARGET,
+                "remote_fs",            SPECIAL_REMOTE_FS_TARGET,
+                "syslog",               SPECIAL_SYSLOG_TARGET,
+                "time",                 SPECIAL_RTC_SET_TARGET,
 
                 /* Debian extensions */
 #ifdef TARGET_DEBIAN
-                "$mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
+                "mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
 #endif
-                "$mail-transfer-agent",  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
-                "$x-display-manager",    SPECIAL_DISPLAY_MANAGER_SERVICE,
+                "mail-transfer-agent",  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
+                "x-display-manager",    SPECIAL_DISPLAY_MANAGER_SERVICE,
 
 #ifdef TARGET_FEDORA
-                /* Fedora extensions, lacking the $ prefix */
-                "MTA",        SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
-                "smtpdaemon", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
-                "httpd",      SPECIAL_HTTP_DAEMON_TARGET,
+                /* Fedora extensions */
+                "MTA",                  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
+                "smtpdaemon",           SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
+                "httpd",                SPECIAL_HTTP_DAEMON_TARGET,
 #endif
+
+                /* SuSE extensions */
+                "null",                 NULL
+
         };
 
         unsigned i;
         char *r;
 
-        /* SuSE insserv extension */
-        if (streq(name, "$null"))
-                return 0;
-
         for (i = 0; i < ELEMENTSOF(table); i += 2)
-                if (streq(table[i], name)) {
+
+                if (streq(table[i], name) ||
+                    (*name == '$' && streq(table[i], name+1))) {
+
+                        if (!table[i+1])
+                                return 0;
+
                         if (!(r = strdup(table[i+1])))
                                 return -ENOMEM;
 
                         goto finish;
                 }
 
+        /* If we don't know this name, fallback heuristics to figure
+         * out whether something is a target or an service alias. */
+
         if (*name == '$')
-                /* This is a heuristic. */
                 r = unit_name_build(name+1, NULL, ".target");
         else
                 r = sysv_translate_name(name);


More information about the systemd-commits mailing list