[glib: 2/3] gspawn: safe_fdwalk for Solaris 11.4
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 2/3] gspawn: safe_fdwalk for Solaris 11.4
- Date: Mon, 2 Aug 2021 11:35:55 +0000 (UTC)
commit a75ffc51120b328d95df960eb00e2637efb9df65
Author: Casper Dik <casper dik oracle com>
Date: Sun Aug 1 12:45:13 2021 -0700
gspawn: safe_fdwalk for Solaris 11.4
Use F_NEXTFD/F_PREVFD for fdwalk when they are available.
Closes #2429
glib/gspawn.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
---
diff --git a/glib/gspawn.c b/glib/gspawn.c
index c75619c08..3f432a576 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -1444,6 +1444,27 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
#endif
+#if defined(__sun__) && defined(F_PREVFD) && defined(F_NEXTFD)
+/*
+ * Solaris 11.4 has a signal-safe way which allows
+ * us to find all file descriptors in a process.
+ *
+ * fcntl(fd, F_NEXTFD, maxfd)
+ * - returns the first allocated file descriptor <= maxfd > fd.
+ *
+ * fcntl(fd, F_PREVFD)
+ * - return highest allocated file descriptor < fd.
+ */
+
+ open_max = fcntl (INT_MAX, F_PREVFD); /* find the maximum fd */
+ if (open_max < 0) /* No open files */
+ return 0;
+
+ for (fd = -1; (fd = fcntl (fd, F_NEXTFD, open_max)) != -1; )
+ if ((res = cb (data, fd)) != 0 || fd == open_max)
+ break;
+#else
+
#if 0 && defined(HAVE_SYS_RESOURCE_H)
/* Use getrlimit() function provided by the system if it is known to be
* async-signal safe.
@@ -1477,6 +1498,7 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
for (fd = 0; fd < open_max; fd++)
if ((res = cb (data, fd)) != 0)
break;
+#endif
return res;
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]