mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 07:08:02 +02:00
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.
This commit is contained in:
parent
f09e7797d4
commit
515663519f
1 changed files with 25 additions and 24 deletions
|
|
@ -135,7 +135,9 @@ G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, NM_TYPE_DBUS_OBJECT)
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void _ppp_cleanup (NMPPPManager *manager);
|
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");
|
_LOGW ("pppd timed out or didn't initialize our dbus module");
|
||||||
_ppp_cleanup (manager);
|
_ppp_cleanup (manager);
|
||||||
_ppp_kill (manager);
|
_ppp_kill (manager, NULL, NULL);
|
||||||
|
|
||||||
g_signal_emit (manager, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD);
|
g_signal_emit (manager, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD);
|
||||||
|
|
||||||
|
|
@ -1121,19 +1123,23 @@ out:
|
||||||
return priv->pid > 0;
|
return priv->pid > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static gboolean
|
||||||
_ppp_kill (NMPPPManager *manager)
|
_ppp_kill (NMPPPManager *manager,
|
||||||
|
NMUtilsKillChildAsyncCb callback,
|
||||||
|
void *user_data)
|
||||||
{
|
{
|
||||||
NMPPPManagerPrivate *priv;
|
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
|
||||||
|
|
||||||
g_return_if_fail (NM_IS_PPP_MANAGER (manager));
|
if (!priv->pid) {
|
||||||
|
/* not PID. Signal that there was nothing to kill, which consequently
|
||||||
priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
|
* implies that the callback will not be invoked. */
|
||||||
|
return FALSE;
|
||||||
if (priv->pid) {
|
|
||||||
nm_utils_kill_child_async (priv->pid, SIGTERM, LOGD_PPP, "pppd", 2000, NULL, NULL);
|
|
||||||
priv->pid = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nm_utils_kill_child_async (nm_steal_int (&priv->pid),
|
||||||
|
SIGTERM, LOGD_PPP, "pppd", 2000,
|
||||||
|
callback, user_data);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -1204,8 +1210,10 @@ static void
|
||||||
kill_child_ready (pid_t pid,
|
kill_child_ready (pid_t pid,
|
||||||
gboolean success,
|
gboolean success,
|
||||||
int child_status,
|
int child_status,
|
||||||
StopContext *ctx)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
|
StopContext *ctx = user_data;
|
||||||
|
|
||||||
if (stop_context_complete_if_cancelled (ctx))
|
if (stop_context_complete_if_cancelled (ctx))
|
||||||
return;
|
return;
|
||||||
stop_context_complete (ctx);
|
stop_context_complete (ctx);
|
||||||
|
|
@ -1243,15 +1251,8 @@ _ppp_manager_stop_async (NMPPPManager *manager,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No cancellable operation, so just wait until it returns always */
|
if (!_ppp_kill (manager, kill_child_ready, ctx))
|
||||||
nm_utils_kill_child_async (priv->pid,
|
nm_assert_not_reached ();
|
||||||
SIGTERM,
|
|
||||||
LOGD_PPP,
|
|
||||||
"pppd",
|
|
||||||
2000,
|
|
||||||
(NMUtilsKillChildAsyncCb) kill_child_ready,
|
|
||||||
ctx);
|
|
||||||
priv->pid = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -1263,7 +1264,7 @@ _ppp_manager_stop_sync (NMPPPManager *manager)
|
||||||
nm_dbus_object_unexport (dbus);
|
nm_dbus_object_unexport (dbus);
|
||||||
|
|
||||||
_ppp_cleanup (manager);
|
_ppp_cleanup (manager);
|
||||||
_ppp_kill (manager);
|
_ppp_kill (manager, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
@ -1337,7 +1338,7 @@ dispose (GObject *object)
|
||||||
nm_dbus_object_unexport (dbus);
|
nm_dbus_object_unexport (dbus);
|
||||||
|
|
||||||
_ppp_cleanup (self);
|
_ppp_cleanup (self);
|
||||||
_ppp_kill (self);
|
_ppp_kill (self, NULL, NULL);
|
||||||
|
|
||||||
g_clear_object (&priv->act_req);
|
g_clear_object (&priv->act_req);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue