X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=socket.c;h=f387ebed866a6bb407f0e77110ab778249ec93d6;hb=5e94833f4193890f27b30591965970627d645247;hp=00994daa2907c438e1703a2315efefdf22615ccb;hpb=e537352b9bfffe6f6286483bff2c7601c78407e3;p=elogind.git diff --git a/socket.c b/socket.c index 00994daa2..f387ebed8 100644 --- a/socket.c +++ b/socket.c @@ -63,6 +63,16 @@ static const char* const state_string_table[_SOCKET_STATE_MAX] = { [SOCKET_MAINTAINANCE] = "maintainance" }; +static void socket_unwatch_control_pid(Socket *s) { + assert(s); + + if (s->control_pid <= 0) + return; + + unit_unwatch_pid(UNIT(s), s->control_pid); + s->control_pid = 0; +} + static void socket_done(Unit *u) { Socket *s = SOCKET(u); SocketPort *p; @@ -82,10 +92,7 @@ static void socket_done(Unit *u) { exec_command_free_array(s->exec_command, _SOCKET_EXEC_COMMAND_MAX); s->control_command = NULL; - if (s->control_pid > 0) { - unit_unwatch_pid(u, s->control_pid); - s->control_pid = 0; - } + socket_unwatch_control_pid(s); s->service = NULL; @@ -361,12 +368,7 @@ static void socket_set_state(Socket *s, SocketState state) { state != SOCKET_STOP_POST_SIGTERM && state != SOCKET_STOP_POST_SIGKILL) { unit_unwatch_timer(UNIT(s), &s->timer_watch); - - if (s->control_pid > 0) { - unit_unwatch_pid(UNIT(s), s->control_pid); - s->control_pid = 0; - } - + socket_unwatch_control_pid(s); s->control_command = NULL; } @@ -437,6 +439,8 @@ static void socket_enter_stop_post(Socket *s, bool success) { if (!success) s->failure = true; + socket_unwatch_control_pid(s); + if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST])) if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) goto fail; @@ -506,6 +510,8 @@ static void socket_enter_stop_pre(Socket *s, bool success) { if (!success) s->failure = true; + socket_unwatch_control_pid(s); + if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE])) if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) goto fail; @@ -547,6 +553,8 @@ static void socket_enter_start_post(Socket *s) { goto fail; } + socket_unwatch_control_pid(s); + if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) { log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s)), strerror(-r)); @@ -568,6 +576,8 @@ static void socket_enter_start_pre(Socket *s) { int r; assert(s); + socket_unwatch_control_pid(s); + if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE])) if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) goto fail; @@ -610,6 +620,8 @@ static void socket_run_next(Socket *s, bool success) { if (!success) s->failure = true; + socket_unwatch_control_pid(s); + s->control_command = s->control_command->command_next; if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)