X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsocket.c;h=01af34c1052585736dcd89406bdb874f2663c077;hb=4fe60156fc45e34c7bcba4779123e15620532dff;hp=9045a2fc85a3c7c454bcc8ccd4408676bb91236d;hpb=f6a6225e414858ff222d2b175369cc42459abf9a;p=elogind.git diff --git a/src/socket.c b/src/socket.c index 9045a2fc8..01af34c10 100644 --- a/src/socket.c +++ b/src/socket.c @@ -366,7 +366,10 @@ static int socket_load(Unit *u) { return socket_verify(s); } -static const char* listen_lookup(int type) { +static const char* listen_lookup(int family, int type) { + + if (family == AF_NETLINK) + return "ListenNetlink"; if (type == SOCK_STREAM) return "ListenStream"; @@ -477,7 +480,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { else t = k; - fprintf(f, "%s%s: %s\n", prefix, listen_lookup(p->address.type), t); + fprintf(f, "%s%s: %s\n", prefix, listen_lookup(socket_address_family(&p->address), p->address.type), t); free(k); } else fprintf(f, "%sListenFIFO: %s\n", prefix, p->path); @@ -771,8 +774,10 @@ static int socket_open_fds(Socket *s) { return r; if (s->service && s->service->exec_command[SERVICE_EXEC_START]) - if ((r = label_get_socket_label_from_exe(s->service->exec_command[SERVICE_EXEC_START]->path, &label)) < 0) - return r; + if ((r = label_get_socket_label_from_exe(s->service->exec_command[SERVICE_EXEC_START]->path, &label)) < 0) { + if (r != -EPERM) + return r; + } know_label = true; } @@ -1040,9 +1045,7 @@ static void socket_enter_signal(Socket *s, SocketState state, bool success) { int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL; if (s->control_pid > 0) { - if (kill_and_sigcont(s->exec_context.kill_mode == KILL_PROCESS_GROUP ? - -s->control_pid : - s->control_pid, sig) < 0 && errno != ESRCH) + if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH) log_warning("Failed to kill control process %li: %m", (long) s->control_pid); else @@ -1068,6 +1071,7 @@ static void socket_enter_signal(Socket *s, SocketState state, bool success) { wait_for_exit = true; set_free(pid_set); + pid_set = NULL; } } @@ -1361,15 +1365,19 @@ static int socket_start(Unit *u) { /* Cannot run this without the service being around */ if (s->service) { - if (s->service->meta.load_state != UNIT_LOADED) + if (s->service->meta.load_state != UNIT_LOADED) { + log_error("Socket service %s not loaded, refusing.", s->service->meta.id); return -ENOENT; + } /* If the service is already active we cannot start the * socket */ if (s->service->state != SERVICE_DEAD && s->service->state != SERVICE_FAILED && - s->service->state != SERVICE_AUTO_RESTART) + s->service->state != SERVICE_AUTO_RESTART) { + log_error("Socket service %s already active, refusing.", s->service->meta.id); return -EBUSY; + } #ifdef HAVE_SYSV_COMPAT if (s->service->sysv_path) { @@ -1448,7 +1456,10 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) { if ((r = socket_address_print(&p->address, &t)) < 0) return r; - unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t); + if (socket_address_family(&p->address) == AF_NETLINK) + unit_serialize_item_format(u, f, "netlink", "%i %s", copy, t); + else + unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t); free(t); } else { assert(p->type == SOCKET_FIFO); @@ -1543,6 +1554,25 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, } } + } else if (streq(key, "netlink")) { + int fd, skip = 0; + SocketPort *p; + + if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd)) + log_debug("Failed to parse socket value %s", value); + else { + + LIST_FOREACH(port, p, s->ports) + if (socket_address_is_netlink(&p->address, value+skip)) + break; + + if (p) { + if (p->fd >= 0) + close_nointr_nofail(p->fd); + p->fd = fdset_remove(fds, fd); + } + } + } else log_debug("Unknown serialization key '%s'", key); @@ -1697,6 +1727,7 @@ static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) { case SOCKET_START_PRE: log_warning("%s starting timed out. Terminating.", u->meta.id); socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false); + break; case SOCKET_START_POST: log_warning("%s starting timed out. Stopping.", u->meta.id); @@ -1837,7 +1868,7 @@ static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError } if (s->control_pid > 0) - if (kill(mode == KILL_PROCESS_GROUP ? -s->control_pid : s->control_pid, signo) < 0) + if (kill(s->control_pid, signo) < 0) r = -errno; if (mode == KILL_CONTROL_GROUP) {