On Thu, 20 Aug 2015 at 12:09:42 +0200, Michael Biebl wrote:
> nodm provides a special kind of display manager.
> I therefor think, it should use the same mechanism as other display
> managers like gdm3 or lightdm, to make sure that only ever one display
> manager is started during boot.

Here are patches; I based them on what gdm3 does. In my testing on an
embedded Debian derivative, they seem to interoperate nicely with xdm.

I haven't tried to do anything clever with NODM_ENABLED: even if nodm is
the default display manager, it still won't start unless NODM_ENABLED has
a suitable value. In practice I would expect that the sort of platforms
where nodm is useful will pre-seed nodm's configuration (that's what
we do on the platform I'm interested in).

    S
>From 9e68000e4a84b708aa8817859216b67a9e179e7b Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvit...@collabora.co.uk>
Date: Wed, 6 Jul 2016 17:45:19 +0100
Subject: [PATCH 2/3] nodm.service: add a native systemd service

In particular this makes sure to run nodm.service only after
systemd-user-sessions.service has allowed user logins.

Closes: #796203
Signed-off-by: Simon McVittie <simon.mcvit...@collabora.co.uk>
---
 Makefile.am      | 13 ++++++++++++-
 debian/changelog |  1 +
 debian/rules     |  3 +++
 nodm.service.in  | 14 ++++++++++++++
 4 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 nodm.service.in

diff --git a/Makefile.am b/Makefile.am
index 28709f9..299020f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -64,9 +64,12 @@ test_internals_SOURCES = $(testlibsources)	\
 EXTRA_DIST = test_nodm		\
              nodm-man-extras	\
              autogen.sh		\
+             nodm.service.in	\
              $(NULL)
 
-CLEANFILES = nodm.8
+CLEANFILES = $(man_MANS) \
+             $(systemdsystemunit_DATA) \
+             $(NULL)
 
 DISTCLEANFILES = Makefile.in   \
                  aclocal.m4    \
