mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-06 07:58:00 +02:00
dhcpcd: fix killing all processes
With kill(), the PID -1 means to send a signal to all processes. nm_dhcp_client_get_pid() can return -1, if no PID is set. This must be handled. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/726 Fixes:a2abd15fe0('DHCP: Support dhcpcd-9.x') (cherry picked from commit80ced3f1fb)
This commit is contained in:
parent
7751177474
commit
6c0e7922c2
1 changed files with 21 additions and 19 deletions
|
|
@ -169,27 +169,29 @@ stop(NMDhcpClient *client, gboolean release)
|
|||
int sig, errsv;
|
||||
|
||||
pid = nm_dhcp_client_get_pid(client);
|
||||
sig = release ? SIGALRM : SIGTERM;
|
||||
_LOGD("sending %s to dhcpcd pid %d", sig == SIGALRM ? "SIGALRM" : "SIGTERM", pid);
|
||||
if (pid > 1) {
|
||||
sig = release ? SIGALRM : SIGTERM;
|
||||
_LOGD("sending %s to dhcpcd pid %d", sig == SIGALRM ? "SIGALRM" : "SIGTERM", pid);
|
||||
|
||||
/* dhcpcd-9.x features privilege separation.
|
||||
* It's not our job to track all these processes so we rely on dhcpcd
|
||||
* to always cleanup after itself.
|
||||
* Because it also re-parents itself to PID 1, the process cannot be
|
||||
* reaped or waited for.
|
||||
* As such, just send the correct signal.
|
||||
*/
|
||||
if (kill(pid, sig) == -1) {
|
||||
errsv = errno;
|
||||
_LOGE("failed to kill dhcpcd %d:%s", errsv, strerror(errsv));
|
||||
/* dhcpcd-9.x features privilege separation.
|
||||
* It's not our job to track all these processes so we rely on dhcpcd
|
||||
* to always cleanup after itself.
|
||||
* Because it also re-parents itself to PID 1, the process cannot be
|
||||
* reaped or waited for.
|
||||
* As such, just send the correct signal.
|
||||
*/
|
||||
if (kill(pid, sig) == -1) {
|
||||
errsv = errno;
|
||||
_LOGE("failed to kill dhcpcd %d:%s", errsv, strerror(errsv));
|
||||
}
|
||||
|
||||
/* When this function exits NM expects the PID to be -1.
|
||||
* This means we also need to stop watching the pid.
|
||||
* If we need to know the exit status then we need to refactor NM
|
||||
* to allow a non -1 to mean we're waiting to exit still.
|
||||
*/
|
||||
nm_dhcp_client_stop_watch_child(client, pid);
|
||||
}
|
||||
|
||||
/* When this function exits NM expects the PID to be -1.
|
||||
* This means we also need to stop watching the pid.
|
||||
* If we need to know the exit status then we need to refactor NM
|
||||
* to allow a non -1 to mean we're waiting to exit still.
|
||||
*/
|
||||
nm_dhcp_client_stop_watch_child(client, pid);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue