summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2021-03-16 22:45:53 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-03-16 22:45:53 +0000
commit437dd9c51167f085315a134253e8c4f18c63138d (patch)
treee71cf512b56796e5109ec3d9e722e058c2929917
parentac1e123e56a2757cb3332e464fff6b23c36fdec1 (diff)
Do not hardcode /libexec libexecdir
So that distributions can use the --libexecdir configure parameter. * configure.ac (AC_CONFIG_FILES): Add daemons/runsystem.hurd.sh. * config/ttys: Rename to ttys.in, replace /libexec with @libexecdir@. * config/Makefile (ttys): Generate from ttys.in * daemons/runsystem.hurd.sh.in (prefix): Define to @prefix@. (exec_prefix): Define to @exec_prefix@. (RUNCOM, RUNTTYS): Replace /libexec with @libexecdir@. * init/Makefile (init-CPPFLAGS): Define LIBEXECDIR. * init/init.c (main): Use LIBEXECDIR instead of hardcoding /libexec. * startup/Makefile (startup-CPPFLAGS): Define LIBEXECDIR. * startup/startup.c (start_child, launch_something): Use LIBEXECDIR instead of hardcoding /libexec.
-rw-r--r--config/Makefile4
-rw-r--r--config/ttys.in14
-rw-r--r--configure.ac2
-rw-r--r--daemons/runsystem.hurd.sh6
-rw-r--r--daemons/runsystem.hurd.sh.in157
-rw-r--r--init/Makefile2
-rw-r--r--init/init.c2
-rw-r--r--startup/Makefile1
-rw-r--r--startup/startup.c6
9 files changed, 187 insertions, 7 deletions
diff --git a/config/Makefile b/config/Makefile
index e6cb61c8..2317eebc 100644
--- a/config/Makefile
+++ b/config/Makefile
@@ -51,3 +51,7 @@ $(addprefix $(DESTDIR),$(installed_logins)): $(DESTDIR)$(sysconfdir)/login/%: lo
$(addprefix $(DESTDIR),$(installed_conf)): $(DESTDIR)$(sysconfdir)/%: %
$(INSTALL_DATA) $< $(DESTDIR)$(sysconfdir)/$*
+
+cleantarg += ttys
+ttys: ttys.in
+ sed -e 's:@libexecdir@:'$(libexecdir)':g' < $< > $@
diff --git a/config/ttys.in b/config/ttys.in
new file mode 100644
index 00000000..d78dc836
--- /dev/null
+++ b/config/ttys.in
@@ -0,0 +1,14 @@
+# Programs to be maintained on terminal lines. init runs these programs,
+# and restartsthem when they die. Note that in GNU, unlike in BSD, there
+# is no need to list pseudo-ttys here.
+
+# name program type status comments
+
+console "@libexecdir@/getty 9600" mach-gnu-color on secure trusted console
+tty1 "@libexecdir@/getty 38400" hurd on secure trusted console
+tty2 "@libexecdir@/getty 38400" hurd on secure trusted console
+tty3 "@libexecdir@/getty 38400" hurd on secure trusted console
+tty4 "@libexecdir@/getty 38400" hurd on secure trusted console
+tty5 "@libexecdir@/getty 38400" hurd on secure trusted console
+tty6 "@libexecdir@/getty 38400" hurd on secure trusted console
+#com0 "@libexecdir@/getty 9600" dialup on secure
diff --git a/configure.ac b/configure.ac
index dcb9e7cd..6dbb97e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -368,7 +368,7 @@ AC_SUBST([HAVE_LIBPCIACCESS])
AC_SUBST([libpciaccess_CFLAGS])
AC_SUBST([libpciaccess_LIBS])
-AC_CONFIG_FILES([config.make ${makefiles}])
+AC_CONFIG_FILES([config.make ${makefiles} daemons/runsystem.hurd.sh])
AC_OUTPUT
dnl Local Variables:
diff --git a/daemons/runsystem.hurd.sh b/daemons/runsystem.hurd.sh
index f4f27711..54f427dc 100644
--- a/daemons/runsystem.hurd.sh
+++ b/daemons/runsystem.hurd.sh
@@ -23,8 +23,10 @@ fallback_shells='/bin/sh /bin/bash /bin/csh /bin/ash /bin/shd'
SHELL=/bin/sh
# Programs that do multi-user startup.
-RUNCOM=/libexec/rc
-RUNTTYS=/libexec/runttys
+prefix=
+exec_prefix=${prefix}
+RUNCOM=${exec_prefix}/libexec/rc
+RUNTTYS=${exec_prefix}/libexec/runttys
# Signals that we should pass down to runttys.
runttys_sigs='TERM INT HUP TSTP'
diff --git a/daemons/runsystem.hurd.sh.in b/daemons/runsystem.hurd.sh.in
new file mode 100644
index 00000000..9ce350b4
--- /dev/null
+++ b/daemons/runsystem.hurd.sh.in
@@ -0,0 +1,157 @@
+#!/bin/bash
+#
+# 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
+export PATH
+
+umask 022
+
+# 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
+
+# Programs that do multi-user startup.
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+RUNCOM=@libexecdir@/rc
+RUNTTYS=@libexecdir@/runttys
+# Signals that we should pass down to runttys.
+runttys_sigs='TERM INT HUP TSTP'
+
+###
+
+
+# If we get a SIGLOST, attempt to reopen the console in case
+# our console ports were revoked. This lets us print messages.
+function reopen_console ()
+{
+ exec 1>/dev/console 2>&1 || exit 3
+}
+trap 'reopen_console' SIGLOST
+
+
+# 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.
+function singleuser ()
+{
+ test $# -eq 0 || echo "$0: $*"
+ for try in ${fallback_shells}; do
+ SHELL=${try}
+ exec ${SHELL}
+ done
+ exit 127
+}
+
+
+# See whether pflocal is set up already, and do so if not (install case)
+#
+# 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 ; 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=
+while [ $# -gt 0 ]; do
+ arg="$1"
+ shift
+ case "$arg" in
+ --*) ;;
+ *=*) ;;
+ -*)
+ flags="${flags}${arg#-}"
+ ;;
+ 'single'|'emergency') # Linux compat
+ flags="${flags}s"
+ ;;
+ 'fastboot')
+ flags="${flags}f"
+ ;;
+ esac
+done
+
+# Check boot flags.
+case "$flags" in
+*s*)
+ rc=false # force single-user
+ ;;
+*f*)
+ rc="${RUNCOM}" # fastboot
+ ;;
+*)
+ rc="${RUNCOM} autoboot" # multi-user default
+ ;;
+esac
+
+# Large infinite loop. If this script ever exits, init considers that
+# a serious bogosity and punts to a fallback single-user shell.
+# We handle here the normal transitions between single-user and multi-user.
+while : ; do
+
+ # Run the rc script. As long as it exits nonzero, punt to single-user.
+ # After the single-user shell exits, we will start over attempting to
+ # run rc; but later invocations strip the `autoboot' argument.
+ until $rc; do
+ rc=${RUNCOM}
+
+ # Run single-user shell and repeat as long as it dies with a signal.
+ until ${SHELL} || test $? -lt 128; do
+ :
+ done
+ done
+
+ # Now we are officially ready for normal multi-user operation.
+
+ # Trap certain signals and send them on to runttys. For this to work, we
+ # must run it asynchronously and wait for it with the `wait' built-in.
+ runttys_pid=0
+ for sig in $runttys_sigs; do
+ trap "kill -$sig \${runttys_pid}" $sig
+ done
+
+ # This program reads /etc/ttys and starts the programs it says to.
+ ${RUNTTYS} &
+ runttys_pid=$!
+
+ # Wait for runttys to die, meanwhile handling trapped signals.
+ wait
+
+ # Go back to the top of the infinite loop, as if booting single-user.
+ rc=false
+
+done
diff --git a/init/Makefile b/init/Makefile
index 07b80261..be4b768b 100644
--- a/init/Makefile
+++ b/init/Makefile
@@ -21,4 +21,6 @@ SRCS = init.c
OBJS = $(SRCS:.c=.o)
target = init
+init-CPPFLAGS=-DLIBEXECDIR=\"${libexecdir}\"
+
include ../Makeconf
diff --git a/init/init.c b/init/init.c
index 93e0470a..ca40d527 100644
--- a/init/init.c
+++ b/init/init.c
@@ -139,7 +139,7 @@ main (int argc, char **argv)
sa.sa_flags |= SA_RESTART;
sigaction (SIGCHLD, &sa, NULL);
- char *args[] = { "/libexec/runsystem.hurd", NULL };
+ char *args[] = { LIBEXECDIR "/runsystem.hurd", NULL };
switch (child_pid = fork ())
{
diff --git a/startup/Makefile b/startup/Makefile
index 8df0bd85..43c75187 100644
--- a/startup/Makefile
+++ b/startup/Makefile
@@ -34,6 +34,7 @@ notifyServer-CFLAGS="-DMIG_EOPNOTSUPP=EOPNOTSUPP"
fsysServer-CFLAGS="-DMIG_EOPNOTSUPP=EOPNOTSUPP"
fsServer-CFLAGS="-DMIG_EOPNOTSUPP=EOPNOTSUPP"
ioServer-CFLAGS="-DMIG_EOPNOTSUPP=EOPNOTSUPP"
+startup-CPPFLAGS=-DLIBEXECDIR=\"${libexecdir}\"
include ../Makeconf
diff --git a/startup/startup.c b/startup/startup.c
index 00d58989..9faeb462 100644
--- a/startup/startup.c
+++ b/startup/startup.c
@@ -1261,7 +1261,7 @@ start_child (const char *prog, char **progargs)
if (progargs == 0)
{
- const char *argv[] = { "/libexec/console-run", prog, 0 };
+ const char *argv[] = { LIBEXECDIR "/console-run", prog, 0 };
err = argz_create ((char **) argv, &args, &arglen);
}
else
@@ -1271,7 +1271,7 @@ start_child (const char *prog, char **progargs)
++argc;
{
const char *argv[2 + argc + 1];
- argv[0] = "/libexec/console-run";
+ argv[0] = LIBEXECDIR "/console-run";
argv[1] = prog;
argv[2 + argc] = 0;
while (argc-- > 0)
@@ -1347,7 +1347,7 @@ launch_something (const char *why)
static unsigned int try;
static const char *const tries[] =
{
- "/libexec/runsystem",
+ LIBEXECDIR "/runsystem",
_PATH_BSHELL,
"/bin/shd", /* XXX */
};