chiark / gitweb /
unit: suppress incorrect deserialization errors
[elogind.git] / src / service.c
index 6d6c540a725aef480d677f0418f5cb74ac2e8105..5cf78966a15f9f2fbdd94cf0df5eeadd19ef9f7f 100644 (file)
@@ -65,7 +65,7 @@ static const struct {
         { "boot.d", SPECIAL_SYSINIT_TARGET,   RUNLEVEL_SYSINIT },
 #endif
 
-#ifdef TARGET_DEBIAN
+#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU)
         /* Debian style rcS.d */
         { "rcS.d",  SPECIAL_SYSINIT_TARGET,   RUNLEVEL_SYSINIT },
 #endif
@@ -274,7 +274,7 @@ static int sysv_translate_facility(const char *name, const char *filename, char
                 "time",                 SPECIAL_RTC_SET_TARGET,
 
                 /* Debian extensions */
-#ifdef TARGET_DEBIAN
+#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU)
                 "mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
 #endif
                 "mail-transfer-agent",  SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
@@ -1220,6 +1220,30 @@ static int service_load_pid_file(Service *s) {
         return 0;
 }
 
+static int service_search_main_pid(Service *s) {
+        pid_t pid;
+        int r;
+
+        assert(s);
+
+        if (s->main_pid_known)
+                return 0;
+
+        assert(s->main_pid <= 0);
+
+        if ((pid = cgroup_bonding_search_main_pid_list(s->meta.cgroup_bondings)) <= 0)
+                return -ENOENT;
+
+        if ((r = service_set_main_pid(s, pid)) < 0)
+                return r;
+
+        if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
+                /* FIXME: we need to do something here */
+                return r;
+
+        return 0;
+}
+
 static int service_get_sockets(Service *s, Set **_set) {
         Set *set;
         Iterator i;
@@ -1568,7 +1592,7 @@ static int service_spawn(
                 goto fail;
         }
 
-        if (!(our_env = new0(char*, 3))) {
+        if (!(our_env = new0(char*, 4))) {
                 r = -ENOMEM;
                 goto fail;
         }
@@ -1585,6 +1609,16 @@ 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,
@@ -2585,8 +2619,8 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
                                  * START_POST script */
 
                                 if (success) {
-                                        if (s->pid_file)
-                                                service_load_pid_file(s);
+                                        service_load_pid_file(s);
+                                        service_search_main_pid(s);
 
                                         service_enter_start_post(s);
                                 } else