> diff --git a/gcc/gcc.c b/gcc/gcc.c
> index a4323eb146e..e43f46246ad 100644
> --- a/gcc/gcc.c
> +++ b/gcc/gcc.c
> @@ -8268,6 +8268,44 @@ driver::maybe_run_linker (const char *argv0) const
>      {
>        int tmp = execution_count;
>  
> +      /* Detect jobserver and drop it if it's not working.  */
> +      const char *makeflags = env.get ("MAKEFLAGS");
> +      if (makeflags != NULL)
> +     {
> +       const char *needle = "--jobserver-auth=";
> +       const char *n = strstr (makeflags, needle);
> +       if (n != NULL)
> +         {
> +           int rfd = -1;
> +           int wfd = -1;
> +
> +           bool jobserver
> +             = ((sscanf(n, "--jobserver-auth=%d,%d", &rfd, &wfd) == 2)
> +                && rfd > 0
> +                && wfd > 0
> +                && fcntl (rfd, F_GETFD) >= 0
> +                && fcntl (wfd, F_GETFD) >= 0);

Yes, I suppose this is the test whether file descriptors are open that
should work in our context.

Honza
> +
> +           /* Drop the jobserver if it's not working now.  */
> +           if (!jobserver)
> +             {
> +               unsigned offset = n - makeflags;
> +               char *dup = xstrdup (makeflags);
> +               dup[offset] = '\0';
> +
> +               const char *space = strchr (makeflags + offset, ' ');
> +               if (space != NULL)
> +                 strcpy (dup + offset, space);
> +               xputenv (concat ("MAKEFLAGS=", dup, NULL));
> +
> +               // TODO: remove
> +               FILE *f = fopen ("/tmp/111x", "a"); 
> +               fprintf (f, "dropping MAKEFLAGS\n"); 
> +               fclose (f); 
> +             }
> +         }
> +     }
> +
>        if (! have_c)
>       {
>  #if HAVE_LTO_PLUGIN > 0
> diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
> index 353187c6043..10b74d84af7 100644
> --- a/gcc/lto-wrapper.c
> +++ b/gcc/lto-wrapper.c
> @@ -1430,6 +1430,13 @@ run_gcc (unsigned argc, char *argv[])
>        jobserver or number of cores.  */
>        auto_parallel = 1;
>        jobserver = jobserver_active_p ();
> +
> +FILE *f = fopen ("/tmp/111x", "a"); 
> +fprintf (f, "%d %s\n", jobserver, getenv ("MAKEFLAGS")); 
> +fclose (f); 
> +char buf[1024]; 
> +sprintf (buf, "ls -l /proc/%d/fd >> /tmp/111x", getpid ()); 
> +system (buf); 
>      }
>  
>    if (linker_output)

Reply via email to