@@ -74,3 +77,11 @@ DISTCLEANFILES = Makefile.in   \
                  config/*      \
                  configure     \
                  $(NULL)
+
+systemdsystemunitdir = $(prefix)/lib/systemd/system
+systemdsystemunit_DATA = nodm.service
+
+nodm.service: nodm.service.in
+	sed \
+		-e 's![@]sbindir[@]!${sbindir}!g' \
+		< $< > $@
diff --git a/debian/changelog b/debian/changelog
index ad15d48..88f62c6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -13,6 +13,7 @@ nodm (0.12-2) UNRELEASED; urgency=medium
 
   [ Simon McVittie ]
   * Vcs-Git, Vcs-Browser: update to point to the GitHub repository
+  * nodm.service: add a native systemd service (Closes: #796203)
 
  -- Mike Gabriel <sunwea...@debian.org>  Thu, 24 Mar 2016 14:43:36 +0100
 
diff --git a/debian/rules b/debian/rules
index 01dbed9..a460bc2 100755
--- a/debian/rules
+++ b/debian/rules
@@ -12,6 +12,9 @@ override_dh_auto_configure:
 	NOCONFIGURE=1 ./autogen.sh
 	dh_auto_configure $(DHFLAGS)
 
+override_dh_auto_install:
+	dh_auto_install -- systemdsystemunitdir=/lib/systemd/system
+
 override_dh_auto_test:
 	#make check
 
diff --git a/nodm.service.in b/nodm.service.in
new file mode 100644
index 0000000..fdc4785
--- /dev/null
+++ b/nodm.service.in
@@ -0,0 +1,14 @@
+[Unit]
+Description=Display manager for automatic session logins
+Documentation=man:nodm(8)
+After=console-screen.service
+After=console-setup.service
+After=kbd.service
+After=systemd-user-sessions.service
+
+[Service]
+EnvironmentFile=-/etc/default/nodm
+ExecStartPre=/usr/bin/test ${NODM_ENABLED} != no
+ExecStartPre=/usr/bin/test ${NODM_ENABLED} != false
+ExecStart=@sbindir@/nodm $NODM_OPTIONS
+Restart=always
-- 
2.8.1

>From e0f5d2ec9cb95e3187ca4ce5801224a651a5d774 Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvit...@collabora.co.uk>
Date: Wed, 6 Jul 2016 17:20:21 +0100
Subject: [PATCH 3/3] Participate in the /etc/X11/default-display-manager
 mechanism

Signed-off-by: Simon McVittie <simon.mcvit...@collabora.co.uk>
---
 debian/changelog      |  1 +
 debian/copyright      | 15 ++++++++++
 debian/nodm.config    | 36 ++++++++++++++++++++++
 debian/nodm.postinst  | 41 ++++++++++++++++++++++++-
 debian/nodm.prerm     | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++
 debian/nodm.templates | 20 +++++++++++++
 debian/rules          |  2 ++
 7 files changed, 197 insertions(+), 1 deletion(-)
 create mode 100644 debian/nodm.prerm

diff --git a/debian/changelog b/debian/changelog
index 88f62c6..c72471d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,6 +14,7 @@ nodm (0.12-2) UNRELEASED; urgency=medium
   [ Simon McVittie ]
   * Vcs-Git, Vcs-Browser: update to point to the GitHub repository
   * nodm.service: add a native systemd service (Closes: #796203)
+  * Participate in the /etc/X11/default-display-manager mechanism
 
  -- Mike Gabriel <sunwea...@debian.org>  Thu, 24 Mar 2016 14:43:36 +0100
 
diff --git a/debian/copyright b/debian/copyright
index c3be889..577d7d8 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -63,6 +63,17 @@ Copyright: 2008, Joachim Breitner <nome...@debian.org>
            2016, Mike Gabriel <sunwea...@debian.org>
 License: GPL-2+
 
+Files:
+ debian/nodm.config
+ debian/nodm.postinst
+ debian/nodm.prerm
+Copyright:
+ 2000-2001, Branden Robinson
+ 2008, Joachim Breitner <nome...@debian.org>
+ 2009-2011, Enrico Zini <enr...@debian.org>
+ 2016, Mike Gabriel <sunwea...@debian.org>
+License: GPL-2
+
 License: GPL-2+
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
@@ -81,3 +92,7 @@ License: GPL-2+
  On Debian systems, the full text of the GNU General Public
  License version 2 can be found in the file
  `/usr/share/common-licenses/GPL-2'.
+
+License: GPL-2
+ Licensed under the GNU General Public License, version 2.  See the file
+ /usr/share/common-licenses/GPL-2 or <http://www.gnu.org/copyleft/gpl.txt>.
diff --git a/debian/nodm.config b/debian/nodm.config
index 68fc680..40af76b 100644
--- a/debian/nodm.config
+++ b/debian/nodm.config
@@ -1,9 +1,45 @@
 #!/bin/sh
 
+# Partially based on gdm3.config, © 2000-2001 Branden Robinson.
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL-2 or <http://www.gnu.org/copyleft/gpl.txt>.
+
+
 set -e
 
 . /usr/share/debconf/confmodule
 
+THIS_PACKAGE=nodm
+DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
+
+# set default display manager
+
+db_get shared/default-x-display-manager
+OLD_DEFAULT="$RET"
+
+db_metaget shared/default-x-display-manager owners
+OWNERS="$RET"
+db_metaget shared/default-x-display-manager choices
+CHOICES="$RET"
+
+if [ "$OWNERS" != "$CHOICES" ]; then
+  db_subst shared/default-x-display-manager choices $OWNERS
+  db_fset shared/default-x-display-manager seen false
+fi
+
+db_input high shared/default-x-display-manager || true
+db_go
+
+# using this display manager?
+db_get shared/default-x-display-manager
+CURRENT_DEFAULT="$RET"
+# set a flag to indicate to postinst that we need to update from debconf
+if [ "$OLD_DEFAULT" != "$CURRENT_DEFAULT" ]; then
+  DEFAULT_DISPLAY_MANAGER_DIR=$(dirname $DEFAULT_DISPLAY_MANAGER_FILE)
+  test -e $DEFAULT_DISPLAY_MANAGER_DIR || mkdir -p $DEFAULT_DISPLAY_MANAGER_DIR
+  touch $DEFAULT_DISPLAY_MANAGER_FILE.debconf-update
+fi
+
 if [ -s /etc/default/nodm ] ; then
 	. /etc/default/nodm
 
diff --git a/debian/nodm.postinst b/debian/nodm.postinst
index b209bce..9216c13 100644
--- a/debian/nodm.postinst
+++ b/debian/nodm.postinst
@@ -1,10 +1,49 @@
 #! /bin/sh
-# postinst script for nodm
+# postinst script for nodm, partially based on gdm3.postinst
 
 set -e
 
+THIS_PACKAGE=nodm
+DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
+
 . /usr/share/debconf/confmodule
 
+# debconf is not a registry, so we only fiddle with the default file if
+# the configure script requested an update
+if [ -e $DEFAULT_DISPLAY_MANAGER_FILE.debconf-update ]; then
+  rm -f $DEFAULT_DISPLAY_MANAGER_FILE.debconf-update
+  if db_get shared/default-x-display-manager; then
+    # workaround debconf passthru bug (#379198)
+    if [ -z "$RET" ]; then
+      RET="$THIS_PACKAGE"
+    fi
+    if [ "$THIS_PACKAGE" != "$RET" ]; then
+      echo "Please be sure to run \"dpkg --configure $RET\"."
+    fi
+    if db_get "$RET"/daemon_name; then
+      echo "$RET" > $DEFAULT_DISPLAY_MANAGER_FILE
+    fi
+  fi
+fi
+
+DEFAULT_SERVICE=/etc/systemd/system/display-manager.service
+# set default-display-manager systemd service link according to our config
+if [ "$1" = configure ] && [ -d /etc/systemd/system/ ]; then
+  if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
+    SERVICE=/lib/systemd/system/$(basename $(cat "$DEFAULT_DISPLAY_MANAGER_FILE")).service
+    if [ -h "$DEFAULT_SERVICE" ] && [ $(readlink "$DEFAULT_SERVICE") = /dev/null ]; then
+      echo "Display manager service is masked" >&2
+    elif [ -e "$SERVICE" ]; then
+      ln -sf "$SERVICE" "$DEFAULT_SERVICE"
+    else
+      echo "WARNING: $SERVICE is the selected default display manager but does not exist" >&2
+      rm -f "$DEFAULT_SERVICE"
+    fi
+  else
+    rm -f "$DEFAULT_SERVICE"
+  fi
+fi
+
 if [ "$1" = "configure" ] ; then
 	if [ -n "$2" ] && dpkg --compare-versions "$2" lt "0.2"; then
 		# Before version 0.2, nodm was only used on the OpenMoko.  To
diff --git a/debian/nodm.prerm b/debian/nodm.prerm
new file mode 100644
index 0000000..f9aa470
--- /dev/null
+++ b/debian/nodm.prerm
@@ -0,0 +1,83 @@
+#!/bin/bash
+# Debian nodm package pre-removal script
+#
+# Based on gdm3.prerm:
+# © 2001 Branden Robinson
+#
+# Licensed under the GNU General Public License, version 2.  See the file
+# /usr/share/common-licenses/GPL-2 or <http://www.gnu.org/copyleft/gpl.txt>.
+# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
+
+set -e
+
+THIS_PACKAGE=nodm
+DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
+
+if [ "$1" = "remove" -o "$1" = "deconfigure" ]; then
+  if [ -e /usr/share/debconf/confmodule ]; then
+    . /usr/share/debconf/confmodule
+    # disown this question
+    db_unregister shared/default-x-display-manager || true
+    # does the question still exist?
+    if db_get shared/default-x-display-manager; then
+      db_metaget shared/default-x-display-manager owners
+      db_subst shared/default-x-display-manager choices "$RET"
+      db_get shared/default-x-display-manager
+      # are we removing the currently selected display manager?
+      if [ "$THIS_PACKAGE" = "$RET" ]; then
+        if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
+          db_get "$RET"/daemon_name
+          if [ "$(cat $DEFAULT_DISPLAY_MANAGER_FILE)" = "$RET" ]; then
+            rm "$DEFAULT_DISPLAY_MANAGER_FILE"
+          fi
+        fi
+        # ask the user to choose a new default
+        db_fset shared/default-x-display-manager seen false
+        db_input critical shared/default-x-display-manager || true
+        db_go
+        # if the display manager file doesn't exist, write it with the path
+        # to the new default display manager
+        if [ ! -e $DEFAULT_DISPLAY_MANAGER_FILE ]; then
+          db_get shared/default-x-display-manager
+          echo "Please be sure to run \"dpkg-reconfigure $RET\"."
+          db_get "$RET"/daemon_name
+          echo "$RET" > "$DEFAULT_DISPLAY_MANAGER_FILE"
+        fi
+      fi
+    fi
+  fi
+
+  DEFAULT_SERVICE=/etc/systemd/system/display-manager.service
+  # set default-display-manager systemd service link according to our config
+  if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
+    SERVICE=/lib/systemd/system/$(basename $(cat "$DEFAULT_DISPLAY_MANAGER_FILE")).service
+    if [ -h "$DEFAULT_SERVICE" ] && [ $(readlink "$DEFAULT_SERVICE") = /dev/null ]; then
+      echo "Display manager service is masked" >&2
+    elif [ -e "$SERVICE" ]; then
+      ln -sf "$SERVICE" "$DEFAULT_SERVICE"
+    else
+      echo "WARNING: $SERVICE is the selected default display manager but does not exist" >&2
+      rm -f "$DEFAULT_SERVICE"
+    fi
+  else
+    rm -f "$DEFAULT_SERVICE"
+  fi
+fi
+
+if [ "$1" = "remove" ]; then
+  if [ -x /etc/init.d/nodm ]; then
+    nostop=
+    for hostname in "" "localhost" "$(hostname)" "$(hostname -f)"; do
+      if echo $DISPLAY | grep -q "^$hostname:0.*"; then
+        nostop=yes
+      fi
+    done
+    if [ -z $nostop ]; then
+      invoke-rc.d nodm stop
+    fi
+  fi
+fi
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/nodm.templates b/debian/nodm.templates
index 5d1223a..fd4b79b 100644
--- a/debian/nodm.templates
+++ b/debian/nodm.templates
@@ -72,3 +72,23 @@ Default: /etc/X11/Xsession
 _Description: X session to use:
  Please choose the name of the X session script to use with nodm.
 
+Template: nodm/daemon_name
+Type: string
+Default: /usr/sbin/nodm
+Description: for internal use only
+
+Template: shared/default-x-display-manager
+Type: select
+Choices: ${choices}
+_Description: Default display manager:
+ A display manager is a program that provides graphical login capabilities for
+ the X Window System.
+ .
+ Only one display manager can manage a given X server, but multiple display
+ manager packages are installed. Please select which display manager should
+ run by default.
+ .
+ Multiple display managers can run simultaneously if they are configured to
+ manage different servers; to achieve this, configure the display managers
+ accordingly, edit each of their init scripts in /etc/init.d, and disable the
+ check for a default display manager.
diff --git a/debian/rules b/debian/rules
index a460bc2..62a74da 100755
--- a/debian/rules
+++ b/debian/rules
@@ -14,6 +14,8 @@ override_dh_auto_configure:
 
 override_dh_auto_install:
 	dh_auto_install -- systemdsystemunitdir=/lib/systemd/system
+	echo "# Debian-specific change until all display managers participate in /etc/X11/default-display-manager" >> debian/nodm/lib/systemd/system/nodm.service
+	echo "ExecStartPre=/bin/sh -c '[ \"\$$(cat /etc/X11/default-display-manager 2>/dev/null)\" = \"/usr/sbin/nodm\" ]'" >> debian/nodm/lib/systemd/system/nodm.service
 
 override_dh_auto_test:
 	#make check
-- 
2.8.1

Reply via email to