Skip to content

unix: use async-signal-safe functions between fork and exec#1167

Closed
jBarz wants to merge 2 commits intolibuv:v1.xfrom
jBarz:v1.x-fork
Closed

unix: use async-signal-safe functions between fork and exec#1167
jBarz wants to merge 2 commits intolibuv:v1.xfrom
jBarz:v1.x-fork

Conversation

@jBarz
Copy link
Copy Markdown
Contributor

@jBarz jBarz commented Dec 12, 2016

From the manual for fork

After a fork() in a multithreaded program, the child can safely call only async-signal-safe functions (see signal(7)) until such time as it calls execve(2).

So we should force uv__process_child_init to use

  • fcntl instead of ioctl
  • execve instead of execvp

I tested this on linux x86 and z/OS. Other posix compliant operating systems should also work.

Comment thread src/unix/process.c Outdated

execvp(options->file, options->args);
execve(options->file, options->args,
options->env != NULL ? options->env : environ);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execve() doesn't search the PATH like execvp() does. I realize it may be more POSIX-compliant but it would break a lot of existing code for mostly academic reasons. We rely on the platform's libc to implement execvp() properly and they all do.

The other change looks fine to me.

@saghul
Copy link
Copy Markdown
Member

saghul commented Dec 13, 2016

For reference: #998

Copy link
Copy Markdown
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

For reference: #998

Hah, completely forgot I'd filed that.

Thinking about it again, I don't know if simulating execvp() by calling getenv("PATH") before forking is really better - it's not MT-safe. After the fork you can at least be sure you are the only thread left.

(On the other hand, if another thread was halfway done updating an environment variable, the environment can be in an inconsistent state. Threads and fork, it's all terrible.)

@saghul
Copy link
Copy Markdown
Member

saghul commented Dec 13, 2016

I'm fine either way :-) We can probably close it after this lands with a backreference?

@bnoordhuis
Copy link
Copy Markdown
Member

@santigimeno
Copy link
Copy Markdown
Member

saghul pushed a commit that referenced this pull request Jan 18, 2017
Refs: #998
PR-URL: #1167
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
@saghul
Copy link
Copy Markdown
Member

saghul commented Jan 18, 2017

Landed in 4499336, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants