mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
socket: replace failure boolean by enum
This commit is contained in:
parent
f42806df7d
commit
cfc4eb4cba
@ -58,6 +58,7 @@
|
|||||||
" <property name=\"NConnections\" type=\"u\" access=\"read\"/>\n" \
|
" <property name=\"NConnections\" type=\"u\" access=\"read\"/>\n" \
|
||||||
" <property name=\"MessageQueueMaxMessages\" type=\"x\" access=\"read\"/>\n" \
|
" <property name=\"MessageQueueMaxMessages\" type=\"x\" access=\"read\"/>\n" \
|
||||||
" <property name=\"MessageQueueMessageSize\" type=\"x\" access=\"read\"/>\n" \
|
" <property name=\"MessageQueueMessageSize\" type=\"x\" access=\"read\"/>\n" \
|
||||||
|
" <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
|
||||||
" </interface>\n" \
|
" </interface>\n" \
|
||||||
|
|
||||||
#define INTROSPECTION \
|
#define INTROSPECTION \
|
||||||
@ -83,9 +84,11 @@ const char bus_socket_invalidating_properties[] =
|
|||||||
"ExecStopPost\0"
|
"ExecStopPost\0"
|
||||||
"ControlPID\0"
|
"ControlPID\0"
|
||||||
"NAccepted\0"
|
"NAccepted\0"
|
||||||
"NConnections\0";
|
"NConnections\0"
|
||||||
|
"Result\0";
|
||||||
|
|
||||||
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
|
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
|
||||||
|
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_socket_result, socket_result, SocketResult);
|
||||||
|
|
||||||
static const BusProperty bus_socket_properties[] = {
|
static const BusProperty bus_socket_properties[] = {
|
||||||
{ "BindIPv6Only", bus_socket_append_bind_ipv6_only, "s", offsetof(Socket, bind_ipv6_only) },
|
{ "BindIPv6Only", bus_socket_append_bind_ipv6_only, "s", offsetof(Socket, bind_ipv6_only) },
|
||||||
@ -117,6 +120,7 @@ static const BusProperty bus_socket_properties[] = {
|
|||||||
{ "NAccepted", bus_property_append_unsigned, "u", offsetof(Socket, n_accepted) },
|
{ "NAccepted", bus_property_append_unsigned, "u", offsetof(Socket, n_accepted) },
|
||||||
{ "MessageQueueMaxMessages", bus_property_append_long, "x", offsetof(Socket, mq_maxmsg) },
|
{ "MessageQueueMaxMessages", bus_property_append_long, "x", offsetof(Socket, mq_maxmsg) },
|
||||||
{ "MessageQueueMessageSize", bus_property_append_long, "x", offsetof(Socket, mq_msgsize) },
|
{ "MessageQueueMessageSize", bus_property_append_long, "x", offsetof(Socket, mq_msgsize) },
|
||||||
|
{ "Result", bus_socket_append_socket_result, "s", offsetof(Socket, result) },
|
||||||
{ NULL, }
|
{ NULL, }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2402,9 +2402,9 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
|
|||||||
if (s->status_text)
|
if (s->status_text)
|
||||||
unit_serialize_item(u, f, "status-text", s->status_text);
|
unit_serialize_item(u, f, "status-text", s->status_text);
|
||||||
|
|
||||||
/* There's a minor uncleanliness here: if there are multiple
|
/* FIXME: There's a minor uncleanliness here: if there are
|
||||||
* commands attached here, we will start from the first one
|
* multiple commands attached here, we will start from the
|
||||||
* again */
|
* first one again */
|
||||||
if (s->control_command_id >= 0)
|
if (s->control_command_id >= 0)
|
||||||
unit_serialize_item(u, f, "control-command", service_exec_command_to_string(s->control_command_id));
|
unit_serialize_item(u, f, "control-command", service_exec_command_to_string(s->control_command_id));
|
||||||
|
|
||||||
@ -2693,7 +2693,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|||||||
else if (code == CLD_DUMPED)
|
else if (code == CLD_DUMPED)
|
||||||
f = SERVICE_FAILURE_CORE_DUMP;
|
f = SERVICE_FAILURE_CORE_DUMP;
|
||||||
else
|
else
|
||||||
f = SERVICE_FAILURE_RESOURCES;
|
assert_not_reached("Unknown code");
|
||||||
|
|
||||||
if (s->main_pid == pid) {
|
if (s->main_pid == pid) {
|
||||||
/* Forking services may occasionally move to a new PID.
|
/* Forking services may occasionally move to a new PID.
|
||||||
|
170
src/socket.c
170
src/socket.c
@ -1156,23 +1156,23 @@ fail:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_enter_dead(Socket *s, bool success) {
|
static void socket_enter_dead(Socket *s, SocketResult f) {
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
if (!success)
|
if (f != SOCKET_SUCCESS)
|
||||||
s->failure = true;
|
s->result = f;
|
||||||
|
|
||||||
socket_set_state(s, s->failure ? SOCKET_FAILED : SOCKET_DEAD);
|
socket_set_state(s, s->result != SOCKET_SUCCESS ? SOCKET_FAILED : SOCKET_DEAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_enter_signal(Socket *s, SocketState state, bool success);
|
static void socket_enter_signal(Socket *s, SocketState state, SocketResult f);
|
||||||
|
|
||||||
static void socket_enter_stop_post(Socket *s, bool success) {
|
static void socket_enter_stop_post(Socket *s, SocketResult f) {
|
||||||
int r;
|
int r;
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
if (!success)
|
if (f != SOCKET_SUCCESS)
|
||||||
s->failure = true;
|
s->result = f;
|
||||||
|
|
||||||
socket_unwatch_control_pid(s);
|
socket_unwatch_control_pid(s);
|
||||||
|
|
||||||
@ -1184,24 +1184,24 @@ static void socket_enter_stop_post(Socket *s, bool success) {
|
|||||||
|
|
||||||
socket_set_state(s, SOCKET_STOP_POST);
|
socket_set_state(s, SOCKET_STOP_POST);
|
||||||
} else
|
} else
|
||||||
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, true);
|
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_SUCCESS);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
log_warning("%s failed to run 'stop-post' task: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to run 'stop-post' task: %s", UNIT(s)->id, strerror(-r));
|
||||||
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
|
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_FAILURE_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_enter_signal(Socket *s, SocketState state, bool success) {
|
static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) {
|
||||||
int r;
|
int r;
|
||||||
Set *pid_set = NULL;
|
Set *pid_set = NULL;
|
||||||
bool wait_for_exit = false;
|
bool wait_for_exit = false;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
if (!success)
|
if (f != SOCKET_SUCCESS)
|
||||||
s->failure = true;
|
s->result = f;
|
||||||
|
|
||||||
if (s->exec_context.kill_mode != KILL_NONE) {
|
if (s->exec_context.kill_mode != KILL_NONE) {
|
||||||
int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
|
int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
|
||||||
@ -1243,9 +1243,9 @@ static void socket_enter_signal(Socket *s, SocketState state, bool success) {
|
|||||||
|
|
||||||
socket_set_state(s, state);
|
socket_set_state(s, state);
|
||||||
} else if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
|
} else if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
|
||||||
socket_enter_stop_post(s, true);
|
socket_enter_stop_post(s, SOCKET_SUCCESS);
|
||||||
else
|
else
|
||||||
socket_enter_dead(s, true);
|
socket_enter_dead(s, SOCKET_SUCCESS);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1253,20 +1253,20 @@ fail:
|
|||||||
log_warning("%s failed to kill processes: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to kill processes: %s", UNIT(s)->id, strerror(-r));
|
||||||
|
|
||||||
if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
|
if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
|
||||||
socket_enter_stop_post(s, false);
|
socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES);
|
||||||
else
|
else
|
||||||
socket_enter_dead(s, false);
|
socket_enter_dead(s, SOCKET_FAILURE_RESOURCES);
|
||||||
|
|
||||||
if (pid_set)
|
if (pid_set)
|
||||||
set_free(pid_set);
|
set_free(pid_set);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_enter_stop_pre(Socket *s, bool success) {
|
static void socket_enter_stop_pre(Socket *s, SocketResult f) {
|
||||||
int r;
|
int r;
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
if (!success)
|
if (f != SOCKET_SUCCESS)
|
||||||
s->failure = true;
|
s->result = f;
|
||||||
|
|
||||||
socket_unwatch_control_pid(s);
|
socket_unwatch_control_pid(s);
|
||||||
|
|
||||||
@ -1278,20 +1278,21 @@ static void socket_enter_stop_pre(Socket *s, bool success) {
|
|||||||
|
|
||||||
socket_set_state(s, SOCKET_STOP_PRE);
|
socket_set_state(s, SOCKET_STOP_PRE);
|
||||||
} else
|
} else
|
||||||
socket_enter_stop_post(s, true);
|
socket_enter_stop_post(s, SOCKET_SUCCESS);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
log_warning("%s failed to run 'stop-pre' task: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to run 'stop-pre' task: %s", UNIT(s)->id, strerror(-r));
|
||||||
socket_enter_stop_post(s, false);
|
socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_enter_listening(Socket *s) {
|
static void socket_enter_listening(Socket *s) {
|
||||||
int r;
|
int r;
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
if ((r = socket_watch_fds(s)) < 0) {
|
r = socket_watch_fds(s);
|
||||||
|
if (r < 0) {
|
||||||
log_warning("%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -1300,14 +1301,15 @@ static void socket_enter_listening(Socket *s) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_enter_start_post(Socket *s) {
|
static void socket_enter_start_post(Socket *s) {
|
||||||
int r;
|
int r;
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|
||||||
if ((r = socket_open_fds(s)) < 0) {
|
r = socket_open_fds(s);
|
||||||
|
if (r < 0) {
|
||||||
log_warning("%s failed to listen on sockets: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to listen on sockets: %s", UNIT(s)->id, strerror(-r));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -1317,7 +1319,8 @@ static void socket_enter_start_post(Socket *s) {
|
|||||||
s->control_command_id = SOCKET_EXEC_START_POST;
|
s->control_command_id = SOCKET_EXEC_START_POST;
|
||||||
|
|
||||||
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, &s->control_pid)) < 0) {
|
r = socket_spawn(s, s->control_command, &s->control_pid);
|
||||||
|
if (r < 0) {
|
||||||
log_warning("%s failed to run 'start-post' task: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to run 'start-post' task: %s", UNIT(s)->id, strerror(-r));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -1329,7 +1332,7 @@ static void socket_enter_start_post(Socket *s) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_enter_start_pre(Socket *s) {
|
static void socket_enter_start_pre(Socket *s) {
|
||||||
@ -1352,7 +1355,7 @@ static void socket_enter_start_pre(Socket *s) {
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
log_warning("%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r));
|
||||||
socket_enter_dead(s, false);
|
socket_enter_dead(s, SOCKET_FAILURE_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_enter_running(Socket *s, int cfd) {
|
static void socket_enter_running(Socket *s, int cfd) {
|
||||||
@ -1376,7 +1379,7 @@ static void socket_enter_running(Socket *s, int cfd) {
|
|||||||
r = socket_watch_fds(s);
|
r = socket_watch_fds(s);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_warning("%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r));
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1478,7 +1481,7 @@ static void socket_enter_running(Socket *s, int cfd) {
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
log_warning("%s failed to queue socket startup job: %s", UNIT(s)->id, bus_error(&error, r));
|
log_warning("%s failed to queue socket startup job: %s", UNIT(s)->id, bus_error(&error, r));
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
||||||
|
|
||||||
if (cfd >= 0)
|
if (cfd >= 0)
|
||||||
close_nointr_nofail(cfd);
|
close_nointr_nofail(cfd);
|
||||||
@ -1486,16 +1489,13 @@ fail:
|
|||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_run_next(Socket *s, bool success) {
|
static void socket_run_next(Socket *s) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
assert(s->control_command);
|
assert(s->control_command);
|
||||||
assert(s->control_command->command_next);
|
assert(s->control_command->command_next);
|
||||||
|
|
||||||
if (!success)
|
|
||||||
s->failure = true;
|
|
||||||
|
|
||||||
socket_unwatch_control_pid(s);
|
socket_unwatch_control_pid(s);
|
||||||
|
|
||||||
s->control_command = s->control_command->command_next;
|
s->control_command = s->control_command->command_next;
|
||||||
@ -1509,11 +1509,11 @@ fail:
|
|||||||
log_warning("%s failed to run next task: %s", UNIT(s)->id, strerror(-r));
|
log_warning("%s failed to run next task: %s", UNIT(s)->id, strerror(-r));
|
||||||
|
|
||||||
if (s->state == SOCKET_START_POST)
|
if (s->state == SOCKET_START_POST)
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
||||||
else if (s->state == SOCKET_STOP_POST)
|
else if (s->state == SOCKET_STOP_POST)
|
||||||
socket_enter_dead(s, false);
|
socket_enter_dead(s, SOCKET_FAILURE_RESOURCES);
|
||||||
else
|
else
|
||||||
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
|
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_FAILURE_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int socket_start(Unit *u) {
|
static int socket_start(Unit *u) {
|
||||||
@ -1565,7 +1565,7 @@ static int socket_start(Unit *u) {
|
|||||||
|
|
||||||
assert(s->state == SOCKET_DEAD || s->state == SOCKET_FAILED);
|
assert(s->state == SOCKET_DEAD || s->state == SOCKET_FAILED);
|
||||||
|
|
||||||
s->failure = false;
|
s->result = SOCKET_SUCCESS;
|
||||||
socket_enter_start_pre(s);
|
socket_enter_start_pre(s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1588,13 +1588,13 @@ static int socket_stop(Unit *u) {
|
|||||||
* kill mode. */
|
* kill mode. */
|
||||||
if (s->state == SOCKET_START_PRE ||
|
if (s->state == SOCKET_START_PRE ||
|
||||||
s->state == SOCKET_START_POST) {
|
s->state == SOCKET_START_POST) {
|
||||||
socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, true);
|
socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, SOCKET_SUCCESS);
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
|
assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
|
||||||
|
|
||||||
socket_enter_stop_pre(s, true);
|
socket_enter_stop_pre(s, SOCKET_SUCCESS);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1608,7 +1608,7 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
|
|||||||
assert(fds);
|
assert(fds);
|
||||||
|
|
||||||
unit_serialize_item(u, f, "state", socket_state_to_string(s->state));
|
unit_serialize_item(u, f, "state", socket_state_to_string(s->state));
|
||||||
unit_serialize_item(u, f, "failure", yes_no(s->failure));
|
unit_serialize_item(u, f, "result", socket_result_to_string(s->result));
|
||||||
unit_serialize_item_format(u, f, "n-accepted", "%u", s->n_accepted);
|
unit_serialize_item_format(u, f, "n-accepted", "%u", s->n_accepted);
|
||||||
|
|
||||||
if (s->control_pid > 0)
|
if (s->control_pid > 0)
|
||||||
@ -1663,13 +1663,14 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
|
|||||||
log_debug("Failed to parse state value %s", value);
|
log_debug("Failed to parse state value %s", value);
|
||||||
else
|
else
|
||||||
s->deserialized_state = state;
|
s->deserialized_state = state;
|
||||||
} else if (streq(key, "failure")) {
|
} else if (streq(key, "result")) {
|
||||||
int b;
|
SocketResult f;
|
||||||
|
|
||||||
if ((b = parse_boolean(value)) < 0)
|
f = socket_result_from_string(value);
|
||||||
log_debug("Failed to parse failure value %s", value);
|
if (f < 0)
|
||||||
else
|
log_debug("Failed to parse result value %s", value);
|
||||||
s->failure = b || s->failure;
|
else if (f != SOCKET_SUCCESS)
|
||||||
|
s->result = f;
|
||||||
|
|
||||||
} else if (streq(key, "n-accepted")) {
|
} else if (streq(key, "n-accepted")) {
|
||||||
unsigned k;
|
unsigned k;
|
||||||
@ -1842,12 +1843,12 @@ static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||||
Socket *s = SOCKET(u);
|
Socket *s = SOCKET(u);
|
||||||
bool success;
|
SocketResult f;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
assert(pid >= 0);
|
assert(pid >= 0);
|
||||||
@ -1857,22 +1858,36 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|||||||
|
|
||||||
s->control_pid = 0;
|
s->control_pid = 0;
|
||||||
|
|
||||||
success = is_clean_exit(code, status);
|
if (is_clean_exit(code, status))
|
||||||
|
f = SOCKET_SUCCESS;
|
||||||
|
else if (code == CLD_EXITED)
|
||||||
|
f = SOCKET_FAILURE_EXIT_CODE;
|
||||||
|
else if (code == CLD_KILLED)
|
||||||
|
f = SOCKET_FAILURE_SIGNAL;
|
||||||
|
else if (code == CLD_DUMPED)
|
||||||
|
f = SOCKET_FAILURE_CORE_DUMP;
|
||||||
|
else
|
||||||
|
assert_not_reached("Unknown code");
|
||||||
|
|
||||||
if (s->control_command) {
|
if (s->control_command) {
|
||||||
exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
|
exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
|
||||||
|
|
||||||
if (s->control_command->ignore)
|
if (s->control_command->ignore)
|
||||||
success = true;
|
f = SOCKET_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_full(success ? LOG_DEBUG : LOG_NOTICE,
|
log_full(f == SOCKET_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
|
||||||
"%s control process exited, code=%s status=%i", u->id, sigchld_code_to_string(code), status);
|
"%s control process exited, code=%s status=%i", u->id, sigchld_code_to_string(code), status);
|
||||||
s->failure = s->failure || !success;
|
|
||||||
|
|
||||||
if (s->control_command && s->control_command->command_next && success) {
|
if (f != SOCKET_SUCCESS)
|
||||||
|
s->result = f;
|
||||||
|
|
||||||
|
if (s->control_command &&
|
||||||
|
s->control_command->command_next &&
|
||||||
|
f == SOCKET_SUCCESS) {
|
||||||
|
|
||||||
log_debug("%s running next command for state %s", u->id, socket_state_to_string(s->state));
|
log_debug("%s running next command for state %s", u->id, socket_state_to_string(s->state));
|
||||||
socket_run_next(s, success);
|
socket_run_next(s);
|
||||||
} else {
|
} else {
|
||||||
s->control_command = NULL;
|
s->control_command = NULL;
|
||||||
s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
|
s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
|
||||||
@ -1885,29 +1900,29 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|||||||
switch (s->state) {
|
switch (s->state) {
|
||||||
|
|
||||||
case SOCKET_START_PRE:
|
case SOCKET_START_PRE:
|
||||||
if (success)
|
if (f == SOCKET_SUCCESS)
|
||||||
socket_enter_start_post(s);
|
socket_enter_start_post(s);
|
||||||
else
|
else
|
||||||
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
|
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, f);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_START_POST:
|
case SOCKET_START_POST:
|
||||||
if (success)
|
if (f == SOCKET_SUCCESS)
|
||||||
socket_enter_listening(s);
|
socket_enter_listening(s);
|
||||||
else
|
else
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, f);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_STOP_PRE:
|
case SOCKET_STOP_PRE:
|
||||||
case SOCKET_STOP_PRE_SIGTERM:
|
case SOCKET_STOP_PRE_SIGTERM:
|
||||||
case SOCKET_STOP_PRE_SIGKILL:
|
case SOCKET_STOP_PRE_SIGKILL:
|
||||||
socket_enter_stop_post(s, success);
|
socket_enter_stop_post(s, f);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_STOP_POST:
|
case SOCKET_STOP_POST:
|
||||||
case SOCKET_FINAL_SIGTERM:
|
case SOCKET_FINAL_SIGTERM:
|
||||||
case SOCKET_FINAL_SIGKILL:
|
case SOCKET_FINAL_SIGKILL:
|
||||||
socket_enter_dead(s, success);
|
socket_enter_dead(s, f);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1930,52 +1945,52 @@ static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
|
|||||||
|
|
||||||
case SOCKET_START_PRE:
|
case SOCKET_START_PRE:
|
||||||
log_warning("%s starting timed out. Terminating.", u->id);
|
log_warning("%s starting timed out. Terminating.", u->id);
|
||||||
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
|
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_FAILURE_TIMEOUT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_START_POST:
|
case SOCKET_START_POST:
|
||||||
log_warning("%s starting timed out. Stopping.", u->id);
|
log_warning("%s starting timed out. Stopping.", u->id);
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, SOCKET_FAILURE_TIMEOUT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_STOP_PRE:
|
case SOCKET_STOP_PRE:
|
||||||
log_warning("%s stopping timed out. Terminating.", u->id);
|
log_warning("%s stopping timed out. Terminating.", u->id);
|
||||||
socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, false);
|
socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, SOCKET_FAILURE_TIMEOUT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_STOP_PRE_SIGTERM:
|
case SOCKET_STOP_PRE_SIGTERM:
|
||||||
if (s->exec_context.send_sigkill) {
|
if (s->exec_context.send_sigkill) {
|
||||||
log_warning("%s stopping timed out. Killing.", u->id);
|
log_warning("%s stopping timed out. Killing.", u->id);
|
||||||
socket_enter_signal(s, SOCKET_STOP_PRE_SIGKILL, false);
|
socket_enter_signal(s, SOCKET_STOP_PRE_SIGKILL, SOCKET_FAILURE_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
log_warning("%s stopping timed out. Skipping SIGKILL. Ignoring.", u->id);
|
log_warning("%s stopping timed out. Skipping SIGKILL. Ignoring.", u->id);
|
||||||
socket_enter_stop_post(s, false);
|
socket_enter_stop_post(s, SOCKET_FAILURE_TIMEOUT);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_STOP_PRE_SIGKILL:
|
case SOCKET_STOP_PRE_SIGKILL:
|
||||||
log_warning("%s still around after SIGKILL. Ignoring.", u->id);
|
log_warning("%s still around after SIGKILL. Ignoring.", u->id);
|
||||||
socket_enter_stop_post(s, false);
|
socket_enter_stop_post(s, SOCKET_FAILURE_TIMEOUT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_STOP_POST:
|
case SOCKET_STOP_POST:
|
||||||
log_warning("%s stopping timed out (2). Terminating.", u->id);
|
log_warning("%s stopping timed out (2). Terminating.", u->id);
|
||||||
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
|
socket_enter_signal(s, SOCKET_FINAL_SIGTERM, SOCKET_FAILURE_TIMEOUT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_FINAL_SIGTERM:
|
case SOCKET_FINAL_SIGTERM:
|
||||||
if (s->exec_context.send_sigkill) {
|
if (s->exec_context.send_sigkill) {
|
||||||
log_warning("%s stopping timed out (2). Killing.", u->id);
|
log_warning("%s stopping timed out (2). Killing.", u->id);
|
||||||
socket_enter_signal(s, SOCKET_FINAL_SIGKILL, false);
|
socket_enter_signal(s, SOCKET_FINAL_SIGKILL, SOCKET_FAILURE_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
log_warning("%s stopping timed out (2). Skipping SIGKILL. Ignoring.", u->id);
|
log_warning("%s stopping timed out (2). Skipping SIGKILL. Ignoring.", u->id);
|
||||||
socket_enter_dead(s, false);
|
socket_enter_dead(s, SOCKET_FAILURE_TIMEOUT);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOCKET_FINAL_SIGKILL:
|
case SOCKET_FINAL_SIGKILL:
|
||||||
log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->id);
|
log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->id);
|
||||||
socket_enter_dead(s, false);
|
socket_enter_dead(s, SOCKET_FAILURE_TIMEOUT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -2057,7 +2072,7 @@ static void socket_reset_failed(Unit *u) {
|
|||||||
if (s->state == SOCKET_FAILED)
|
if (s->state == SOCKET_FAILED)
|
||||||
socket_set_state(s, SOCKET_DEAD);
|
socket_set_state(s, SOCKET_DEAD);
|
||||||
|
|
||||||
s->failure = false;
|
s->result = SOCKET_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
|
static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
|
||||||
@ -2133,6 +2148,17 @@ static const char* const socket_exec_command_table[_SOCKET_EXEC_COMMAND_MAX] = {
|
|||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP(socket_exec_command, SocketExecCommand);
|
DEFINE_STRING_TABLE_LOOKUP(socket_exec_command, SocketExecCommand);
|
||||||
|
|
||||||
|
static const char* const socket_result_table[_SOCKET_RESULT_MAX] = {
|
||||||
|
[SOCKET_SUCCESS] = "success",
|
||||||
|
[SOCKET_FAILURE_RESOURCES] = "resources",
|
||||||
|
[SOCKET_FAILURE_TIMEOUT] = "timeout",
|
||||||
|
[SOCKET_FAILURE_EXIT_CODE] = "exit-code",
|
||||||
|
[SOCKET_FAILURE_SIGNAL] = "signal",
|
||||||
|
[SOCKET_FAILURE_CORE_DUMP] = "core-dump"
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_STRING_TABLE_LOOKUP(socket_result, SocketResult);
|
||||||
|
|
||||||
const UnitVTable socket_vtable = {
|
const UnitVTable socket_vtable = {
|
||||||
.suffix = ".socket",
|
.suffix = ".socket",
|
||||||
.object_size = sizeof(Socket),
|
.object_size = sizeof(Socket),
|
||||||
|
16
src/socket.h
16
src/socket.h
@ -65,6 +65,17 @@ typedef enum SocketType {
|
|||||||
_SOCKET_FIFO_INVALID = -1
|
_SOCKET_FIFO_INVALID = -1
|
||||||
} SocketType;
|
} SocketType;
|
||||||
|
|
||||||
|
typedef enum SocketResult {
|
||||||
|
SOCKET_SUCCESS,
|
||||||
|
SOCKET_FAILURE_RESOURCES,
|
||||||
|
SOCKET_FAILURE_TIMEOUT,
|
||||||
|
SOCKET_FAILURE_EXIT_CODE,
|
||||||
|
SOCKET_FAILURE_SIGNAL,
|
||||||
|
SOCKET_FAILURE_CORE_DUMP,
|
||||||
|
_SOCKET_RESULT_MAX,
|
||||||
|
_SOCKET_RESULT_INVALID = -1
|
||||||
|
} SocketResult;
|
||||||
|
|
||||||
typedef struct SocketPort {
|
typedef struct SocketPort {
|
||||||
SocketType type;
|
SocketType type;
|
||||||
int fd;
|
int fd;
|
||||||
@ -107,7 +118,7 @@ struct Socket {
|
|||||||
mode_t directory_mode;
|
mode_t directory_mode;
|
||||||
mode_t socket_mode;
|
mode_t socket_mode;
|
||||||
|
|
||||||
bool failure;
|
SocketResult result;
|
||||||
|
|
||||||
bool accept;
|
bool accept;
|
||||||
|
|
||||||
@ -154,4 +165,7 @@ SocketState socket_state_from_string(const char *s);
|
|||||||
const char* socket_exec_command_to_string(SocketExecCommand i);
|
const char* socket_exec_command_to_string(SocketExecCommand i);
|
||||||
SocketExecCommand socket_exec_command_from_string(const char *s);
|
SocketExecCommand socket_exec_command_from_string(const char *s);
|
||||||
|
|
||||||
|
const char* socket_result_to_string(SocketResult i);
|
||||||
|
SocketResult socket_result_from_string(const char *s);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user