summaryrefslogtreecommitdiffstats
path: root/source/n/NetworkManager/patches/dhcpcd.graceful.exit.patch
blob: 6abc3e4684f20d47af254bdc8793c320077ba9fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--- ./src/core/dhcp/nm-dhcp-client.h.orig	2024-02-22 00:44:13.335158315 -0600
+++ ./src/core/dhcp/nm-dhcp-client.h	2024-02-22 19:41:56.134066083 -0600
@@ -249,7 +249,7 @@
 /* Backend helpers for subclasses */
 void nm_dhcp_client_stop_existing(const char *pid_file, const char *binary_name);
 
-void nm_dhcp_client_stop_pid(pid_t pid, const char *iface);
+void nm_dhcp_client_stop_pid(pid_t pid, const char *iface, int sig);
 
 void nm_dhcp_client_start_timeout(NMDhcpClient *self);
 
--- ./src/core/dhcp/nm-dhcp-dhcpcd.c.orig	2024-02-22 19:41:56.134066083 -0600
+++ ./src/core/dhcp/nm-dhcp-dhcpcd.c	2024-02-22 19:47:18.556073296 -0600
@@ -158,31 +158,17 @@
 {
     NMDhcpDhcpcd *self = NM_DHCP_DHCPCD(client);
     pid_t         pid;
-    int           sig, errsv;
+    int           sig;
 
     pid = nm_dhcp_client_get_pid(client);
     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, nm_strerror_native(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.
-         */
+        /* We need to remove the watch before stopping the process */
         nm_dhcp_client_stop_watch_child(client, pid);
+
+        nm_dhcp_client_stop_pid(pid, nm_dhcp_client_get_iface(client), sig);
     }
 }
 
--- ./src/core/dhcp/nm-dhcp-dhclient.c.orig	2024-02-22 00:44:13.335158315 -0600
+++ ./src/core/dhcp/nm-dhcp-dhclient.c	2024-02-22 19:41:56.134066083 -0600
@@ -622,7 +622,7 @@
 
         if (dhclient_start(client, FALSE, TRUE, FALSE, &rpid, NULL)) {
             /* Wait a few seconds for the release to happen */
-            nm_dhcp_client_stop_pid(rpid, nm_dhcp_client_get_iface(client));
+            nm_dhcp_client_stop_pid(rpid, nm_dhcp_client_get_iface(client), SIGTERM);
         }
     }
 }
--- ./src/core/dhcp/nm-dhcp-client.c.orig	2024-02-22 00:44:13.334158313 -0600
+++ ./src/core/dhcp/nm-dhcp-client.c	2024-02-22 19:41:56.134066083 -0600
@@ -367,14 +367,14 @@
 }
 
 void
-nm_dhcp_client_stop_pid(pid_t pid, const char *iface)
+nm_dhcp_client_stop_pid(pid_t pid, const char *iface, int sig)
 {
     char *name = iface ? g_strdup_printf("dhcp-client-%s", iface) : NULL;
 
     g_return_if_fail(pid > 1);
 
     nm_utils_kill_child_sync(pid,
-                             SIGTERM,
+                             sig,
                              LOGD_DHCP,
                              name ?: "dhcp-client",
                              NULL,
@@ -395,7 +395,7 @@
     if (priv->pid > 0) {
         /* Clean up the watch handler since we're explicitly killing the daemon */
         watch_cleanup(self);
-        nm_dhcp_client_stop_pid(priv->pid, priv->config.iface);
+        nm_dhcp_client_stop_pid(priv->pid, priv->config.iface, SIGTERM);
     }
     priv->pid = -1;
 }