diff --git a/src/fu-tool.c b/src/fu-tool.c index 73f538cd4..5508c12b0 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -28,11 +28,6 @@ #include "fwupd-common-private.h" #include "fwupd-device-private.h" -#define SYSTEMD_SERVICE "org.freedesktop.systemd1" -#define SYSTEMD_OBJECT_PATH "/org/freedesktop/systemd1" -#define SYSTEMD_MANAGER_INTERFACE "org.freedesktop.systemd1.Manager" -#define SYSTEMD_FWUPD_UNIT "fwupd.service" - /* custom return code */ #define EXIT_NOTHING_TO_DO 2 @@ -62,56 +57,6 @@ struct FuUtilPrivate { FwupdDeviceFlags completion_flags; }; -static gboolean -fu_util_stop_daemon (GError **error) -{ - g_autoptr(GDBusConnection) connection = NULL; - g_autoptr(GDBusProxy) proxy = NULL; - g_autoptr(GVariant) val = NULL; - - /* try to stop any already running daemon */ - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); - if (connection == NULL) { - g_prefix_error (error, "failed to get bus: "); - return FALSE; - } - proxy = g_dbus_proxy_new_sync (connection, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - SYSTEMD_SERVICE, - SYSTEMD_OBJECT_PATH, - SYSTEMD_MANAGER_INTERFACE, - NULL, - error); - if (proxy == NULL) { - g_prefix_error (error, "failed to find %s: ", SYSTEMD_SERVICE); - return FALSE; - } - val = g_dbus_proxy_call_sync (proxy, - "GetUnit", - g_variant_new ("(s)", - SYSTEMD_FWUPD_UNIT), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - error); - if (val == NULL) { - g_prefix_error (error, "failed to find %s: ", SYSTEMD_FWUPD_UNIT); - return FALSE; - } - g_variant_unref (val); - val = g_dbus_proxy_call_sync (proxy, - "StopUnit", - g_variant_new ("(ss)", - SYSTEMD_FWUPD_UNIT, - "replace"), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - error); - return val != NULL; -} - static gboolean fu_util_save_current_state (FuUtilPrivate *priv, GError **error) { diff --git a/src/fu-util-common.c b/src/fu-util-common.c index f6d8f4f74..eac2235fd 100644 --- a/src/fu-util-common.c +++ b/src/fu-util-common.c @@ -13,6 +13,61 @@ #include "fu-util-common.h" #include "fu-device.h" +#define SYSTEMD_SERVICE "org.freedesktop.systemd1" +#define SYSTEMD_OBJECT_PATH "/org/freedesktop/systemd1" +#define SYSTEMD_MANAGER_INTERFACE "org.freedesktop.systemd1.Manager" +#define SYSTEMD_FWUPD_UNIT "fwupd.service" + +gboolean +fu_util_stop_daemon (GError **error) +{ + g_autoptr(GDBusConnection) connection = NULL; + g_autoptr(GDBusProxy) proxy = NULL; + g_autoptr(GVariant) val = NULL; + + /* try to stop any already running daemon */ + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); + if (connection == NULL) { + g_prefix_error (error, "failed to get bus: "); + return FALSE; + } + proxy = g_dbus_proxy_new_sync (connection, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + SYSTEMD_SERVICE, + SYSTEMD_OBJECT_PATH, + SYSTEMD_MANAGER_INTERFACE, + NULL, + error); + if (proxy == NULL) { + g_prefix_error (error, "failed to find %s: ", SYSTEMD_SERVICE); + return FALSE; + } + val = g_dbus_proxy_call_sync (proxy, + "GetUnit", + g_variant_new ("(s)", + SYSTEMD_FWUPD_UNIT), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + error); + if (val == NULL) { + g_prefix_error (error, "failed to find %s: ", SYSTEMD_FWUPD_UNIT); + return FALSE; + } + g_variant_unref (val); + val = g_dbus_proxy_call_sync (proxy, + "StopUnit", + g_variant_new ("(ss)", + SYSTEMD_FWUPD_UNIT, + "replace"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + error); + return val != NULL; +} + void fu_util_print_data (const gchar *title, const gchar *msg) { diff --git a/src/fu-util-common.h b/src/fu-util-common.h index cee74c9f9..8ad27c77f 100644 --- a/src/fu-util-common.h +++ b/src/fu-util-common.h @@ -58,4 +58,6 @@ gboolean fu_util_cmd_array_run (GPtrArray *array, GError **error); gchar *fu_util_release_get_name (FwupdRelease *release); +gboolean fu_util_stop_daemon (GError **error); + G_END_DECLS