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

When manually marking service status, use SIGUSR1 to skip default. #746

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mark_service/mark_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv)
if (ok && svcname && strcmp(svcname, service) == 0) {
openrc_pid = getenv("RC_OPENRC_PID");
if (openrc_pid && sscanf(openrc_pid, "%d", &pid) == 1)
if (kill(pid, SIGHUP) != 0)
if (kill(pid, SIGUSR1) != 0)
eerror("%s: failed to signal parent %d: %s",
applet, pid, strerror(errno));

Expand Down
23 changes: 16 additions & 7 deletions src/openrc-run/openrc-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static RC_STRINGLIST *use_services;
static RC_STRINGLIST *want_services;
static RC_HOOK hook_out;
static int exclusive_fd = -1, master_tty = -1;
static bool sighup, in_background, deps, dry_run;
static bool sighup, skip_mark, in_background, deps, dry_run;
static pid_t service_pid;
static int signal_pipe[2] = { -1, -1 };

Expand All @@ -117,6 +117,10 @@ handle_signal(int sig)
sighup = true;
break;

case SIGUSR1:
skip_mark = true;
break;

case SIGCHLD:
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
if (signal_pipe[1] > -1 && pid == service_pid) {
Expand Down Expand Up @@ -802,6 +806,7 @@ static void svc_start_real(void)
setenv("IN_BACKGROUND", ibsave, 1);
hook_out = RC_HOOK_SERVICE_START_DONE;
rc_plugin_run(RC_HOOK_SERVICE_START_NOW, applet);
skip_mark = false;
started = (svc_exec("start", NULL) == 0);
if (ibsave)
unsetenv("IN_BACKGROUND");
Expand All @@ -811,7 +816,8 @@ static void svc_start_real(void)
else if (!started)
eerrorx("ERROR: %s failed to start", applet);

rc_service_mark(service, RC_SERVICE_STARTED);
if (!skip_mark)
rc_service_mark(service, RC_SERVICE_STARTED);
exclusive_fd = svc_unlock(applet, exclusive_fd);
hook_out = RC_HOOK_SERVICE_START_OUT;
rc_plugin_run(RC_HOOK_SERVICE_START_DONE, applet);
Expand Down Expand Up @@ -1008,18 +1014,20 @@ svc_stop_real(void)
setenv("IN_BACKGROUND", ibsave, 1);
hook_out = RC_HOOK_SERVICE_STOP_DONE;
rc_plugin_run(RC_HOOK_SERVICE_STOP_NOW, applet);
skip_mark = false;
stopped = (svc_exec("stop", NULL) == 0);
if (ibsave)
unsetenv("IN_BACKGROUND");

if (!stopped)
eerrorx("ERROR: %s failed to stop", applet);

if (in_background)
rc_service_mark(service, RC_SERVICE_INACTIVE);
else
rc_service_mark(service, RC_SERVICE_STOPPED);

if (!skip_mark) {
if (in_background)
rc_service_mark(service, RC_SERVICE_INACTIVE);
else
rc_service_mark(service, RC_SERVICE_STOPPED);
}
hook_out = RC_HOOK_SERVICE_STOP_OUT;
rc_plugin_run(RC_HOOK_SERVICE_STOP_DONE, applet);
hook_out = 0;
Expand Down Expand Up @@ -1275,6 +1283,7 @@ int main(int argc, char **argv)

/* Setup a signal handler */
signal_setup(SIGHUP, handle_signal);
signal_setup(SIGUSR1, handle_signal);
signal_setup(SIGINT, handle_signal);
signal_setup(SIGQUIT, handle_signal);
signal_setup(SIGTERM, handle_signal);
Expand Down
Loading