chiark / gitweb /
service: ifdef distro-specific compat logic
[elogind.git] / src / service.c
index 184ddf91437f8d4a1e70845e5ff3dca7ce43cc09..ca0db8e7f181e06b5a8bdf65656d67e0c3a46b4b 100644 (file)
@@ -65,7 +65,7 @@ static const struct {
         { "boot.d", SPECIAL_SYSINIT_TARGET,   RUNLEVEL_SYSINIT },
 #endif
 
-#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU)
+#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) || defined(TARGET_FRUGALWARE)
         /* Debian style rcS.d */
         { "rcS.d",  SPECIAL_SYSINIT_TARGET,   RUNLEVEL_SYSINIT },
 #endif
@@ -247,6 +247,11 @@ static char *sysv_translate_name(const char *name) {
         else if (startswith(name, "@"))
                 /* Drop Arch-style background prefix */
                 strcpy(stpcpy(r, name + 1), ".service");
+#endif
+#ifdef TARGET_FRUGALWARE
+        else if (startswith(name, "rc."))
+                /* Drop Frugalware-style rc. prefix */
+                strcpy(stpcpy(r, name + 3), ".service");
 #endif
         else
                 /* Normal init scripts */
@@ -273,23 +278,24 @@ static int sysv_translate_facility(const char *name, const char *filename, char
                 "syslog",               SPECIAL_SYSLOG_TARGET,
                 "time",                 SPECIAL_RTC_SET_TARGET,
 
-                /* Debian extensions */
+                /* common extensions */
+                "mail-transfer-agent",  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
+                "x-display-manager",    SPECIAL_DISPLAY_MANAGER_SERVICE,
+                "null",                 NULL,
+
 #if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU)
                 "mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
 #endif
-                "mail-transfer-agent",  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
-                "x-display-manager",    SPECIAL_DISPLAY_MANAGER_SERVICE,
 
 #ifdef TARGET_FEDORA
-                /* Fedora extensions */
                 "MTA",                  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
                 "smtpdaemon",           SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
                 "httpd",                SPECIAL_HTTP_DAEMON_TARGET,
 #endif
 
-                /* SuSE extensions */
-                "null",                 NULL
-
+#ifdef TARGET_SUSE
+                "smtp",                 SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
+#endif
         };
 
         unsigned i;
@@ -849,9 +855,10 @@ static int service_load_sysv_name(Service *s, const char *name) {
         assert(s);
         assert(name);
 
-        /* For SysV services we strip the boot. or .sh
+        /* For SysV services we strip the boot.*, rc.* and *.sh
          * prefixes/suffixes. */
         if (startswith(name, "boot.") ||
+            startswith(name, "rc.") ||
             endswith(name, ".sh.service"))
                 return -ENOENT;
 
@@ -867,24 +874,42 @@ static int service_load_sysv_name(Service *s, const char *name) {
 
                 r = service_load_sysv_path(s, path);
 
+#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU)
                 if (r >= 0 && s->meta.load_state == UNIT_STUB) {
-                        /* Try Debian style xxx.sh source'able init scripts */
+                        /* Try Debian style *.sh source'able init scripts */
                         strcat(path, ".sh");
                         r = service_load_sysv_path(s, path);
                 }
-
+#endif
                 free(path);
 
+#ifdef TARGET_SUSE
                 if (r >= 0 && s->meta.load_state == UNIT_STUB) {
-                        /* Try SUSE style boot.xxx init scripts */
+                        /* Try SUSE style boot.* init scripts */
 
                         if (asprintf(&path, "%s/boot.%s", *p, name) < 0)
                                 return -ENOMEM;
 
+                        /* Drop .service suffix */
                         path[strlen(path)-8] = 0;
                         r = service_load_sysv_path(s, path);
                         free(path);
                 }
+#endif
+
+#ifdef TARGET_FRUGALWARE
+                if (r >= 0 && s->meta.load_state == UNIT_STUB) {
+                        /* Try Frugalware style rc.* init scripts */
+
+                        if (asprintf(&path, "%s/rc.%s", *p, name) < 0)
+                                return -ENOMEM;
+
+                        /* Drop .service suffix */
+                        path[strlen(path)-8] = 0;
+                        r = service_load_sysv_path(s, path);
+                        free(path);
+                }
+#endif
 
                 if (r < 0)
                         return r;
@@ -1055,7 +1080,7 @@ static int service_load(Unit *u) {
                 if ((r = unit_add_exec_dependencies(u, &s->exec_context)) < 0)
                         return r;
 
-                if ((r = unit_add_default_cgroup(u)) < 0)
+                if ((r = unit_add_default_cgroups(u)) < 0)
                         return r;
 
 #ifdef HAVE_SYSV_COMPAT
@@ -1609,16 +1634,6 @@ static int service_spawn(
                         goto fail;
                 }
 
-#ifdef HAVE_SYSV_COMPAT
-        /* Make sure we set TERM=linux for SysV scripts, since some
-         * require it to be set from the kernel */
-        if (s->sysv_path && !strv_env_get(s->meta.manager->environment, "TERM"))
-                if (!(our_env[n_env++] = strdup("TERM=linux"))) {
-                        r = -ENOMEM;
-                        goto fail;
-                }
-#endif
-
         if (!(final_env = strv_env_merge(2,
                                          s->meta.manager->environment,
                                          our_env,