bug-hurd
[Top][All Lists]
Advanced

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

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


From: Justus Winter
Subject: [PATCH 4/7] initscripts: add runsystem.sysv
Date: Thu, 15 Aug 2013 09:45:31 +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                    |   30 +++++++
 debian/rules                                   |    3 +
 debian/src/initscripts/etc/hurd/runsystem.sysv |  106 ++++++++++++++++++++++++
 5 files changed, 145 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 <address@hidden>  Sat, 04 May 2013 13:13:51 +0100
 
diff --git a/debian/control b/debian/control
index f9b9700..c90e760 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 (>> 20130727) [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..9b59845 100755
--- a/debian/initscripts.postinst
+++ b/debian/initscripts.postinst
@@ -219,6 +219,36 @@ 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 10 \
+               --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
+       fi
+
+       echo "You can use update-alternatives --config runsystem to select"
+       echo "the runsystem to use."
+       echo
+       echo "You must use halt-hurd or reboot-hurd to halt or reboot the"
+       echo "system whenever you change the runsystem."
+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..c80c9f3
--- /dev/null
+++ b/debian/src/initscripts/etc/hurd/runsystem.sysv
@@ -0,0 +1,106 @@
+#!/bin/sh
+#
+# This program is run by /hurd/init at boot time after the essential
+# servers are up.  It does some initialization of its own and then
+# execs the SysV init to bring up the "userland" parts of a normal
+# system.
+#
+
+###
+### 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/dash /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
+}
+
+# Print a newline.
+echo
+
+# See whether pflocal is setup
+#
+# Normally this should be the case, but we better make sure since
+# without the pflocal server, pipe(2) does not work.
+if ! test -e /servers/socket/1 && which settrans >/dev/null ; then
+  # The root filesystem should be read-only at this point.
+  if fsysopts / --update --writable ; then
+    settrans -c /servers/socket/1 /hurd/pflocal
+  else
+    singleuser "Failed to create /servers/socket/1."
+  fi
+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.
+sleep 0.1 # Work around a race condition (probably in the root
+         # translator).
+fsysopts / --update --readonly
+
+# Finally, start the actual SysV init.
+exec /sbin/init ${single} -a
-- 
1.7.10.4




reply via email to

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