X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fsocket.c;h=2105369018e4b80f59011156b988fde96a33313c;hb=d2f1f23ad2636cf05589a67b5229c7fd604bc21f;hp=fcbcdbe192f306e3e999e27720c384eaa96e3ad8;hpb=f274ece0f76b5709408821e317e87aef76123db6;p=elogind.git diff --git a/src/core/socket.c b/src/core/socket.c index fcbcdbe19..210536901 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -102,8 +102,7 @@ static void socket_unwatch_control_pid(Socket *s) { s->control_pid = 0; } -static void socket_done(Unit *u) { - Socket *s = SOCKET(u); +void socket_free_ports(Socket *s) { SocketPort *p; assert(s); @@ -119,6 +118,14 @@ static void socket_done(Unit *u) { free(p->path); free(p); } +} + +static void socket_done(Unit *u) { + Socket *s = SOCKET(u); + + assert(s); + + socket_free_ports(s); exec_context_done(&s->exec_context); exec_command_free_array(s->exec_command, _SOCKET_EXEC_COMMAND_MAX); @@ -308,7 +315,7 @@ static int socket_add_device_link(Socket *s) { assert(s); - if (!s->bind_to_device) + if (!s->bind_to_device || streq(s->bind_to_device, "lo")) return 0; if (asprintf(&t, "/sys/subsystem/net/devices/%s", s->bind_to_device) < 0) @@ -1281,54 +1288,23 @@ fail: static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) { int r; - Set *pid_set = NULL; - bool wait_for_exit = false; assert(s); if (f != SOCKET_SUCCESS) s->result = f; - if (s->kill_context.kill_mode != KILL_NONE) { - int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->kill_context.kill_signal : SIGKILL; - - if (s->control_pid > 0) { - if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH) - - log_warning_unit(UNIT(s)->id, - "Failed to kill control process %li: %m", - (long) s->control_pid); - else - wait_for_exit = true; - } - - if (s->kill_context.kill_mode == KILL_CONTROL_GROUP) { - - if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) { - r = -ENOMEM; - goto fail; - } - - /* Exclude the control pid from being killed via the cgroup */ - if (s->control_pid > 0) - if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) - goto fail; - - r = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, sig, true, false, pid_set, NULL); - if (r < 0) { - if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) - log_warning_unit(UNIT(s)->id, - "Failed to kill control group: %s", - strerror(-r)); - } else if (r > 0) - wait_for_exit = true; - - set_free(pid_set); - pid_set = NULL; - } - } + r = unit_kill_context( + UNIT(s), + &s->kill_context, + state != SOCKET_STOP_PRE_SIGTERM && state != SOCKET_FINAL_SIGTERM, + -1, + s->control_pid, + false); + if (r < 0) + goto fail; - if (wait_for_exit) { + if (r > 0) { r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->timeout_usec, &s->timer_watch); if (r < 0) goto fail; @@ -1350,9 +1326,6 @@ fail: socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES); else socket_enter_dead(s, SOCKET_FAILURE_RESOURCES); - - if (pid_set) - set_free(pid_set); } static void socket_enter_stop_pre(Socket *s, SocketResult f) { @@ -2381,13 +2354,15 @@ DEFINE_STRING_TABLE_LOOKUP(socket_result, SocketResult); const UnitVTable socket_vtable = { .object_size = sizeof(Socket), - .exec_context_offset = offsetof(Socket, exec_context), .sections = "Unit\0" "Socket\0" "Install\0", + .exec_context_offset = offsetof(Socket, exec_context), + .exec_section = "Socket", + .init = socket_init, .done = socket_done, .load = socket_load,