From 31f06008c7e8cc739968cc01809252080b3bd075 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 30 Jun 2015 14:53:10 +0200 Subject: [PATCH] dhcp: properly reap child process in nm_dhcp_client_stop_existing() We kill the process based on the PID from the pidfile. This can be our own child process so we must use nm_utils_kill_child_sync() instead of nm_utils_kill_process_sync(). (cherry picked from commit c61c71a168d1c994424b2933169b48cbe1519614) --- src/dhcp-manager/nm-dhcp-client.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index cab3776ac3..eb31733071 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -590,9 +590,10 @@ nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name) if ((errno == 0) && (tmp > 1)) { guint64 start_time; const char *exe; + pid_t ppid; /* Ensure the process is a DHCP client */ - start_time = nm_utils_get_start_time_for_pid (tmp, NULL, NULL); + start_time = nm_utils_get_start_time_for_pid (tmp, NULL, &ppid); proc_path = g_strdup_printf ("/proc/%ld/cmdline", tmp); if ( start_time && g_file_get_contents (proc_path, &proc_contents, NULL, NULL)) { @@ -602,9 +603,15 @@ nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name) else exe = proc_contents; - if (!strcmp (exe, binary_name)) - nm_utils_kill_process_sync (tmp, start_time, SIGTERM, LOGD_DHCP, - "dhcp-client", 1000 / 2, 1000 / 20, 2000); + if (!strcmp (exe, binary_name)) { + if (ppid == getpid ()) { + /* the process is our own child. */ + nm_utils_kill_child_sync (tmp, SIGTERM, LOGD_DHCP, "dhcp-client", NULL, 1000 / 2, 1000 / 20); + } else { + nm_utils_kill_process_sync (tmp, start_time, SIGTERM, LOGD_DHCP, + "dhcp-client", 1000 / 2, 1000 / 20, 2000); + } + } } }