public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Handle jobserver file descriptors in btest.
@ 2021-10-21  7:47 Martin Liška
  2021-10-21 18:15 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2021-10-21  7:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ian Lance Taylor

Hi.

The patch is about sensitive handling of file descriptors opened
by make's jobserver.

Ready for master?
Thanks,
Martin

	PR testsuite/102742

libbacktrace/ChangeLog:

	* btest.c (check_open_files): Ignore file descriptors provided
	by jobserver.
---
  libbacktrace/btest.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)

diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c
index 9f9c03babf3..a1ea93728be 100644
--- a/libbacktrace/btest.c
+++ b/libbacktrace/btest.c
@@ -464,9 +464,25 @@ static void
  check_open_files (void)
  {
    int i;
+  int rfd = -1;
+  int wfd = -1;
+
+#define JS_NEEDLE "--jobserver-auth="
+
+  /* Ignore file descriptors provided by jobserver.  */
+  const char *makeflags = getenv ("MAKEFLAGS");
+  if (makeflags != NULL)
+    {
+      const char *n = strstr (makeflags, JS_NEEDLE);
+      if (n != NULL)
+	sscanf (n + strlen (JS_NEEDLE), "%d,%d", &rfd, &wfd);
+    }
  
    for (i = 3; i < 10; i++)
      {
+      if (i == rfd || i == wfd)
+	continue;
+
        if (close (i) == 0)
  	{
  	  fprintf (stderr,
-- 
2.33.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-22 17:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21  7:47 [PATCH] Handle jobserver file descriptors in btest Martin Liška
2021-10-21 18:15 ` Ian Lance Taylor
2021-10-22  8:15   ` Martin Liška
2021-10-22 17:32     ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).