]> err.no Git - systemd/commitdiff
socket: fail the socket if the service keeps dying on start
authorMichal Schmidt <mschmidt@redhat.com>
Mon, 5 Mar 2012 21:47:54 +0000 (22:47 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Mon, 5 Mar 2012 21:47:54 +0000 (22:47 +0100)
If the service reaches the start limit, mark the sockets that activate
it as failed (with the result code 'service-broken').
This way the sockets won't act as tarpits for clients connecting to
them.

src/service.c
src/socket.c
src/socket.h

index ec2725a7badb39c98159d22cbbfe960ba5c48d85..5764f5f8423763345e5a0b511df41f0093fabf2f 100644 (file)
@@ -1436,7 +1436,7 @@ static int service_search_main_pid(Service *s) {
         return 0;
 }
 
-static void service_notify_sockets_dead(Service *s) {
+static void service_notify_sockets_dead(Service *s, bool broken) {
         Iterator i;
         Unit *u;
 
@@ -1449,7 +1449,7 @@ static void service_notify_sockets_dead(Service *s) {
 
         SET_FOREACH(u, UNIT(s)->dependencies[UNIT_TRIGGERED_BY], i)
                 if (u->type == UNIT_SOCKET)
-                        socket_notify_service_dead(SOCKET(u));
+                        socket_notify_service_dead(SOCKET(u), broken);
 
         return;
 }
@@ -1511,7 +1511,7 @@ static void service_set_state(Service *s, ServiceState state) {
             state == SERVICE_FINAL_SIGKILL ||
             state == SERVICE_FAILED ||
             state == SERVICE_AUTO_RESTART)
-                service_notify_sockets_dead(s);
+                service_notify_sockets_dead(s, false);
 
         if (state != SERVICE_START_PRE &&
             state != SERVICE_START &&
@@ -2402,8 +2402,10 @@ static int service_start(Unit *u) {
 
         /* Make sure we don't enter a busy loop of some kind. */
         r = service_start_limit_test(s);
-        if (r < 0)
+        if (r < 0) {
+                service_notify_sockets_dead(s, true);
                 return r;
+        }
 
         s->result = SERVICE_SUCCESS;
         s->reload_result = SERVICE_SUCCESS;
index 15a517bed7813aae53ad8b8727f9690d4000a1f4..6bcc1297f0a9e9d29326e6e50bdba2a451884d28 100644 (file)
@@ -2038,7 +2038,7 @@ int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
         return 0;
 }
 
-void socket_notify_service_dead(Socket *s) {
+void socket_notify_service_dead(Socket *s, bool broken) {
         assert(s);
 
         /* The service is dead. Dang!
@@ -2047,8 +2047,11 @@ void socket_notify_service_dead(Socket *s) {
          * services. */
 
         if (s->state == SOCKET_RUNNING) {
-                log_debug("%s got notified about service death.", UNIT(s)->id);
-                socket_enter_listening(s);
+                log_debug("%s got notified about service death (broken: %s)", UNIT(s)->id, yes_no(broken));
+                if (broken)
+                        socket_enter_stop_pre(s, SOCKET_FAILURE_SERVICE_BROKEN);
+                else
+                        socket_enter_listening(s);
         }
 }
 
@@ -2156,7 +2159,8 @@ static const char* const socket_result_table[_SOCKET_RESULT_MAX] = {
         [SOCKET_FAILURE_TIMEOUT] = "timeout",
         [SOCKET_FAILURE_EXIT_CODE] = "exit-code",
         [SOCKET_FAILURE_SIGNAL] = "signal",
-        [SOCKET_FAILURE_CORE_DUMP] = "core-dump"
+        [SOCKET_FAILURE_CORE_DUMP] = "core-dump",
+        [SOCKET_FAILURE_SERVICE_BROKEN] = "service-broken"
 };
 
 DEFINE_STRING_TABLE_LOOKUP(socket_result, SocketResult);
index d242796a31f1beb39f0a469c10b1b5a6fc2db7d0..1f4f23c96458d96c63d12bbdb34c6896c15e9294 100644 (file)
@@ -72,6 +72,7 @@ typedef enum SocketResult {
         SOCKET_FAILURE_EXIT_CODE,
         SOCKET_FAILURE_SIGNAL,
         SOCKET_FAILURE_CORE_DUMP,
+        SOCKET_FAILURE_SERVICE_BROKEN,
         _SOCKET_RESULT_MAX,
         _SOCKET_RESULT_INVALID = -1
 } SocketResult;
@@ -148,7 +149,7 @@ struct Socket {
 int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds);
 
 /* Called from the service when it shut down */
-void socket_notify_service_dead(Socket *s);
+void socket_notify_service_dead(Socket *s, bool broken);
 
 /* Called from the mount code figure out if a mount is a dependency of
  * any of the sockets of this socket */