From 474b832d5e596c5f0713afbcdea5a19c6770cfac Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 8 May 2014 23:21:45 +0200 Subject: linux-initrd: Don't leak /dev/console file descriptors. * guix/build/linux-initrd.scm (switch-root): Simplify /dev/console code. This fixes a bug where we would leak the IN and OUT file descriptors. --- guix/build/linux-initrd.scm | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/guix/build/linux-initrd.scm b/guix/build/linux-initrd.scm index 6dd7c6e958..16c741f931 100644 --- a/guix/build/linux-initrd.scm +++ b/guix/build/linux-initrd.scm @@ -324,22 +324,15 @@ bailing out.~%root contents: ~s~%" (scandir "/")) (when (file-exists? "/dev/console") ;; Close the standard file descriptors since they refer to the old - ;; /dev/console. - (for-each close-fdes '(0 1 2)) - - ;; Reopen them. - (let ((in (open-file "/dev/console" "rbl")) - (out (open-file "/dev/console" "wbl"))) - (dup2 (fileno in) 0) - (dup2 (fileno out) 1) - (dup2 (fileno out) 2) - - ;; Safely close IN and OUT. - (for-each (lambda (port) - (if (memv (fileno port) '(0 1 2)) - (set-port-revealed! port 1) - (close-port port))) - (list in out))))) + ;; /dev/console, and reopen them. + (let ((console (open-file "/dev/console" "r+b0"))) + (for-each close-fdes '(0 1 2)) + + (dup2 (fileno console) 0) + (dup2 (fileno console) 1) + (dup2 (fileno console) 2) + + (close-port console)))) (define* (boot-system #:key (linux-modules '()) -- cgit v1.2.3