chiark / gitweb /
kill: always send SIGCONT after SIGTERM
authorLennart Poettering <lennart@poettering.net>
Thu, 3 Mar 2011 22:55:30 +0000 (23:55 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 3 Mar 2011 22:55:30 +0000 (23:55 +0100)
When we kill a process to terminate it make sure to send SIGCONT to
ensure it is unpaused and processes the signal.

14 files changed:
TODO
src/cgroup-util.c
src/cgroup-util.h
src/cgroup.c
src/cgroup.h
src/execute.c
src/mount.c
src/service.c
src/socket.c
src/swap.c
src/systemctl.c
src/test-cgroup.c
src/util.c
src/util.h

diff --git a/TODO b/TODO
index 848ea2138d0825571ee120f50f6da300a62ddc50..820391dbc7938f2585f1b6561d36a77a04146840 100644 (file)
--- a/TODO
+++ b/TODO
@@ -20,13 +20,11 @@ F15:
 
 * hook emergency.target into local-fs.target in some way as OnFailure with isolate
 
-* convince Karel to give us our own mount option prefix
-
 Features:
 
-* show failure error string in "systemctl status"
+* introduce "x-systemd-automount" as alternative to the "comment=systemd.automount" mount option
 
-* send SIGCONT before SIGTERM
+* show failure error string in "systemctl status"
 
 * make sure timeouts are applied to Type=oneshot services.
 
index b68b9ad3a33a20c9c85e2e0c7a5d495e3f7cb71a..055c906106afd0a0f9c10499fd3e0063b42bcd14 100644 (file)
@@ -166,7 +166,7 @@ int cg_rmdir(const char *controller, const char *path) {
         return r < 0 ? -errno : 0;
 }
 
-int cg_kill(const char *controller, const char *path, int sig, bool ignore_self, Set *s) {
+int cg_kill(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, Set *s) {
         bool done = false;
         int r, ret = 0;
         pid_t my_pid;
@@ -211,8 +211,13 @@ int cg_kill(const char *controller, const char *path, int sig, bool ignore_self,
                         if (kill(pid, sig) < 0) {
                                 if (ret >= 0 && errno != ESRCH)
                                         ret = -errno;
-                        } else if (ret == 0)
+                        } else if (ret == 0) {
+
+                                if (sigcont)
+                                        kill(pid, SIGCONT);
+
                                 ret = 1;
+                        }
 
                         done = false;
 
@@ -250,7 +255,7 @@ finish:
         return ret;
 }
 
-int cg_kill_recursive(const char *controller, const char *path, int sig, bool ignore_self, bool rem, Set *s) {
+int cg_kill_recursive(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, bool rem, Set *s) {
         int r, ret = 0;
         DIR *d = NULL;
         char *fn;
@@ -264,7 +269,7 @@ int cg_kill_recursive(const char *controller, const char *path, int sig, bool ig
                 if (!(s = allocated_set = set_new(trivial_hash_func, trivial_compare_func)))
                         return -ENOMEM;
 
-        ret = cg_kill(controller, path, sig, ignore_self, s);
+        ret = cg_kill(controller, path, sig, sigcont, ignore_self, s);
 
         if ((r = cg_enumerate_subgroups(controller, path, &d)) < 0) {
                 if (ret >= 0 && r != -ENOENT)
@@ -286,7 +291,7 @@ int cg_kill_recursive(const char *controller, const char *path, int sig, bool ig
                         goto finish;
                 }
 
-                r = cg_kill_recursive(controller, p, sig, ignore_self, rem, s);
+                r = cg_kill_recursive(controller, p, sig, sigcont, ignore_self, rem, s);
                 free(p);
 
                 if (r != 0 && ret >= 0)
@@ -336,7 +341,7 @@ int cg_kill_recursive_and_wait(const char *controller, const char *path, bool re
                 else
                         sig = 0;
 
-                if ((r = cg_kill_recursive(controller, path, sig, true, rem, NULL)) <= 0)
+                if ((r = cg_kill_recursive(controller, path, sig, true, true, rem, NULL)) <= 0)
                         return r;
 
                 usleep(200 * USEC_PER_MSEC);
index 2cb6ede4a4b06d081968caf9dc2212a182cc3008..73df9697ed83778fd0bb5af9c546eb6c92055f03 100644 (file)
@@ -37,8 +37,8 @@ int cg_read_pid(FILE *f, pid_t *_pid);
 int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d);
 int cg_read_subgroup(DIR *d, char **fn);
 
-int cg_kill(const char *controller, const char *path, int sig, bool ignore_self, Set *s);
-int cg_kill_recursive(const char *controller, const char *path, int sig, bool ignore_self, bool remove, Set *s);
+int cg_kill(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, Set *s);
+int cg_kill_recursive(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, bool remove, Set *s);
 int cg_kill_recursive_and_wait(const char *controller, const char *path, bool remove);
 
 int cg_migrate(const char *controller, const char *from, const char *to, bool ignore_self);
index 729cc75e6704cf39e35f98a68eed1ad0f6eb18d4..b75fe0bee0c9116f9736b8153db15de1fd1fef67 100644 (file)
@@ -140,7 +140,7 @@ int cgroup_bonding_install_list(CGroupBonding *first, pid_t pid) {
         return 0;
 }
 
-int cgroup_bonding_kill(CGroupBonding *b, int sig, Set *s) {
+int cgroup_bonding_kill(CGroupBonding *b, int sig, bool sigcont, Set *s) {
         assert(b);
         assert(sig >= 0);
 
@@ -148,10 +148,10 @@ int cgroup_bonding_kill(CGroupBonding *b, int sig, Set *s) {
         if (!b->realized || !b->ours)
                 return 0;
 
-        return cg_kill_recursive(b->controller, b->path, sig, true, false, s);
+        return cg_kill_recursive(b->controller, b->path, sig, sigcont, true, false, s);
 }
 
-int cgroup_bonding_kill_list(CGroupBonding *first, int sig, Set *s) {
+int cgroup_bonding_kill_list(CGroupBonding *first, int sig, bool sigcont, Set *s) {
         CGroupBonding *b;
         Set *allocated_set = NULL;
         int ret = -EAGAIN, r;
@@ -161,7 +161,7 @@ int cgroup_bonding_kill_list(CGroupBonding *first, int sig, Set *s) {
                         return -ENOMEM;
 
         LIST_FOREACH(by_unit, b, first) {
-                if ((r = cgroup_bonding_kill(b, sig, s)) < 0) {
+                if ((r = cgroup_bonding_kill(b, sig, sigcont, s)) < 0) {
                         if (r == -EAGAIN || r == -ESRCH)
                                 continue;
 
index 89854ff34ee0088a1ae3038fa437ee833a314e0a..a6ac90fb094bfecd7a5d0ba12ad1831aea244d3e 100644 (file)
@@ -59,8 +59,8 @@ void cgroup_bonding_free_list(CGroupBonding *first);
 int cgroup_bonding_install(CGroupBonding *b, pid_t pid);
 int cgroup_bonding_install_list(CGroupBonding *first, pid_t pid);
 
-int cgroup_bonding_kill(CGroupBonding *b, int sig, Set *s);
-int cgroup_bonding_kill_list(CGroupBonding *first, int sig, Set *s);
+int cgroup_bonding_kill(CGroupBonding *b, int sig, bool sigcont, Set *s);
+int cgroup_bonding_kill_list(CGroupBonding *first, int sig, bool sigcont, Set *s);
 
 void cgroup_bonding_trim(CGroupBonding *first, bool delete_root);
 void cgroup_bonding_trim_list(CGroupBonding *first, bool delete_root);
index d6f09e26fea39c9519fe5cd13a485553f44e516c..281d90da2e5013d6d1858a58e376731d3801ddd0 100644 (file)
@@ -894,8 +894,10 @@ fail:
 
         closelog();
 
-        if (pam_pid > 1)
+        if (pam_pid > 1) {
                 kill(pam_pid, SIGTERM);
+                kill(pam_pid, SIGCONT);
+        }
 
         return EXIT_PAM;
 }
index 88b54bbb2913a1057f03471c35e07c5cce3aa081..8a9ab167210373f0a4cbec4d2bb9665954c68c45 100644 (file)
@@ -729,9 +729,9 @@ static void mount_enter_signal(Mount *m, MountState state, bool success) {
                            state == MOUNT_REMOUNTING_SIGTERM) ? m->exec_context.kill_signal : SIGKILL;
 
                 if (m->control_pid > 0) {
-                        if (kill(m->exec_context.kill_mode == KILL_PROCESS_GROUP ?
-                                 -m->control_pid :
-                                 m->control_pid, sig) < 0 && errno != ESRCH)
+                        if (kill_and_sigcont(m->exec_context.kill_mode == KILL_PROCESS_GROUP ?
+                                             -m->control_pid :
+                                             m->control_pid, sig) < 0 && errno != ESRCH)
 
                                 log_warning("Failed to kill control process %li: %m", (long) m->control_pid);
                         else
@@ -750,7 +750,7 @@ static void mount_enter_signal(Mount *m, MountState state, bool success) {
                                 if ((r = set_put(pid_set, LONG_TO_PTR(m->control_pid))) < 0)
                                         goto fail;
 
-                        if ((r = cgroup_bonding_kill_list(m->meta.cgroup_bondings, sig, pid_set)) < 0) {
+                        if ((r = cgroup_bonding_kill_list(m->meta.cgroup_bondings, sig, true, pid_set)) < 0) {
                                 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
                                         log_warning("Failed to kill control group: %s", strerror(-r));
                         } else if (r > 0)
@@ -1678,7 +1678,7 @@ static int mount_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError
                                 goto finish;
                         }
 
-                if ((q = cgroup_bonding_kill_list(m->meta.cgroup_bondings, signo, pid_set)) < 0)
+                if ((q = cgroup_bonding_kill_list(m->meta.cgroup_bondings, signo, false, pid_set)) < 0)
                         if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
                                 r = q;
         }
index 39a46d6cf563a1b47edc41f583cac0c6f4ea17bc..85175793428f77b8d7ac8261a40dc11490329e82 100644 (file)
@@ -1830,9 +1830,9 @@ static void service_enter_signal(Service *s, ServiceState state, bool success) {
                 int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
 
                 if (s->main_pid > 0) {
-                        if (kill(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
-                                 -s->main_pid :
-                                 s->main_pid, sig) < 0 && errno != ESRCH)
+                        if (kill_and_sigcont(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
+                                             -s->main_pid :
+                                             s->main_pid, sig) < 0 && errno != ESRCH)
 
                                 log_warning("Failed to kill main process %li: %m", (long) s->main_pid);
                         else
@@ -1840,9 +1840,9 @@ static void service_enter_signal(Service *s, ServiceState state, bool success) {
                 }
 
                 if (s->control_pid > 0) {
-                        if (kill(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
-                                 -s->control_pid :
-                                 s->control_pid, sig) < 0 && errno != ESRCH)
+                        if (kill_and_sigcont(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
+                                             -s->control_pid :
+                                             s->control_pid, sig) < 0 && errno != ESRCH)
 
                                 log_warning("Failed to kill control process %li: %m", (long) s->control_pid);
                         else
@@ -1865,7 +1865,7 @@ static void service_enter_signal(Service *s, ServiceState state, bool success) {
                                 if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
                                         goto fail;
 
-                        if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, pid_set)) < 0) {
+                        if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, true, pid_set)) < 0) {
                                 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
                                         log_warning("Failed to kill control group: %s", strerror(-r));
                         } else if (r > 0)
@@ -3230,7 +3230,7 @@ static int service_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusErro
                                 goto finish;
                         }
 
-                if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, pid_set)) < 0)
+                if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0)
                         if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
                                 r = q;
         }
index 96c649b0ab04bf6171db46cda9c7f08b4121feca..77bbe43ee19f884929cb09a499a71ae102f7d67b 100644 (file)
@@ -1039,9 +1039,9 @@ static void socket_enter_signal(Socket *s, SocketState state, bool success) {
                 int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
 
                 if (s->control_pid > 0) {
-                        if (kill(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
-                                 -s->control_pid :
-                                 s->control_pid, sig) < 0 && errno != ESRCH)
+                        if (kill_and_sigcont(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
+                                             -s->control_pid :
+                                             s->control_pid, sig) < 0 && errno != ESRCH)
 
                                 log_warning("Failed to kill control process %li: %m", (long) s->control_pid);
                         else
@@ -1060,7 +1060,7 @@ static void socket_enter_signal(Socket *s, SocketState state, bool success) {
                                 if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
                                         goto fail;
 
-                        if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, pid_set)) < 0) {
+                        if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, true, pid_set)) < 0) {
                                 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
                                         log_warning("Failed to kill control group: %s", strerror(-r));
                         } else if (r > 0)
@@ -1852,7 +1852,7 @@ static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError
                                 goto finish;
                         }
 
-                if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, pid_set)) < 0)
+                if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0)
                         if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
                                 r = q;
         }
