X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fsocket.c;h=c1bbaec4477402f9eae3a5d29571dd40387155f1;hp=f3cbe08a4476385d03dea1d66f475f9f8f0639b0;hb=4ad490007b70e6ac18d3cb04fa2ed92eba1451fa;hpb=67419600875f3dae2182e3f92640bae4c8cd1f2f diff --git a/src/core/socket.c b/src/core/socket.c index f3cbe08a4..c1bbaec44 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -28,7 +28,7 @@ #include #include #include -#ifdef HAVE_ATTR_XATTR_H +#ifdef HAVE_XATTR #include #endif @@ -46,7 +46,7 @@ #include "dbus-socket.h" #include "missing.h" #include "special.h" -#include "bus-errors.h" +#include "dbus-common.h" #include "label.h" #include "exit-status.h" #include "def.h" @@ -88,6 +88,7 @@ static void socket_init(Unit *u) { s->exec_context.std_output = u->manager->default_std_output; s->exec_context.std_error = u->manager->default_std_error; kill_context_init(&s->kill_context); + cgroup_context_init(&s->cgroup_context); s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID; } @@ -128,6 +129,8 @@ static void socket_done(Unit *u) { socket_free_ports(s); exec_context_done(&s->exec_context, manager_is_reloading_or_reexecuting(u->manager)); + cgroup_context_init(&s->cgroup_context); + exec_command_free_array(s->exec_command, _SOCKET_EXEC_COMMAND_MAX); s->control_command = NULL; @@ -344,7 +347,7 @@ static int socket_add_default_dependencies(Socket *s) { return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true); } -static bool socket_has_exec(Socket *s) { +_pure_ static bool socket_has_exec(Socket *s) { unsigned i; assert(s); @@ -395,7 +398,8 @@ static int socket_load(Unit *u) { if ((r = unit_add_exec_dependencies(u, &s->exec_context)) < 0) return r; - if ((r = unit_add_default_cgroups(u)) < 0) + r = unit_add_default_slice(u); + if (r < 0) return r; if (UNIT(s)->default_dependencies) @@ -410,7 +414,7 @@ static int socket_load(Unit *u) { return socket_verify(s); } -static const char* listen_lookup(int family, int type) { +_const_ static const char* listen_lookup(int family, int type) { if (family == AF_NETLINK) return "ListenNetlink"; @@ -788,7 +792,7 @@ static void socket_apply_socket_options(Socket *s, int fd) { if (setsockopt(fd, SOL_TCP, TCP_CONGESTION, s->tcp_congestion, strlen(s->tcp_congestion)+1) < 0) log_warning_unit(UNIT(s)->id, "TCP_CONGESTION failed: %m"); -#ifdef HAVE_ATTR_XATTR_H +#ifdef HAVE_SMACK if (s->smack_ip_in) if (fsetxattr(fd, "security.SMACK64IPIN", s->smack_ip_in, strlen(s->smack_ip_in), 0) < 0) log_error_unit(UNIT(s)->id, @@ -810,7 +814,7 @@ static void socket_apply_fifo_options(Socket *s, int fd) { log_warning_unit(UNIT(s)->id, "F_SETPIPE_SZ: %m"); -#ifdef HAVE_ATTR_XATTR_H +#ifdef HAVE_SMACK if (s->smack) if (fsetxattr(fd, "security.SMACK64", s->smack, strlen(s->smack), 0) < 0) log_error_unit(UNIT(s)->id, @@ -1000,7 +1004,7 @@ static int socket_open_fds(Socket *s) { if ((r = socket_instantiate_service(s)) < 0) return r; - if (UNIT_DEREF(s->service) && + if (UNIT_ISSET(s->service) && SERVICE(UNIT_DEREF(s->service))->exec_command[SERVICE_EXEC_START]) { r = label_get_create_label_from_exe(SERVICE(UNIT_DEREF(s->service))->exec_command[SERVICE_EXEC_START]->path, &label); @@ -1205,6 +1209,8 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) { assert(c); assert(_pid); + unit_realize_cgroup(UNIT(s)); + r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->timeout_usec, &s->timer_watch); if (r < 0) goto fail; @@ -1224,9 +1230,8 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) { true, true, UNIT(s)->manager->confirm_spawn, - UNIT(s)->cgroup_bondings, - UNIT(s)->cgroup_attributes, - NULL, + UNIT(s)->cgroup_mask, + UNIT(s)->cgroup_path, UNIT(s)->id, NULL, &pid); @@ -1447,7 +1452,7 @@ static void socket_enter_running(Socket *s, int cfd) { /* We don't take connections anymore if we are supposed to * shut down anyway */ - if (unit_pending_inactive(UNIT(s))) { + if (unit_stop_pending(UNIT(s))) { log_debug_unit(UNIT(s)->id, "Suppressing connection request on %s since unit stop is scheduled.", UNIT(s)->id); @@ -1478,7 +1483,7 @@ static void socket_enter_running(Socket *s, int cfd) { /* If there's already a start pending don't bother to * do anything */ SET_FOREACH(u, UNIT(s)->dependencies[UNIT_TRIGGERS], i) - if (unit_pending_active(u)) { + if (unit_active_or_pending(u)) { pending = true; break; } @@ -1628,7 +1633,7 @@ static int socket_start(Unit *u) { return 0; /* Cannot run this without the service being around */ - if (UNIT_DEREF(s->service)) { + if (UNIT_ISSET(s->service)) { Service *service; service = SERVICE(UNIT_DEREF(s->service)); @@ -1957,13 +1962,13 @@ static int socket_distribute_fds(Unit *u, FDSet *fds) { return 0; } -static UnitActiveState socket_active_state(Unit *u) { +_pure_ static UnitActiveState socket_active_state(Unit *u) { assert(u); return state_translation_table[SOCKET(u)->state]; } -static const char *socket_sub_state_to_string(Unit *u) { +_pure_ static const char *socket_sub_state_to_string(Unit *u) { assert(u); return socket_state_to_string(SOCKET(u)->state); @@ -1991,7 +1996,7 @@ const char* socket_port_type_to_string(SocketPort *p) { } } -static bool socket_check_gc(Unit *u) { +_pure_ static bool socket_check_gc(Unit *u) { Socket *s = SOCKET(u); assert(u); @@ -2356,8 +2361,9 @@ const UnitVTable socket_vtable = { "Socket\0" "Install\0", + .private_section = "Socket", .exec_context_offset = offsetof(Socket, exec_context), - .exec_section = "Socket", + .cgroup_context_offset = offsetof(Socket, cgroup_context), .init = socket_init, .done = socket_done,