[systemd-commits] src/service.c

Lennart Poettering lennart at kemper.freedesktop.org
Tue Sep 28 12:08:45 PDT 2010


 src/service.c |   49 +++++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 24 deletions(-)

New commits:
commit ee95669fb6922d6f45601ab76db5f19b3d8c0eb6
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Sep 28 21:08:39 2010 +0200

    service: first lookup LSB facility names in tables, only then suppress self-provides

diff --git a/src/service.c b/src/service.c
index d9e0b20..b18c950 100644
--- a/src/service.c
+++ b/src/service.c
@@ -250,7 +250,7 @@ static char *sysv_translate_name(const char *name) {
         return r;
 }
 
-static int sysv_translate_facility(const char *name, char **_r) {
+static int sysv_translate_facility(const char *name, const char *filename, char **_r) {
 
         /* We silently ignore the $ prefix here. According to the LSB
          * spec it simply indicates whether something is a
@@ -289,28 +289,39 @@ static int sysv_translate_facility(const char *name, char **_r) {
 
         unsigned i;
         char *r;
+        const char *n;
 
-        for (i = 0; i < ELEMENTSOF(table); i += 2)
+        assert(name);
+        assert(_r);
 
-                if (streq(table[i], name) ||
-                    (*name == '$' && streq(table[i], name+1))) {
+        n = *name == '$' ? name + 1 : name;
 
-                        if (!table[i+1])
-                                return 0;
+        for (i = 0; i < ELEMENTSOF(table); i += 2) {
 
-                        if (!(r = strdup(table[i+1])))
-                                return -ENOMEM;
+                if (!streq(table[i], n))
+                        continue;
 
-                        goto finish;
-                }
+                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 == '$')
-                r = unit_name_build(name+1, NULL, ".target");
+                /* Facilities starting with $ are most likely targets */
+                r = unit_name_build(n, NULL, ".target");
+        else if (filename && streq(name, filename))
+                /* Names equalling the file name of the services are redundant */
+                return 0;
         else
-                r = sysv_translate_name(name);
+                /* Everything else we assume to be normal service names */
+                r = sysv_translate_name(n);
 
         if (!r)
                 return -ENOMEM;
@@ -612,12 +623,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                                 goto finish;
                                         }
 
-                                        if (streq(n, file_name_from_path(path))) {
-                                                free(n);
-                                                continue;
-                                        }
-
-                                        r = sysv_translate_facility(n, &m);
+                                        r = sysv_translate_facility(n, file_name_from_path(path), &m);
                                         free(n);
 
                                         if (r < 0)
@@ -662,12 +668,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
                                                 goto finish;
                                         }
 
-                                        if (streq(n, file_name_from_path(path))) {
-                                                free(n);
-                                                continue;
-                                        }
-
-                                        r = sysv_translate_facility(n, &m);
+                                        r = sysv_translate_facility(n, file_name_from_path(path), &m);
                                         free(n);
 
                                         if (r < 0)


More information about the systemd-commits mailing list