1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
27 #include <sys/epoll.h>
29 #include <arpa/inet.h>
34 #include "netinet/tcp.h"
36 #include "load-dropin.h"
37 #include "load-fragment.h"
39 #include "unit-name.h"
40 #include "dbus-socket.h"
43 #include "bus-errors.h"
45 #include "exit-status.h"
48 static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
49 [SOCKET_DEAD] = UNIT_INACTIVE,
50 [SOCKET_START_PRE] = UNIT_ACTIVATING,
51 [SOCKET_START_POST] = UNIT_ACTIVATING,
52 [SOCKET_LISTENING] = UNIT_ACTIVE,
53 [SOCKET_RUNNING] = UNIT_ACTIVE,
54 [SOCKET_STOP_PRE] = UNIT_DEACTIVATING,
55 [SOCKET_STOP_PRE_SIGTERM] = UNIT_DEACTIVATING,
56 [SOCKET_STOP_PRE_SIGKILL] = UNIT_DEACTIVATING,
57 [SOCKET_STOP_POST] = UNIT_DEACTIVATING,
58 [SOCKET_FINAL_SIGTERM] = UNIT_DEACTIVATING,
59 [SOCKET_FINAL_SIGKILL] = UNIT_DEACTIVATING,
60 [SOCKET_FAILED] = UNIT_FAILED
63 static void socket_init(Unit *u) {
64 Socket *s = SOCKET(u);
67 assert(u->meta.load_state == UNIT_STUB);
69 s->backlog = SOMAXCONN;
70 s->timeout_usec = DEFAULT_TIMEOUT_USEC;
71 s->directory_mode = 0755;
72 s->socket_mode = 0666;
74 s->max_connections = 64;
81 exec_context_init(&s->exec_context);
82 s->exec_context.std_output = u->meta.manager->default_std_output;
83 s->exec_context.std_error = u->meta.manager->default_std_error;
85 s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
88 static void socket_unwatch_control_pid(Socket *s) {
91 if (s->control_pid <= 0)
94 unit_unwatch_pid(UNIT(s), s->control_pid);
98 static void socket_done(Unit *u) {
99 Socket *s = SOCKET(u);
105 while ((p = s->ports)) {
106 LIST_REMOVE(SocketPort, port, s->ports, p);
109 unit_unwatch_fd(UNIT(s), &p->fd_watch);
110 close_nointr_nofail(p->fd);
117 exec_context_done(&s->exec_context);
118 exec_command_free_array(s->exec_command, _SOCKET_EXEC_COMMAND_MAX);
119 s->control_command = NULL;
121 socket_unwatch_control_pid(s);
125 free(s->tcp_congestion);
126 s->tcp_congestion = NULL;
128 free(s->bind_to_device);
129 s->bind_to_device = NULL;
131 unit_unwatch_timer(u, &s->timer_watch);
133 /* Make sure no service instance refers to us anymore. */
134 LIST_FOREACH(units_per_type, i, u->meta.manager->units_per_type[UNIT_SERVICE]) {
135 Service *service = (Service *) i;
137 if (service->accept_socket == s)
138 service->accept_socket = NULL;
140 set_remove(service->configured_sockets, s);
144 static int socket_instantiate_service(Socket *s) {
151 /* This fills in s->service if it isn't filled in yet. For
152 * Accept=yes sockets we create the next connection service
153 * here. For Accept=no this is mostly a NOP since the service
154 * is figured out at load time anyway. */
161 if (!(prefix = unit_name_to_prefix(s->meta.id)))
164 r = asprintf(&name, "%s@%u.service", prefix, s->n_accepted);
170 r = manager_load_unit(s->meta.manager, name, NULL, NULL, &u);
176 #ifdef HAVE_SYSV_COMPAT
177 if (SERVICE(u)->sysv_path) {
178 log_error("Using SysV services for socket activation is not supported. Refusing.");
183 u->meta.no_gc = true;
184 s->service = SERVICE(u);
188 static bool have_non_accept_socket(Socket *s) {
196 LIST_FOREACH(port, p, s->ports) {
198 if (p->type != SOCKET_SOCKET)
201 if (!socket_address_can_accept(&p->address))
208 static int socket_verify(Socket *s) {
211 if (s->meta.load_state != UNIT_LOADED)
215 log_error("%s lacks Listen setting. Refusing.", s->meta.id);
219 if (s->accept && have_non_accept_socket(s)) {
220 log_error("%s configured for accepting sockets, but sockets are non-accepting. Refusing.", s->meta.id);
224 if (s->accept && s->max_connections <= 0) {
225 log_error("%s's MaxConnection setting too small. Refusing.", s->meta.id);
229 if (s->accept && s->service) {
230 log_error("Explicit service configuration for accepting sockets not supported on %s. Refusing.", s->meta.id);
234 if (s->exec_context.pam_name && s->exec_context.kill_mode != KILL_CONTROL_GROUP) {
235 log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", s->meta.id);
242 static bool socket_needs_mount(Socket *s, const char *prefix) {
247 LIST_FOREACH(port, p, s->ports) {
249 if (p->type == SOCKET_SOCKET) {
250 if (socket_address_needs_mount(&p->address, prefix))
252 } else if (p->type == SOCKET_FIFO || p->type == SOCKET_SPECIAL) {
253 if (path_startswith(p->path, prefix))
261 int socket_add_one_mount_link(Socket *s, Mount *m) {
267 if (s->meta.load_state != UNIT_LOADED ||
268 m->meta.load_state != UNIT_LOADED)
271 if (!socket_needs_mount(s, m->where))
274 if ((r = unit_add_two_dependencies(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0)
280 static int socket_add_mount_links(Socket *s) {
286 LIST_FOREACH(units_per_type, other, s->meta.manager->units_per_type[UNIT_MOUNT])
287 if ((r = socket_add_one_mount_link(s, (Mount*) other)) < 0)
293 static int socket_add_device_link(Socket *s) {
299 if (!s->bind_to_device)
302 if (asprintf(&t, "/sys/subsystem/net/devices/%s", s->bind_to_device) < 0)
305 r = unit_add_node_link(UNIT(s), t, false);
311 static int socket_add_default_dependencies(Socket *s) {
315 if (s->meta.manager->running_as == MANAGER_SYSTEM) {
316 if ((r = unit_add_dependency_by_name(UNIT(s), UNIT_BEFORE, SPECIAL_SOCKETS_TARGET, NULL, true)) < 0)
319 if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0)
323 return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
326 static int socket_load(Unit *u) {
327 Socket *s = SOCKET(u);
331 assert(u->meta.load_state == UNIT_STUB);
333 if ((r = unit_load_fragment_and_dropin(u)) < 0)
336 /* This is a new unit? Then let's add in some extras */
337 if (u->meta.load_state == UNIT_LOADED) {
339 if (have_non_accept_socket(s)) {
342 if ((r = unit_load_related_unit(u, ".service", (Unit**) &s->service)) < 0)
345 if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(s->service), true)) < 0)
349 if ((r = socket_add_mount_links(s)) < 0)
352 if ((r = socket_add_device_link(s)) < 0)
355 if ((r = unit_add_exec_dependencies(u, &s->exec_context)) < 0)
358 if ((r = unit_add_default_cgroups(u)) < 0)
361 if (s->meta.default_dependencies)
362 if ((r = socket_add_default_dependencies(s)) < 0)
366 return socket_verify(s);
369 static const char* listen_lookup(int family, int type) {
371 if (family == AF_NETLINK)
372 return "ListenNetlink";
374 if (type == SOCK_STREAM)
375 return "ListenStream";
376 else if (type == SOCK_DGRAM)
377 return "ListenDatagram";
378 else if (type == SOCK_SEQPACKET)
379 return "ListenSequentialPacket";
381 assert_not_reached("Unknown socket type");
385 static void socket_dump(Unit *u, FILE *f, const char *prefix) {
388 Socket *s = SOCKET(u);
396 p2 = strappend(prefix, "\t");
397 prefix2 = p2 ? p2 : prefix;
400 "%sSocket State: %s\n"
401 "%sBindIPv6Only: %s\n"
403 "%sSocketMode: %04o\n"
404 "%sDirectoryMode: %04o\n"
407 "%sTransparent: %s\n"
409 "%sTCPCongestion: %s\n",
410 prefix, socket_state_to_string(s->state),
411 prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only),
413 prefix, s->socket_mode,
414 prefix, s->directory_mode,
415 prefix, yes_no(s->keep_alive),
416 prefix, yes_no(s->free_bind),
417 prefix, yes_no(s->transparent),
418 prefix, yes_no(s->broadcast),
419 prefix, strna(s->tcp_congestion));
421 if (s->control_pid > 0)
423 "%sControl PID: %lu\n",
424 prefix, (unsigned long) s->control_pid);
426 if (s->bind_to_device)
428 "%sBindToDevice: %s\n",
429 prefix, s->bind_to_device);
434 "%sNConnections: %u\n"
435 "%sMaxConnections: %u\n",
436 prefix, s->n_accepted,
437 prefix, s->n_connections,
438 prefix, s->max_connections);
440 if (s->priority >= 0)
443 prefix, s->priority);
445 if (s->receive_buffer > 0)
447 "%sReceiveBuffer: %zu\n",
448 prefix, s->receive_buffer);
450 if (s->send_buffer > 0)
452 "%sSendBuffer: %zu\n",
453 prefix, s->send_buffer);
465 if (s->pipe_size > 0)
468 prefix, s->pipe_size);
475 if (s->mq_maxmsg > 0)
477 "%sMessageQueueMaxMessages: %li\n",
478 prefix, s->mq_maxmsg);
480 if (s->mq_msgsize > 0)
482 "%sMessageQueueMessageSize: %li\n",
483 prefix, s->mq_msgsize);
485 LIST_FOREACH(port, p, s->ports) {
487 if (p->type == SOCKET_SOCKET) {
492 if ((r = socket_address_print(&p->address, &k)) < 0)
497 fprintf(f, "%s%s: %s\n", prefix, listen_lookup(socket_address_family(&p->address), p->address.type), t);
499 } else if (p->type == SOCKET_SPECIAL)
500 fprintf(f, "%sListenSpecial: %s\n", prefix, p->path);
501 else if (p->type == SOCKET_MQUEUE)
502 fprintf(f, "%sListenMessageQueue: %s\n", prefix, p->path);
504 fprintf(f, "%sListenFIFO: %s\n", prefix, p->path);
507 exec_context_dump(&s->exec_context, f, prefix);
509 for (c = 0; c < _SOCKET_EXEC_COMMAND_MAX; c++) {
510 if (!s->exec_command[c])
513 fprintf(f, "%s-> %s:\n",
514 prefix, socket_exec_command_to_string(c));
516 exec_command_dump_list(s->exec_command[c], f, prefix2);
522 static int instance_from_socket(int fd, unsigned nr, char **instance) {
527 struct sockaddr_un un;
528 struct sockaddr_in in;
529 struct sockaddr_in6 in6;
530 struct sockaddr_storage storage;
537 if (getsockname(fd, &local.sa, &l) < 0)
541 if (getpeername(fd, &remote.sa, &l) < 0)
544 switch (local.sa.sa_family) {
548 a = ntohl(local.in.sin_addr.s_addr),
549 b = ntohl(remote.in.sin_addr.s_addr);
552 "%u.%u.%u.%u:%u-%u.%u.%u.%u:%u",
553 a >> 24, (a >> 16) & 0xFF, (a >> 8) & 0xFF, a & 0xFF,
554 ntohs(local.in.sin_port),
555 b >> 24, (b >> 16) & 0xFF, (b >> 8) & 0xFF, b & 0xFF,
556 ntohs(remote.in.sin_port)) < 0)
563 static const char ipv4_prefix[] = {
564 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF
567 if (memcmp(&local.in6.sin6_addr, ipv4_prefix, sizeof(ipv4_prefix)) == 0 &&
568 memcmp(&remote.in6.sin6_addr, ipv4_prefix, sizeof(ipv4_prefix)) == 0) {
570 *a = local.in6.sin6_addr.s6_addr+12,
571 *b = remote.in6.sin6_addr.s6_addr+12;
574 "%u.%u.%u.%u:%u-%u.%u.%u.%u:%u",
575 a[0], a[1], a[2], a[3],
576 ntohs(local.in6.sin6_port),
577 b[0], b[1], b[2], b[3],
578 ntohs(remote.in6.sin6_port)) < 0)
581 char a[INET6_ADDRSTRLEN], b[INET6_ADDRSTRLEN];
585 inet_ntop(AF_INET6, &local.in6.sin6_addr, a, sizeof(a)),
586 ntohs(local.in6.sin6_port),
587 inet_ntop(AF_INET6, &remote.in6.sin6_addr, b, sizeof(b)),
588 ntohs(remote.in6.sin6_port)) < 0)
599 if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l) < 0)
605 (unsigned long) ucred.pid,
606 (unsigned long) ucred.uid) < 0)
613 assert_not_reached("Unhandled socket type.");
620 static void socket_close_fds(Socket *s) {
625 LIST_FOREACH(port, p, s->ports) {
629 unit_unwatch_fd(UNIT(s), &p->fd_watch);
630 close_nointr_nofail(p->fd);
632 /* One little note: we should never delete any sockets
633 * in the file system here! After all some other
634 * process we spawned might still have a reference of
635 * this fd and wants to continue to use it. Therefore
636 * we delete sockets in the file system before we
637 * create a new one, not after we stopped using
644 static void socket_apply_socket_options(Socket *s, int fd) {
649 int b = s->keep_alive;
650 if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &b, sizeof(b)) < 0)
651 log_warning("SO_KEEPALIVE failed: %m");
656 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)) < 0)
657 log_warning("SO_BROADCAST failed: %m");
660 if (s->priority >= 0)
661 if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &s->priority, sizeof(s->priority)) < 0)
662 log_warning("SO_PRIORITY failed: %m");
664 if (s->receive_buffer > 0) {
665 int value = (int) s->receive_buffer;
666 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &value, sizeof(value)) < 0)
667 log_warning("SO_RCVBUFFORCE failed: %m");
670 if (s->send_buffer > 0) {
671 int value = (int) s->send_buffer;
672 if (setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &value, sizeof(value)) < 0)
673 log_warning("SO_SNDBUFFORCE failed: %m");
677 if (setsockopt(fd, SOL_SOCKET, SO_MARK, &s->mark, sizeof(s->mark)) < 0)
678 log_warning("SO_MARK failed: %m");
681 if (setsockopt(fd, IPPROTO_IP, IP_TOS, &s->ip_tos, sizeof(s->ip_tos)) < 0)
682 log_warning("IP_TOS failed: %m");
684 if (s->ip_ttl >= 0) {
687 r = setsockopt(fd, IPPROTO_IP, IP_TTL, &s->ip_ttl, sizeof(s->ip_ttl));
689 if (socket_ipv6_is_supported())
690 x = setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &s->ip_ttl, sizeof(s->ip_ttl));
693 errno = EAFNOSUPPORT;
697 log_warning("IP_TTL/IPV6_UNICAST_HOPS failed: %m");
700 if (s->tcp_congestion)
701 if (setsockopt(fd, SOL_TCP, TCP_CONGESTION, s->tcp_congestion, strlen(s->tcp_congestion)+1) < 0)
702 log_warning("TCP_CONGESTION failed: %m");
705 static void socket_apply_fifo_options(Socket *s, int fd) {
709 if (s->pipe_size > 0)
710 if (fcntl(fd, F_SETPIPE_SZ, s->pipe_size) < 0)
711 log_warning("F_SETPIPE_SZ: %m");
714 static int fifo_address_create(
716 mode_t directory_mode,
727 mkdir_parents(path, directory_mode);
729 if ((r = label_fifofile_set(path)) < 0)
732 /* Enforce the right access mode for the fifo */
733 old_mask = umask(~ socket_mode);
735 /* Include the original umask in our mask */
736 umask(~socket_mode | old_mask);
738 r = mkfifo(path, socket_mode);
741 if (r < 0 && errno != EEXIST) {
746 if ((fd = open(path, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW)) < 0) {
753 if (fstat(fd, &st) < 0) {
758 if (!S_ISFIFO(st.st_mode) ||
759 (st.st_mode & 0777) != (socket_mode & ~old_mask) ||
760 st.st_uid != getuid() ||
761 st.st_gid != getgid()) {
774 close_nointr_nofail(fd);
779 static int special_address_create(
789 if ((fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW)) < 0) {
794 if (fstat(fd, &st) < 0) {
799 /* Check whether this is a /proc, /sys or /dev file or char device */
800 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) {
810 close_nointr_nofail(fd);
815 static int mq_address_create(
825 struct mq_attr _attr, *attr = NULL;
830 if (maxmsg > 0 && msgsize > 0) {
832 _attr.mq_flags = O_NONBLOCK;
833 _attr.mq_maxmsg = maxmsg;
834 _attr.mq_msgsize = msgsize;
838 /* Enforce the right access mode for the mq */
839 old_mask = umask(~ mq_mode);
841 /* Include the original umask in our mask */
842 umask(~mq_mode | old_mask);
844 fd = mq_open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_CREAT, mq_mode, attr);
847 if (fd < 0 && errno != EEXIST) {
852 if (fstat(fd, &st) < 0) {
857 if ((st.st_mode & 0777) != (mq_mode & ~old_mask) ||
858 st.st_uid != getuid() ||
859 st.st_gid != getgid()) {
870 close_nointr_nofail(fd);
875 static int socket_open_fds(Socket *s) {
879 bool know_label = false;
883 LIST_FOREACH(port, p, s->ports) {
888 if (p->type == SOCKET_SOCKET) {
892 if ((r = socket_instantiate_service(s)) < 0)
895 if (s->service && s->service->exec_command[SERVICE_EXEC_START])
896 if ((r = label_get_socket_label_from_exe(s->service->exec_command[SERVICE_EXEC_START]->path, &label)) < 0) {
904 if ((r = socket_address_listen(
917 socket_apply_socket_options(s, p->fd);
919 } else if (p->type == SOCKET_SPECIAL) {
921 if ((r = special_address_create(
926 } else if (p->type == SOCKET_FIFO) {
928 if ((r = fifo_address_create(
935 socket_apply_fifo_options(s, p->fd);
936 } else if (p->type == SOCKET_MQUEUE) {
938 if ((r = mq_address_create(
946 assert_not_reached("Unknown port type");
958 static void socket_unwatch_fds(Socket *s) {
963 LIST_FOREACH(port, p, s->ports) {
967 unit_unwatch_fd(UNIT(s), &p->fd_watch);
971 static int socket_watch_fds(Socket *s) {
977 LIST_FOREACH(port, p, s->ports) {
981 p->fd_watch.socket_accept =
983 p->type == SOCKET_SOCKET &&
984 socket_address_can_accept(&p->address);
986 if ((r = unit_watch_fd(UNIT(s), p->fd, EPOLLIN, &p->fd_watch)) < 0)
993 socket_unwatch_fds(s);
997 static void socket_set_state(Socket *s, SocketState state) {
998 SocketState old_state;
1001 old_state = s->state;
1004 if (state != SOCKET_START_PRE &&
1005 state != SOCKET_START_POST &&
1006 state != SOCKET_STOP_PRE &&
1007 state != SOCKET_STOP_PRE_SIGTERM &&
1008 state != SOCKET_STOP_PRE_SIGKILL &&
1009 state != SOCKET_STOP_POST &&
1010 state != SOCKET_FINAL_SIGTERM &&
1011 state != SOCKET_FINAL_SIGKILL) {
1012 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1013 socket_unwatch_control_pid(s);
1014 s->control_command = NULL;
1015 s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
1018 if (state != SOCKET_LISTENING)
1019 socket_unwatch_fds(s);
1021 if (state != SOCKET_START_POST &&
1022 state != SOCKET_LISTENING &&
1023 state != SOCKET_RUNNING &&
1024 state != SOCKET_STOP_PRE &&
1025 state != SOCKET_STOP_PRE_SIGTERM &&
1026 state != SOCKET_STOP_PRE_SIGKILL)
1027 socket_close_fds(s);
1029 if (state != old_state)
1030 log_debug("%s changed %s -> %s",
1032 socket_state_to_string(old_state),
1033 socket_state_to_string(state));
1035 unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true);
1038 static int socket_coldplug(Unit *u) {
1039 Socket *s = SOCKET(u);
1043 assert(s->state == SOCKET_DEAD);
1045 if (s->deserialized_state != s->state) {
1047 if (s->deserialized_state == SOCKET_START_PRE ||
1048 s->deserialized_state == SOCKET_START_POST ||
1049 s->deserialized_state == SOCKET_STOP_PRE ||
1050 s->deserialized_state == SOCKET_STOP_PRE_SIGTERM ||
1051 s->deserialized_state == SOCKET_STOP_PRE_SIGKILL ||
1052 s->deserialized_state == SOCKET_STOP_POST ||
1053 s->deserialized_state == SOCKET_FINAL_SIGTERM ||
1054 s->deserialized_state == SOCKET_FINAL_SIGKILL) {
1056 if (s->control_pid <= 0)
1059 if ((r = unit_watch_pid(UNIT(s), s->control_pid)) < 0)
1062 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1066 if (s->deserialized_state == SOCKET_START_POST ||
1067 s->deserialized_state == SOCKET_LISTENING ||
1068 s->deserialized_state == SOCKET_RUNNING ||
1069 s->deserialized_state == SOCKET_STOP_PRE ||
1070 s->deserialized_state == SOCKET_STOP_PRE_SIGTERM ||
1071 s->deserialized_state == SOCKET_STOP_PRE_SIGKILL)
1072 if ((r = socket_open_fds(s)) < 0)
1075 if (s->deserialized_state == SOCKET_LISTENING)
1076 if ((r = socket_watch_fds(s)) < 0)
1079 socket_set_state(s, s->deserialized_state);
1085 static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
1094 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1097 if (!(argv = unit_full_printf_strv(UNIT(s), c->argv))) {
1106 s->meta.manager->environment,
1110 s->meta.manager->confirm_spawn,
1111 s->meta.cgroup_bondings,
1118 if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
1119 /* FIXME: we need to do something here */
1127 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1132 static void socket_enter_dead(Socket *s, bool success) {
1138 socket_set_state(s, s->failure ? SOCKET_FAILED : SOCKET_DEAD);
1141 static void socket_enter_signal(Socket *s, SocketState state, bool success);
1143 static void socket_enter_stop_post(Socket *s, bool success) {
1150 socket_unwatch_control_pid(s);
1152 s->control_command_id = SOCKET_EXEC_STOP_POST;
1154 if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST])) {
1155 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1158 socket_set_state(s, SOCKET_STOP_POST);
1160 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, true);
1165 log_warning("%s failed to run 'stop-post' task: %s", s->meta.id, strerror(-r));
1166 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1169 static void socket_enter_signal(Socket *s, SocketState state, bool success) {
1171 Set *pid_set = NULL;
1172 bool wait_for_exit = false;
1179 if (s->exec_context.kill_mode != KILL_NONE) {
1180 int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
1182 if (s->control_pid > 0) {
1183 if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH)
1185 log_warning("Failed to kill control process %li: %m", (long) s->control_pid);
1187 wait_for_exit = true;
1190 if (s->exec_context.kill_mode == KILL_CONTROL_GROUP) {
1192 if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) {
1197 /* Exclude the control pid from being killed via the cgroup */
1198 if (s->control_pid > 0)
1199 if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
1202 if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, true, pid_set)) < 0) {
1203 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
1204 log_warning("Failed to kill control group: %s", strerror(-r));
1206 wait_for_exit = true;
1213 if (wait_for_exit) {
1214 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1217 socket_set_state(s, state);
1218 } else if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
1219 socket_enter_stop_post(s, true);
1221 socket_enter_dead(s, true);
1226 log_warning("%s failed to kill processes: %s", s->meta.id, strerror(-r));
1228 if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
1229 socket_enter_stop_post(s, false);
1231 socket_enter_dead(s, false);
1237 static void socket_enter_stop_pre(Socket *s, bool success) {
1244 socket_unwatch_control_pid(s);
1246 s->control_command_id = SOCKET_EXEC_STOP_PRE;
1248 if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE])) {
1249 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1252 socket_set_state(s, SOCKET_STOP_PRE);
1254 socket_enter_stop_post(s, true);
1259 log_warning("%s failed to run 'stop-pre' task: %s", s->meta.id, strerror(-r));
1260 socket_enter_stop_post(s, false);
1263 static void socket_enter_listening(Socket *s) {
1267 if ((r = socket_watch_fds(s)) < 0) {
1268 log_warning("%s failed to watch sockets: %s", s->meta.id, strerror(-r));
1272 socket_set_state(s, SOCKET_LISTENING);
1276 socket_enter_stop_pre(s, false);
1279 static void socket_enter_start_post(Socket *s) {
1283 if ((r = socket_open_fds(s)) < 0) {
1284 log_warning("%s failed to listen on sockets: %s", s->meta.id, strerror(-r));
1288 socket_unwatch_control_pid(s);
1290 s->control_command_id = SOCKET_EXEC_START_POST;
1292 if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) {
1293 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) {
1294 log_warning("%s failed to run 'start-post' task: %s", s->meta.id, strerror(-r));
1298 socket_set_state(s, SOCKET_START_POST);
1300 socket_enter_listening(s);
1305 socket_enter_stop_pre(s, false);
1308 static void socket_enter_start_pre(Socket *s) {
1312 socket_unwatch_control_pid(s);
1314 s->control_command_id = SOCKET_EXEC_START_PRE;
1316 if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE])) {
1317 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1320 socket_set_state(s, SOCKET_START_PRE);
1322 socket_enter_start_post(s);
1327 log_warning("%s failed to run 'start-pre' task: %s", s->meta.id, strerror(-r));
1328 socket_enter_dead(s, false);
1331 static void socket_enter_running(Socket *s, int cfd) {
1336 dbus_error_init(&error);
1338 /* We don't take connections anymore if we are supposed to
1339 * shut down anyway */
1340 if (unit_pending_inactive(UNIT(s))) {
1341 log_debug("Suppressing connection request on %s since unit stop is scheduled.", s->meta.id);
1344 close_nointr_nofail(cfd);
1346 /* Flush all sockets by closing and reopening them */
1347 socket_close_fds(s);
1349 if ((r = socket_watch_fds(s)) < 0) {
1350 log_warning("%s failed to watch sockets: %s", s->meta.id, strerror(-r));
1351 socket_enter_stop_pre(s, false);
1359 bool pending = false;
1362 /* If there's already a start pending don't bother to
1364 LIST_FOREACH(units_per_type, i, s->meta.manager->units_per_type[UNIT_SERVICE]) {
1365 Service *service = (Service *) i;
1367 if (!set_get(service->configured_sockets, s))
1370 if (!unit_pending_active(UNIT(service)))
1378 if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s->service), JOB_REPLACE, true, &error, NULL)) < 0)
1381 socket_set_state(s, SOCKET_RUNNING);
1383 char *prefix, *instance = NULL, *name;
1386 if (s->n_connections >= s->max_connections) {
1387 log_warning("Too many incoming connections (%u)", s->n_connections);
1388 close_nointr_nofail(cfd);
1392 if ((r = socket_instantiate_service(s)) < 0)
1395 if ((r = instance_from_socket(cfd, s->n_accepted, &instance)) < 0)
1398 if (!(prefix = unit_name_to_prefix(s->meta.id))) {
1404 name = unit_name_build(prefix, instance, ".service");
1413 if ((r = unit_add_name(UNIT(s->service), name)) < 0) {
1418 service = s->service;
1422 service->meta.no_gc = false;
1424 unit_choose_id(UNIT(service), name);
1427 if ((r = service_set_socket_fd(service, cfd, s)) < 0)
1431 s->n_connections ++;
1433 if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(service), JOB_REPLACE, true, &error, NULL)) < 0)
1436 /* Notify clients about changed counters */
1437 unit_add_to_dbus_queue(UNIT(s));
1443 log_warning("%s failed to queue socket startup job: %s", s->meta.id, bus_error(&error, r));
1444 socket_enter_stop_pre(s, false);
1447 close_nointr_nofail(cfd);
1449 dbus_error_free(&error);
1452 static void socket_run_next(Socket *s, bool success) {
1456 assert(s->control_command);
1457 assert(s->control_command->command_next);
1462 socket_unwatch_control_pid(s);
1464 s->control_command = s->control_command->command_next;
1466 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1472 log_warning("%s failed to run next task: %s", s->meta.id, strerror(-r));
1474 if (s->state == SOCKET_START_POST)
1475 socket_enter_stop_pre(s, false);
1476 else if (s->state == SOCKET_STOP_POST)
1477 socket_enter_dead(s, false);
1479 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1482 static int socket_start(Unit *u) {
1483 Socket *s = SOCKET(u);
1487 /* We cannot fulfill this request right now, try again later
1489 if (s->state == SOCKET_STOP_PRE ||
1490 s->state == SOCKET_STOP_PRE_SIGKILL ||
1491 s->state == SOCKET_STOP_PRE_SIGTERM ||
1492 s->state == SOCKET_STOP_POST ||
1493 s->state == SOCKET_FINAL_SIGTERM ||
1494 s->state == SOCKET_FINAL_SIGKILL)
1497 if (s->state == SOCKET_START_PRE ||
1498 s->state == SOCKET_START_POST)
1501 /* Cannot run this without the service being around */
1503 if (s->service->meta.load_state != UNIT_LOADED) {
1504 log_error("Socket service %s not loaded, refusing.", s->service->meta.id);
1508 /* If the service is already active we cannot start the
1510 if (s->service->state != SERVICE_DEAD &&
1511 s->service->state != SERVICE_FAILED &&
1512 s->service->state != SERVICE_AUTO_RESTART) {
1513 log_error("Socket service %s already active, refusing.", s->service->meta.id);
1517 #ifdef HAVE_SYSV_COMPAT
1518 if (s->service->sysv_path) {
1519 log_error("Using SysV services for socket activation is not supported. Refusing.");
1525 assert(s->state == SOCKET_DEAD || s->state == SOCKET_FAILED);
1528 socket_enter_start_pre(s);
1532 static int socket_stop(Unit *u) {
1533 Socket *s = SOCKET(u);
1538 if (s->state == SOCKET_STOP_PRE ||
1539 s->state == SOCKET_STOP_PRE_SIGTERM ||
1540 s->state == SOCKET_STOP_PRE_SIGKILL ||
1541 s->state == SOCKET_STOP_POST ||
1542 s->state == SOCKET_FINAL_SIGTERM ||
1543 s->state == SOCKET_FINAL_SIGKILL)
1546 /* If there's already something running we go directly into
1548 if (s->state == SOCKET_START_PRE ||
1549 s->state == SOCKET_START_POST) {
1550 socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, true);
1554 assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
1556 socket_enter_stop_pre(s, true);
1560 static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
1561 Socket *s = SOCKET(u);
1569 unit_serialize_item(u, f, "state", socket_state_to_string(s->state));
1570 unit_serialize_item(u, f, "failure", yes_no(s->failure));
1571 unit_serialize_item_format(u, f, "n-accepted", "%u", s->n_accepted);
1573 if (s->control_pid > 0)
1574 unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid);
1576 if (s->control_command_id >= 0)
1577 unit_serialize_item(u, f, "control-command", socket_exec_command_to_string(s->control_command_id));
1579 LIST_FOREACH(port, p, s->ports) {
1585 if ((copy = fdset_put_dup(fds, p->fd)) < 0)
1588 if (p->type == SOCKET_SOCKET) {
1591 if ((r = socket_address_print(&p->address, &t)) < 0)
1594 if (socket_address_family(&p->address) == AF_NETLINK)
1595 unit_serialize_item_format(u, f, "netlink", "%i %s", copy, t);
1597 unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t);
1599 } else if (p->type == SOCKET_SPECIAL)
1600 unit_serialize_item_format(u, f, "special", "%i %s", copy, p->path);
1602 assert(p->type == SOCKET_FIFO);
1603 unit_serialize_item_format(u, f, "fifo", "%i %s", copy, p->path);
1610 static int socket_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
1611 Socket *s = SOCKET(u);
1618 if (streq(key, "state")) {
1621 if ((state = socket_state_from_string(value)) < 0)
1622 log_debug("Failed to parse state value %s", value);
1624 s->deserialized_state = state;
1625 } else if (streq(key, "failure")) {
1628 if ((b = parse_boolean(value)) < 0)
1629 log_debug("Failed to parse failure value %s", value);
1631 s->failure = b || s->failure;
1633 } else if (streq(key, "n-accepted")) {
1636 if (safe_atou(value, &k) < 0)
1637 log_debug("Failed to parse n-accepted value %s", value);
1640 } else if (streq(key, "control-pid")) {
1643 if (parse_pid(value, &pid) < 0)
1644 log_debug("Failed to parse control-pid value %s", value);
1646 s->control_pid = pid;
1647 } else if (streq(key, "control-command")) {
1648 SocketExecCommand id;
1650 if ((id = socket_exec_command_from_string(value)) < 0)
1651 log_debug("Failed to parse exec-command value %s", value);
1653 s->control_command_id = id;
1654 s->control_command = s->exec_command[id];
1656 } else if (streq(key, "fifo")) {
1660 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1661 log_debug("Failed to parse fifo value %s", value);
1664 LIST_FOREACH(port, p, s->ports)
1665 if (p->type == SOCKET_FIFO &&
1666 streq_ptr(p->path, value+skip))
1671 close_nointr_nofail(p->fd);
1672 p->fd = fdset_remove(fds, fd);
1676 } else if (streq(key, "special")) {
1680 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1681 log_debug("Failed to parse special value %s", value);
1684 LIST_FOREACH(port, p, s->ports)
1685 if (p->type == SOCKET_SPECIAL &&
1686 streq_ptr(p->path, value+skip))
1691 close_nointr_nofail(p->fd);
1692 p->fd = fdset_remove(fds, fd);
1696 } else if (streq(key, "socket")) {
1697 int fd, type, skip = 0;
1700 if (sscanf(value, "%i %i %n", &fd, &type, &skip) < 2 || fd < 0 || type < 0 || !fdset_contains(fds, fd))
1701 log_debug("Failed to parse socket value %s", value);
1704 LIST_FOREACH(port, p, s->ports)
1705 if (socket_address_is(&p->address, value+skip, type))
1710 close_nointr_nofail(p->fd);
1711 p->fd = fdset_remove(fds, fd);
1715 } else if (streq(key, "netlink")) {
1719 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1720 log_debug("Failed to parse socket value %s", value);
1723 LIST_FOREACH(port, p, s->ports)
1724 if (socket_address_is_netlink(&p->address, value+skip))
1729 close_nointr_nofail(p->fd);
1730 p->fd = fdset_remove(fds, fd);
1735 log_debug("Unknown serialization key '%s'", key);
1740 static UnitActiveState socket_active_state(Unit *u) {
1743 return state_translation_table[SOCKET(u)->state];
1746 static const char *socket_sub_state_to_string(Unit *u) {
1749 return socket_state_to_string(SOCKET(u)->state);
1752 static bool socket_check_gc(Unit *u) {
1753 Socket *s = SOCKET(u);
1757 return s->n_connections > 0;
1760 static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
1761 Socket *s = SOCKET(u);
1767 if (s->state != SOCKET_LISTENING)
1770 log_debug("Incoming traffic on %s", u->meta.id);
1772 if (events != EPOLLIN) {
1774 if (events & EPOLLHUP)
1775 log_error("%s: Got POLLHUP on a listening socket. The service probably invoked shutdown() on it, and should better not do that.", u->meta.id);
1777 log_error("%s: Got unexpected poll event (0x%x) on socket.", u->meta.id, events);
1782 if (w->socket_accept) {
1785 if ((cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK)) < 0) {
1790 log_error("Failed to accept socket: %m");
1797 socket_apply_socket_options(s, cfd);
1800 socket_enter_running(s, cfd);
1804 socket_enter_stop_pre(s, false);
1807 static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
1808 Socket *s = SOCKET(u);
1814 if (pid != s->control_pid)
1819 success = is_clean_exit(code, status);
1821 if (s->control_command) {
1822 exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
1824 if (s->control_command->ignore)
1828 log_full(success ? LOG_DEBUG : LOG_NOTICE,
1829 "%s control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
1830 s->failure = s->failure || !success;
1832 if (s->control_command && s->control_command->command_next && success) {
1833 log_debug("%s running next command for state %s", u->meta.id, socket_state_to_string(s->state));
1834 socket_run_next(s, success);
1836 s->control_command = NULL;
1837 s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
1839 /* No further commands for this step, so let's figure
1840 * out what to do next */
1842 log_debug("%s got final SIGCHLD for state %s", u->meta.id, socket_state_to_string(s->state));
1846 case SOCKET_START_PRE:
1848 socket_enter_start_post(s);
1850 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1853 case SOCKET_START_POST:
1855 socket_enter_listening(s);
1857 socket_enter_stop_pre(s, false);
1860 case SOCKET_STOP_PRE:
1861 case SOCKET_STOP_PRE_SIGTERM:
1862 case SOCKET_STOP_PRE_SIGKILL:
1863 socket_enter_stop_post(s, success);
1866 case SOCKET_STOP_POST:
1867 case SOCKET_FINAL_SIGTERM:
1868 case SOCKET_FINAL_SIGKILL:
1869 socket_enter_dead(s, success);
1873 assert_not_reached("Uh, control process died at wrong time.");
1877 /* Notify clients about changed exit status */
1878 unit_add_to_dbus_queue(u);
1881 static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
1882 Socket *s = SOCKET(u);
1885 assert(elapsed == 1);
1886 assert(w == &s->timer_watch);
1890 case SOCKET_START_PRE:
1891 log_warning("%s starting timed out. Terminating.", u->meta.id);
1892 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1895 case SOCKET_START_POST:
1896 log_warning("%s starting timed out. Stopping.", u->meta.id);
1897 socket_enter_stop_pre(s, false);
1900 case SOCKET_STOP_PRE:
1901 log_warning("%s stopping timed out. Terminating.", u->meta.id);
1902 socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, false);
1905 case SOCKET_STOP_PRE_SIGTERM:
1906 if (s->exec_context.send_sigkill) {
1907 log_warning("%s stopping timed out. Killing.", u->meta.id);
1908 socket_enter_signal(s, SOCKET_STOP_PRE_SIGKILL, false);
1910 log_warning("%s stopping timed out. Skipping SIGKILL. Ignoring.", u->meta.id);
1911 socket_enter_stop_post(s, false);
1915 case SOCKET_STOP_PRE_SIGKILL:
1916 log_warning("%s still around after SIGKILL. Ignoring.", u->meta.id);
1917 socket_enter_stop_post(s, false);
1920 case SOCKET_STOP_POST:
1921 log_warning("%s stopping timed out (2). Terminating.", u->meta.id);
1922 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1925 case SOCKET_FINAL_SIGTERM:
1926 if (s->exec_context.send_sigkill) {
1927 log_warning("%s stopping timed out (2). Killing.", u->meta.id);
1928 socket_enter_signal(s, SOCKET_FINAL_SIGKILL, false);
1930 log_warning("%s stopping timed out (2). Skipping SIGKILL. Ignoring.", u->meta.id);
1931 socket_enter_dead(s, false);
1935 case SOCKET_FINAL_SIGKILL:
1936 log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->meta.id);
1937 socket_enter_dead(s, false);
1941 assert_not_reached("Timeout at wrong time.");
1945 int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
1954 /* Called from the service code for requesting our fds */
1957 LIST_FOREACH(port, p, s->ports)
1961 if (!(rfds = new(int, rn_fds)))
1965 LIST_FOREACH(port, p, s->ports)
1969 assert(k == rn_fds);
1977 void socket_notify_service_dead(Socket *s) {
1980 /* The service is dead. Dang!
1982 * This is strictly for one-instance-for-all-connections
1985 if (s->state == SOCKET_RUNNING) {
1986 log_debug("%s got notified about service death.", s->meta.id);
1987 socket_enter_listening(s);
1991 void socket_connection_unref(Socket *s) {
1994 /* The service is dead. Yay!
1996 * This is strictly for one-instance-per-connection
1999 assert(s->n_connections > 0);
2002 log_debug("%s: One connection closed, %u left.", s->meta.id, s->n_connections);
2005 static void socket_reset_failed(Unit *u) {
2006 Socket *s = SOCKET(u);
2010 if (s->state == SOCKET_FAILED)
2011 socket_set_state(s, SOCKET_DEAD);
2016 static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
2017 Socket *s = SOCKET(u);
2019 Set *pid_set = NULL;
2023 if (who == KILL_MAIN) {
2024 dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "Socket units have no main processes");
2028 if (s->control_pid <= 0 && who == KILL_CONTROL) {
2029 dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
2033 if (s->control_pid > 0)
2034 if (kill(s->control_pid, signo) < 0)
2037 if (mode == KILL_CONTROL_GROUP) {
2040 if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func)))
2043 /* Exclude the control pid from being killed via the cgroup */
2044 if (s->control_pid > 0)
2045 if ((q = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) {
2050 if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0)
2051 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
2062 static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
2063 [SOCKET_DEAD] = "dead",
2064 [SOCKET_START_PRE] = "start-pre",
2065 [SOCKET_START_POST] = "start-post",
2066 [SOCKET_LISTENING] = "listening",
2067 [SOCKET_RUNNING] = "running",
2068 [SOCKET_STOP_PRE] = "stop-pre",
2069 [SOCKET_STOP_PRE_SIGTERM] = "stop-pre-sigterm",
2070 [SOCKET_STOP_PRE_SIGKILL] = "stop-pre-sigkill",
2071 [SOCKET_STOP_POST] = "stop-post",
2072 [SOCKET_FINAL_SIGTERM] = "final-sigterm",
2073 [SOCKET_FINAL_SIGKILL] = "final-sigkill",
2074 [SOCKET_FAILED] = "failed"
2077 DEFINE_STRING_TABLE_LOOKUP(socket_state, SocketState);
2079 static const char* const socket_exec_command_table[_SOCKET_EXEC_COMMAND_MAX] = {
2080 [SOCKET_EXEC_START_PRE] = "StartPre",
2081 [SOCKET_EXEC_START_POST] = "StartPost",
2082 [SOCKET_EXEC_STOP_PRE] = "StopPre",
2083 [SOCKET_EXEC_STOP_POST] = "StopPost"
2086 DEFINE_STRING_TABLE_LOOKUP(socket_exec_command, SocketExecCommand);
2088 const UnitVTable socket_vtable = {
2089 .suffix = ".socket",
2091 .init = socket_init,
2092 .done = socket_done,
2093 .load = socket_load,
2095 .kill = socket_kill,
2097 .coldplug = socket_coldplug,
2099 .dump = socket_dump,
2101 .start = socket_start,
2102 .stop = socket_stop,
2104 .serialize = socket_serialize,
2105 .deserialize_item = socket_deserialize_item,
2107 .active_state = socket_active_state,
2108 .sub_state_to_string = socket_sub_state_to_string,
2110 .check_gc = socket_check_gc,
2112 .fd_event = socket_fd_event,
2113 .sigchld_event = socket_sigchld_event,
2114 .timer_event = socket_timer_event,
2116 .reset_failed = socket_reset_failed,
2118 .bus_interface = "org.freedesktop.systemd1.Socket",
2119 .bus_message_handler = bus_socket_message_handler,
2120 .bus_invalidating_properties = bus_socket_invalidating_properties