diff options
author | Thomas Haller <thaller@redhat.com> | 2018-10-12 15:13:20 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-10-15 08:23:32 +0200 |
commit | 159978390bb2643b6052bfd5aa9c5e6b8879d664 (patch) | |
tree | 16316f7ae455d534f270b18e8f8fbe3399e14d39 | |
parent | a1a80b2e6de6136db69ef85fb8e4caff2ff3fbef (diff) | |
download | NetworkManager-159978390bb2643b6052bfd5aa9c5e6b8879d664.tar.gz |
ppp: make ppp-manager cancellable via GCancellable
Previously nm_ppp_manager_stop() would return a handle which
makes it easy to cancel the operation.
However, sometimes, we may want to cancel an operation based on
an GCancellable. So, extend nm_ppp_manager_stop() to hook it
with a cancellable.
Essentially, move the code from nm-modem.c to nm-ppp-manager-call.c,
where it belongs and where the functionality gets available to every
component.
-rw-r--r-- | src/devices/adsl/nm-device-adsl.c | 2 | ||||
-rw-r--r-- | src/devices/nm-device-ethernet.c | 2 | ||||
-rw-r--r-- | src/devices/nm-device-ppp.c | 2 | ||||
-rw-r--r-- | src/devices/wwan/nm-modem.c | 42 | ||||
-rw-r--r-- | src/ppp/nm-ppp-manager-call.c | 3 | ||||
-rw-r--r-- | src/ppp/nm-ppp-manager-call.h | 1 | ||||
-rw-r--r-- | src/ppp/nm-ppp-manager.c | 39 | ||||
-rw-r--r-- | src/ppp/nm-ppp-plugin-api.h | 1 |
8 files changed, 49 insertions, 43 deletions
diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index c9984f5135..9cec81920f 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -523,7 +523,7 @@ adsl_cleanup (NMDeviceAdsl *self) if (priv->ppp_manager) { g_signal_handlers_disconnect_by_func (priv->ppp_manager, G_CALLBACK (ppp_state_changed), self); g_signal_handlers_disconnect_by_func (priv->ppp_manager, G_CALLBACK (ppp_ip4_config), self); - nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL); + nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL, NULL); g_clear_object (&priv->ppp_manager); } diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 0fb8fea42c..1587a2a343 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1347,7 +1347,7 @@ deactivate (NMDevice *device) nm_clear_g_source (&priv->pppoe_wait_id); if (priv->ppp_manager) { - nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL); + nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL, NULL); g_clear_object (&priv->ppp_manager); } diff --git a/src/devices/nm-device-ppp.c b/src/devices/nm-device-ppp.c index 74b4d710ca..3a3f9054a1 100644 --- a/src/devices/nm-device-ppp.c +++ b/src/devices/nm-device-ppp.c @@ -221,7 +221,7 @@ deactivate (NMDevice *device) NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self); if (priv->ppp_manager) { - nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL); + nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL, NULL); g_clear_object (&priv->ppp_manager); } } diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index e9ec181ddc..3d8dee83dd 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1126,7 +1126,7 @@ deactivate_cleanup (NMModem *self, NMDevice *device) if (priv->ppp_manager) { g_signal_handlers_disconnect_by_data (priv->ppp_manager, self); - nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL); + nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL, NULL); g_clear_object (&priv->ppp_manager); } @@ -1173,19 +1173,11 @@ typedef struct { gpointer callback_user_data; DeactivateContextStep step; NMPPPManager *ppp_manager; - NMPPPManagerStopHandle *ppp_stop_handle; - gulong ppp_stop_cancellable_id; } DeactivateContext; static void deactivate_context_complete (DeactivateContext *ctx, GError *error) { - if (ctx->ppp_stop_handle) - nm_ppp_manager_stop_cancel (ctx->ppp_stop_handle); - - nm_assert (!ctx->ppp_stop_handle); - nm_assert (ctx->ppp_stop_cancellable_id == 0); - if (ctx->callback) ctx->callback (ctx->self, error, ctx->callback_user_data); nm_g_object_unref (ctx->ppp_manager); @@ -1221,14 +1213,6 @@ ppp_manager_stop_ready (NMPPPManager *ppp_manager, { DeactivateContext *ctx = user_data; - nm_assert (ctx->ppp_stop_handle == handle); - ctx->ppp_stop_handle = NULL; - - if (ctx->ppp_stop_cancellable_id) { - g_cancellable_disconnect (ctx->cancellable, - nm_steal_int (&ctx->ppp_stop_cancellable_id)); - } - if (was_cancelled) return; @@ -1237,15 +1221,6 @@ ppp_manager_stop_ready (NMPPPManager *ppp_manager, } static void -ppp_manager_stop_cancelled (GCancellable *cancellable, - gpointer user_data) -{ - DeactivateContext *ctx = user_data; - - nm_ppp_manager_stop_cancel (ctx->ppp_stop_handle); -} - -static void deactivate_step (DeactivateContext *ctx) { NMModem *self = ctx->self; @@ -1274,17 +1249,10 @@ deactivate_step (DeactivateContext *ctx) case DEACTIVATE_CONTEXT_STEP_PPP_MANAGER_STOP: /* If we have a PPP manager, stop it */ if (ctx->ppp_manager) { - nm_assert (!ctx->ppp_stop_handle); - if (ctx->cancellable) { - ctx->ppp_stop_cancellable_id = g_cancellable_connect (ctx->cancellable, - G_CALLBACK (ppp_manager_stop_cancelled), - ctx, - NULL); - } - ctx->ppp_stop_handle = nm_ppp_manager_stop (ctx->ppp_manager, - ppp_manager_stop_ready, - ctx); - return; + nm_ppp_manager_stop (ctx->ppp_manager, + ctx->cancellable, + ppp_manager_stop_ready, + ctx); } ctx->step++; /* fall through */ diff --git a/src/ppp/nm-ppp-manager-call.c b/src/ppp/nm-ppp-manager-call.c index 3d6fee49a0..8f6584167a 100644 --- a/src/ppp/nm-ppp-manager-call.c +++ b/src/ppp/nm-ppp-manager-call.c @@ -126,12 +126,13 @@ nm_ppp_manager_start (NMPPPManager *self, NMPPPManagerStopHandle * nm_ppp_manager_stop (NMPPPManager *self, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data) { g_return_val_if_fail (ppp_ops, NULL); - return ppp_ops->stop (self, callback, user_data); + return ppp_ops->stop (self, cancellable, callback, user_data); } void diff --git a/src/ppp/nm-ppp-manager-call.h b/src/ppp/nm-ppp-manager-call.h index daf8a82e68..a93ed11fc0 100644 --- a/src/ppp/nm-ppp-manager-call.h +++ b/src/ppp/nm-ppp-manager-call.h @@ -40,6 +40,7 @@ gboolean nm_ppp_manager_start (NMPPPManager *self, GError **error); NMPPPManagerStopHandle *nm_ppp_manager_stop (NMPPPManager *self, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data); diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index b231ff2059..1595961f45 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -137,9 +137,12 @@ G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, NM_TYPE_DBUS_OBJECT) static void _ppp_cleanup (NMPPPManager *self); static NMPPPManagerStopHandle *_ppp_manager_stop (NMPPPManager *self, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data); +static void _ppp_manager_stop_cancel (NMPPPManagerStopHandle *handle); + /*****************************************************************************/ static void @@ -791,7 +794,7 @@ pppd_timed_out (gpointer data) NMPPPManager *self = NM_PPP_MANAGER (data); _LOGW ("pppd timed out or didn't initialize our dbus module"); - _ppp_manager_stop (self, NULL, NULL); + _ppp_manager_stop (self, NULL, NULL, NULL); g_signal_emit (self, signals[STATE_CHANGED], 0, (guint) NM_PPP_STATUS_DEAD); @@ -1170,6 +1173,10 @@ struct _NMPPPManagerStopHandle { * pppd process terminated. */ GObject *shutdown_waitobj; + GCancellable *cancellable; + + gulong cancellable_id; + guint idle_id; }; @@ -1179,6 +1186,13 @@ _stop_handle_complete (NMPPPManagerStopHandle *handle, gboolean was_cancelled) gs_unref_object NMPPPManager *self = NULL; NMPPPManagerStopCallback callback; + if (handle->cancellable_id) { + g_cancellable_disconnect (handle->cancellable, + nm_steal_int (&handle->cancellable_id)); + } + + g_clear_object (&handle->cancellable); + self = g_steal_pointer (&handle->self); if (!self) return; @@ -1219,8 +1233,20 @@ _stop_idle_cb (gpointer user_data) return G_SOURCE_REMOVE; } +static void +_stop_cancelled_cb (GCancellable *cancellable, + gpointer user_data) +{ + NMPPPManagerStopHandle *handle = user_data; + + nm_clear_g_signal_handler (handle->cancellable, + &handle->cancellable_id); + _ppp_manager_stop_cancel (handle); +} + static NMPPPManagerStopHandle * _ppp_manager_stop (NMPPPManager *self, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data) { @@ -1246,6 +1272,13 @@ _ppp_manager_stop (NMPPPManager *self, handle->self = g_object_ref (self); handle->callback = callback; handle->user_data = user_data; + if (cancellable) { + handle->cancellable = g_object_ref (cancellable); + handle->cancellable_id = g_cancellable_connect (cancellable, + G_CALLBACK (_stop_cancelled_cb), + handle, + NULL); + } if (!priv->pid) { /* No PID. There is nothing to kill, however, invoke the callback in @@ -1272,6 +1305,8 @@ _ppp_manager_stop (NMPPPManager *self, return handle; } +/*****************************************************************************/ + static void _ppp_manager_stop_cancel (NMPPPManagerStopHandle *handle) { @@ -1360,7 +1395,7 @@ dispose (GObject *object) * still stop. */ g_warn_if_fail (!priv->pid); g_warn_if_fail (!nm_dbus_object_is_exported (NM_DBUS_OBJECT (self))); - _ppp_manager_stop (self, NULL, NULL); + _ppp_manager_stop (self, NULL, NULL, NULL); g_clear_object (&priv->act_req); diff --git a/src/ppp/nm-ppp-plugin-api.h b/src/ppp/nm-ppp-plugin-api.h index 558de2c2c2..95ddd21191 100644 --- a/src/ppp/nm-ppp-plugin-api.h +++ b/src/ppp/nm-ppp-plugin-api.h @@ -40,6 +40,7 @@ typedef const struct { GError **err); NMPPPManagerStopHandle *(*stop) (NMPPPManager *manager, + GCancellable *cancellable, NMPPPManagerStopCallback callback, gpointer user_data); |