X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fservice.c;h=5d82e9b545172516147b59956ac8e386bfd64852;hp=4f0375465986680f6be34e911f7e712b327dbaed;hb=2e9d6c1251abc0af9aa5bc53610bd522d55be776;hpb=feae8adb848e26110b28a06d1244e02f36cdf382 diff --git a/src/core/service.c b/src/core/service.c index 4f0375465..5d82e9b54 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -2436,7 +2436,16 @@ static int service_start(Unit *u) { s->state == SERVICE_START_POST) return 0; - assert(s->state == SERVICE_DEAD || s->state == SERVICE_FAILED || s->state == SERVICE_AUTO_RESTART); + /* A service that will be restarted must be stopped first to + * trigger BindTo and/or OnFailure dependencies. If a user + * does not want to wait for the holdoff time to elapse, the + * service should be manually restarted, not started. */ + if (s->state == SERVICE_AUTO_RESTART) { + log_warning("%s automatic restart is pending, must be stopped before issuing start request.", UNIT(s)->id); + return -ECANCELED; + } + + assert(s->state == SERVICE_DEAD || s->state == SERVICE_FAILED); /* Make sure we don't enter a busy loop of some kind. */ r = service_start_limit_test(s); @@ -2460,8 +2469,7 @@ static int service_stop(Unit *u) { assert(s); - /* This is a user request, so don't do restarts on this - * shutdown. */ + /* Don't create restart jobs from here. */ s->forbid_restart = true; /* Already on it */ @@ -2473,9 +2481,9 @@ static int service_stop(Unit *u) { s->state == SERVICE_FINAL_SIGKILL) return 0; - /* Don't allow a restart */ + /* A restart will be scheduled or is in progress. */ if (s->state == SERVICE_AUTO_RESTART) { - service_set_state(s, SERVICE_DEAD); + service_enter_dead(s, SERVICE_SUCCESS, false); return 0; }