char *prefix2;
assert(s);
+ assert(f);
prefix2 = strappend(prefix, "\t");
if (!prefix2)
if (state != SOCKET_LISTENING)
socket_unwatch_fds(s);
- log_debug("%s changing %s → %s", unit_id(UNIT(s)), state_string_table[old_state], state_string_table[state]);
+ log_debug("%s changed %s → %s", unit_id(UNIT(s)), state_string_table[old_state], state_string_table[state]);
unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state]);
}
if (!success)
s->failure = true;
- if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST])) {
-
+ if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST]))
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
- socket_set_state(s, SOCKET_STOP_POST);
- } else
+ socket_set_state(s, SOCKET_STOP_POST);
+
+ if (!s->control_command)
socket_enter_dead(s, true);
return;
r = -errno;
goto fail;
}
+ }
- socket_set_state(s, state);
- } else
+ socket_set_state(s, state);
+
+ if (s->control_pid <= 0)
socket_enter_dead(s, true);
return;
if (!success)
s->failure = true;
- if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE])) {
-
+ if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE]))
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
- socket_set_state(s, SOCKET_STOP_PRE);
- } else
+ socket_set_state(s, SOCKET_STOP_PRE);
+
+ if (!s->control_command)
socket_enter_stop_post(s, true);
return;
socket_enter_stop_post(s, false);
}
+static void socket_enter_listening(Socket *s) {
+ int r;
+ assert(s);
+
+ if ((r = socket_watch_fds(s)) < 0) {
+ log_warning("%s failed to watch sockets: %s", unit_id(UNIT(s)), strerror(-r));
+ goto fail;
+ }
+
+ socket_set_state(s, SOCKET_LISTENING);
+ return;
+
+fail:
+ socket_enter_stop_pre(s, false);
+}
+
static void socket_enter_start_post(Socket *s) {
int r;
assert(s);
- if ((r = socket_open_fds(s)) < 0 ||
- (r = socket_watch_fds(s)) < 0) {
+ if ((r = socket_open_fds(s)) < 0) {
log_warning("%s failed to listen on sockets: %s", unit_id(UNIT(s)), strerror(-r));
goto fail;
}
- if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) {
-
+ if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST]))
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0) {
log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s)), strerror(-r));
goto fail;
}
- socket_set_state(s, SOCKET_START_POST);
- } else
- socket_set_state(s, SOCKET_LISTENING);
+ socket_set_state(s, SOCKET_START_POST);
+
+ if (!s->control_command)
+ socket_enter_listening(s);
return;
int r;
assert(s);
- if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE])) {
-
+ if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE]))
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
- socket_set_state(s, SOCKET_START_PRE);
- } else
+ socket_set_state(s, SOCKET_START_PRE);
+
+ if (!s->control_command)
socket_enter_start_post(s);
return;
assert(s);
- log_info("Incoming traffic on %s", unit_id(u));
+ log_debug("Incoming traffic on %s", unit_id(u));
if (events != POLLIN)
socket_enter_stop_pre(s, false);
assert(s);
assert(pid >= 0);
- success = code == CLD_EXITED || status == 0;
+ success = code == CLD_EXITED && status == 0;
s->failure = s->failure || !success;
assert(s->control_pid == pid);
/* No further commands for this step, so let's figure
* out what to do next */
- log_debug("%s finished with state %s", unit_id(u), state_string_table[s->state]);
+ log_debug("%s got final SIGCHLD for state %s", unit_id(u), state_string_table[s->state]);
switch (s->state) {
case SOCKET_START_POST:
if (success)
- socket_set_state(s, SOCKET_LISTENING);
+ socket_enter_listening(s);
else
socket_enter_stop_pre(s, false);
break;
return 0;
}
+void socket_notify_service_dead(Socket *s) {
+ assert(s);
+
+ /* The service is dead. Dang. */
+
+ if (s->state == SOCKET_RUNNING) {
+ log_debug("%s got notified about service death.", unit_id(UNIT(s)));
+ socket_enter_listening(s);
+ }
+}
+
const UnitVTable socket_vtable = {
.suffix = ".socket",