From 34b7632d1d2ed38c7251ac8c2869c8fc416a99f5 Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Sat, 31 Dec 2011 03:35:32 +0100 Subject: 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 --- src/rc/runscript.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/rc/runscript.c b/src/rc/runscript.c index cd53b34..2f66971 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -821,7 +821,7 @@ svc_start(void) svc_start_real(); } -static void +static int svc_stop_check(RC_SERVICE *state) { *state = rc_service_state(service); @@ -848,7 +848,7 @@ svc_stop_check(RC_SERVICE *state) if (*state & RC_SERVICE_STOPPED) { ewarn("WARNING: %s is already stopped", applet); - exit(EXIT_SUCCESS); + return 1; } 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)) ewarn("WARNING: you are stopping a boot service"); } + + return 0; } static void @@ -986,7 +988,7 @@ svc_stop_real(void) rc_plugin_run(RC_HOOK_SERVICE_STOP_OUT, applet); } -static void +static int svc_stop(void) { RC_SERVICE state; @@ -995,13 +997,16 @@ svc_stop(void) if (dry_run) einfon("stop:"); else - svc_stop_check(&state); + if (svc_stop_check(&state) == 1) + return 1; /* Service has been stopped already */ if (deps) svc_stop_deps(state); if (dry_run) printf(" %s\n", applet); else svc_stop_real(); + + return 0; } static void @@ -1351,7 +1356,8 @@ runscript(int argc, char **argv) } if (deps && in_background) get_started_services(); - svc_stop(); + if (svc_stop() == 1) + continue; /* Service has been stopped already */ if (deps) { if (!in_background && !rc_runlevel_stopping() && -- cgit v1.2.3