index 4ffe19f1e84a3052f60d48e3ba3d38388264925e..f59b0fb18d6561d157f1a1d55bfed9f7a4786e4b 100644 (file)
@@ -660,9 +660,9 @@ static void swap_enter_signal(Swap *s, SwapState state, bool success) {
                            state == SWAP_DEACTIVATING_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
 
                 if (s->control_pid > 0) {
-                        if (kill(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
-                                 -s->control_pid :
-                                 s->control_pid, sig) < 0 && errno != ESRCH)
+                        if (kill_and_sigcont(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
+                                             -s->control_pid :
+                                             s->control_pid, sig) < 0 && errno != ESRCH)
 
                                 log_warning("Failed to kill control process %li: %m", (long) s->control_pid);
                         else
@@ -681,7 +681,7 @@ static void swap_enter_signal(Swap *s, SwapState state, bool success) {
                                 if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
                                         goto fail;
 
-                        if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, pid_set)) < 0) {
+                        if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, true, pid_set)) < 0) {
                                 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
                                         log_warning("Failed to kill control group: %s", strerror(-r));
                         } else if (r > 0)
@@ -1301,7 +1301,7 @@ static int swap_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *
                                 goto finish;
                         }
 
-                if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, pid_set)) < 0)
+                if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0)
                         if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
                                 r = q;
         }
