Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Allow to spawn a process as a session leader on UNIX #26470

Merged
merged 1 commit into from
Aug 4, 2015

Conversation

l0kod
Copy link
Contributor

@l0kod l0kod commented Jun 21, 2015

Add a new method CommandExt::session_leader(&mut self, on: bool) to create a new session (cf. setsid(2)) for the child process. This means that the child is the leader of a new process group. The parent process remains the child reaper of the new process.

This is not enough to create a daemon process. The init process should be the child reaper of a daemon. This can be achieved if the parent process exit. Moreover, a daemon should not have a controlling terminal. To acheive this, a session leader (the child) must spawn another process (the daemon) in the same session.

cc rust-lang/rfcs#941
cc #17176

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@l0kod
Copy link
Contributor Author

l0kod commented Jun 21, 2015

cc @aturon
cc @alexcrichton

@alexcrichton
Copy link
Member

I don't believe that we want to insta-stabilize this method, but I think it's fine to expose the functionality. I'd also prefer to see if there's a cross-platform interpretation with the CREATE_NEW_PROCESS_GROUP flag on windows, as it may be nice to not bundle this in a unix-only extension trait.

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jun 21, 2015
@alexcrichton alexcrichton added the I-needs-decision Issue: In need of a decision. label Jul 15, 2015
@alexcrichton
Copy link
Member

Sorry for the delay @l0kod, but the libs team convened this week and decided that we'd like to move forward on this, but with an #[unstable] tag instead of a stable one. Could you update with that? THanks!

@alexcrichton alexcrichton removed the I-needs-decision Issue: In need of a decision. label Jul 29, 2015
@l0kod l0kod force-pushed the process-session-leader branch 2 times, most recently from df68ce8 to 743236d Compare August 1, 2015 16:44
@l0kod
Copy link
Contributor Author

l0kod commented Aug 4, 2015

Is it OK now ? I added a new feature gate "process_session_leader".

@alexcrichton
Copy link
Member

@bors: r+ b3df1e6

Thanks!

@bors
Copy link
Contributor

bors commented Aug 4, 2015

⌛ Testing commit b3df1e6 with merge 6afb8f5...

bors added a commit that referenced this pull request Aug 4, 2015
Add a new method `CommandExt::session_leader(&mut self, on: bool)` to create a new session (cf. `setsid(2)`) for the child process. This means that the child is the leader of a new process group. The parent process remains the child reaper of the new process.

This is not enough to create a daemon process. The *init* process should be the child reaper of a daemon. This can be achieved if the parent process exit. Moreover, a daemon should not have a controlling terminal. To acheive this, a session leader (the child) must spawn another process (the daemon) in the same session.

cc rust-lang/rfcs#941
cc #17176
@bors bors merged commit b3df1e6 into rust-lang:master Aug 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants