chiark / gitweb /
service: allow immediate stopping while starting
authorLennart Poettering <lennart@poettering.net>
Sat, 10 Jul 2010 02:52:00 +0000 (04:52 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 10 Jul 2010 02:52:00 +0000 (04:52 +0200)
src/mount.c
src/service.c
src/socket.c

index bff956e..30390de 100644 (file)
@@ -806,23 +806,20 @@ static int mount_stop(Unit *u) {
 
         assert(m);
 
-        /* Cann't do this right now. */
-        if (m->state == MOUNT_MOUNTING ||
-            m->state == MOUNT_MOUNTING_DONE ||
-            m->state == MOUNT_MOUNTING_SIGTERM ||
-            m->state == MOUNT_MOUNTING_SIGKILL ||
-            m->state == MOUNT_REMOUNTING ||
-            m->state == MOUNT_REMOUNTING_SIGTERM ||
-            m->state == MOUNT_REMOUNTING_SIGKILL)
-                return -EAGAIN;
-
         /* Already on it */
         if (m->state == MOUNT_UNMOUNTING ||
             m->state == MOUNT_UNMOUNTING_SIGKILL ||
             m->state == MOUNT_UNMOUNTING_SIGTERM)
                 return 0;
 
-        assert(m->state == MOUNT_MOUNTED);
+        assert(m->state == MOUNT_MOUNTING ||
+               m->state == MOUNT_MOUNTING_DONE ||
+               m->state == MOUNT_MOUNTED ||
+               m->state == MOUNT_MOUNTING_SIGTERM ||
+               m->state == MOUNT_MOUNTING_SIGKILL ||
+               m->state == MOUNT_REMOUNTING ||
+               m->state == MOUNT_REMOUNTING_SIGTERM ||
+               m->state == MOUNT_REMOUNTING_SIGKILL);
 
         mount_enter_unmounting(m, true);
         return 0;
index fc773d2..b837cb8 100644 (file)
@@ -1902,12 +1902,9 @@ static int service_stop(Unit *u) {
 
         assert(s);
 
-        /* Cannot do this now */
-        if (s->state == SERVICE_START_PRE ||
-            s->state == SERVICE_START ||
-            s->state == SERVICE_START_POST ||
-            s->state == SERVICE_RELOAD)
-                return -EAGAIN;
+        /* This is a user request, so don't do restarts on this
+         * shutdown. */
+        s->allow_restart = false;
 
         /* Already on it */
         if (s->state == SERVICE_STOP ||
@@ -1918,16 +1915,24 @@ static int service_stop(Unit *u) {
             s->state == SERVICE_FINAL_SIGKILL)
                 return 0;
 
+        /* Don't allow a restart */
         if (s->state == SERVICE_AUTO_RESTART) {
                 service_set_state(s, SERVICE_DEAD);
                 return 0;
         }
 
-        assert(s->state == SERVICE_RUNNING || s->state == SERVICE_EXITED);
+        /* If there's already something running we go directly into
+         * kill mode. */
+        if (s->state == SERVICE_START_PRE ||
+            s->state == SERVICE_START ||
+            s->state == SERVICE_START_POST ||
+            s->state == SERVICE_RELOAD) {
+                service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
+                return 0;
+        }
 
-        /* This is a user request, so don't do restarts on this
-         * shutdown. */
-        s->allow_restart = false;
+        assert(s->state == SERVICE_RUNNING ||
+               s->state == SERVICE_EXITED);
 
         service_enter_stop(s, true);
         return 0;
index 6cbb141..7ff2927 100644 (file)
@@ -1166,21 +1166,23 @@ static int socket_stop(Unit *u) {
 
         assert(s);
 
-        /* We cannot fulfill this request right now, try again later
-         * please! */
-        if (s->state == SOCKET_START_PRE ||
-            s->state == SOCKET_START_POST)
-                return -EAGAIN;
-
         /* Already on it */
         if (s->state == SOCKET_STOP_PRE ||
             s->state == SOCKET_STOP_PRE_SIGTERM ||
             s->state == SOCKET_STOP_PRE_SIGKILL ||
             s->state == SOCKET_STOP_POST ||
             s->state == SOCKET_FINAL_SIGTERM ||
-            s->state == SOCKET_FINAL_SIGTERM)
+            s->state == SOCKET_FINAL_SIGKILL)
                 return 0;
 
+        /* If there's already something running we go directly into
+         * kill mode. */
+        if (s->state == SOCKET_START_PRE ||
+            s->state == SOCKET_START_POST) {
+                socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, true);
+                return -EAGAIN;
+        }
+
         assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
 
         socket_enter_stop_pre(s, true);