bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/8] initscripts: add runsystem.sysv


From: Justus Winter
Subject: [PATCH 4/8] initscripts: add runsystem.sysv
Date: Tue, 9 Jul 2013 10:46:47 +0200

runsystem.sysv does some very early initialization of Hurd and execs
/sbin/init to start the system using sysvinit. Hurd uses the
alternatives system to choose which runsystem to use and traditionally
shipped a custom init solution. Add runsystem.sysv using
update-alternatives in initscripts.postinst. Since the choice of
runsystems also dictate which halt and reboot to use, add those
utilities as slaves to the runsystem alternative and display
instructions on how to reboot or halt the system if installing the
initscript package switches the runsystem.
---
 debian/changelog                               |    4 +
 debian/control                                 |    3 +-
 debian/initscripts.postinst                    |   25 ++++++
 debian/rules                                   |    3 +
 debian/src/initscripts/etc/hurd/runsystem.sysv |  102 ++++++++++++++++++++++++
 5 files changed, 136 insertions(+), 1 deletion(-)
 create mode 100644 debian/src/initscripts/etc/hurd/runsystem.sysv

diff --git a/debian/changelog b/debian/changelog
index 7d9aa05..743e77e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -54,6 +54,10 @@ sysvinit (2.88dsf-42) UNRELEASED; urgency=low
   * mount-functions.sh: Hurd has a tmpfs translator now, remove workaround.
   * mount-functions.sh: Add -ocompatible to procfs mounts on Hurd.
   * mountall.sh: Use pidof -s /sbin/init for robustness.
+  * Add runsystem.sysv that starts a Hurd system using sysvinit.
+  * debian/control: Depend on a recent hurd package on hurd-any. The
+    initscripts require some functionality that has been implemented
+    only recently.
 
  -- Roger Leigh <rleigh@debian.org>  Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/debian/control b/debian/control
index f9b9700..19064ef 100644
--- a/debian/control
+++ b/debian/control
@@ -75,7 +75,8 @@ Depends:
  debianutils (>= 4),
  lsb-base (>= 3.2-14),
  sysvinit-utils (>= 2.86.ds1-64), sysv-rc | file-rc,
- coreutils (>= 5.93)
+ coreutils (>= 5.93),
+ hurd (>= 20130707-1) [hurd-any]
 Recommends: psmisc, e2fsprogs
 Conflicts:
  libdevmapper1.02.1 (<< 2:1.02.24-1),
diff --git a/debian/initscripts.postinst b/debian/initscripts.postinst
index 0e140cf..82d9abf 100755
--- a/debian/initscripts.postinst
+++ b/debian/initscripts.postinst
@@ -219,6 +219,31 @@ then
        fi
 fi
 
+#
+# Install runsystem.sysv on Hurd.
+#
+if [ "$(uname -s)" = GNU ]
+then
+       get_runsystem() {
+           update-alternatives --query runsystem \
+               | sed -n -e '/^Value:/s|.*\.||p'
+       }
+
+       current="$(get_runsystem)"
+       update-alternatives --quiet \
+               --install /etc/hurd/runsystem runsystem \
+               /etc/hurd/runsystem.sysv 30 \
+               --slave /sbin/halt halt /sbin/halt-sysv \
+               --slave /sbin/reboot reboot /sbin/reboot-sysv
+       new="$(get_runsystem)"
+
+       if [ "$current" != "$new" ]; then
+           echo "Switching from runsystem.$current to runsystem.$new."
+           echo "You must use halt-$current or reboot-$current to halt or"
+           echo "reboot the system."
+       fi
+fi
+
 # Ensure we have a random seed on first boot.
 if [ "$PREV_VER" = "" ]; then
        if which invoke-rc.d >/dev/null 2>&1
