diff options
author | Thomas Haller <thaller@redhat.com> | 2015-06-30 14:53:10 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-06-30 16:15:17 +0200 |
commit | c61c71a168d1c994424b2933169b48cbe1519614 (patch) | |
tree | e71511abd44ce4e7399a3f03a211174ffec26cd0 | |
parent | 7c9eefa7677dce5a36b7a9ee303b2098a11f0efc (diff) | |
download | NetworkManager-c61c71a168d1c994424b2933169b48cbe1519614.tar.gz |
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().
-rw-r--r-- | src/dhcp-manager/nm-dhcp-client.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index f94cdb249f..67be01cf4f 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); + } + } } } |