From c8cf02e6b847ef42b3471e1dd3222019c3e44cc2 Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Tue, 6 Feb 2024 01:04:00 +0100 Subject: [PATCH] manager: abstract code from do_sleep_wake() to reuse it The code that is adding the devices to the sleeping list and taking them down should be moved to a separated function. This way we can reuse it and we avoid duplicating code. --- src/core/nm-manager.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index 072c4262aa..45859488db 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -7215,6 +7215,29 @@ device_sleep_cb(NMDevice *device, GParamSpec *pspec, NMManager *self) } } +static void +_handle_device_takedown(NMManager *self, NMDevice *device, gboolean suspending) +{ + nm_device_notify_sleeping(device); + + if (nm_device_is_activating(device) + || nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) { + _LOGD(LOGD_SUSPEND, + "sleep: wait disconnection of device %s", + nm_device_get_ip_iface(device)); + + if (sleep_devices_add(self, device, suspending)) + nm_device_queue_state(device, + NM_DEVICE_STATE_DEACTIVATING, + NM_DEVICE_STATE_REASON_SLEEPING); + } else { + nm_device_set_unmanaged_by_flags(device, + NM_UNMANAGED_SLEEPING, + NM_UNMAN_FLAG_OP_SET_UNMANAGED, + NM_DEVICE_STATE_REASON_SLEEPING); + } +} + static void do_sleep_wake(NMManager *self, gboolean sleeping_changed) { @@ -7249,24 +7272,7 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) continue; } - nm_device_notify_sleeping(device); - - if (nm_device_is_activating(device) - || nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) { - _LOGD(LOGD_SUSPEND, - "sleep: wait disconnection of device %s", - nm_device_get_ip_iface(device)); - - if (sleep_devices_add(self, device, suspending)) - nm_device_queue_state(device, - NM_DEVICE_STATE_DEACTIVATING, - NM_DEVICE_STATE_REASON_SLEEPING); - } else { - nm_device_set_unmanaged_by_flags(device, - NM_UNMANAGED_SLEEPING, - NM_UNMAN_FLAG_OP_SET_UNMANAGED, - NM_DEVICE_STATE_REASON_SLEEPING); - } + _handle_device_takedown(self, device, suspending); } } else { _LOGD(LOGD_SUSPEND, "sleep: %s...", waking_from_suspend ? "waking up" : "re-enabling");