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.
This commit is contained in:
parent
ef4ab0a4c5
commit
474b832d5e
|
@ -324,22 +324,15 @@ bailing out.~%root contents: ~s~%" (scandir "/"))
|
||||||
|
|
||||||
(when (file-exists? "/dev/console")
|
(when (file-exists? "/dev/console")
|
||||||
;; Close the standard file descriptors since they refer to the old
|
;; Close the standard file descriptors since they refer to the old
|
||||||
;; /dev/console.
|
;; /dev/console, and reopen them.
|
||||||
(for-each close-fdes '(0 1 2))
|
(let ((console (open-file "/dev/console" "r+b0")))
|
||||||
|
(for-each close-fdes '(0 1 2))
|
||||||
|
|
||||||
;; Reopen them.
|
(dup2 (fileno console) 0)
|
||||||
(let ((in (open-file "/dev/console" "rbl"))
|
(dup2 (fileno console) 1)
|
||||||
(out (open-file "/dev/console" "wbl")))
|
(dup2 (fileno console) 2)
|
||||||
(dup2 (fileno in) 0)
|
|
||||||
(dup2 (fileno out) 1)
|
|
||||||
(dup2 (fileno out) 2)
|
|
||||||
|
|
||||||
;; Safely close IN and OUT.
|
(close-port console))))
|
||||||
(for-each (lambda (port)
|
|
||||||
(if (memv (fileno port) '(0 1 2))
|
|
||||||
(set-port-revealed! port 1)
|
|
||||||
(close-port port)))
|
|
||||||
(list in out)))))
|
|
||||||
|
|
||||||
(define* (boot-system #:key
|
(define* (boot-system #:key
|
||||||
(linux-modules '())
|
(linux-modules '())
|
||||||
|
|
Loading…
Reference in New Issue