[vte] spawn: Ignore EBADF in the fdwalk callback



commit 062d504b634dda4627d6fc3e23f450a500ffebdd
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sun May 10 21:57:01 2020 +0200

    spawn: Ignore EBADF in the fdwalk callback
    
    The fallback implementation of fdwalk can call the callback with invalid
    file descriptors on non-Linux systems because it doesn't know how to get
    a list of valid file descriptors. Therefore, we have to ignore bad file
    descriptor errors, otherwise the fdwalk call always fail.
    
    Fixes: https://gitlab.gnome.org/GNOME/vte/-/issues/245

 src/spawn.cc | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/spawn.cc b/src/spawn.cc
index 8abee1a1..354af8fe 100644
--- a/src/spawn.cc
+++ b/src/spawn.cc
@@ -54,8 +54,15 @@ static int
 set_cloexec_cb(void* data,
                int fd)
 {
-        if (fd >= *reinterpret_cast<int*>(data))
-                return vte::libc::fd_set_cloexec(fd);
+        if (fd >= *reinterpret_cast<int*>(data)) {
+                auto r = vte::libc::fd_set_cloexec(fd);
+                /* Ignore EBADF because the libc or fallback implementation
+                 * of fdwalk may call this function on invalid file descriptors.
+                 */
+                if (r < 0 && errno == EBADF)
+                        r = 0;
+                return r;
+        }
         return 0;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]