shell: Refactor internal calls to systemd service
Add some parameters to make these calls useful beyond starting and stopping units. We will need to query the existence of units for starters. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2171>
This commit is contained in:
parent
4b56acb775
commit
adc58ea743
@ -516,9 +516,15 @@ shell_util_get_uid (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SYSTEMD
|
#ifdef HAVE_SYSTEMD
|
||||||
|
typedef enum {
|
||||||
|
SYSTEMD_CALL_FLAGS_NONE = 0,
|
||||||
|
SYSTEMD_CALL_FLAGS_WATCH_JOB = 1 << 0,
|
||||||
|
} SystemdFlags;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GDBusConnection *connection;
|
GDBusConnection *connection;
|
||||||
gchar *command;
|
gchar *command;
|
||||||
|
SystemdFlags flags;
|
||||||
|
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
gulong cancel_id;
|
gulong cancel_id;
|
||||||
@ -593,7 +599,10 @@ on_systemd_call_cb (GObject *source,
|
|||||||
g_assert (data->job == NULL);
|
g_assert (data->job == NULL);
|
||||||
g_variant_get (reply, "(o)", &data->job);
|
g_variant_get (reply, "(o)", &data->job);
|
||||||
|
|
||||||
/* And we wait for the JobRemoved notification. */
|
/* we should either wait for the JobRemoved notification, or
|
||||||
|
* notify here */
|
||||||
|
if ((data->flags & SYSTEMD_CALL_FLAGS_WATCH_JOB) == 0)
|
||||||
|
g_task_return_boolean (task, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -642,8 +651,8 @@ on_systemd_job_removed_cb (GDBusConnection *connection,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
shell_util_systemd_call (const char *command,
|
shell_util_systemd_call (const char *command,
|
||||||
const char *unit,
|
GVariant *params,
|
||||||
const char *mode,
|
SystemdFlags flags,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
@ -690,6 +699,10 @@ shell_util_systemd_call (const char *command,
|
|||||||
data = g_new0 (SystemdCall, 1);
|
data = g_new0 (SystemdCall, 1);
|
||||||
data->command = g_strdup (command);
|
data->command = g_strdup (command);
|
||||||
data->connection = g_object_ref (connection);
|
data->connection = g_object_ref (connection);
|
||||||
|
data->flags = flags;
|
||||||
|
|
||||||
|
if ((data->flags & SYSTEMD_CALL_FLAGS_WATCH_JOB) != 0)
|
||||||
|
{
|
||||||
data->job_watch = g_dbus_connection_signal_subscribe (connection,
|
data->job_watch = g_dbus_connection_signal_subscribe (connection,
|
||||||
"org.freedesktop.systemd1",
|
"org.freedesktop.systemd1",
|
||||||
"org.freedesktop.systemd1.Manager",
|
"org.freedesktop.systemd1.Manager",
|
||||||
@ -700,6 +713,8 @@ shell_util_systemd_call (const char *command,
|
|||||||
on_systemd_job_removed_cb,
|
on_systemd_job_removed_cb,
|
||||||
task,
|
task,
|
||||||
NULL);
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
g_task_set_task_data (task,
|
g_task_set_task_data (task,
|
||||||
data,
|
data,
|
||||||
(GDestroyNotify) shell_util_systemd_call_data_free);
|
(GDestroyNotify) shell_util_systemd_call_data_free);
|
||||||
@ -718,8 +733,7 @@ shell_util_systemd_call (const char *command,
|
|||||||
"/org/freedesktop/systemd1",
|
"/org/freedesktop/systemd1",
|
||||||
"org.freedesktop.systemd1.Manager",
|
"org.freedesktop.systemd1.Manager",
|
||||||
command,
|
command,
|
||||||
g_variant_new ("(ss)",
|
params,
|
||||||
unit, mode),
|
|
||||||
G_VARIANT_TYPE ("(o)"),
|
G_VARIANT_TYPE ("(o)"),
|
||||||
G_DBUS_CALL_FLAGS_NONE,
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
-1, cancellable,
|
-1, cancellable,
|
||||||
@ -740,7 +754,9 @@ shell_util_start_systemd_unit (const char *unit,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
shell_util_systemd_call ("StartUnit", unit, mode,
|
shell_util_systemd_call ("StartUnit",
|
||||||
|
g_variant_new ("(ss)", unit, mode),
|
||||||
|
SYSTEMD_CALL_FLAGS_WATCH_JOB,
|
||||||
cancellable, callback, user_data);
|
cancellable, callback, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -758,7 +774,9 @@ shell_util_stop_systemd_unit (const char *unit,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
shell_util_systemd_call ("StopUnit", unit, mode,
|
shell_util_systemd_call ("StopUnit",
|
||||||
|
g_variant_new ("(ss)", unit, mode),
|
||||||
|
SYSTEMD_CALL_FLAGS_WATCH_JOB,
|
||||||
cancellable, callback, user_data);
|
cancellable, callback, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user