Do not exit immediately when a service has been stopped already

The old behaviour was to exit(EXIT_SUCCESS) in case the service has been stopped
already, even if further commands has been passed to the init script
(like zap, start).
So using for example /etc/init.d/foo stop zap start would abort immediately
after "stop" if the service has been stopped already. Though there may be cases
were we need it to proceed with the remaining commands, zap and start in this
case.
This patch fixes the behaviour to continue and proceed with the remaining
commands whenever necessary.

X-Gentoo-Bug: 371845
X-Gentoo-Bug-URL: https://bugs.gentoo.org/371845
This commit is contained in:
Christian Ruppert 2011-12-31 03:35:32 +01:00
parent fb8db18d79
commit 34b7632d1d

View File

@ -821,7 +821,7 @@ svc_start(void)
svc_start_real(); svc_start_real();
} }
static void static int
svc_stop_check(RC_SERVICE *state) svc_stop_check(RC_SERVICE *state)
{ {
*state = rc_service_state(service); *state = rc_service_state(service);
@ -848,7 +848,7 @@ svc_stop_check(RC_SERVICE *state)
if (*state & RC_SERVICE_STOPPED) { if (*state & RC_SERVICE_STOPPED) {
ewarn("WARNING: %s is already stopped", applet); ewarn("WARNING: %s is already stopped", applet);
exit(EXIT_SUCCESS); return 1;
} }
rc_service_mark(service, RC_SERVICE_STOPPING); rc_service_mark(service, RC_SERVICE_STOPPING);
@ -861,6 +861,8 @@ svc_stop_check(RC_SERVICE *state)
else if (rc_service_in_runlevel(service, RC_LEVEL_BOOT)) else if (rc_service_in_runlevel(service, RC_LEVEL_BOOT))
ewarn("WARNING: you are stopping a boot service"); ewarn("WARNING: you are stopping a boot service");
} }
return 0;
} }
static void static void
@ -986,7 +988,7 @@ svc_stop_real(void)
rc_plugin_run(RC_HOOK_SERVICE_STOP_OUT, applet); rc_plugin_run(RC_HOOK_SERVICE_STOP_OUT, applet);
} }
static void static int
svc_stop(void) svc_stop(void)
{ {
RC_SERVICE state; RC_SERVICE state;
@ -995,13 +997,16 @@ svc_stop(void)
if (dry_run) if (dry_run)
einfon("stop:"); einfon("stop:");
else else
svc_stop_check(&state); if (svc_stop_check(&state) == 1)
return 1; /* Service has been stopped already */
if (deps) if (deps)
svc_stop_deps(state); svc_stop_deps(state);
if (dry_run) if (dry_run)
printf(" %s\n", applet); printf(" %s\n", applet);
else else
svc_stop_real(); svc_stop_real();
return 0;
} }
static void static void
@ -1351,7 +1356,8 @@ runscript(int argc, char **argv)
} }
if (deps && in_background) if (deps && in_background)
get_started_services(); get_started_services();
svc_stop(); if (svc_stop() == 1)
continue; /* Service has been stopped already */
if (deps) { if (deps) {
if (!in_background && if (!in_background &&
!rc_runlevel_stopping() && !rc_runlevel_stopping() &&