Welcome to little lamb

Code » anopa » commit c93faa8

stage{0,2,3}: Set controlling terminal (to use ^C)

author Olivier Brunel
2015-04-21 19:25:11 UTC
committer Olivier Brunel
2015-04-21 19:25:11 UTC
parent aa2147b77cc5bfe7006814062f821a3858ec5442

stage{0,2,3}: Set controlling terminal (to use ^C)

That way one can use Ctrl+C on aa-st{art,op} to manually timeout a
pending service.

src/scripts/aa-stage0 +1 -1
src/scripts/aa-stage2 +9 -3
src/scripts/aa-stage3 +4 -2

diff --git a/src/scripts/aa-stage0 b/src/scripts/aa-stage0
index 03f8804..41dd10e 100755
--- a/src/scripts/aa-stage0
+++ b/src/scripts/aa-stage0
@@ -45,7 +45,7 @@ umask 022
 # Start services
 foreground { if -n
 {
-  if { emptyenv -c aa-start -D -r /services -l /etc/anopa/onboot }
+  if { emptyenv -c s6-setsid aa-ctty -s aa-start -D -r /services -l /etc/anopa/onboot }
   foreground {
     # if "break" was specified on kernel cmdline, let's open a shell
     if -t { aa-incmdline -qf /root-fs/proc/cmdline break }
diff --git a/src/scripts/aa-stage2 b/src/scripts/aa-stage2
index bd42162..577101d 100755
--- a/src/scripts/aa-stage2
+++ b/src/scripts/aa-stage2
@@ -35,14 +35,20 @@ fdmove 2 4
 
 if -n -t
 {
-  # Reopen the console for stdin/stdout
-  redirfd -r 0 /dev/console
+  # We want the actual tty on stdin
+  backtick -n TTY { aa-tty }
+  import -u TTY
+  redirfd -r 0 ${TTY}
+  # Reopen the console for stdout
   redirfd -w 1 /dev/console
   # And start everything
   foreground { aa-echo -DB "Stage 2: Initializing system..." }
   backtick -n -D default LISTDIR { aa-incmdline -rs aa }
   import -u LISTDIR
-  if { emptyenv -c aa-start -D -l /etc/anopa/onboot/${LISTDIR} }
+  # We have a tty in stdin, become session leader and set controlling terminal.
+  # This is so Ctrl+C will trigger a SIGINT to aa-start, so one can manually
+  # timeout a service.
+  if { emptyenv -c s6-setsid aa-ctty aa-start -D -l /etc/anopa/onboot/${LISTDIR} }
   foreground { aa-echo -DB "System ready." }
   # close logger
   fdmove -c 2 1
diff --git a/src/scripts/aa-stage3 b/src/scripts/aa-stage3
index c753670..017efcb 100755
--- a/src/scripts/aa-stage3
+++ b/src/scripts/aa-stage3
@@ -35,14 +35,16 @@ fdmove 2 4
 
 # Make sure we're sane
 cd /
-redirfd -r 0 /dev/console
+backtick -n TTY { aa-tty }
+import -u TTY
+redirfd -r 0 ${TTY}
 redirfd -w 1 /dev/console
 
 foreground { aa-echo -DB "Stage 3: Preparing ${1}..." }
 # Stop all running services -- s6-svscan did only exec into us, leaving the
 # whole supervised tree intact. Here we stop everything (longrun & oneshot) in
 # order.
-foreground { emptyenv -c aa-stop -D -ak uncaught-logs }
+foreground { emptyenv -c s6-setsid aa-ctty -s aa-stop -D -ak uncaught-logs }
 # We left the catch-all running (in case), make sure everything will exit
 # properly when we send TERM
 foreground { s6-svc -x /run/services/uncaught-logs }