[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/04: processes: 'process-open-files' ignores disappeared /proc/PID/fd
From: |
guix-commits |
Subject: |
01/04: processes: 'process-open-files' ignores disappeared /proc/PID/fd entries. |
Date: |
Mon, 29 Apr 2019 16:25:35 -0400 (EDT) |
civodul pushed a commit to branch version-1.0.0
in repository guix.
commit c21d912a027056c30ee86c1ce021322e89f474c3
Author: Ludovic Courtès <address@hidden>
Date: Mon Apr 29 21:39:38 2019 +0200
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'.
---
guix/scripts/processes.scm | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/guix/scripts/processes.scm b/guix/scripts/processes.scm
index 6a2f603..2dd3bbf 100644
--- a/guix/scripts/processes.scm
+++ b/guix/scripts/processes.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2018 Ludovic Courtès <address@hidden>
+;;; Copyright © 2018, 2019 Ludovic Courtès <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -103,9 +103,16 @@ processes."
(let ((directory (string-append "/proc/"
(number->string (process-id process))
"/fd")))
- (map (lambda (fd)
- (readlink (string-append directory "/" fd)))
- (or (scandir directory string->number) '()))))
+ (filter-map (lambda (fd)
+ ;; There's a TOCTTOU race here, hence the 'catch'.
+ (catch 'system-error
+ (lambda ()
+ (readlink (string-append directory "/" fd)))
+ (lambda args
+ (if (= ENOENT (system-error-errno args))
+ #f
+ (apply throw args)))))
+ (or (scandir directory string->number) '()))))
;; Daemon session.
(define-record-type <daemon-session>