From f56c82d86122fc45304fc829b5f1e4766ed51589 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 Mar 2014 18:47:19 +0100 Subject: [PATCH] core/dhcp: reduce the wait time when killing dhcp client process We kill the dhcp process synchronously, so waiting for up to 3 seconds is really painful. Instead, give the client only 0.5 to terminate before sending SIGKILL. The proper solution would be to kill it asynchronously and dhcp manager making sure that it does not start a new instance before the old process was killed. Signed-off-by: Thomas Haller --- src/dhcp-manager/nm-dhcp-client.c | 10 +++++----- src/dhcp-manager/nm-dhcp-client.h | 2 +- src/dhcp-manager/nm-dhcp-dhclient.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c index 5b3b3f8ea6..3a056d3726 100644 --- a/src/dhcp-manager/nm-dhcp-client.c +++ b/src/dhcp-manager/nm-dhcp-client.c @@ -135,9 +135,9 @@ watch_cleanup (NMDHCPClient *self) } void -nm_dhcp_client_stop_pid (GPid pid, const char *iface, guint timeout_secs) +nm_dhcp_client_stop_pid (GPid pid, const char *iface) { - int i = (timeout_secs ? timeout_secs : 3) * 5; /* default 3 seconds */ + int i = 5; /* roughly 0.5 seconds */ g_return_if_fail (pid > 0); @@ -164,7 +164,7 @@ nm_dhcp_client_stop_pid (GPid pid, const char *iface, guint timeout_secs) break; } } - g_usleep (G_USEC_PER_SEC / 5); + g_usleep (G_USEC_PER_SEC / 10); } if (i <= 0) { @@ -193,7 +193,7 @@ stop (NMDHCPClient *self, gboolean release, const GByteArray *duid) /* Clean up the watch handler since we're explicitly killing the daemon */ watch_cleanup (self); - nm_dhcp_client_stop_pid (priv->pid, priv->iface, 0); + nm_dhcp_client_stop_pid (priv->pid, priv->iface); priv->info_only = FALSE; } @@ -518,7 +518,7 @@ nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name) exe = proc_contents; if (!strcmp (exe, binary_name)) - nm_dhcp_client_stop_pid ((GPid) tmp, NULL, 0); + nm_dhcp_client_stop_pid ((GPid) tmp, NULL); } } diff --git a/src/dhcp-manager/nm-dhcp-client.h b/src/dhcp-manager/nm-dhcp-client.h index 930ec1a5e5..5cc1e39026 100644 --- a/src/dhcp-manager/nm-dhcp-client.h +++ b/src/dhcp-manager/nm-dhcp-client.h @@ -148,7 +148,7 @@ NMIP6Config *nm_dhcp_client_get_ip6_config (NMDHCPClient *self, gboolean test) /* Backend helpers */ void nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name); -void nm_dhcp_client_stop_pid (GPid pid, const char *iface, guint timeout_secs); +void nm_dhcp_client_stop_pid (GPid pid, const char *iface); #endif /* NM_DHCP_CLIENT_H */ diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c index d9ecdd9b74..d3677406c8 100644 --- a/src/dhcp-manager/nm-dhcp-dhclient.c +++ b/src/dhcp-manager/nm-dhcp-dhclient.c @@ -541,7 +541,7 @@ stop (NMDHCPClient *client, gboolean release, const GByteArray *duid) rpid = dhclient_start (client, NULL, duid, TRUE); if (rpid > 0) { /* Wait a few seconds for the release to happen */ - nm_dhcp_client_stop_pid (rpid, nm_dhcp_client_get_iface (client), 5); + nm_dhcp_client_stop_pid (rpid, nm_dhcp_client_get_iface (client)); } } }