X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fsocket.c;h=7d052f2ef97808ae2d8e4e1b6757f64207860788;hb=5bd4b173605142c7be493aa4d958ebaef21f421d;hp=8f87ef2e8eacdad4214ee15a4f7769e1cb68330b;hpb=da927ba997d68401563b927f92e6e40e021a8e5c;p=elogind.git diff --git a/src/core/socket.c b/src/core/socket.c index 8f87ef2e8..7d052f2ef 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -19,7 +19,6 @@ along with systemd; If not, see . ***/ -#include #include #include #include @@ -29,12 +28,9 @@ #include #include #include -#include #include "sd-event.h" #include "log.h" -#include "load-dropin.h" -#include "load-fragment.h" #include "strv.h" #include "mkdir.h" #include "path-util.h" @@ -48,6 +44,7 @@ #include "smack-util.h" #include "bus-util.h" #include "bus-error.h" +#include "selinux-util.h" #include "dbus-socket.h" #include "unit.h" #include "socket.h" @@ -265,7 +262,7 @@ static int socket_add_device_link(Socket *s) { if (!s->bind_to_device || streq(s->bind_to_device, "lo")) return 0; - t = strappenda("/sys/subsystem/net/devices/", s->bind_to_device); + t = strjoina("/sys/subsystem/net/devices/", s->bind_to_device); return unit_add_node_link(UNIT(s), t, false); } @@ -472,7 +469,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { assert(f); prefix = strempty(prefix); - prefix2 = strappenda(prefix, "\t"); + prefix2 = strjoina(prefix, "\t"); fprintf(f, "%sSocket State: %s\n" @@ -925,13 +922,13 @@ static void socket_apply_socket_options(Socket *s, int fd) { if (s->smack_ip_in) { r = mac_smack_apply_ip_in_fd(fd, s->smack_ip_in); if (r < 0) - log_unit_error(UNIT(s)->id, "mac_smack_apply_ip_in_fd: %s", strerror(-r)); + log_unit_error_errno(UNIT(s)->id, r, "mac_smack_apply_ip_in_fd: %m"); } if (s->smack_ip_out) { r = mac_smack_apply_ip_out_fd(fd, s->smack_ip_out); if (r < 0) - log_unit_error(UNIT(s)->id, "mac_smack_apply_ip_out_fd: %s", strerror(-r)); + log_unit_error_errno(UNIT(s)->id, r, "mac_smack_apply_ip_out_fd: %m"); } } @@ -948,7 +945,7 @@ static void socket_apply_fifo_options(Socket *s, int fd) { if (s->smack) { r = mac_smack_apply_fd(fd, s->smack); if (r < 0) - log_unit_error(UNIT(s)->id, "mac_smack_apply_fd: %s", strerror(-r)); + log_unit_error_errno(UNIT(s)->id, r, "mac_smack_apply_fd: %m"); } } @@ -1269,7 +1266,7 @@ static int socket_watch_fds(Socket *s) { r = sd_event_add_io(UNIT(s)->manager->event, &p->event_source, p->fd, EPOLLIN, socket_dispatch_io, p); if (r < 0) { - log_unit_warning(UNIT(s)->id, "Failed to watch listening fds: %s", strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "Failed to watch listening fds: %m"); goto fail; } } @@ -1456,8 +1453,8 @@ static int socket_chown(Socket *s, pid_t *_pid) { if (pid == 0) { SocketPort *p; - uid_t uid = (uid_t) -1; - gid_t gid = (gid_t) -1; + uid_t uid = UID_INVALID; + gid_t gid = GID_INVALID; int ret; default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1); @@ -1605,7 +1602,7 @@ static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) { return; fail: - log_unit_warning(UNIT(s)->id, "%s failed to kill processes: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to kill processes: %m", UNIT(s)->id); if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL) socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES); @@ -1636,7 +1633,7 @@ static void socket_enter_stop_pre(Socket *s, SocketResult f) { return; fail: - log_unit_warning(UNIT(s)->id, "%s failed to run 'stop-pre' task: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run 'stop-pre' task: %m", UNIT(s)->id); socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES); } @@ -1646,7 +1643,7 @@ static void socket_enter_listening(Socket *s) { r = socket_watch_fds(s); if (r < 0) { - log_unit_warning(UNIT(s)->id, "%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to watch sockets: %m", UNIT(s)->id); goto fail; } @@ -1668,7 +1665,7 @@ static void socket_enter_start_post(Socket *s) { if (s->control_command) { r = socket_spawn(s, s->control_command, &s->control_pid); if (r < 0) { - log_unit_warning(UNIT(s)->id, "%s failed to run 'start-post' task: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run 'start-post' task: %m", UNIT(s)->id); goto fail; } @@ -1689,7 +1686,7 @@ static void socket_enter_start_chown(Socket *s) { r = socket_open_fds(s); if (r < 0) { - log_unit_warning(UNIT(s)->id, "%s failed to listen on sockets: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to listen on sockets: %m", UNIT(s)->id); goto fail; } @@ -1701,7 +1698,7 @@ static void socket_enter_start_chown(Socket *s) { r = socket_chown(s, &s->control_pid); if (r < 0) { - log_unit_warning(UNIT(s)->id, "%s failed to fork 'start-chown' task: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to fork 'start-chown' task: %m", UNIT(s)->id); goto fail; } @@ -1726,7 +1723,7 @@ static void socket_enter_start_pre(Socket *s) { if (s->control_command) { r = socket_spawn(s, s->control_command, &s->control_pid); if (r < 0) { - log_unit_warning(UNIT(s)->id, "%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run 'start-pre' task: %m", UNIT(s)->id); goto fail; } @@ -1760,14 +1757,14 @@ static void socket_enter_running(Socket *s, int cfd) { r = socket_open_fds(s); if (r < 0) { - log_unit_warning(UNIT(s)->id, "%s failed to listen on sockets: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to listen on sockets: %m", UNIT(s)->id); socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES); return; } r = socket_watch_fds(s); if (r < 0) { - log_unit_warning(UNIT(s)->id, "%s failed to watch sockets: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to watch sockets: %m", UNIT(s)->id); socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES); } } @@ -1894,7 +1891,7 @@ static void socket_run_next(Socket *s) { return; fail: - log_unit_warning(UNIT(s)->id, "%s failed to run next task: %s", UNIT(s)->id, strerror(-r)); + log_unit_warning_errno(UNIT(s)->id, r, "%s failed to run next task: %m", UNIT(s)->id); if (s->state == SOCKET_START_POST) socket_enter_stop_pre(s, SOCKET_FAILURE_RESOURCES); @@ -1953,7 +1950,7 @@ static int socket_start(Unit *u) { s->result = SOCKET_SUCCESS; socket_enter_start_pre(s); - return 0; + return 1; } static int socket_stop(Unit *u) { @@ -1984,7 +1981,7 @@ static int socket_stop(Unit *u) { assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING); socket_enter_stop_pre(s, SOCKET_SUCCESS); - return 0; + return 1; } static int socket_serialize(Unit *u, FILE *f, FDSet *fds) { @@ -2099,7 +2096,7 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, LIST_FOREACH(port, p, s->ports) if (p->type == SOCKET_FIFO && - streq_ptr(p->path, value+skip)) + path_equal_or_files_same(p->path, value+skip)) break; if (p) { @@ -2118,7 +2115,7 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, LIST_FOREACH(port, p, s->ports) if (p->type == SOCKET_SPECIAL && - streq_ptr(p->path, value+skip)) + path_equal_or_files_same(p->path, value+skip)) break; if (p) { @@ -2137,7 +2134,7 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, LIST_FOREACH(port, p, s->ports) if (p->type == SOCKET_MQUEUE && - streq_ptr(p->path, value+skip)) + streq(p->path, value+skip)) break; if (p) { @@ -2602,10 +2599,6 @@ static void socket_trigger_notify(Unit *u, Unit *other) { socket_notify_service_dead(s, se->result == SERVICE_FAILURE_START_LIMIT); if (se->state == SERVICE_DEAD || - se->state == SERVICE_STOP || - se->state == SERVICE_STOP_SIGTERM || - se->state == SERVICE_STOP_SIGKILL || - se->state == SERVICE_STOP_POST || se->state == SERVICE_FINAL_SIGTERM || se->state == SERVICE_FINAL_SIGKILL || se->state == SERVICE_AUTO_RESTART)