diff --git a/debian/rules b/debian/rules
index a28631f..1006921 100755
--- a/debian/rules
+++ b/debian/rules
@@ -127,6 +127,9 @@ ifeq ($(DEB_HOST_ARCH_OS), hurd)
        mv $(sysvtmp)/sbin/halt $(sysvtmp)/sbin/halt-sysv
        rm $(sysvtmp)/sbin/reboot
        ln -s halt-sysv $(sysvtmp)/sbin/reboot-sysv
+       $(INSTALL) -d $(inittmp)/etc/hurd
+       $(INSTALL) debian/src/initscripts/etc/hurd/runsystem.sysv \
+               $(inittmp)/etc/hurd
 endif
 
 override_dh_installdeb-indep:
diff --git a/debian/src/initscripts/etc/hurd/runsystem.sysv 
b/debian/src/initscripts/etc/hurd/runsystem.sysv
new file mode 100644
index 0000000..b95c2d0
--- /dev/null
+++ b/debian/src/initscripts/etc/hurd/runsystem.sysv
@@ -0,0 +1,102 @@
+#!/bin/sh
+#
+# This program is run by /hurd/init at boot time after the essential
+# servers are up, and is responsible for running the "userland" parts of a
+# normal system.  This includes running the single-user shell as well as a
+# multi-user system.  This program is expected never to exit.
+#
+
+
+###
+### Where to find programs, etc.
+###
+
+PATH=/bin:/sbin:/usr/bin:/usr/sbin
+export PATH
+
+# If we lose badly, try to exec each of these in turn.
+fallback_shells='/bin/sh /bin/bash /bin/csh /bin/ash /bin/shd'
+
+# Shell used for normal single-user startup.
+SHELL=/bin/sh
+
+###
+
+
+# If we get a SIGLOST, attempt to reopen the console in case
+# our console ports were revoked.  This lets us print messages.
+reopen_console ()
+{
+  exec 1>/dev/console 2>&1 || exit 3
+}
+trap 'reopen_console' 32 # SIGLOST = server died on GNU
+
+
+# Call this when we are losing badly enough that we want to punt normal
+# startup entirely.  We exec a single-user shell, so we will not come back
+# here.  The only way to get to multi-user from that shell will be
+# explicitly exec this script or something like that.
+singleuser()
+{
+  test $# -eq 0 || echo "$0: $*"
+  for try in ${fallback_shells}; do
+    SHELL=${try}
+    exec ${SHELL}
+  done
+  exit 127
+}
+
+
+# See whether pflocal is setup already, and do so if not (install case)
+
+if ! test -e /servers/socket/1 && which settrans >/dev/null ; then
+  settrans -c /servers/socket/1 /hurd/pflocal
+fi
+
+# We expect to be started by console-run, which gives us no arguments and
+# puts FALLBACK_CONSOLE=file-name in the environment if our console is
+# other than a normal /dev/console.
+
+if [ "${FALLBACK_CONSOLE+set}" = set ]; then
+  singleuser "Running on fallback console ${FALLBACK_CONSOLE}"
+fi
+
+
+###
+### Normal startup procedures
+###
+
+# Parse the multiboot command line.  We only pay attention to -s and -f.
+# The first argument is the kernel file name; skip that.
+shift
+flags=
+single=
+while [ $# -gt 0 ]; do
+  arg="$1"
+  shift
+  case "$arg" in
+  --*) ;;
+  *=*) ;;
+  -*)
+    flags="${flags}${arg#-}"
+    ;;
+  'single')
+    single="-s"
+    ;;
+  'fastboot'|'emergency')
+    ;;
+  esac
+done
+
+# Start the default pager.  It will bail if there is already one running.
+/hurd/mach-defpager
+
+# This is necessary to make stat / return the correct device ids.
+fsysopts / --update --readonly
+
+# Print a newline.
+echo
+
+# Finally, start the actual SysV init.
+# Pass -i to make `init' work as init, even if its PID is not 1.
+exec /sbin/init -i ${single} -a
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]