Skip to content
Snippets Groups Projects
Commit 474b832d authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

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.
parent ef4ab0a4
No related branches found
No related tags found
No related merge requests found
...@@ -324,22 +324,15 @@ (define (switch-root root) ...@@ -324,22 +324,15 @@ (define (switch-root root)
(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.
(let ((in (open-file "/dev/console" "rbl")) (dup2 (fileno console) 0)
(out (open-file "/dev/console" "wbl"))) (dup2 (fileno console) 1)
(dup2 (fileno in) 0) (dup2 (fileno console) 2)
(dup2 (fileno out) 1)
(dup2 (fileno out) 2) (close-port console))))
;; 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)))))
(define* (boot-system #:key (define* (boot-system #:key
(linux-modules '()) (linux-modules '())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment