mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 15:36:20 -05:00
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
1 changed files with 7 additions and 14 deletions
|
@ -324,22 +324,15 @@ (define (switch-root root)
|
|||
|
||||
(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))
|
||||
;; /dev/console, and reopen them.
|
||||
(let ((console (open-file "/dev/console" "r+b0")))
|
||||
(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)
|
||||
(dup2 (fileno console) 0)
|
||||
(dup2 (fileno console) 1)
|
||||
(dup2 (fileno console) 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)))))
|
||||
(close-port console))))
|
||||
|
||||
(define* (boot-system #:key
|
||||
(linux-modules '())
|
||||
|
|
Loading…
Reference in a new issue