public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: Ian Lance Taylor <iant@golang.org>
Subject: [PATCH] Handle jobserver file descriptors in btest.
Date: Thu, 21 Oct 2021 09:47:36 +0200	[thread overview]
Message-ID: <88d036b7-5304-3673-318f-2ebc159c8b16@suse.cz> (raw)

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


             reply	other threads:[~2021-10-21  7:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21  7:47 Martin Liška [this message]
2021-10-21 18:15 ` Ian Lance Taylor
2021-10-22  8:15   ` Martin Liška
2021-10-22 17:32     ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88d036b7-5304-3673-318f-2ebc159c8b16@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iant@golang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).