index c3f47a1381f4a8f103c9ff9f876fc0990d1a1c13..2e8d10736702c6fc4380540dfec5522569d7df9b 100644 (file)
@@ -5532,6 +5532,7 @@ static void pager_close(void) {
 
         /* Inform pager that we are done */
         fclose(stdout);
+        kill(pager_pid, SIGCONT);
         wait_for_terminate(pager_pid, &dummy);
         pager_pid = 0;
 }
@@ -5544,6 +5545,7 @@ static void agent_close(void) {
 
         /* Inform agent that we are done */
         kill(agent_pid, SIGTERM);
+        kill(agent_pid, SIGCONT);
         wait_for_terminate(agent_pid, &dummy);
         agent_pid = 0;
 }
index 486656b41ddadb0a8f30bdd46aabc08f111d2311..eb189374faf369c820dfcffb66ab633f29f05849 100644 (file)
@@ -61,16 +61,16 @@ int main(int argc, char*argv[]) {
         assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", false) > 0);
         assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", false) == 0);
 
-        assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0, false, false, NULL) == 0);
-        assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0, false, false, NULL) > 0);
+        assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0, false, false, false, NULL) == 0);
+        assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0, false, false, false, NULL) > 0);
 
         assert_se(cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", "/test-a", false, false) > 0);
 
         assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", false) == 0);
         assert_se(cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", false) > 0);
 
-        assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0, false, false, NULL) > 0);
-        assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0, false, false, NULL) == 0);
+        assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-a", 0, false, false, false, NULL) > 0);
+        assert_se(cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, "/test-b", 0, false, false, false, NULL) == 0);
 
         cg_trim(SYSTEMD_CGROUP_CONTROLLER, "/", false);
 
index e2859fafc1b115215eb7638125a126e031aa1bf5..23d7e2211d8a94c1642452627b24ff208ead8559 100644 (file)
@@ -3977,6 +3977,17 @@ finish:
                 hashmap_free_free(pids);
 }
 
+int kill_and_sigcont(pid_t pid, int sig) {
+        int r;
+
+        r = kill(pid, sig) < 0 ? -errno : 0;
+
+        if (r >= 0)
+                kill(pid, SIGCONT);
+
+        return r;
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",
index 7f2cc080a751078042da6468d06c6176b595a84e..3f3347d59a09189cba4b720c90ebbf7130c87952 100644 (file)
@@ -383,6 +383,8 @@ int detect_virtualization(const char **id);
 
 void execute_directory(const char *directory, DIR *_d, char *argv[]);
 
+int kill_and_sigcont(pid_t pid, int sig);
+
 #define NULSTR_FOREACH(i, l)                                    \
         for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)