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_by_type, i, u->meta.manager->units_by_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_by_type, other, s->meta.manager->units_by_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);
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 r = label_get_create_label_from_exe(s->service->exec_command[SERVICE_EXEC_START]->path, &label);
907 if ((r = socket_address_listen(
920 socket_apply_socket_options(s, p->fd);
922 } else if (p->type == SOCKET_SPECIAL) {
924 if ((r = special_address_create(
929 } else if (p->type == SOCKET_FIFO) {
931 if ((r = fifo_address_create(
938 socket_apply_fifo_options(s, p->fd);
939 } else if (p->type == SOCKET_MQUEUE) {
941 if ((r = mq_address_create(
949 assert_not_reached("Unknown port type");
961 static void socket_unwatch_fds(Socket *s) {
966 LIST_FOREACH(port, p, s->ports) {
970 unit_unwatch_fd(UNIT(s), &p->fd_watch);
974 static int socket_watch_fds(Socket *s) {
980 LIST_FOREACH(port, p, s->ports) {
984 p->fd_watch.socket_accept =
986 p->type == SOCKET_SOCKET &&
987 socket_address_can_accept(&p->address);
989 if ((r = unit_watch_fd(UNIT(s), p->fd, EPOLLIN, &p->fd_watch)) < 0)
996 socket_unwatch_fds(s);
1000 static void socket_set_state(Socket *s, SocketState state) {
1001 SocketState old_state;
1004 old_state = s->state;
1007 if (state != SOCKET_START_PRE &&
1008 state != SOCKET_START_POST &&
1009 state != SOCKET_STOP_PRE &&
1010 state != SOCKET_STOP_PRE_SIGTERM &&
1011 state != SOCKET_STOP_PRE_SIGKILL &&
1012 state != SOCKET_STOP_POST &&
1013 state != SOCKET_FINAL_SIGTERM &&
1014 state != SOCKET_FINAL_SIGKILL) {
1015 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1016 socket_unwatch_control_pid(s);
1017 s->control_command = NULL;
1018 s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
1021 if (state != SOCKET_LISTENING)
1022 socket_unwatch_fds(s);
1024 if (state != SOCKET_START_POST &&
1025 state != SOCKET_LISTENING &&
1026 state != SOCKET_RUNNING &&
1027 state != SOCKET_STOP_PRE &&
1028 state != SOCKET_STOP_PRE_SIGTERM &&
1029 state != SOCKET_STOP_PRE_SIGKILL)
1030 socket_close_fds(s);
1032 if (state != old_state)
1033 log_debug("%s changed %s -> %s",
1035 socket_state_to_string(old_state),
1036 socket_state_to_string(state));
1038 unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true);
1041 static int socket_coldplug(Unit *u) {
1042 Socket *s = SOCKET(u);
1046 assert(s->state == SOCKET_DEAD);
1048 if (s->deserialized_state != s->state) {
1050 if (s->deserialized_state == SOCKET_START_PRE ||
1051 s->deserialized_state == SOCKET_START_POST ||
1052 s->deserialized_state == SOCKET_STOP_PRE ||
1053 s->deserialized_state == SOCKET_STOP_PRE_SIGTERM ||
1054 s->deserialized_state == SOCKET_STOP_PRE_SIGKILL ||
1055 s->deserialized_state == SOCKET_STOP_POST ||
1056 s->deserialized_state == SOCKET_FINAL_SIGTERM ||
1057 s->deserialized_state == SOCKET_FINAL_SIGKILL) {
1059 if (s->control_pid <= 0)
1062 if ((r = unit_watch_pid(UNIT(s), s->control_pid)) < 0)
1065 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1069 if (s->deserialized_state == SOCKET_START_POST ||
1070 s->deserialized_state == SOCKET_LISTENING ||
1071 s->deserialized_state == SOCKET_RUNNING ||
1072 s->deserialized_state == SOCKET_STOP_PRE ||
1073 s->deserialized_state == SOCKET_STOP_PRE_SIGTERM ||
1074 s->deserialized_state == SOCKET_STOP_PRE_SIGKILL)
1075 if ((r = socket_open_fds(s)) < 0)
1078 if (s->deserialized_state == SOCKET_LISTENING)
1079 if ((r = socket_watch_fds(s)) < 0)
1082 socket_set_state(s, s->deserialized_state);
1088 static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
1097 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1100 if (!(argv = unit_full_printf_strv(UNIT(s), c->argv))) {
1109 s->meta.manager->environment,
1113 s->meta.manager->confirm_spawn,
1114 s->meta.cgroup_bondings,
1115 s->meta.cgroup_attributes,
1122 if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
1123 /* FIXME: we need to do something here */
1131 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1136 static void socket_enter_dead(Socket *s, bool success) {
1142 socket_set_state(s, s->failure ? SOCKET_FAILED : SOCKET_DEAD);
1145 static void socket_enter_signal(Socket *s, SocketState state, bool success);
1147 static void socket_enter_stop_post(Socket *s, bool success) {
1154 socket_unwatch_control_pid(s);
1156 s->control_command_id = SOCKET_EXEC_STOP_POST;
1158 if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST])) {
1159 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1162 socket_set_state(s, SOCKET_STOP_POST);
1164 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, true);
1169 log_warning("%s failed to run 'stop-post' task: %s", s->meta.id, strerror(-r));
1170 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1173 static void socket_enter_signal(Socket *s, SocketState state, bool success) {
1175 Set *pid_set = NULL;
1176 bool wait_for_exit = false;
1183 if (s->exec_context.kill_mode != KILL_NONE) {
1184 int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
1186 if (s->control_pid > 0) {
1187 if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH)
1189 log_warning("Failed to kill control process %li: %m", (long) s->control_pid);
1191 wait_for_exit = true;
1194 if (s->exec_context.kill_mode == KILL_CONTROL_GROUP) {
1196 if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) {
1201 /* Exclude the control pid from being killed via the cgroup */
1202 if (s->control_pid > 0)
1203 if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
1206 if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, true, pid_set)) < 0) {
1207 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
1208 log_warning("Failed to kill control group: %s", strerror(-r));
1210 wait_for_exit = true;
1217 if (wait_for_exit) {
1218 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1221 socket_set_state(s, state);
1222 } else if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
1223 socket_enter_stop_post(s, true);
1225 socket_enter_dead(s, true);
1230 log_warning("%s failed to kill processes: %s", s->meta.id, strerror(-r));
1232 if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
1233 socket_enter_stop_post(s, false);
1235 socket_enter_dead(s, false);
1241 static void socket_enter_stop_pre(Socket *s, bool success) {
1248 socket_unwatch_control_pid(s);
1250 s->control_command_id = SOCKET_EXEC_STOP_PRE;
1252 if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE])) {
1253 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1256 socket_set_state(s, SOCKET_STOP_PRE);
1258 socket_enter_stop_post(s, true);
1263 log_warning("%s failed to run 'stop-pre' task: %s", s->meta.id, strerror(-r));
1264 socket_enter_stop_post(s, false);
1267 static void socket_enter_listening(Socket *s) {
1271 if ((r = socket_watch_fds(s)) < 0) {
1272 log_warning("%s failed to watch sockets: %s", s->meta.id, strerror(-r));
1276 socket_set_state(s, SOCKET_LISTENING);
1280 socket_enter_stop_pre(s, false);
1283 static void socket_enter_start_post(Socket *s) {
1287 if ((r = socket_open_fds(s)) < 0) {
1288 log_warning("%s failed to listen on sockets: %s", s->meta.id, strerror(-r));
1292 socket_unwatch_control_pid(s);
1294 s->control_command_id = SOCKET_EXEC_START_POST;
1296 if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) {
1297 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) {
1298 log_warning("%s failed to run 'start-post' task: %s", s->meta.id, strerror(-r));
1302 socket_set_state(s, SOCKET_START_POST);
1304 socket_enter_listening(s);
1309 socket_enter_stop_pre(s, false);
1312 static void socket_enter_start_pre(Socket *s) {
1316 socket_unwatch_control_pid(s);
1318 s->control_command_id = SOCKET_EXEC_START_PRE;
1320 if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE])) {
1321 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1324 socket_set_state(s, SOCKET_START_PRE);
1326 socket_enter_start_post(s);
1331 log_warning("%s failed to run 'start-pre' task: %s", s->meta.id, strerror(-r));
1332 socket_enter_dead(s, false);
1335 static void socket_enter_running(Socket *s, int cfd) {
1340 dbus_error_init(&error);
1342 /* We don't take connections anymore if we are supposed to
1343 * shut down anyway */
1344 if (unit_pending_inactive(UNIT(s))) {
1345 log_debug("Suppressing connection request on %s since unit stop is scheduled.", s->meta.id);
1348 close_nointr_nofail(cfd);
1350 /* Flush all sockets by closing and reopening them */
1351 socket_close_fds(s);
1353 if ((r = socket_watch_fds(s)) < 0) {
1354 log_warning("%s failed to watch sockets: %s", s->meta.id, strerror(-r));
1355 socket_enter_stop_pre(s, false);
1363 bool pending = false;
1366 /* If there's already a start pending don't bother to
1368 LIST_FOREACH(units_by_type, i, s->meta.manager->units_by_type[UNIT_SERVICE]) {
1369 Service *service = (Service *) i;
1371 if (!set_get(service->configured_sockets, s))
1374 if (!unit_pending_active(UNIT(service)))
1382 if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s->service), JOB_REPLACE, true, &error, NULL)) < 0)
1385 socket_set_state(s, SOCKET_RUNNING);
1387 char *prefix, *instance = NULL, *name;
1390 if (s->n_connections >= s->max_connections) {
1391 log_warning("Too many incoming connections (%u)", s->n_connections);
1392 close_nointr_nofail(cfd);
1396 if ((r = socket_instantiate_service(s)) < 0)
1399 if ((r = instance_from_socket(cfd, s->n_accepted, &instance)) < 0)
1402 if (!(prefix = unit_name_to_prefix(s->meta.id))) {
1408 name = unit_name_build(prefix, instance, ".service");
1417 if ((r = unit_add_name(UNIT(s->service), name)) < 0) {
1422 service = s->service;
1426 service->meta.no_gc = false;
1428 unit_choose_id(UNIT(service), name);
1431 if ((r = service_set_socket_fd(service, cfd, s)) < 0)
1435 s->n_connections ++;
1437 if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(service), JOB_REPLACE, true, &error, NULL)) < 0)
1440 /* Notify clients about changed counters */
1441 unit_add_to_dbus_queue(UNIT(s));
1447 log_warning("%s failed to queue socket startup job: %s", s->meta.id, bus_error(&error, r));
1448 socket_enter_stop_pre(s, false);
1451 close_nointr_nofail(cfd);
1453 dbus_error_free(&error);
1456 static void socket_run_next(Socket *s, bool success) {
1460 assert(s->control_command);
1461 assert(s->control_command->command_next);
1466 socket_unwatch_control_pid(s);
1468 s->control_command = s->control_command->command_next;
1470 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1476 log_warning("%s failed to run next task: %s", s->meta.id, strerror(-r));
1478 if (s->state == SOCKET_START_POST)
1479 socket_enter_stop_pre(s, false);
1480 else if (s->state == SOCKET_STOP_POST)
1481 socket_enter_dead(s, false);
1483 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1486 static int socket_start(Unit *u) {
1487 Socket *s = SOCKET(u);
1491 /* We cannot fulfill this request right now, try again later
1493 if (s->state == SOCKET_STOP_PRE ||
1494 s->state == SOCKET_STOP_PRE_SIGKILL ||
1495 s->state == SOCKET_STOP_PRE_SIGTERM ||
1496 s->state == SOCKET_STOP_POST ||
1497 s->state == SOCKET_FINAL_SIGTERM ||
1498 s->state == SOCKET_FINAL_SIGKILL)
1501 if (s->state == SOCKET_START_PRE ||
1502 s->state == SOCKET_START_POST)
1505 /* Cannot run this without the service being around */
1507 if (s->service->meta.load_state != UNIT_LOADED) {
1508 log_error("Socket service %s not loaded, refusing.", s->service->meta.id);
1512 /* If the service is already active we cannot start the
1514 if (s->service->state != SERVICE_DEAD &&
1515 s->service->state != SERVICE_FAILED &&
1516 s->service->state != SERVICE_AUTO_RESTART) {
1517 log_error("Socket service %s already active, refusing.", s->service->meta.id);
1521 #ifdef HAVE_SYSV_COMPAT
1522 if (s->service->sysv_path) {
1523 log_error("Using SysV services for socket activation is not supported. Refusing.");
1529 assert(s->state == SOCKET_DEAD || s->state == SOCKET_FAILED);
1532 socket_enter_start_pre(s);
1536 static int socket_stop(Unit *u) {
1537 Socket *s = SOCKET(u);
1542 if (s->state == SOCKET_STOP_PRE ||
1543 s->state == SOCKET_STOP_PRE_SIGTERM ||
1544 s->state == SOCKET_STOP_PRE_SIGKILL ||
1545 s->state == SOCKET_STOP_POST ||
1546 s->state == SOCKET_FINAL_SIGTERM ||
1547 s->state == SOCKET_FINAL_SIGKILL)
1550 /* If there's already something running we go directly into
1552 if (s->state == SOCKET_START_PRE ||
1553 s->state == SOCKET_START_POST) {
1554 socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, true);
1558 assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
1560 socket_enter_stop_pre(s, true);
1564 static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
1565 Socket *s = SOCKET(u);
1573 unit_serialize_item(u, f, "state", socket_state_to_string(s->state));
1574 unit_serialize_item(u, f, "failure", yes_no(s->failure));
1575 unit_serialize_item_format(u, f, "n-accepted", "%u", s->n_accepted);
1577 if (s->control_pid > 0)
1578 unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid);
1580 if (s->control_command_id >= 0)
1581 unit_serialize_item(u, f, "control-command", socket_exec_command_to_string(s->control_command_id));
1583 LIST_FOREACH(port, p, s->ports) {
1589 if ((copy = fdset_put_dup(fds, p->fd)) < 0)
1592 if (p->type == SOCKET_SOCKET) {
1595 if ((r = socket_address_print(&p->address, &t)) < 0)
1598 if (socket_address_family(&p->address) == AF_NETLINK)
1599 unit_serialize_item_format(u, f, "netlink", "%i %s", copy, t);
1601 unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t);
1603 } else if (p->type == SOCKET_SPECIAL)
1604 unit_serialize_item_format(u, f, "special", "%i %s", copy, p->path);
1606 assert(p->type == SOCKET_FIFO);
1607 unit_serialize_item_format(u, f, "fifo", "%i %s", copy, p->path);
1614 static int socket_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
1615 Socket *s = SOCKET(u);
1622 if (streq(key, "state")) {
1625 if ((state = socket_state_from_string(value)) < 0)
1626 log_debug("Failed to parse state value %s", value);
1628 s->deserialized_state = state;
1629 } else if (streq(key, "failure")) {
1632 if ((b = parse_boolean(value)) < 0)
1633 log_debug("Failed to parse failure value %s", value);
1635 s->failure = b || s->failure;
1637 } else if (streq(key, "n-accepted")) {
1640 if (safe_atou(value, &k) < 0)
1641 log_debug("Failed to parse n-accepted value %s", value);
1644 } else if (streq(key, "control-pid")) {
1647 if (parse_pid(value, &pid) < 0)
1648 log_debug("Failed to parse control-pid value %s", value);
1650 s->control_pid = pid;
1651 } else if (streq(key, "control-command")) {
1652 SocketExecCommand id;
1654 if ((id = socket_exec_command_from_string(value)) < 0)
1655 log_debug("Failed to parse exec-command value %s", value);
1657 s->control_command_id = id;
1658 s->control_command = s->exec_command[id];
1660 } else if (streq(key, "fifo")) {
1664 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1665 log_debug("Failed to parse fifo value %s", value);
1668 LIST_FOREACH(port, p, s->ports)
1669 if (p->type == SOCKET_FIFO &&
1670 streq_ptr(p->path, value+skip))
1675 close_nointr_nofail(p->fd);
1676 p->fd = fdset_remove(fds, fd);
1680 } else if (streq(key, "special")) {
1684 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1685 log_debug("Failed to parse special value %s", value);
1688 LIST_FOREACH(port, p, s->ports)
1689 if (p->type == SOCKET_SPECIAL &&
1690 streq_ptr(p->path, value+skip))
1695 close_nointr_nofail(p->fd);
1696 p->fd = fdset_remove(fds, fd);
1700 } else if (streq(key, "socket")) {
1701 int fd, type, skip = 0;
1704 if (sscanf(value, "%i %i %n", &fd, &type, &skip) < 2 || fd < 0 || type < 0 || !fdset_contains(fds, fd))
1705 log_debug("Failed to parse socket value %s", value);
1708 LIST_FOREACH(port, p, s->ports)
1709 if (socket_address_is(&p->address, value+skip, type))
1714 close_nointr_nofail(p->fd);
1715 p->fd = fdset_remove(fds, fd);
1719 } else if (streq(key, "netlink")) {
1723 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1724 log_debug("Failed to parse socket value %s", value);
1727 LIST_FOREACH(port, p, s->ports)
1728 if (socket_address_is_netlink(&p->address, value+skip))
1733 close_nointr_nofail(p->fd);
1734 p->fd = fdset_remove(fds, fd);
1739 log_debug("Unknown serialization key '%s'", key);
1744 static UnitActiveState socket_active_state(Unit *u) {
1747 return state_translation_table[SOCKET(u)->state];
1750 static const char *socket_sub_state_to_string(Unit *u) {
1753 return socket_state_to_string(SOCKET(u)->state);
1756 static bool socket_check_gc(Unit *u) {
1757 Socket *s = SOCKET(u);
1761 return s->n_connections > 0;
1764 static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
1765 Socket *s = SOCKET(u);
1771 if (s->state != SOCKET_LISTENING)
1774 log_debug("Incoming traffic on %s", u->meta.id);
1776 if (events != EPOLLIN) {
1778 if (events & EPOLLHUP)
1779 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);
1781 log_error("%s: Got unexpected poll event (0x%x) on socket.", u->meta.id, events);
1786 if (w->socket_accept) {
1789 if ((cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK)) < 0) {
1794 log_error("Failed to accept socket: %m");
1801 socket_apply_socket_options(s, cfd);
1804 socket_enter_running(s, cfd);
1808 socket_enter_stop_pre(s, false);
1811 static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
1812 Socket *s = SOCKET(u);
1818 if (pid != s->control_pid)
1823 success = is_clean_exit(code, status);
1825 if (s->control_command) {
1826 exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
1828 if (s->control_command->ignore)
1832 log_full(success ? LOG_DEBUG : LOG_NOTICE,
1833 "%s control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
1834 s->failure = s->failure || !success;
1836 if (s->control_command && s->control_command->command_next && success) {
1837 log_debug("%s running next command for state %s", u->meta.id, socket_state_to_string(s->state));
1838 socket_run_next(s, success);
1840 s->control_command = NULL;
1841 s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
1843 /* No further commands for this step, so let's figure
1844 * out what to do next */
1846 log_debug("%s got final SIGCHLD for state %s", u->meta.id, socket_state_to_string(s->state));
1850 case SOCKET_START_PRE:
1852 socket_enter_start_post(s);
1854 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1857 case SOCKET_START_POST:
1859 socket_enter_listening(s);
1861 socket_enter_stop_pre(s, false);
1864 case SOCKET_STOP_PRE:
1865 case SOCKET_STOP_PRE_SIGTERM:
1866 case SOCKET_STOP_PRE_SIGKILL:
1867 socket_enter_stop_post(s, success);
1870 case SOCKET_STOP_POST:
1871 case SOCKET_FINAL_SIGTERM:
1872 case SOCKET_FINAL_SIGKILL:
1873 socket_enter_dead(s, success);
1877 assert_not_reached("Uh, control process died at wrong time.");
1881 /* Notify clients about changed exit status */
1882 unit_add_to_dbus_queue(u);
1885 static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
1886 Socket *s = SOCKET(u);
1889 assert(elapsed == 1);
1890 assert(w == &s->timer_watch);
1894 case SOCKET_START_PRE:
1895 log_warning("%s starting timed out. Terminating.", u->meta.id);
1896 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1899 case SOCKET_START_POST:
1900 log_warning("%s starting timed out. Stopping.", u->meta.id);
1901 socket_enter_stop_pre(s, false);
1904 case SOCKET_STOP_PRE:
1905 log_warning("%s stopping timed out. Terminating.", u->meta.id);
1906 socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, false);
1909 case SOCKET_STOP_PRE_SIGTERM:
1910 if (s->exec_context.send_sigkill) {
1911 log_warning("%s stopping timed out. Killing.", u->meta.id);
1912 socket_enter_signal(s, SOCKET_STOP_PRE_SIGKILL, false);
1914 log_warning("%s stopping timed out. Skipping SIGKILL. Ignoring.", u->meta.id);
1915 socket_enter_stop_post(s, false);
1919 case SOCKET_STOP_PRE_SIGKILL:
1920 log_warning("%s still around after SIGKILL. Ignoring.", u->meta.id);
1921 socket_enter_stop_post(s, false);
1924 case SOCKET_STOP_POST:
1925 log_warning("%s stopping timed out (2). Terminating.", u->meta.id);
1926 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1929 case SOCKET_FINAL_SIGTERM:
1930 if (s->exec_context.send_sigkill) {
1931 log_warning("%s stopping timed out (2). Killing.", u->meta.id);
1932 socket_enter_signal(s, SOCKET_FINAL_SIGKILL, false);
1934 log_warning("%s stopping timed out (2). Skipping SIGKILL. Ignoring.", u->meta.id);
1935 socket_enter_dead(s, false);
1939 case SOCKET_FINAL_SIGKILL:
1940 log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->meta.id);
1941 socket_enter_dead(s, false);
1945 assert_not_reached("Timeout at wrong time.");
1949 int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
1958 /* Called from the service code for requesting our fds */
1961 LIST_FOREACH(port, p, s->ports)
1971 if (!(rfds = new(int, rn_fds)))
1975 LIST_FOREACH(port, p, s->ports)
1979 assert(k == rn_fds);
1987 void socket_notify_service_dead(Socket *s) {
1990 /* The service is dead. Dang!
1992 * This is strictly for one-instance-for-all-connections
1995 if (s->state == SOCKET_RUNNING) {
1996 log_debug("%s got notified about service death.", s->meta.id);
1997 socket_enter_listening(s);
2001 void socket_connection_unref(Socket *s) {
2004 /* The service is dead. Yay!
2006 * This is strictly for one-instance-per-connection
2009 assert(s->n_connections > 0);
2012 log_debug("%s: One connection closed, %u left.", s->meta.id, s->n_connections);
2015 static void socket_reset_failed(Unit *u) {
2016 Socket *s = SOCKET(u);
2020 if (s->state == SOCKET_FAILED)
2021 socket_set_state(s, SOCKET_DEAD);
2026 static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
2027 Socket *s = SOCKET(u);
2029 Set *pid_set = NULL;
2033 if (who == KILL_MAIN) {
2034 dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "Socket units have no main processes");
2038 if (s->control_pid <= 0 && who == KILL_CONTROL) {
2039 dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
2043 if (who == KILL_CONTROL || who == KILL_ALL)
2044 if (s->control_pid > 0)
2045 if (kill(s->control_pid, signo) < 0)
2048 if (who == KILL_ALL && mode == KILL_CONTROL_GROUP) {
2051 if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func)))
2054 /* Exclude the control pid from being killed via the cgroup */
2055 if (s->control_pid > 0)
2056 if ((q = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) {
2061 if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0)
2062 if (q != -EAGAIN && q != -ESRCH && q != -ENOENT)
2073 static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
2074 [SOCKET_DEAD] = "dead",
2075 [SOCKET_START_PRE] = "start-pre",
2076 [SOCKET_START_POST] = "start-post",
2077 [SOCKET_LISTENING] = "listening",
2078 [SOCKET_RUNNING] = "running",
2079 [SOCKET_STOP_PRE] = "stop-pre",
2080 [SOCKET_STOP_PRE_SIGTERM] = "stop-pre-sigterm",
2081 [SOCKET_STOP_PRE_SIGKILL] = "stop-pre-sigkill",
2082 [SOCKET_STOP_POST] = "stop-post",
2083 [SOCKET_FINAL_SIGTERM] = "final-sigterm",
2084 [SOCKET_FINAL_SIGKILL] = "final-sigkill",
2085 [SOCKET_FAILED] = "failed"
2088 DEFINE_STRING_TABLE_LOOKUP(socket_state, SocketState);
2090 static const char* const socket_exec_command_table[_SOCKET_EXEC_COMMAND_MAX] = {
2091 [SOCKET_EXEC_START_PRE] = "StartPre",
2092 [SOCKET_EXEC_START_POST] = "StartPost",
2093 [SOCKET_EXEC_STOP_PRE] = "StopPre",
2094 [SOCKET_EXEC_STOP_POST] = "StopPost"
2097 DEFINE_STRING_TABLE_LOOKUP(socket_exec_command, SocketExecCommand);
2099 const UnitVTable socket_vtable = {
2100 .suffix = ".socket",
2106 .init = socket_init,
2107 .done = socket_done,
2108 .load = socket_load,
2110 .kill = socket_kill,
2112 .coldplug = socket_coldplug,
2114 .dump = socket_dump,
2116 .start = socket_start,
2117 .stop = socket_stop,
2119 .serialize = socket_serialize,
2120 .deserialize_item = socket_deserialize_item,
2122 .active_state = socket_active_state,
2123 .sub_state_to_string = socket_sub_state_to_string,
2125 .check_gc = socket_check_gc,
2127 .fd_event = socket_fd_event,
2128 .sigchld_event = socket_sigchld_event,
2129 .timer_event = socket_timer_event,
2131 .reset_failed = socket_reset_failed,
2133 .bus_interface = "org.freedesktop.systemd1.Socket",
2134 .bus_message_handler = bus_socket_message_handler,
2135 .bus_invalidating_properties = bus_socket_invalidating_properties