X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsocket.c;h=66131f867d7a6e240a35722a2ae957c9f316a580;hb=8c47c7325fa1ab72febf807f8831ff24c75fbf45;hp=03d322ba00e59a64c191fa3742ef7c0589fd5565;hpb=2b061f5a4b4e8927c7c1077e494455a189e34d59;p=elogind.git diff --git a/src/socket.c b/src/socket.c index 03d322ba0..66131f867 100644 --- a/src/socket.c +++ b/src/socket.c @@ -58,7 +58,6 @@ static void socket_init(Unit *u) { assert(u); assert(u->meta.load_state == UNIT_STUB); - s->timer_watch.type = WATCH_INVALID; s->backlog = SOMAXCONN; s->timeout_usec = DEFAULT_TIMEOUT_USEC; s->directory_mode = 0755; @@ -290,7 +289,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { "%sSocketMode: %04o\n" "%sDirectoryMode: %04o\n", prefix, socket_state_to_string(s->state), - prefix, yes_no(s->bind_ipv6_only), + prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only), prefix, s->backlog, prefix, kill_mode_to_string(s->kill_mode), prefix, s->socket_mode, @@ -896,7 +895,7 @@ static void socket_enter_running(Socket *s, int cfd) { Unit *u; char *prefix, *instance, *name; - if ((r = instance_from_socket(cfd, s->n_accepted++, &instance))) + if ((r = instance_from_socket(cfd, s->n_accepted++, &instance)) < 0) goto fail; if (!(prefix = unit_name_to_prefix(UNIT(s)->meta.id))) { @@ -909,8 +908,10 @@ static void socket_enter_running(Socket *s, int cfd) { free(prefix); free(instance); - if (!name) + if (!name) { r = -ENOMEM; + goto fail; + } r = manager_load_unit(UNIT(s)->meta.manager, name, NULL, &u); free(name); @@ -918,7 +919,7 @@ static void socket_enter_running(Socket *s, int cfd) { if (r < 0) goto fail; - if ((r = service_set_socket_fd(SERVICE(u), cfd) < 0)) + if ((r = service_set_socket_fd(SERVICE(u), cfd)) < 0) goto fail; cfd = -1; @@ -1066,7 +1067,7 @@ 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 %s", copy, t); + unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t); free(t); } else { assert(p->type == SOCKET_FIFO); @@ -1144,15 +1145,15 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value, } } else if (streq(key, "socket")) { - int fd, skip = 0; + int fd, type, skip = 0; SocketPort *p; - if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd)) + if (sscanf(value, "%i %i %n", &fd, &type, &skip) < 2 || fd < 0 || type < 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(&p->address, value+skip)) + if (socket_address_is(&p->address, value+skip, type)) break; if (p) { @@ -1187,6 +1188,9 @@ static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) { assert(s); assert(fd >= 0); + if (s->state != SOCKET_LISTENING) + return; + log_debug("Incoming traffic on %s", u->meta.id); if (events != EPOLLIN) { @@ -1224,12 +1228,14 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) { assert(s); assert(pid >= 0); - success = is_clean_exit(code, status); - s->failure = s->failure || !success; + if (pid != s->control_pid) + return; - assert(s->control_pid == pid); s->control_pid = 0; + success = is_clean_exit(code, status); + s->failure = s->failure || !success; + if (s->control_command) exec_status_fill(&s->control_command->exec_status, pid, code, status);