-
Notifications
You must be signed in to change notification settings - Fork 273
implement readiness notification #767
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,7 @@ enum { | |
| LONGOPT_SECBITS, | ||
| LONGOPT_STDERR_LOGGER, | ||
| LONGOPT_STDOUT_LOGGER, | ||
| LONGOPT_READY, | ||
| }; | ||
|
|
||
| const char *applet = NULL; | ||
|
|
@@ -116,6 +117,7 @@ const struct option longopts[] = { | |
| { "stdout-logger",1, NULL, LONGOPT_STDOUT_LOGGER}, | ||
| { "stderr-logger",1, NULL, LONGOPT_STDERR_LOGGER}, | ||
| { "reexec", 0, NULL, '3'}, | ||
| { "ready", 1, NULL, LONGOPT_READY}, | ||
| longopts_COMMON | ||
| }; | ||
| const char * const longopts_help[] = { | ||
|
|
@@ -165,6 +167,7 @@ static int devnull_fd = -1; | |
| static int stdin_fd; | ||
| static int stdout_fd; | ||
| static int stderr_fd; | ||
| static struct ready ready; | ||
| static char *redirect_stderr = NULL; | ||
| static char *redirect_stdout = NULL; | ||
| static char *stderr_process = NULL; | ||
|
|
@@ -588,6 +591,9 @@ RC_NORETURN static void child_process(char *exec, char **argv) | |
|
|
||
| cloexec_fds_from(3); | ||
|
|
||
| if (ready.type == READY_FD) | ||
| dup2(ready.pipe[1], ready.fd); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
|
||
| cmdline = make_cmdline(argv); | ||
| syslog(LOG_INFO, "Child command line: %s", cmdline); | ||
| free(cmdline); | ||
|
|
@@ -1070,6 +1076,10 @@ int main(int argc, char **argv) | |
| stderr_process = optarg; | ||
| break; | ||
|
|
||
| case LONGOPT_READY: | ||
| ready = ready_parse(applet, optarg); | ||
| break; | ||
|
|
||
| case_RC_COMMON_GETOPT | ||
| } | ||
|
|
||
|
|
@@ -1207,19 +1217,25 @@ int main(int argc, char **argv) | |
| if (child_pid == -1) | ||
| eerrorx("%s: fork: %s", applet, strerror(errno)); | ||
| if (child_pid != 0) | ||
| /* first parent process, do nothing. */ | ||
| exit(EXIT_SUCCESS); | ||
| exit(ready_wait(applet, ready) ? EXIT_SUCCESS : EXIT_FAILURE); | ||
|
|
||
| #ifdef TIOCNOTTY | ||
| tty_fd = open("/dev/tty", O_RDWR); | ||
| #endif | ||
| devnull_fd = open("/dev/null", O_RDWR); | ||
| dup2(devnull_fd, STDIN_FILENO); | ||
| dup2(devnull_fd, STDOUT_FILENO); | ||
| dup2(devnull_fd, STDERR_FILENO); | ||
|
|
||
| if (ready.type == READY_FD) | ||
| close(ready.pipe[0]); | ||
|
|
||
| child_pid = fork(); | ||
| if (child_pid == -1) | ||
| eerrorx("%s: fork: %s", applet, strerror(errno)); | ||
| else if (child_pid != 0) { | ||
| if (ready.type == READY_FD) | ||
| close(ready.pipe[1]); | ||
| c = argv; | ||
| x = 0; | ||
| while (c && *c) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those don't really matter at this point. if they fail, the daemon can't write the \n, so the supervisor will already be waiting on
readyuntil openrc-run times out and kill itthe best we can do is check and log, if we exit same thing happens, supervisor will start waiting until timeout and s-s-d won't be doing healthchecks
i'd argue for s-s-d it's better to let the exec go through, since then we have a chance of the daemon writing it's pid file so the timeout can kill it cleanly. for s-d that doesn't matter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily. Let's say the ready fd is supposed to be 3 and the dup2 fails. And in the daemon there's code like this:
Now you end up with the deamon potentially writing nonsense elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, i'll add the checks then