diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2012-03-05 22:47:54 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2012-03-05 22:47:54 +0100 |
commit | c2f3480897b51dd9b2137f1eeddb4c851e9c6e3b (patch) | |
tree | 0b67acba3f0705b4e78c1d1643785ea6b223d56d /src | |
parent | 82bdec0d65e38333286ae025e5d1aae29b8463f5 (diff) |
socket: fail the socket if the service keeps dying on start
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/service.c | 10 | ||||
-rw-r--r-- | src/socket.c | 12 | ||||
-rw-r--r-- | src/socket.h | 3 |
3 files changed, 16 insertions, 9 deletions
diff --git a/src/service.c b/src/service.c index ec2725a7ba..5764f5f842 100644 --- a/src/service.c +++ b/src/service.c @@ -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; diff --git a/src/socket.c b/src/socket.c index 15a517bed7..6bcc1297f0 100644 --- a/src/socket.c +++ b/src/socket.c @@ -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); diff --git a/src/socket.h b/src/socket.h index d242796a31..1f4f23c964 100644 --- a/src/socket.h +++ b/src/socket.h @@ -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 */ |