Commit 86e37e61 authored by Martin Pitt's avatar Martin Pitt
Browse files

Handle multiple display managers which don't ship a systemd unit, part 1

Add a generator to ensure /etc/X11/default-display-manager is controlling which
display-manager is started.

Closes: #771287
parent 0885f4c2
......@@ -4,6 +4,10 @@ systemd (215-8) UNRELEASED; urgency=medium
the generator.
* Cherry-pick util-allow-strappenda-to-take-any-number-of-args.patch, we
will use that function in the generator.
* Handle multiple display managers which don't ship a systemd unit:
- Add a generator to ensure /etc/X11/default-display-manager is
controlling which display-manager is started.
- (Closes: #771287)
-- Didier Roche <didrocks@ubuntu.com> Fri, 28 Nov 2014 08:50:35 +0100
......
From: Didier Roche <didrocks@ubuntu.com>
Date: Thu, 27 Nov 2014 10:51:50 +0100
Subject: Prefer /etc/X11/default-display-manager if present
Add a generator to ensure /etc/X11/default-display-manager is controlling
which display-manager is started.
---
Makefile.am | 11 ++-
src/default-display-manager-generator/Makefile | 28 ++++++
.../default-display-manager-generator.c | 105 +++++++++++++++++++++
3 files changed, 143 insertions(+), 1 deletion(-)
create mode 100644 src/default-display-manager-generator/Makefile
create mode 100644 src/default-display-manager-generator/default-display-manager-generator.c
diff --git a/Makefile.am b/Makefile.am
index ec5b871..b607a4a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -402,7 +402,8 @@ systemgenerator_PROGRAMS = \
systemd-getty-generator \
systemd-fstab-generator \
systemd-system-update-generator \
- systemd-debug-generator
+ systemd-debug-generator \
+ systemd-default-display-manager-generator
dist_bashcompletion_DATA = \
shell-completion/bash/busctl \
@@ -2190,6 +2191,14 @@ systemd_delta_LDADD = \
libsystemd-shared.la
# ------------------------------------------------------------------------------
+systemd_default_display_manager_generator_SOURCES = \
+ src/default-display-manager-generator/default-display-manager-generator.c
+
+systemd_default_display_manager_generator_LDADD = \
+ libsystemd-label.la \
+ libsystemd-shared.la
+
+# ------------------------------------------------------------------------------
systemd_insserv_generator_SOURCES = \
src/insserv-generator/insserv-generator.c
diff --git a/src/default-display-manager-generator/Makefile b/src/default-display-manager-generator/Makefile
new file mode 100644
index 0000000..b29b937
--- /dev/null
+++ b/src/default-display-manager-generator/Makefile
@@ -0,0 +1,28 @@
+# This file is part of systemd.
+#
+# Copyright 2014 Canonical
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# systemd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+
+# This file is a dirty trick to simplify compilation from within
+# emacs. This file is not intended to be distributed. So, don't touch
+# it, even better ignore it!
+
+all:
+ $(MAKE) -C ..
+
+clean:
+ $(MAKE) -C .. clean
+
+.PHONY: all clean
diff --git a/src/default-display-manager-generator/default-display-manager-generator.c b/src/default-display-manager-generator/default-display-manager-generator.c
new file mode 100644
index 0000000..2fe9521
--- /dev/null
+++ b/src/default-display-manager-generator/default-display-manager-generator.c
@@ -0,0 +1,105 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Canonical
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <errno.h>
+#include <unistd.h>
+
+#include "fileio.h"
+#include "log.h"
+#include "mkdir.h"
+#include "util.h"
+
+
+/*
+ * Ensure that the started display-manager is matching
+ * /etc/X11/default-display-manager if present, otherwise
+ * let display-manager.service symlinks pick the preferred one
+ * if any.
+ */
+
+static const char *dm_service_unit = SYSTEM_CONFIG_UNIT_PATH "/display-manager.service";
+static const char *default_dm_file = "/etc/X11/default-display-manager";
+static const char *dest = NULL;
+
+static int generate_display_manager_alias(void) {
+
+ _cleanup_free_ char *default_dm_path = NULL, *enabled_dm_unit = NULL;
+ const char *default_dm = NULL, *in_mem_symlink = NULL, *target_unit_path = NULL;
+ int r;
+
+ r = read_full_file(default_dm_file, &default_dm_path, NULL);
+ if (r < 0) {
+ log_debug("No %s file, nothing to generate", default_dm_file);
+ return 0;
+ }
+ default_dm = strstrip(basename(default_dm_path));
+
+ r = readlink_value(dm_service_unit, &enabled_dm_unit);
+ if (r < 0) {
+ log_warning("No default display manager unit service enabled, setup is manual or a sysvinit file");
+ return 0;
+ }
+
+ /* all is fine if the info matches */
+ if (streq(strappenda(default_dm, ".service"), enabled_dm_unit))
+ return 0;
+
+ target_unit_path = strappenda(SYSTEM_DATA_UNIT_PATH, "/", default_dm, ".service");
+
+ /* we only create the alias symlink for non sysvinit services */
+ if (access(target_unit_path, F_OK) < 0 && (errno == ENOENT)) {
+ log_warning("%s doesn't seem to be a system unit, we disable the systemd enabled display manager", target_unit_path);
+ target_unit_path = "/dev/null";
+ } else {
+ log_warning("%s point at %s while the default systemd unit is %s. Reconfiguring %s as default.",
+ default_dm_file, default_dm, enabled_dm_unit, default_dm);
+ }
+
+ in_mem_symlink = strappenda(dest, "/display-manager.service");
+ mkdir_parents_label(in_mem_symlink, 0755);
+ if (symlink(target_unit_path, in_mem_symlink) < 0) {
+ log_error("Failed to create symlink %s: %m", in_mem_symlink);
+ return -errno;
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ int r;
+
+ if (argc != 4) {
+ log_error("This program takes three arguments.");
+ return EXIT_FAILURE;
+ }
+
+ dest = argv[2];
+
+ log_set_target(LOG_TARGET_SAFE);
+ log_parse_environment();
+ log_open();
+
+ umask(0022);
+
+ r = generate_display_manager_alias();
+
+ return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}
......@@ -168,3 +168,4 @@ login-don-t-overmount-run-user-UID-on-upgrades.patch
udev-re-enable-mount-propagation-for-udevd.patch
Add-env-variable-for-machine-ID-path.patch
sysv-generator-Avoid-wrong-dependencies-for-failing-.patch
Prefer-etc-X11-default-display-manager-if-present.patch
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment