aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-05-08 23:21:45 +0200
committerLudovic Courtès <ludo@gnu.org>2014-05-08 23:42:15 +0200
commit474b832d5e596c5f0713afbcdea5a19c6770cfac (patch)
tree07eb6c72d12664d2ecd8440fe2916b1d42688952 /guix
parentef4ab0a4c55f47e581e7a47622061f1583676d1e (diff)
downloadgnu-guix-474b832d5e596c5f0713afbcdea5a19c6770cfac.tar
gnu-guix-474b832d5e596c5f0713afbcdea5a19c6770cfac.tar.gz
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.
Diffstat (limited to 'guix')
-rw-r--r--guix/build/linux-initrd.scm25
1 files 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 '())