chiark / gitweb /
service: fix auto-restart handling in service_start()
authorDavid Ward <david.ward@ll.mit.edu>
Sun, 29 Apr 2012 13:35:51 +0000 (09:35 -0400)
committerLennart Poettering <lennart@poettering.net>
Mon, 21 May 2012 23:57:21 +0000 (01:57 +0200)
Do not bypass the SERVICE_DEAD/SERVICE_FAILED state by manually issuing
a start job while an automatic restart is pending.

src/core/service.c

index 9512e0e98d3b180cac72161a674bcc82bb11220d..5d82e9b545172516147b59956ac8e386bfd64852 100644 (file)
@@ -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);