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

Have the parent wait for an exit code from the child during startup, when daemonizing #443

Merged
merged 4 commits into from
Feb 8, 2016

Conversation

lminiero
Copy link
Member

A quick'n'dirty patch to allow for feedback on whether Janus started or not, when daemonizing. A pipe is created, and the parent waits on one end for an exit code before actually exiting: the child either writes a 0 when everything was started correctly, or a 1 when it didn't (currently done in janus_termination_handler).

The patch is much more basic than what @saghul proposed in #408 (no grandparents/grandchildren, for instance, but just the parent/child we already had), but seems to do the job. I'm just puzzled as to how to handle the cases where Janus crashes instead: I thought this would result in the child end of the pipe being closed, and so the poll to exit, but it didn't (the poll keeps waiting), meaning we should handle it accordingly. I guess there are some flags/controls that can be set on the pipe for that, I'll look into it.

Feedback welcome!

/* If we're daemonizing, we send an error code to the parent */
if(daemonize) {
int code = 1;
write(pipefd[1], &code, sizeof(int));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd surround the write with a do - while, which checks if the return code is == -1 and errno is EINTR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks for noticing!

@lminiero lminiero mentioned this pull request Feb 2, 2016
@lminiero
Copy link
Member Author

lminiero commented Feb 8, 2016

This fix (checking POLLERR/POLLHUP) makes the parent aware also when the child crashes, and so fixes the last concern I had. This seems to be working fine for me, so merging as this has been around a while already: there will be time for improving it along the road.

lminiero added a commit that referenced this pull request Feb 8, 2016
Have the parent wait for an exit code from the child during startup, when daemonizing
@lminiero lminiero merged commit 8844162 into master Feb 8, 2016
@lminiero lminiero deleted the daemon-pipe branch February 8, 2016 16:43
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.

None yet

2 participants