diff options
author | Thomas Haller <thaller@redhat.com> | 2018-05-18 10:02:42 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-05-25 12:35:49 +0200 |
commit | 515663519fbefcc86b7965dacd59e2f1dd10a9ea (patch) | |
tree | d72c9db0b2be2635da019558324f70153eaa758f /src/ppp | |
parent | f09e7797d448f7fe5d9cee8c4e351ad5b3837770 (diff) | |
download | NetworkManager-515663519fbefcc86b7965dacd59e2f1dd10a9ea.tar.gz |
ppp-manager: refactor killing pppd process by using _ppp_kill() function
- add callback arguments to _ppp_kill(). Although most callers don't
care, it makes it more obvious that this kills the process
asynchronously.
- the call to nm_utils_kill_child_async() is complicated, with many
arguments. Only call it from one place, and re-use the simpler wrapper
function _ppp_kill() everywhere.
Diffstat (limited to 'src/ppp')
-rw-r--r-- | src/ppp/nm-ppp-manager.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index 7d1eb4089d..40fd8e1d87 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -135,7 +135,9 @@ G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, NM_TYPE_DBUS_OBJECT) /*****************************************************************************/ static void _ppp_cleanup (NMPPPManager *manager); -static void _ppp_kill (NMPPPManager *manager); +static gboolean _ppp_kill (NMPPPManager *manager, + NMUtilsKillChildAsyncCb callback, + void *user_data); /*****************************************************************************/ @@ -781,7 +783,7 @@ pppd_timed_out (gpointer data) _LOGW ("pppd timed out or didn't initialize our dbus module"); _ppp_cleanup (manager); - _ppp_kill (manager); + _ppp_kill (manager, NULL, NULL); g_signal_emit (manager, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD); @@ -1121,19 +1123,23 @@ out: return priv->pid > 0; } -static void -_ppp_kill (NMPPPManager *manager) +static gboolean +_ppp_kill (NMPPPManager *manager, + NMUtilsKillChildAsyncCb callback, + void *user_data) { - NMPPPManagerPrivate *priv; - - g_return_if_fail (NM_IS_PPP_MANAGER (manager)); - - priv = NM_PPP_MANAGER_GET_PRIVATE (manager); + NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); - if (priv->pid) { - nm_utils_kill_child_async (priv->pid, SIGTERM, LOGD_PPP, "pppd", 2000, NULL, NULL); - priv->pid = 0; + if (!priv->pid) { + /* not PID. Signal that there was nothing to kill, which consequently + * implies that the callback will not be invoked. */ + return FALSE; } + + nm_utils_kill_child_async (nm_steal_int (&priv->pid), + SIGTERM, LOGD_PPP, "pppd", 2000, + callback, user_data); + return TRUE; } static void @@ -1204,8 +1210,10 @@ static void kill_child_ready (pid_t pid, gboolean success, int child_status, - StopContext *ctx) + gpointer user_data) { + StopContext *ctx = user_data; + if (stop_context_complete_if_cancelled (ctx)) return; stop_context_complete (ctx); @@ -1243,15 +1251,8 @@ _ppp_manager_stop_async (NMPPPManager *manager, return; } - /* No cancellable operation, so just wait until it returns always */ - nm_utils_kill_child_async (priv->pid, - SIGTERM, - LOGD_PPP, - "pppd", - 2000, - (NMUtilsKillChildAsyncCb) kill_child_ready, - ctx); - priv->pid = 0; + if (!_ppp_kill (manager, kill_child_ready, ctx)) + nm_assert_not_reached (); } static void @@ -1263,7 +1264,7 @@ _ppp_manager_stop_sync (NMPPPManager *manager) nm_dbus_object_unexport (dbus); _ppp_cleanup (manager); - _ppp_kill (manager); + _ppp_kill (manager, NULL, NULL); } /*****************************************************************************/ @@ -1337,7 +1338,7 @@ dispose (GObject *object) nm_dbus_object_unexport (dbus); _ppp_cleanup (self); - _ppp_kill (self); + _ppp_kill (self, NULL, NULL); g_clear_object (&priv->act_req); |