Subject: [PATCH] [BZ 107865] iucvterm: provide ttyrun/iucvtty system instance units
From: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>

Description:  iucvterm: provide ttyrun/iucvtty system instance units
Symptom:      The /etc/inittab can no longer be used to configure ttyrun
              or iucvtty instances.
Problem:      The system daemon, systemd, replaces the traditional
              /etc/inittab and SysV initialization approach.  Also, systemd
              uses a different configuration scheme to manage system services
              and resources.
Solution:     Provide systemd instance units to start getty programs on HVC
              terminal devices with ttyrun.  Also provide an instance unit to
              configure and manage iucvtty instances.

              To install the systemd system units, specify the
              SYSTEMDSYSTEMUNITDIR for the "make install" command.  The value
              of the SYSTEMDSYSTEMUNITDIR variable must point to the system
              unit directory of your systemd installation (which is typically
              "/usr/lib/systemd/system").
Reproduction: None.
Upstream-ID:  -
Problem-ID:   107865

Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
---
 Makefile                          |    2 +-
 README                            |    4 ++++
 common.mak                        |    6 +++++-
 systemd/Makefile                  |   31 +++++++++++++++++++++++++++++++
 systemd/iucvtty-login@.service.in |   26 ++++++++++++++++++++++++++
 systemd/ttyrun-getty@.service.in  |   29 +++++++++++++++++++++++++++++
 6 files changed, 96 insertions(+), 2 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ LIB_DIRS = libvtoc libu2s libutil libzds
 SUB_DIRS = $(LIB_DIRS) zipl zdump fdasd dasdfmt dasdview tunedasd \
 	   tape390 osasnmpd qetharp ip_watcher qethconf scripts zconf \
 	   vmconvert vmcp man mon_tools dasdinfo vmur cpuplugd ipl_tools \
-	   ziomon iucvterm hyptop cmsfs-fuse qethqoat zfcpdump zdsfs
+	   ziomon iucvterm hyptop cmsfs-fuse qethqoat zfcpdump zdsfs systemd
 
 all: subdirs_make
 
--- a/README
+++ b/README
@@ -26,6 +26,10 @@ s390-tools (1.24.1)
      - 60-readahead.rules: udev rules to set increased "default max readahead".
      - 40-z90crypt.rules: udev rules for z90crypt driver
 
+   * systemd units:
+     - iucvtty-login@.service: Instance unit to manage iucvtty instances
+     - ttyrun-getty@.service: Instance unit to manage ttyrun
+
    * zipl:
      Make DASDs or tapes bootable for system IPL or system dump.
 
--- a/common.mak
+++ b/common.mak
@@ -58,8 +58,12 @@ SYSCONFDIR      = $(INSTROOT)/etc
 MANDIR          = $(INSTROOT)/usr/share/man
 TOOLS_LIBDIR    = $(INSTROOT)/lib/s390-tools
 ZFCPDUMP_DIR    = $(INSTROOT)/lib/s390-tools/zfcpdump
+# Systemd support files are installed only if a directory is specified
+# for SYSTEMDSYSTEMUNITDIR
+SYSTEMDSYSTEMUNITDIR =
 INSTDIRS        = $(USRSBINDIR) $(USRBINDIR) $(BINDIR) $(LIBDIR) $(MANDIR) \
-			$(SYSCONFDIR) $(TOOLS_LIBDIR) $(ZFCPDUMP_DIR)
+			$(SYSCONFDIR) $(TOOLS_LIBDIR) $(ZFCPDUMP_DIR) \
+			$(SYSTEMDSYSTEMUNITDIR)
 OWNER           = $(shell id -un)
 GROUP		= $(shell id -gn)
 export INSTROOT BINDIR LIBDIR MANDIR OWNER GROUP
--- /dev/null
+++ b/systemd/Makefile
@@ -0,0 +1,31 @@
+include ../common.mak
+
+SYSTEM_UNITS = ttyrun-getty@.service iucvtty-login@.service
+
+all:
+
+system_units: $(SYSTEM_UNITS)
+
+check:
+
+install: system_units
+	for unit in $(SYSTEM_UNITS); do \
+	  test -d "$(SYSTEMDSYSTEMUNITDIR)" || continue ; \
+	  $(INSTALL) -g $(GROUP) -o $(OWNER) \
+	             -m 644 $$unit $(SYSTEMDSYSTEMUNITDIR) ; \
+	done
+
+clean:
+	rm -f $(SYSTEM_UNITS)
+
+%: %.in
+	real_bin_dir=`echo $(BINDIR) |sed 's#^$(INSTROOT)##'` ; \
+	real_usrbin_dir=`echo $(USRBINDIR) |sed 's#^$(INSTROOT)##'` ; \
+	real_usrsbin_dir=`echo $(USRSBINDIR) |sed 's#^$(INSTROOT)##'` ; \
+	sed    -e "s#@bin_path@#$$real_bin_dir#g" \
+	       -e "s#@usrbin_path@#$$real_usrbin_dir#g" \
+	       -e "s#@usrsbin_path@#$$real_usrsbin_dir#g" \
+	       -e 's#@S390_TOOLS_RELEASE@#$(S390_TOOLS_RELEASE)#g' \
+	< $< > $@
+
+.PHONY: all check install clean system_units
--- /dev/null
+++ b/systemd/iucvtty-login@.service.in
@@ -0,0 +1,26 @@
+# Systemd unit for starting iucvtty instances.
+#
+# The instance ID corresponds to the terminal identifier for the iucvtty
+# instance.
+#
+
+[Unit]
+Description=iucvtty login for terminal ID %I
+Documentation=man:iucvtty(1) man:iucvconn(1) man:login(1)
+After=systemd-user-sessions.service plymouth-quit-wait.service
+After=rc-local.service
+Before=getty.target
+Conflicts=rescue.service
+IgnoreOnIsolate=yes
+
+
+[Service]
+ExecStart=-@usrbin_path@/iucvtty %I
+KillMode=process
+Restart=always
+RestartSec=0
+IgnoreSIGPIPE=no
+SendSIGHUP=yes
+
+[Install]
+WantedBy=getty.target
--- /dev/null
+++ b/systemd/ttyrun-getty@.service.in
@@ -0,0 +1,29 @@
+# Systemd unit to start getty programs if a terminal is available using
+# the ttyrun program
+#
+
+[Unit]
+Description=TTYRun on %I
+Documentation=man:ttyrun(8) man:agetty(8)
+BindTo=dev-%i.device
+After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service
+After=rc-local.service
+Before=getty.target
+IgnoreOnIsolate=yes
+
+
+[Service]
+Environment=TERM=linux
+ExecStart=-@bin_path@/ttyrun %I /sbin/agetty -L 115200,38400,9600 %I
+IgnoreSIGPIPE=no
+KillMode=process
+Restart=always
+RestartSec=0
+SendSIGHUP=yes
+TTYPath=/dev/%I
+TTYReset=yes
+TTYVHangup=yes
+UtmpIdentifier=%I
+
+[Install]
+WantedBy=getty.target
