Handle jobserver file descriptors in btest.
Commit Message
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(+)
Comments
On Thu, Oct 21, 2021 at 12:48 AM Martin Liška <mliska@suse.cz> wrote:
>
> The patch is about sensitive handling of file descriptors opened
> by make's jobserver.
Thanks. I think a better approach would be, at the start of main,
fstat the descriptors up to 10 and record the ones for which fstat
succeeds. Then at the end of main only check the descriptors for
which fstat failed earlier.
I can work on that at some point if you don't want to tackle it.
Ian
On 10/21/21 20:15, Ian Lance Taylor wrote:
> On Thu, Oct 21, 2021 at 12:48 AM Martin Liška <mliska@suse.cz> wrote:
>>
>> The patch is about sensitive handling of file descriptors opened
>> by make's jobserver.
>
> Thanks. I think a better approach would be, at the start of main,
> fstat the descriptors up to 10 and record the ones for which fstat
> succeeds. Then at the end of main only check the descriptors for
> which fstat failed earlier.
Sure, makes sense.
>
> I can work on that at some point if you don't want to tackle it.
I've just done that in the attached patch.
Is it fine?
Thanks,
Martin
>
> Ian
>
On Fri, Oct 22, 2021 at 1:15 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 10/21/21 20:15, Ian Lance Taylor wrote:
> > On Thu, Oct 21, 2021 at 12:48 AM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> The patch is about sensitive handling of file descriptors opened
> >> by make's jobserver.
> >
> > Thanks. I think a better approach would be, at the start of main,
> > fstat the descriptors up to 10 and record the ones for which fstat
> > succeeds. Then at the end of main only check the descriptors for
> > which fstat failed earlier.
>
> Sure, makes sense.
>
> >
> > I can work on that at some point if you don't want to tackle it.
>
> I've just done that in the attached patch.
>
> Is it fine?
This is OK.
Thanks.
Ian
@@ -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,