From 65d53383845ed85b91b379a37e2a51a75af049ef Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 27 Jul 2008 19:42:54 +0000 Subject: [PATCH] 2008-07-27 Dan Williams * src/dnsmasq-manager/nm-dnsmasq-manager.c src/nm-device.c src/ppp-manager/nm-ppp-manager.c - Ensure child process gets reaped. The child watch function may be removed from the mainloop before the child gets killed, so we have to make sure the child is reaped when it's told to die intentionally git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3857 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 9 +++++++++ src/dnsmasq-manager/nm-dnsmasq-manager.c | 12 ++++++------ src/nm-device.c | 12 +++++++----- src/ppp-manager/nm-ppp-manager.c | 16 ++++++++-------- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f3a3c762c..7bd2ed1239 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-07-27 Dan Williams + + * src/dnsmasq-manager/nm-dnsmasq-manager.c + src/nm-device.c + src/ppp-manager/nm-ppp-manager.c + - Ensure child process gets reaped. The child watch function may be + removed from the mainloop before the child gets killed, so we have + to make sure the child is reaped when it's told to die intentionally + 2008-07-27 Dan Williams Patch from Roy Marples diff --git a/src/dnsmasq-manager/nm-dnsmasq-manager.c b/src/dnsmasq-manager/nm-dnsmasq-manager.c index bb69d114b4..e064a7e6c7 100644 --- a/src/dnsmasq-manager/nm-dnsmasq-manager.c +++ b/src/dnsmasq-manager/nm-dnsmasq-manager.c @@ -357,7 +357,6 @@ nm_dnsmasq_manager_start (NMDnsMasqManager *manager, NMDnsMasqManagerPrivate *priv; NMCmdLine *dm_cmd; char *cmd_str; - GSource *dm_watch; g_return_val_if_fail (NM_IS_DNSMASQ_MANAGER (manager), FALSE); if (error) @@ -389,11 +388,7 @@ nm_dnsmasq_manager_start (NMDnsMasqManager *manager, nm_debug ("dnsmasq started with pid %d", priv->pid); - dm_watch = g_child_watch_source_new (priv->pid); - g_source_set_callback (dm_watch, (GSourceFunc) dm_watch_cb, manager, NULL); - g_source_attach (dm_watch, NULL); - priv->dm_watch_id = g_source_get_id (dm_watch); - g_source_unref (dm_watch); + priv->dm_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) dm_watch_cb, manager); out: if (dm_cmd) @@ -410,6 +405,9 @@ ensure_killed (gpointer data) if (kill (pid, 0) == 0) kill (pid, SIGKILL); + /* ensure child is reaped */ + waitpid (pid, NULL, WNOHANG); + return FALSE; } @@ -433,6 +431,8 @@ nm_dnsmasq_manager_stop (NMDnsMasqManager *manager) else kill (priv->pid, SIGKILL); + /* ensure child is reaped */ + waitpid (priv->pid, NULL, WNOHANG); priv->pid = 0; } diff --git a/src/nm-device.c b/src/nm-device.c index 049bf6b0bd..ea0910c539 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -551,16 +551,18 @@ aipd_cleanup (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - if (priv->aipd_pid > 0) { - kill (priv->aipd_pid, SIGKILL); - priv->aipd_pid = -1; - } - if (priv->aipd_watch) { g_source_remove (priv->aipd_watch); priv->aipd_watch = 0; } + if (priv->aipd_pid > 0) { + kill (priv->aipd_pid, SIGKILL); + /* Ensure child is reaped */ + waitpid (priv->aipd_pid, NULL, WNOHANG); + priv->aipd_pid = -1; + } + aipd_timeout_remove (self); priv->aipd_addr = 0; diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index b3cf53c2b4..7a9881235a 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -737,7 +737,6 @@ nm_ppp_manager_start (NMPPPManager *manager, NMSettingPPPOE *pppoe_setting; NMCmdLine *ppp_cmd; char *cmd_str; - GSource *ppp_watch; g_return_val_if_fail (NM_IS_PPP_MANAGER (manager), FALSE); g_return_val_if_fail (device != NULL, FALSE); @@ -775,12 +774,7 @@ nm_ppp_manager_start (NMPPPManager *manager, nm_debug ("ppp started with pid %d", priv->pid); - ppp_watch = g_child_watch_source_new (priv->pid); - g_source_set_callback (ppp_watch, (GSourceFunc) ppp_watch_cb, manager, NULL); - g_source_attach (ppp_watch, NULL); - priv->ppp_watch_id = g_source_get_id (ppp_watch); - g_source_unref (ppp_watch); - + priv->ppp_watch_id = g_child_watch_add (priv->pid, (GChildWatchFunc) ppp_watch_cb, manager); priv->ppp_timeout_handler = g_timeout_add (NM_PPP_WAIT_PPPD, pppd_timed_out, manager); priv->act_req = g_object_ref (req); @@ -842,6 +836,9 @@ ensure_killed (gpointer data) if (kill (pid, 0) == 0) kill (pid, SIGKILL); + /* ensure the child is reaped */ + waitpid (pid, NULL, WNOHANG); + return FALSE; } @@ -881,8 +878,11 @@ nm_ppp_manager_stop (NMPPPManager *manager) if (priv->pid) { if (kill (priv->pid, SIGTERM) == 0) g_timeout_add (2000, ensure_killed, GINT_TO_POINTER (priv->pid)); - else + else { kill (priv->pid, SIGKILL); + /* ensure the child is reaped */ + waitpid (priv->pid, NULL, WNOHANG); + } priv->pid = 0; }