On Sun, Sep 25, 2022 at 2:09 AM Martin Dorey <martin.do...@hitachivantara.com> wrote: > And vfork is where that happens. If I’ve followed the thicket of #ifdef > correctly and understood the vfork man page, then this is illegal when using > vfork: > > https://github.com/mirror/make/blob/master/src/job.c#L2556
Thanks, Martin. This is indeed the culprit. I was able to find a linux where this reproduces. However, the this does this reproduce on my sun. Denis, can you please try this patch on your sun? regards, Dmitry Here is a patch index d12a9138..1ed71f0a 100644 --- a/src/job.c +++ b/src/job.c @@ -2286,6 +2286,8 @@ child_execute_job (struct childbase *child, int good_stdin, char **argv) posix_spawnattr_t attr; posix_spawn_file_actions_t fa; short flags = 0; +#else + char **parent_environ = environ; #endif /* Divert child output if we want to capture it. */ @@ -2301,7 +2303,12 @@ child_execute_job (struct childbase *child, int good_stdin, char **argv) pid = vfork(); if (pid != 0) + { + /* The child sets environ to child->environment before calling execvp. + * Restore it here. */ + environ = parent_environ; return pid; + } /* We are the child. */ unblock_all_sigs (); @@ -2552,7 +2559,8 @@ exec_command (char **argv, char **envp) errno = ENOEXEC; # else - /* Run the program. */ + /* Run the program. + * The parent has to restore environ. */ environ = envp; execvp (argv[0], argv);