[gnome-shell/wip/carlosg/check-systemd: 19/19] shell: Check we are in a systemd environment before starting systemd units
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/carlosg/check-systemd: 19/19] shell: Check we are in a systemd environment before starting systemd units
- Date: Wed, 6 May 2020 09:08:37 +0000 (UTC)
commit 8c6ea9bfff37e62485a0969464e313767dd448ca
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed May 6 10:57:54 2020 +0200
shell: Check we are in a systemd environment before starting systemd units
Avoid starting/stopping the gsd-xsettings systemd unit if the shell itself
was not started via systemd. In the lack of a user session manager, we
have no means to neatly start/stop services, so should rely on the good
ol' gnome-session to do this for us.
Fixes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2755
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1238
src/shell-util.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
---
diff --git a/src/shell-util.c b/src/shell-util.c
index bb2329536b..4690dbd5cd 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -31,6 +31,7 @@
#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
#else
/* So we don't need to add ifdef's everywhere */
#define sd_notify(u, m) do {} while (0)
@@ -673,7 +674,27 @@ shell_util_systemd_call (const char *command,
const char *mode,
GError **error)
{
+#ifdef HAVE_SYSTEMD
g_autoptr (GDBusConnection) connection = NULL;
+ g_autofree char *self_unit = NULL;
+ int res;
+
+ res = sd_pid_get_user_unit (getpid (), &self_unit);
+
+ if (res == -ENODATA)
+ {
+ g_debug ("Not systemd-managed, not starting '%s'", unit);
+ return TRUE;
+ }
+ else if (res < 0)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ g_io_error_from_errno (-res),
+ "Error trying to start systemd unit '%s': %s",
+ unit, g_strerror (-res));
+ return FALSE;
+ }
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
@@ -692,6 +713,8 @@ shell_util_systemd_call (const char *command,
-1, NULL,
on_systemd_call_cb,
(gpointer) command);
+#endif /* HAVE_SYSTEMD */
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]