From 8cce4095d3465863fcb26b7264371d97db31990a Mon Sep 17 00:00:00 2001
From: Luke Shumaker <LukeShu@sbcglobal.net>
Date: Mon, 7 Oct 2013 16:08:00 -0400
Subject: revert last commit, it makes systemd-nspawn not handle signals
 correctly.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

I'm a fan of systemd-nspawn.  I really am.  It handles a lot of things the
"right" way, so you don't have to.

However, it handles PTYs and signals in an incredibly stupid way.  Working
around one is f---ed up by the other being wrong.

Before I implemented the change that this reverts, this is what happens:

    systemd-nspawn> I need to create a PTY and proxy between it and stdio.
                    I can specify a terminal size when doing this--I should
                    set it to reflect the terminal I am connected to.
    systemd-nspawn> /dev/stdout: Are you a TTY?
    /dev/stdout> systemd-nspawn: No.
    ---- The correct thing to do here would be to either not set the size,
    ---- or set it to 80×24
    systemd-nspawn> /dev/stdin: Are you a TTY?
    /dev/stdin> systemd-nspawn: Yes.
    systemd-nspawn> /dev/stdin: Great, what size are you?
    /dev/stdin> systemd-nspawn: I am X×Y.
    systemd-nspawn: libc: Please give me a PTY that is X×Y.
    ---- Why the f--- would you do this?  The size only effects *output*.
    ---- If you don't know the characteristics of the output, set
    ---- reasonable defaults!  Don't base it on the characteristics of the
    ---- input!

My solution was to make /dev/stdin not be a TTY by closing it.  This had
the desired effect, but tripped up the signal handling.

Here is how signals were handled before:

    systemd-nspawn> /dev/stdin: Are you a TTY?
    /dev/stdin> systemd-nspawn: Yes.
    systemd-nspawn> /dev/stdin: Great, please don't send SIGINT on C-c.
                                I will handle it myself.
    *user presses C-c, systemd reads it*
    systemd-nspawn> child processes: here's a SIGINT.

Here's what happens when I close, or do other things to make stdin not be a
TTY:

    systemd-nspawn> /dev/stdin: Are you a TTY?
    /dev/stdin> systemd-nspawn: No.
    systemd-nspawn> /dev/stdin: Oh, OK.
    *user presses C-c, /dev/stdin interprets it*
    /dev/stdin> systemd-nspawn: Here's a SIGINT.
    systemd-nspawn> *dies, abandoning child processes*

The clear correct thing to do would have been to *handle* SIGINT, and pass
it along to the children.
---
 src/chroot-tools/libremakepkg | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index 963747f..fc6418c 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -117,10 +117,10 @@ build() (
 	fi
 
 	prepare_chroot "$copydir" "$LIBREHOME" "$repack" false
-	"${run[@]}" /chrootprepare "$@" 0>&- |& indent
+	"${run[@]}" /chrootprepare "$@" |& indent
 	run_hook pre_build "$copydir"
 	trap "run_hook post_build '$copydir'" EXIT
-	"${run[@]}" /chrootbuild "$@" 0>&- |& indent
+	"${run[@]}" /chrootbuild "$@" |& indent
 )
 
 # The main program #############################################################
@@ -244,7 +244,7 @@ main() {
 			"Waiting for existing lock on chroot copy to be released: [%s]" "$copy"
 		# Create the chroot if it does not exist
 		msg 'Initializing the chroot...'
-		librechroot "${librechroot_flags[@]}" make 0>&- |& indent
+		librechroot "${librechroot_flags[@]}" make |& indent
 	fi
 
 	# Set target CARCH
@@ -255,7 +255,7 @@ main() {
 	msg 'Starting pre-build activities...'
 	run_hook check_pkgbuild
 	msg 'Downloading sources...'
-	download_sources "$copydir" "$LIBREUSER" 0>&- |& indent
+	download_sources "$copydir" "$LIBREUSER" |& indent
 
 	# Build
 	msg 'Starting to build the package...'
@@ -265,7 +265,7 @@ main() {
 	# Post-build
 	msg 'Starting post-build activities...'
 	run_hook check_pkg
-	add_to_local_repo "$copydir" "$copydir"/pkgdest/*.pkg.tar* 0>&- |& indent
+	add_to_local_repo "$copydir" "$copydir"/pkgdest/*.pkg.tar* |& indent
 }
 
 main "$@"
-- 
cgit v1.2.3-2-g168b