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"
408 "%sTCPCongestion: %s\n",
409 prefix, socket_state_to_string(s->state),
410 prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only),
412 prefix, s->socket_mode,
413 prefix, s->directory_mode,
414 prefix, yes_no(s->keep_alive),
415 prefix, yes_no(s->free_bind),
416 prefix, yes_no(s->transparent),
417 prefix, strna(s->tcp_congestion));
419 if (s->control_pid > 0)
421 "%sControl PID: %lu\n",
422 prefix, (unsigned long) s->control_pid);
424 if (s->bind_to_device)
426 "%sBindToDevice: %s\n",
427 prefix, s->bind_to_device);
432 "%sNConnections: %u\n"
433 "%sMaxConnections: %u\n",
434 prefix, s->n_accepted,
435 prefix, s->n_connections,
436 prefix, s->max_connections);
438 if (s->priority >= 0)
441 prefix, s->priority);
443 if (s->receive_buffer > 0)
445 "%sReceiveBuffer: %zu\n",
446 prefix, s->receive_buffer);
448 if (s->send_buffer > 0)
450 "%sSendBuffer: %zu\n",
451 prefix, s->send_buffer);
463 if (s->pipe_size > 0)
466 prefix, s->pipe_size);
473 if (s->mq_maxmsg > 0)
475 "%sMessageQueueMaxMessages: %li\n",
476 prefix, s->mq_maxmsg);
478 if (s->mq_msgsize > 0)
480 "%sMessageQueueMessageSize: %li\n",
481 prefix, s->mq_msgsize);
483 LIST_FOREACH(port, p, s->ports) {
485 if (p->type == SOCKET_SOCKET) {
490 if ((r = socket_address_print(&p->address, &k)) < 0)
495 fprintf(f, "%s%s: %s\n", prefix, listen_lookup(socket_address_family(&p->address), p->address.type), t);
497 } else if (p->type == SOCKET_SPECIAL)
498 fprintf(f, "%sListenSpecial: %s\n", prefix, p->path);
499 else if (p->type == SOCKET_MQUEUE)
500 fprintf(f, "%sListenMessageQueue: %s\n", prefix, p->path);
502 fprintf(f, "%sListenFIFO: %s\n", prefix, p->path);
505 exec_context_dump(&s->exec_context, f, prefix);
507 for (c = 0; c < _SOCKET_EXEC_COMMAND_MAX; c++) {
508 if (!s->exec_command[c])
511 fprintf(f, "%s-> %s:\n",
512 prefix, socket_exec_command_to_string(c));
514 exec_command_dump_list(s->exec_command[c], f, prefix2);
520 static int instance_from_socket(int fd, unsigned nr, char **instance) {
525 struct sockaddr_un un;
526 struct sockaddr_in in;
527 struct sockaddr_in6 in6;
528 struct sockaddr_storage storage;
535 if (getsockname(fd, &local.sa, &l) < 0)
539 if (getpeername(fd, &remote.sa, &l) < 0)
542 switch (local.sa.sa_family) {
546 a = ntohl(local.in.sin_addr.s_addr),
547 b = ntohl(remote.in.sin_addr.s_addr);
550 "%u.%u.%u.%u:%u-%u.%u.%u.%u:%u",
551 a >> 24, (a >> 16) & 0xFF, (a >> 8) & 0xFF, a & 0xFF,
552 ntohs(local.in.sin_port),
553 b >> 24, (b >> 16) & 0xFF, (b >> 8) & 0xFF, b & 0xFF,
554 ntohs(remote.in.sin_port)) < 0)
561 static const char ipv4_prefix[] = {
562 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF
565 if (memcmp(&local.in6.sin6_addr, ipv4_prefix, sizeof(ipv4_prefix)) == 0 &&
566 memcmp(&remote.in6.sin6_addr, ipv4_prefix, sizeof(ipv4_prefix)) == 0) {
568 *a = local.in6.sin6_addr.s6_addr+12,
569 *b = remote.in6.sin6_addr.s6_addr+12;
572 "%u.%u.%u.%u:%u-%u.%u.%u.%u:%u",
573 a[0], a[1], a[2], a[3],
574 ntohs(local.in6.sin6_port),
575 b[0], b[1], b[2], b[3],
576 ntohs(remote.in6.sin6_port)) < 0)
579 char a[INET6_ADDRSTRLEN], b[INET6_ADDRSTRLEN];
583 inet_ntop(AF_INET6, &local.in6.sin6_addr, a, sizeof(a)),
584 ntohs(local.in6.sin6_port),
585 inet_ntop(AF_INET6, &remote.in6.sin6_addr, b, sizeof(b)),
586 ntohs(remote.in6.sin6_port)) < 0)
597 if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l) < 0)
603 (unsigned long) ucred.pid,
604 (unsigned long) ucred.uid) < 0)
611 assert_not_reached("Unhandled socket type.");
618 static void socket_close_fds(Socket *s) {
623 LIST_FOREACH(port, p, s->ports) {
627 unit_unwatch_fd(UNIT(s), &p->fd_watch);
628 close_nointr_nofail(p->fd);
630 /* One little note: we should never delete any sockets
631 * in the file system here! After all some other
632 * process we spawned might still have a reference of
633 * this fd and wants to continue to use it. Therefore
634 * we delete sockets in the file system before we
635 * create a new one, not after we stopped using
642 static void socket_apply_socket_options(Socket *s, int fd) {
647 int b = s->keep_alive;
648 if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &b, sizeof(b)) < 0)
649 log_warning("SO_KEEPALIVE failed: %m");
652 if (s->priority >= 0)
653 if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &s->priority, sizeof(s->priority)) < 0)
654 log_warning("SO_PRIORITY failed: %m");
656 if (s->receive_buffer > 0) {
657 int value = (int) s->receive_buffer;
658 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value)) < 0)
659 log_warning("SO_RCVBUF failed: %m");
662 if (s->send_buffer > 0) {
663 int value = (int) s->send_buffer;
664 if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value)) < 0)
665 log_warning("SO_SNDBUF failed: %m");
669 if (setsockopt(fd, SOL_SOCKET, SO_MARK, &s->mark, sizeof(s->mark)) < 0)
670 log_warning("SO_MARK failed: %m");
673 if (setsockopt(fd, IPPROTO_IP, IP_TOS, &s->ip_tos, sizeof(s->ip_tos)) < 0)
674 log_warning("IP_TOS failed: %m");
676 if (s->ip_ttl >= 0) {
679 r = setsockopt(fd, IPPROTO_IP, IP_TTL, &s->ip_ttl, sizeof(s->ip_ttl));
681 if (socket_ipv6_is_supported())
682 x = setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &s->ip_ttl, sizeof(s->ip_ttl));
685 errno = EAFNOSUPPORT;
689 log_warning("IP_TTL/IPV6_UNICAST_HOPS failed: %m");
692 if (s->tcp_congestion)
693 if (setsockopt(fd, SOL_TCP, TCP_CONGESTION, s->tcp_congestion, strlen(s->tcp_congestion)+1) < 0)
694 log_warning("TCP_CONGESTION failed: %m");
697 static void socket_apply_fifo_options(Socket *s, int fd) {
701 if (s->pipe_size > 0)
702 if (fcntl(fd, F_SETPIPE_SZ, s->pipe_size) < 0)
703 log_warning("F_SETPIPE_SZ: %m");
706 static int fifo_address_create(
708 mode_t directory_mode,
719 mkdir_parents(path, directory_mode);
721 if ((r = label_fifofile_set(path)) < 0)
724 /* Enforce the right access mode for the fifo */
725 old_mask = umask(~ socket_mode);
727 /* Include the original umask in our mask */
728 umask(~socket_mode | old_mask);
730 r = mkfifo(path, socket_mode);
733 if (r < 0 && errno != EEXIST) {
738 if ((fd = open(path, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW)) < 0) {
745 if (fstat(fd, &st) < 0) {
750 if (!S_ISFIFO(st.st_mode) ||
751 (st.st_mode & 0777) != (socket_mode & ~old_mask) ||
752 st.st_uid != getuid() ||
753 st.st_gid != getgid()) {
766 close_nointr_nofail(fd);
771 static int special_address_create(
781 if ((fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW)) < 0) {
786 if (fstat(fd, &st) < 0) {
791 /* Check whether this is a /proc, /sys or /dev file or char device */
792 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) {
802 close_nointr_nofail(fd);
807 static int mq_address_create(
817 struct mq_attr _attr, *attr = NULL;
822 if (maxmsg > 0 && msgsize > 0) {
824 _attr.mq_flags = O_NONBLOCK;
825 _attr.mq_maxmsg = maxmsg;
826 _attr.mq_msgsize = msgsize;
830 /* Enforce the right access mode for the mq */
831 old_mask = umask(~ mq_mode);
833 /* Include the original umask in our mask */
834 umask(~mq_mode | old_mask);
836 fd = mq_open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_CREAT, mq_mode, attr);
839 if (fd < 0 && errno != EEXIST) {
844 if (fstat(fd, &st) < 0) {
849 if ((st.st_mode & 0777) != (mq_mode & ~old_mask) ||
850 st.st_uid != getuid() ||
851 st.st_gid != getgid()) {
862 close_nointr_nofail(fd);
867 static int socket_open_fds(Socket *s) {
871 bool know_label = false;
875 LIST_FOREACH(port, p, s->ports) {
880 if (p->type == SOCKET_SOCKET) {
884 if ((r = socket_instantiate_service(s)) < 0)
887 if (s->service && s->service->exec_command[SERVICE_EXEC_START])
888 if ((r = label_get_socket_label_from_exe(s->service->exec_command[SERVICE_EXEC_START]->path, &label)) < 0) {
896 if ((r = socket_address_listen(
909 socket_apply_socket_options(s, p->fd);
911 } else if (p->type == SOCKET_SPECIAL) {
913 if ((r = special_address_create(
918 } else if (p->type == SOCKET_FIFO) {
920 if ((r = fifo_address_create(
927 socket_apply_fifo_options(s, p->fd);
928 } else if (p->type == SOCKET_MQUEUE) {
930 if ((r = mq_address_create(
938 assert_not_reached("Unknown port type");
950 static void socket_unwatch_fds(Socket *s) {
955 LIST_FOREACH(port, p, s->ports) {
959 unit_unwatch_fd(UNIT(s), &p->fd_watch);
963 static int socket_watch_fds(Socket *s) {
969 LIST_FOREACH(port, p, s->ports) {
973 p->fd_watch.socket_accept =
975 p->type == SOCKET_SOCKET &&
976 socket_address_can_accept(&p->address);
978 if ((r = unit_watch_fd(UNIT(s), p->fd, EPOLLIN, &p->fd_watch)) < 0)
985 socket_unwatch_fds(s);
989 static void socket_set_state(Socket *s, SocketState state) {
990 SocketState old_state;
993 old_state = s->state;
996 if (state != SOCKET_START_PRE &&
997 state != SOCKET_START_POST &&
998 state != SOCKET_STOP_PRE &&
999 state != SOCKET_STOP_PRE_SIGTERM &&
1000 state != SOCKET_STOP_PRE_SIGKILL &&
1001 state != SOCKET_STOP_POST &&
1002 state != SOCKET_FINAL_SIGTERM &&
1003 state != SOCKET_FINAL_SIGKILL) {
1004 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1005 socket_unwatch_control_pid(s);
1006 s->control_command = NULL;
1007 s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
1010 if (state != SOCKET_LISTENING)
1011 socket_unwatch_fds(s);
1013 if (state != SOCKET_START_POST &&
1014 state != SOCKET_LISTENING &&
1015 state != SOCKET_RUNNING &&
1016 state != SOCKET_STOP_PRE &&
1017 state != SOCKET_STOP_PRE_SIGTERM &&
1018 state != SOCKET_STOP_PRE_SIGKILL)
1019 socket_close_fds(s);
1021 if (state != old_state)
1022 log_debug("%s changed %s -> %s",
1024 socket_state_to_string(old_state),
1025 socket_state_to_string(state));
1027 unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true);
1030 static int socket_coldplug(Unit *u) {
1031 Socket *s = SOCKET(u);
1035 assert(s->state == SOCKET_DEAD);
1037 if (s->deserialized_state != s->state) {
1039 if (s->deserialized_state == SOCKET_START_PRE ||
1040 s->deserialized_state == SOCKET_START_POST ||
1041 s->deserialized_state == SOCKET_STOP_PRE ||
1042 s->deserialized_state == SOCKET_STOP_PRE_SIGTERM ||
1043 s->deserialized_state == SOCKET_STOP_PRE_SIGKILL ||
1044 s->deserialized_state == SOCKET_STOP_POST ||
1045 s->deserialized_state == SOCKET_FINAL_SIGTERM ||
1046 s->deserialized_state == SOCKET_FINAL_SIGKILL) {
1048 if (s->control_pid <= 0)
1051 if ((r = unit_watch_pid(UNIT(s), s->control_pid)) < 0)
1054 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1058 if (s->deserialized_state == SOCKET_START_POST ||
1059 s->deserialized_state == SOCKET_LISTENING ||
1060 s->deserialized_state == SOCKET_RUNNING ||
1061 s->deserialized_state == SOCKET_STOP_PRE ||
1062 s->deserialized_state == SOCKET_STOP_PRE_SIGTERM ||
1063 s->deserialized_state == SOCKET_STOP_PRE_SIGKILL)
1064 if ((r = socket_open_fds(s)) < 0)
1067 if (s->deserialized_state == SOCKET_LISTENING)
1068 if ((r = socket_watch_fds(s)) < 0)
1071 socket_set_state(s, s->deserialized_state);
1077 static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
1086 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1089 if (!(argv = unit_full_printf_strv(UNIT(s), c->argv))) {
1098 s->meta.manager->environment,
1102 s->meta.manager->confirm_spawn,
1103 s->meta.cgroup_bondings,
1110 if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
1111 /* FIXME: we need to do something here */
1119 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1124 static void socket_enter_dead(Socket *s, bool success) {
1130 socket_set_state(s, s->failure ? SOCKET_FAILED : SOCKET_DEAD);
1133 static void socket_enter_signal(Socket *s, SocketState state, bool success);
1135 static void socket_enter_stop_post(Socket *s, bool success) {
1142 socket_unwatch_control_pid(s);
1144 s->control_command_id = SOCKET_EXEC_STOP_POST;
1146 if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST])) {
1147 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1150 socket_set_state(s, SOCKET_STOP_POST);
1152 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, true);
1157 log_warning("%s failed to run 'stop-post' task: %s", s->meta.id, strerror(-r));
1158 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1161 static void socket_enter_signal(Socket *s, SocketState state, bool success) {
1163 Set *pid_set = NULL;
1164 bool wait_for_exit = false;
1171 if (s->exec_context.kill_mode != KILL_NONE) {
1172 int sig = (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
1174 if (s->control_pid > 0) {
1175 if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH)
1177 log_warning("Failed to kill control process %li: %m", (long) s->control_pid);
1179 wait_for_exit = true;
1182 if (s->exec_context.kill_mode == KILL_CONTROL_GROUP) {
1184 if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) {
1189 /* Exclude the control pid from being killed via the cgroup */
1190 if (s->control_pid > 0)
1191 if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
1194 if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, true, pid_set)) < 0) {
1195 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
1196 log_warning("Failed to kill control group: %s", strerror(-r));
1198 wait_for_exit = true;
1205 if (wait_for_exit) {
1206 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1209 socket_set_state(s, state);
1210 } else if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
1211 socket_enter_stop_post(s, true);
1213 socket_enter_dead(s, true);
1218 log_warning("%s failed to kill processes: %s", s->meta.id, strerror(-r));
1220 if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
1221 socket_enter_stop_post(s, false);
1223 socket_enter_dead(s, false);
1229 static void socket_enter_stop_pre(Socket *s, bool success) {
1236 socket_unwatch_control_pid(s);
1238 s->control_command_id = SOCKET_EXEC_STOP_PRE;
1240 if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE])) {
1241 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1244 socket_set_state(s, SOCKET_STOP_PRE);
1246 socket_enter_stop_post(s, true);
1251 log_warning("%s failed to run 'stop-pre' task: %s", s->meta.id, strerror(-r));
1252 socket_enter_stop_post(s, false);
1255 static void socket_enter_listening(Socket *s) {
1259 if ((r = socket_watch_fds(s)) < 0) {
1260 log_warning("%s failed to watch sockets: %s", s->meta.id, strerror(-r));
1264 socket_set_state(s, SOCKET_LISTENING);
1268 socket_enter_stop_pre(s, false);
1271 static void socket_enter_start_post(Socket *s) {
1275 if ((r = socket_open_fds(s)) < 0) {
1276 log_warning("%s failed to listen on sockets: %s", s->meta.id, strerror(-r));
1280 socket_unwatch_control_pid(s);
1282 s->control_command_id = SOCKET_EXEC_START_POST;
1284 if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) {
1285 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) {
1286 log_warning("%s failed to run 'start-post' task: %s", s->meta.id, strerror(-r));
1290 socket_set_state(s, SOCKET_START_POST);
1292 socket_enter_listening(s);
1297 socket_enter_stop_pre(s, false);
1300 static void socket_enter_start_pre(Socket *s) {
1304 socket_unwatch_control_pid(s);
1306 s->control_command_id = SOCKET_EXEC_START_PRE;
1308 if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE])) {
1309 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1312 socket_set_state(s, SOCKET_START_PRE);
1314 socket_enter_start_post(s);
1319 log_warning("%s failed to run 'start-pre' task: %s", s->meta.id, strerror(-r));
1320 socket_enter_dead(s, false);
1323 static void socket_enter_running(Socket *s, int cfd) {
1328 dbus_error_init(&error);
1330 /* We don't take connections anymore if we are supposed to
1331 * shut down anyway */
1332 if (unit_pending_inactive(UNIT(s))) {
1333 log_debug("Suppressing connection request on %s since unit stop is scheduled.", s->meta.id);
1336 close_nointr_nofail(cfd);
1338 /* Flush all sockets by closing and reopening them */
1339 socket_close_fds(s);
1341 if ((r = socket_watch_fds(s)) < 0) {
1342 log_warning("%s failed to watch sockets: %s", s->meta.id, strerror(-r));
1343 socket_enter_stop_pre(s, false);
1351 bool pending = false;
1354 /* If there's already a start pending don't bother to
1356 LIST_FOREACH(units_per_type, i, s->meta.manager->units_per_type[UNIT_SERVICE]) {
1357 Service *service = (Service *) i;
1359 if (!set_get(service->configured_sockets, s))
1362 if (!unit_pending_active(UNIT(service)))
1370 if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s->service), JOB_REPLACE, true, &error, NULL)) < 0)
1373 socket_set_state(s, SOCKET_RUNNING);
1375 char *prefix, *instance = NULL, *name;
1378 if (s->n_connections >= s->max_connections) {
1379 log_warning("Too many incoming connections (%u)", s->n_connections);
1380 close_nointr_nofail(cfd);
1384 if ((r = socket_instantiate_service(s)) < 0)
1387 if ((r = instance_from_socket(cfd, s->n_accepted, &instance)) < 0)
1390 if (!(prefix = unit_name_to_prefix(s->meta.id))) {
1396 name = unit_name_build(prefix, instance, ".service");
1405 if ((r = unit_add_name(UNIT(s->service), name)) < 0) {
1410 service = s->service;
1414 service->meta.no_gc = false;
1416 unit_choose_id(UNIT(service), name);
1419 if ((r = service_set_socket_fd(service, cfd, s)) < 0)
1423 s->n_connections ++;
1425 if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(service), JOB_REPLACE, true, &error, NULL)) < 0)
1428 /* Notify clients about changed counters */
1429 unit_add_to_dbus_queue(UNIT(s));
1435 log_warning("%s failed to queue socket startup job: %s", s->meta.id, bus_error(&error, r));
1436 socket_enter_stop_pre(s, false);
1439 close_nointr_nofail(cfd);
1441 dbus_error_free(&error);
1444 static void socket_run_next(Socket *s, bool success) {
1448 assert(s->control_command);
1449 assert(s->control_command->command_next);
1454 socket_unwatch_control_pid(s);
1456 s->control_command = s->control_command->command_next;
1458 if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0)
1464 log_warning("%s failed to run next task: %s", s->meta.id, strerror(-r));
1466 if (s->state == SOCKET_START_POST)
1467 socket_enter_stop_pre(s, false);
1468 else if (s->state == SOCKET_STOP_POST)
1469 socket_enter_dead(s, false);
1471 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1474 static int socket_start(Unit *u) {
1475 Socket *s = SOCKET(u);
1479 /* We cannot fulfill this request right now, try again later
1481 if (s->state == SOCKET_STOP_PRE ||
1482 s->state == SOCKET_STOP_PRE_SIGKILL ||
1483 s->state == SOCKET_STOP_PRE_SIGTERM ||
1484 s->state == SOCKET_STOP_POST ||
1485 s->state == SOCKET_FINAL_SIGTERM ||
1486 s->state == SOCKET_FINAL_SIGKILL)
1489 if (s->state == SOCKET_START_PRE ||
1490 s->state == SOCKET_START_POST)
1493 /* Cannot run this without the service being around */
1495 if (s->service->meta.load_state != UNIT_LOADED) {
1496 log_error("Socket service %s not loaded, refusing.", s->service->meta.id);
1500 /* If the service is already active we cannot start the
1502 if (s->service->state != SERVICE_DEAD &&
1503 s->service->state != SERVICE_FAILED &&
1504 s->service->state != SERVICE_AUTO_RESTART) {
1505 log_error("Socket service %s already active, refusing.", s->service->meta.id);
1509 #ifdef HAVE_SYSV_COMPAT
1510 if (s->service->sysv_path) {
1511 log_error("Using SysV services for socket activation is not supported. Refusing.");
1517 assert(s->state == SOCKET_DEAD || s->state == SOCKET_FAILED);
1520 socket_enter_start_pre(s);
1524 static int socket_stop(Unit *u) {
1525 Socket *s = SOCKET(u);
1530 if (s->state == SOCKET_STOP_PRE ||
1531 s->state == SOCKET_STOP_PRE_SIGTERM ||
1532 s->state == SOCKET_STOP_PRE_SIGKILL ||
1533 s->state == SOCKET_STOP_POST ||
1534 s->state == SOCKET_FINAL_SIGTERM ||
1535 s->state == SOCKET_FINAL_SIGKILL)
1538 /* If there's already something running we go directly into
1540 if (s->state == SOCKET_START_PRE ||
1541 s->state == SOCKET_START_POST) {
1542 socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, true);
1546 assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
1548 socket_enter_stop_pre(s, true);
1552 static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
1553 Socket *s = SOCKET(u);
1561 unit_serialize_item(u, f, "state", socket_state_to_string(s->state));
1562 unit_serialize_item(u, f, "failure", yes_no(s->failure));
1563 unit_serialize_item_format(u, f, "n-accepted", "%u", s->n_accepted);
1565 if (s->control_pid > 0)
1566 unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid);
1568 if (s->control_command_id >= 0)
1569 unit_serialize_item(u, f, "control-command", socket_exec_command_to_string(s->control_command_id));
1571 LIST_FOREACH(port, p, s->ports) {
1577 if ((copy = fdset_put_dup(fds, p->fd)) < 0)
1580 if (p->type == SOCKET_SOCKET) {
1583 if ((r = socket_address_print(&p->address, &t)) < 0)
1586 if (socket_address_family(&p->address) == AF_NETLINK)
1587 unit_serialize_item_format(u, f, "netlink", "%i %s", copy, t);
1589 unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t);
1591 } else if (p->type == SOCKET_SPECIAL)
1592 unit_serialize_item_format(u, f, "special", "%i %s", copy, p->path);
1594 assert(p->type == SOCKET_FIFO);
1595 unit_serialize_item_format(u, f, "fifo", "%i %s", copy, p->path);
1602 static int socket_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
1603 Socket *s = SOCKET(u);
1610 if (streq(key, "state")) {
1613 if ((state = socket_state_from_string(value)) < 0)
1614 log_debug("Failed to parse state value %s", value);
1616 s->deserialized_state = state;
1617 } else if (streq(key, "failure")) {
1620 if ((b = parse_boolean(value)) < 0)
1621 log_debug("Failed to parse failure value %s", value);
1623 s->failure = b || s->failure;
1625 } else if (streq(key, "n-accepted")) {
1628 if (safe_atou(value, &k) < 0)
1629 log_debug("Failed to parse n-accepted value %s", value);
1632 } else if (streq(key, "control-pid")) {
1635 if (parse_pid(value, &pid) < 0)
1636 log_debug("Failed to parse control-pid value %s", value);
1638 s->control_pid = pid;
1639 } else if (streq(key, "control-command")) {
1640 SocketExecCommand id;
1642 if ((id = socket_exec_command_from_string(value)) < 0)
1643 log_debug("Failed to parse exec-command value %s", value);
1645 s->control_command_id = id;
1646 s->control_command = s->exec_command[id];
1648 } else if (streq(key, "fifo")) {
1652 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1653 log_debug("Failed to parse fifo value %s", value);
1656 LIST_FOREACH(port, p, s->ports)
1657 if (p->type == SOCKET_FIFO &&
1658 streq_ptr(p->path, value+skip))
1663 close_nointr_nofail(p->fd);
1664 p->fd = fdset_remove(fds, fd);
1668 } else if (streq(key, "special")) {
1672 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1673 log_debug("Failed to parse special value %s", value);
1676 LIST_FOREACH(port, p, s->ports)
1677 if (p->type == SOCKET_SPECIAL &&
1678 streq_ptr(p->path, value+skip))
1683 close_nointr_nofail(p->fd);
1684 p->fd = fdset_remove(fds, fd);
1688 } else if (streq(key, "socket")) {
1689 int fd, type, skip = 0;
1692 if (sscanf(value, "%i %i %n", &fd, &type, &skip) < 2 || fd < 0 || type < 0 || !fdset_contains(fds, fd))
1693 log_debug("Failed to parse socket value %s", value);
1696 LIST_FOREACH(port, p, s->ports)
1697 if (socket_address_is(&p->address, value+skip, type))
1702 close_nointr_nofail(p->fd);
1703 p->fd = fdset_remove(fds, fd);
1707 } else if (streq(key, "netlink")) {
1711 if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
1712 log_debug("Failed to parse socket value %s", value);
1715 LIST_FOREACH(port, p, s->ports)
1716 if (socket_address_is_netlink(&p->address, value+skip))
1721 close_nointr_nofail(p->fd);
1722 p->fd = fdset_remove(fds, fd);
1727 log_debug("Unknown serialization key '%s'", key);
1732 static UnitActiveState socket_active_state(Unit *u) {
1735 return state_translation_table[SOCKET(u)->state];
1738 static const char *socket_sub_state_to_string(Unit *u) {
1741 return socket_state_to_string(SOCKET(u)->state);
1744 static bool socket_check_gc(Unit *u) {
1745 Socket *s = SOCKET(u);
1749 return s->n_connections > 0;
1752 static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
1753 Socket *s = SOCKET(u);
1759 if (s->state != SOCKET_LISTENING)
1762 log_debug("Incoming traffic on %s", u->meta.id);
1764 if (events != EPOLLIN) {
1766 if (events & EPOLLHUP)
1767 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);
1769 log_error("%s: Got unexpected poll event (0x%x) on socket.", u->meta.id, events);
1774 if (w->socket_accept) {
1777 if ((cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK)) < 0) {
1782 log_error("Failed to accept socket: %m");
1789 socket_apply_socket_options(s, cfd);
1792 socket_enter_running(s, cfd);
1796 socket_enter_stop_pre(s, false);
1799 static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
1800 Socket *s = SOCKET(u);
1806 if (pid != s->control_pid)
1811 success = is_clean_exit(code, status);
1813 if (s->control_command) {
1814 exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
1816 if (s->control_command->ignore)
1820 log_full(success ? LOG_DEBUG : LOG_NOTICE,
1821 "%s control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
1822 s->failure = s->failure || !success;
1824 if (s->control_command && s->control_command->command_next && success) {
1825 log_debug("%s running next command for state %s", u->meta.id, socket_state_to_string(s->state));
1826 socket_run_next(s, success);
1828 s->control_command = NULL;
1829 s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
1831 /* No further commands for this step, so let's figure
1832 * out what to do next */
1834 log_debug("%s got final SIGCHLD for state %s", u->meta.id, socket_state_to_string(s->state));
1838 case SOCKET_START_PRE:
1840 socket_enter_start_post(s);
1842 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1845 case SOCKET_START_POST:
1847 socket_enter_listening(s);
1849 socket_enter_stop_pre(s, false);
1852 case SOCKET_STOP_PRE:
1853 case SOCKET_STOP_PRE_SIGTERM:
1854 case SOCKET_STOP_PRE_SIGKILL:
1855 socket_enter_stop_post(s, success);
1858 case SOCKET_STOP_POST:
1859 case SOCKET_FINAL_SIGTERM:
1860 case SOCKET_FINAL_SIGKILL:
1861 socket_enter_dead(s, success);
1865 assert_not_reached("Uh, control process died at wrong time.");
1869 /* Notify clients about changed exit status */
1870 unit_add_to_dbus_queue(u);
1873 static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) {
1874 Socket *s = SOCKET(u);
1877 assert(elapsed == 1);
1878 assert(w == &s->timer_watch);
1882 case SOCKET_START_PRE:
1883 log_warning("%s starting timed out. Terminating.", u->meta.id);
1884 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1887 case SOCKET_START_POST:
1888 log_warning("%s starting timed out. Stopping.", u->meta.id);
1889 socket_enter_stop_pre(s, false);
1892 case SOCKET_STOP_PRE:
1893 log_warning("%s stopping timed out. Terminating.", u->meta.id);
1894 socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, false);
1897 case SOCKET_STOP_PRE_SIGTERM:
1898 if (s->exec_context.send_sigkill) {
1899 log_warning("%s stopping timed out. Killing.", u->meta.id);
1900 socket_enter_signal(s, SOCKET_STOP_PRE_SIGKILL, false);
1902 log_warning("%s stopping timed out. Skipping SIGKILL. Ignoring.", u->meta.id);
1903 socket_enter_stop_post(s, false);
1907 case SOCKET_STOP_PRE_SIGKILL:
1908 log_warning("%s still around after SIGKILL. Ignoring.", u->meta.id);
1909 socket_enter_stop_post(s, false);
1912 case SOCKET_STOP_POST:
1913 log_warning("%s stopping timed out (2). Terminating.", u->meta.id);
1914 socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false);
1917 case SOCKET_FINAL_SIGTERM:
1918 if (s->exec_context.send_sigkill) {
1919 log_warning("%s stopping timed out (2). Killing.", u->meta.id);
1920 socket_enter_signal(s, SOCKET_FINAL_SIGKILL, false);
1922 log_warning("%s stopping timed out (2). Skipping SIGKILL. Ignoring.", u->meta.id);
1923 socket_enter_dead(s, false);
1927 case SOCKET_FINAL_SIGKILL:
1928 log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->meta.id);
1929 socket_enter_dead(s, false);
1933 assert_not_reached("Timeout at wrong time.");
1937 int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
1946 /* Called from the service code for requesting our fds */
1949 LIST_FOREACH(port, p, s->ports)
1953 if (!(rfds = new(int, rn_fds)))
1957 LIST_FOREACH(port, p, s->ports)
1961 assert(k == rn_fds);
1969 void socket_notify_service_dead(Socket *s) {
1972 /* The service is dead. Dang!
1974 * This is strictly for one-instance-for-all-connections
1977 if (s->state == SOCKET_RUNNING) {
1978 log_debug("%s got notified about service death.", s->meta.id);
1979 socket_enter_listening(s);
1983 void socket_connection_unref(Socket *s) {
1986 /* The service is dead. Yay!
1988 * This is strictly for one-instance-per-connection
1991 assert(s->n_connections > 0);
1994 log_debug("%s: One connection closed, %u left.", s->meta.id, s->n_connections);
1997 static void socket_reset_failed(Unit *u) {
1998 Socket *s = SOCKET(u);
2002 if (s->state == SOCKET_FAILED)
2003 socket_set_state(s, SOCKET_DEAD);
2008 static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
2009 Socket *s = SOCKET(u);
2011 Set *pid_set = NULL;
2015 if (who == KILL_MAIN) {
2016 dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "Socket units have no main processes");
2020 if (s->control_pid <= 0 && who == KILL_CONTROL) {
2021 dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
2025 if (s->control_pid > 0)
2026 if (kill(s->control_pid, signo) < 0)
2029 if (mode == KILL_CONTROL_GROUP) {
2032 if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func)))
2035 /* Exclude the control pid from being killed via the cgroup */
2036 if (s->control_pid > 0)
2037 if ((q = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0) {
2042 if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0)
2043 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
2054 static const char* const socket_state_table[_SOCKET_STATE_MAX] = {
2055 [SOCKET_DEAD] = "dead",
2056 [SOCKET_START_PRE] = "start-pre",
2057 [SOCKET_START_POST] = "start-post",
2058 [SOCKET_LISTENING] = "listening",
2059 [SOCKET_RUNNING] = "running",
2060 [SOCKET_STOP_PRE] = "stop-pre",
2061 [SOCKET_STOP_PRE_SIGTERM] = "stop-pre-sigterm",
2062 [SOCKET_STOP_PRE_SIGKILL] = "stop-pre-sigkill",
2063 [SOCKET_STOP_POST] = "stop-post",
2064 [SOCKET_FINAL_SIGTERM] = "final-sigterm",
2065 [SOCKET_FINAL_SIGKILL] = "final-sigkill",
2066 [SOCKET_FAILED] = "failed"
2069 DEFINE_STRING_TABLE_LOOKUP(socket_state, SocketState);
2071 static const char* const socket_exec_command_table[_SOCKET_EXEC_COMMAND_MAX] = {
2072 [SOCKET_EXEC_START_PRE] = "StartPre",
2073 [SOCKET_EXEC_START_POST] = "StartPost",
2074 [SOCKET_EXEC_STOP_PRE] = "StopPre",
2075 [SOCKET_EXEC_STOP_POST] = "StopPost"
2078 DEFINE_STRING_TABLE_LOOKUP(socket_exec_command, SocketExecCommand);
2080 const UnitVTable socket_vtable = {
2081 .suffix = ".socket",
2083 .init = socket_init,
2084 .done = socket_done,
2085 .load = socket_load,
2087 .kill = socket_kill,
2089 .coldplug = socket_coldplug,
2091 .dump = socket_dump,
2093 .start = socket_start,
2094 .stop = socket_stop,
2096 .serialize = socket_serialize,
2097 .deserialize_item = socket_deserialize_item,
2099 .active_state = socket_active_state,
2100 .sub_state_to_string = socket_sub_state_to_string,
2102 .check_gc = socket_check_gc,
2104 .fd_event = socket_fd_event,
2105 .sigchld_event = socket_sigchld_event,
2106 .timer_event = socket_timer_event,
2108 .reset_failed = socket_reset_failed,
2110 .bus_interface = "org.freedesktop.systemd1.Socket",
2111 .bus_message_handler = bus_socket_message_handler,
2112 .bus_invalidating_properties = bus_socket_invalidating_properties