processes: 'process-open-files' ignores disappeared /proc/PID/fd entries.

Previously, 'process-open-files' would throw ENOENT if an entry had
vanished after the 'scandir' call and before the 'readlink' call.

* guix/scripts/processes.scm (process-open-files): Catch ENOENT errors
from 'readlink'.
This commit is contained in:
Ludovic Courtès 2019-04-29 21:39:38 +02:00
parent 6b99afeef8
commit c21d912a02
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -103,8 +103,15 @@ processes."
(let ((directory (string-append "/proc/" (let ((directory (string-append "/proc/"
(number->string (process-id process)) (number->string (process-id process))
"/fd"))) "/fd")))
(map (lambda (fd) (filter-map (lambda (fd)
;; There's a TOCTTOU race here, hence the 'catch'.
(catch 'system-error
(lambda ()
(readlink (string-append directory "/" fd))) (readlink (string-append directory "/" fd)))
(lambda args
(if (= ENOENT (system-error-errno args))
#f
(apply throw args)))))
(or (scandir directory string->number) '())))) (or (scandir directory string->number) '()))))
;; Daemon session. ;; Daemon session.