]>
Commit | Line | Data |
---|---|---|
d6c9574f | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
5cb5a6ff | 2 | |
a7334b09 LP |
3 | /*** |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2010 Lennart Poettering | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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/>. | |
20 | ***/ | |
21 | ||
83c60c9f LP |
22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | |
24 | #include <unistd.h> | |
25 | #include <errno.h> | |
26 | #include <fcntl.h> | |
f94ea366 | 27 | #include <sys/epoll.h> |
034c6ed7 | 28 | #include <signal.h> |
4f2d528d | 29 | #include <arpa/inet.h> |
916abb21 | 30 | #include <mqueue.h> |
83c60c9f | 31 | |
87f0e418 | 32 | #include "unit.h" |
5cb5a6ff | 33 | #include "socket.h" |
cebf8b20 | 34 | #include "netinet/tcp.h" |
83c60c9f | 35 | #include "log.h" |
23a177ef LP |
36 | #include "load-dropin.h" |
37 | #include "load-fragment.h" | |
9e2f7c11 | 38 | #include "strv.h" |
4f2d528d | 39 | #include "unit-name.h" |
4139c1b2 | 40 | #include "dbus-socket.h" |
4fd5948e | 41 | #include "missing.h" |
a40eb732 | 42 | #include "special.h" |
398ef8ba | 43 | #include "bus-errors.h" |
e51bc1a2 | 44 | #include "label.h" |
9a57c629 | 45 | #include "exit-status.h" |
f6a6225e | 46 | #include "def.h" |
83c60c9f | 47 | |
acbb0225 | 48 | static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = { |
87f0e418 LP |
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, | |
80876c20 LP |
58 | [SOCKET_FINAL_SIGTERM] = UNIT_DEACTIVATING, |
59 | [SOCKET_FINAL_SIGKILL] = UNIT_DEACTIVATING, | |
fdf20a31 | 60 | [SOCKET_FAILED] = UNIT_FAILED |
83c60c9f | 61 | }; |
5cb5a6ff | 62 | |
a16e1123 LP |
63 | static void socket_init(Unit *u) { |
64 | Socket *s = SOCKET(u); | |
65 | ||
66 | assert(u); | |
67 | assert(u->meta.load_state == UNIT_STUB); | |
68 | ||
a16e1123 LP |
69 | s->backlog = SOMAXCONN; |
70 | s->timeout_usec = DEFAULT_TIMEOUT_USEC; | |
71 | s->directory_mode = 0755; | |
9131f660 | 72 | s->socket_mode = 0666; |
a16e1123 | 73 | |
6cf6bbc2 LP |
74 | s->max_connections = 64; |
75 | ||
4fd5948e | 76 | s->priority = -1; |
4fd5948e LP |
77 | s->ip_tos = -1; |
78 | s->ip_ttl = -1; | |
4fd5948e | 79 | s->mark = -1; |
4fd5948e | 80 | |
a16e1123 | 81 | exec_context_init(&s->exec_context); |
0a494f1f LP |
82 | s->exec_context.std_output = u->meta.manager->default_std_output; |
83 | s->exec_context.std_error = u->meta.manager->default_std_error; | |
a16e1123 LP |
84 | |
85 | s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID; | |
86 | } | |
acbb0225 | 87 | |
5e94833f LP |
88 | static void socket_unwatch_control_pid(Socket *s) { |
89 | assert(s); | |
90 | ||
91 | if (s->control_pid <= 0) | |
92 | return; | |
93 | ||
94 | unit_unwatch_pid(UNIT(s), s->control_pid); | |
95 | s->control_pid = 0; | |
96 | } | |
97 | ||
87f0e418 LP |
98 | static void socket_done(Unit *u) { |
99 | Socket *s = SOCKET(u); | |
034c6ed7 | 100 | SocketPort *p; |
6cf6bbc2 | 101 | Meta *i; |
034c6ed7 LP |
102 | |
103 | assert(s); | |
104 | ||
105 | while ((p = s->ports)) { | |
106 | LIST_REMOVE(SocketPort, port, s->ports, p); | |
107 | ||
a16e1123 LP |
108 | if (p->fd >= 0) { |
109 | unit_unwatch_fd(UNIT(s), &p->fd_watch); | |
110 | close_nointr_nofail(p->fd); | |
111 | } | |
112 | ||
034c6ed7 LP |
113 | free(p->path); |
114 | free(p); | |
115 | } | |
116 | ||
117 | exec_context_done(&s->exec_context); | |
e537352b | 118 | exec_command_free_array(s->exec_command, _SOCKET_EXEC_COMMAND_MAX); |
034c6ed7 LP |
119 | s->control_command = NULL; |
120 | ||
5e94833f | 121 | socket_unwatch_control_pid(s); |
034c6ed7 LP |
122 | |
123 | s->service = NULL; | |
124 | ||
cebf8b20 TT |
125 | free(s->tcp_congestion); |
126 | s->tcp_congestion = NULL; | |
127 | ||
acbb0225 | 128 | free(s->bind_to_device); |
e537352b | 129 | s->bind_to_device = NULL; |
acbb0225 LP |
130 | |
131 | unit_unwatch_timer(u, &s->timer_watch); | |
6cf6bbc2 LP |
132 | |
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; | |
136 | ||
f976f3f6 LP |
137 | if (service->accept_socket == s) |
138 | service->accept_socket = NULL; | |
139 | ||
140 | set_remove(service->configured_sockets, s); | |
6cf6bbc2 | 141 | } |
5cb5a6ff LP |
142 | } |
143 | ||
b15bdda8 LP |
144 | static int socket_instantiate_service(Socket *s) { |
145 | char *prefix, *name; | |
146 | int r; | |
147 | Unit *u; | |
148 | ||
149 | assert(s); | |
150 | ||
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. */ | |
155 | ||
156 | if (s->service) | |
157 | return 0; | |
158 | ||
159 | assert(s->accept); | |
160 | ||
161 | if (!(prefix = unit_name_to_prefix(s->meta.id))) | |
162 | return -ENOMEM; | |
163 | ||
164 | r = asprintf(&name, "%s@%u.service", prefix, s->n_accepted); | |
165 | free(prefix); | |
166 | ||
167 | if (r < 0) | |
168 | return -ENOMEM; | |
169 | ||
170 | r = manager_load_unit(s->meta.manager, name, NULL, NULL, &u); | |
171 | free(name); | |
172 | ||
173 | if (r < 0) | |
174 | return r; | |
175 | ||
7b4bf06b LP |
176 | #ifdef HAVE_SYSV_COMPAT |
177 | if (SERVICE(u)->sysv_path) { | |
178 | log_error("Using SysV services for socket activation is not supported. Refusing."); | |
179 | return -ENOENT; | |
180 | } | |
181 | #endif | |
182 | ||
6c073082 | 183 | u->meta.no_gc = true; |
b15bdda8 LP |
184 | s->service = SERVICE(u); |
185 | return 0; | |
186 | } | |
187 | ||
4f2d528d LP |
188 | static bool have_non_accept_socket(Socket *s) { |
189 | SocketPort *p; | |
190 | ||
191 | assert(s); | |
192 | ||
193 | if (!s->accept) | |
194 | return true; | |
195 | ||
dd5ad9d4 LP |
196 | LIST_FOREACH(port, p, s->ports) { |
197 | ||
198 | if (p->type != SOCKET_SOCKET) | |
199 | return true; | |
200 | ||
4f2d528d LP |
201 | if (!socket_address_can_accept(&p->address)) |
202 | return true; | |
dd5ad9d4 | 203 | } |
4f2d528d LP |
204 | |
205 | return false; | |
206 | } | |
207 | ||
208 | static int socket_verify(Socket *s) { | |
209 | assert(s); | |
210 | ||
4cd1fbcc | 211 | if (s->meta.load_state != UNIT_LOADED) |
4f2d528d LP |
212 | return 0; |
213 | ||
214 | if (!s->ports) { | |
4cd1fbcc | 215 | log_error("%s lacks Listen setting. Refusing.", s->meta.id); |
4f2d528d LP |
216 | return -EINVAL; |
217 | } | |
218 | ||
0009d2a6 LP |
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); | |
221 | return -EINVAL; | |
222 | } | |
223 | ||
6cf6bbc2 | 224 | if (s->accept && s->max_connections <= 0) { |
4d0e5dbd LP |
225 | log_error("%s's MaxConnection setting too small. Refusing.", s->meta.id); |
226 | return -EINVAL; | |
227 | } | |
228 | ||
d9ff321a LP |
229 | if (s->accept && s->service) { |
230 | log_error("Explicit service configuration for accepting sockets not supported on %s. Refusing.", s->meta.id); | |
231 | return -EINVAL; | |
232 | } | |
233 | ||
2e22afe9 | 234 | if (s->exec_context.pam_name && s->exec_context.kill_mode != KILL_CONTROL_GROUP) { |
4d0e5dbd | 235 | log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", s->meta.id); |
6cf6bbc2 LP |
236 | return -EINVAL; |
237 | } | |
238 | ||
4f2d528d LP |
239 | return 0; |
240 | } | |
241 | ||
6e2ef85b LP |
242 | static bool socket_needs_mount(Socket *s, const char *prefix) { |
243 | SocketPort *p; | |
244 | ||
245 | assert(s); | |
246 | ||
247 | LIST_FOREACH(port, p, s->ports) { | |
248 | ||
249 | if (p->type == SOCKET_SOCKET) { | |
250 | if (socket_address_needs_mount(&p->address, prefix)) | |
251 | return true; | |
916abb21 | 252 | } else if (p->type == SOCKET_FIFO || p->type == SOCKET_SPECIAL) { |
6e2ef85b LP |
253 | if (path_startswith(p->path, prefix)) |
254 | return true; | |
255 | } | |
256 | } | |
257 | ||
258 | return false; | |
259 | } | |
260 | ||
261 | int socket_add_one_mount_link(Socket *s, Mount *m) { | |
262 | int r; | |
263 | ||
264 | assert(s); | |
265 | assert(m); | |
266 | ||
267 | if (s->meta.load_state != UNIT_LOADED || | |
268 | m->meta.load_state != UNIT_LOADED) | |
269 | return 0; | |
270 | ||
271 | if (!socket_needs_mount(s, m->where)) | |
272 | return 0; | |
273 | ||
2c966c03 | 274 | if ((r = unit_add_two_dependencies(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0) |
6e2ef85b LP |
275 | return r; |
276 | ||
277 | return 0; | |
278 | } | |
279 | ||
280 | static int socket_add_mount_links(Socket *s) { | |
281 | Meta *other; | |
282 | int r; | |
283 | ||
284 | assert(s); | |
285 | ||
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) | |
288 | return r; | |
289 | ||
290 | return 0; | |
291 | } | |
292 | ||
293 | static int socket_add_device_link(Socket *s) { | |
294 | char *t; | |
295 | int r; | |
296 | ||
297 | assert(s); | |
298 | ||
299 | if (!s->bind_to_device) | |
300 | return 0; | |
301 | ||
302 | if (asprintf(&t, "/sys/subsystem/net/devices/%s", s->bind_to_device) < 0) | |
303 | return -ENOMEM; | |
304 | ||
305 | r = unit_add_node_link(UNIT(s), t, false); | |
306 | free(t); | |
307 | ||
308 | return r; | |
309 | } | |
310 | ||
a40eb732 LP |
311 | static int socket_add_default_dependencies(Socket *s) { |
312 | int r; | |
313 | assert(s); | |
314 | ||
2a77d31d LP |
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) | |
317 | return r; | |
318 | ||
a40eb732 LP |
319 | if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0) |
320 | return r; | |
2a77d31d | 321 | } |
a40eb732 | 322 | |
ead8e478 | 323 | return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true); |
a40eb732 LP |
324 | } |
325 | ||
e537352b LP |
326 | static int socket_load(Unit *u) { |
327 | Socket *s = SOCKET(u); | |
328 | int r; | |
44d8db9e | 329 | |
e537352b LP |
330 | assert(u); |
331 | assert(u->meta.load_state == UNIT_STUB); | |
44d8db9e | 332 | |
e537352b | 333 | if ((r = unit_load_fragment_and_dropin(u)) < 0) |
23a177ef | 334 | return r; |
44d8db9e | 335 | |
23a177ef | 336 | /* This is a new unit? Then let's add in some extras */ |
e537352b | 337 | if (u->meta.load_state == UNIT_LOADED) { |
44d8db9e | 338 | |
4f2d528d | 339 | if (have_non_accept_socket(s)) { |
d9ff321a LP |
340 | |
341 | if (!s->service) | |
342 | if ((r = unit_load_related_unit(u, ".service", (Unit**) &s->service)) < 0) | |
343 | return r; | |
23a177ef | 344 | |
701cc384 | 345 | if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(s->service), true)) < 0) |
4f2d528d LP |
346 | return r; |
347 | } | |
44d8db9e | 348 | |
6e2ef85b LP |
349 | if ((r = socket_add_mount_links(s)) < 0) |
350 | return r; | |
351 | ||
352 | if ((r = socket_add_device_link(s)) < 0) | |
353 | return r; | |
354 | ||
23a177ef LP |
355 | if ((r = unit_add_exec_dependencies(u, &s->exec_context)) < 0) |
356 | return r; | |
357 | ||
d686d8a9 | 358 | if ((r = unit_add_default_cgroups(u)) < 0) |
23a177ef | 359 | return r; |
a40eb732 LP |
360 | |
361 | if (s->meta.default_dependencies) | |
362 | if ((r = socket_add_default_dependencies(s)) < 0) | |
363 | return r; | |
23a177ef LP |
364 | } |
365 | ||
4f2d528d | 366 | return socket_verify(s); |
44d8db9e LP |
367 | } |
368 | ||
7a22745a LP |
369 | static const char* listen_lookup(int family, int type) { |
370 | ||
371 | if (family == AF_NETLINK) | |
372 | return "ListenNetlink"; | |
542563ba LP |
373 | |
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"; | |
380 | ||
034c6ed7 | 381 | assert_not_reached("Unknown socket type"); |
542563ba LP |
382 | return NULL; |
383 | } | |
384 | ||
87f0e418 | 385 | static void socket_dump(Unit *u, FILE *f, const char *prefix) { |
5cb5a6ff | 386 | |
5cb5a6ff | 387 | SocketExecCommand c; |
87f0e418 | 388 | Socket *s = SOCKET(u); |
542563ba | 389 | SocketPort *p; |
82ba9f08 LP |
390 | const char *prefix2; |
391 | char *p2; | |
5cb5a6ff LP |
392 | |
393 | assert(s); | |
fa068367 | 394 | assert(f); |
5cb5a6ff | 395 | |
82ba9f08 LP |
396 | p2 = strappend(prefix, "\t"); |
397 | prefix2 = p2 ? p2 : prefix; | |
c43d20a0 | 398 | |
5cb5a6ff LP |
399 | fprintf(f, |
400 | "%sSocket State: %s\n" | |
542563ba | 401 | "%sBindIPv6Only: %s\n" |
b5a0699f LP |
402 | "%sBacklog: %u\n" |
403 | "%sSocketMode: %04o\n" | |
4fd5948e LP |
404 | "%sDirectoryMode: %04o\n" |
405 | "%sKeepAlive: %s\n" | |
cebf8b20 | 406 | "%sFreeBind: %s\n" |
6b6d2dee | 407 | "%sTransparent: %s\n" |
cebf8b20 | 408 | "%sTCPCongestion: %s\n", |
a16e1123 | 409 | prefix, socket_state_to_string(s->state), |
c0120d99 | 410 | prefix, socket_address_bind_ipv6_only_to_string(s->bind_ipv6_only), |
b5a0699f LP |
411 | prefix, s->backlog, |
412 | prefix, s->socket_mode, | |
4fd5948e LP |
413 | prefix, s->directory_mode, |
414 | prefix, yes_no(s->keep_alive), | |
cebf8b20 | 415 | prefix, yes_no(s->free_bind), |
6b6d2dee | 416 | prefix, yes_no(s->transparent), |
83a95334 | 417 | prefix, strna(s->tcp_congestion)); |
542563ba | 418 | |
70123e68 LP |
419 | if (s->control_pid > 0) |
420 | fprintf(f, | |
bb00e604 LP |
421 | "%sControl PID: %lu\n", |
422 | prefix, (unsigned long) s->control_pid); | |
70123e68 | 423 | |
acbb0225 LP |
424 | if (s->bind_to_device) |
425 | fprintf(f, | |
426 | "%sBindToDevice: %s\n", | |
427 | prefix, s->bind_to_device); | |
428 | ||
4f2d528d LP |
429 | if (s->accept) |
430 | fprintf(f, | |
6cf6bbc2 LP |
431 | "%sAccepted: %u\n" |
432 | "%sNConnections: %u\n" | |
433 | "%sMaxConnections: %u\n", | |
434 | prefix, s->n_accepted, | |
435 | prefix, s->n_connections, | |
436 | prefix, s->max_connections); | |
4f2d528d | 437 | |
4fd5948e LP |
438 | if (s->priority >= 0) |
439 | fprintf(f, | |
440 | "%sPriority: %i\n", | |
441 | prefix, s->priority); | |
442 | ||
443 | if (s->receive_buffer > 0) | |
444 | fprintf(f, | |
445 | "%sReceiveBuffer: %zu\n", | |
446 | prefix, s->receive_buffer); | |
447 | ||
448 | if (s->send_buffer > 0) | |
449 | fprintf(f, | |
450 | "%sSendBuffer: %zu\n", | |
451 | prefix, s->send_buffer); | |
452 | ||
453 | if (s->ip_tos >= 0) | |
454 | fprintf(f, | |
455 | "%sIPTOS: %i\n", | |
456 | prefix, s->ip_tos); | |
457 | ||
458 | if (s->ip_ttl >= 0) | |
459 | fprintf(f, | |
460 | "%sIPTTL: %i\n", | |
461 | prefix, s->ip_ttl); | |
462 | ||
463 | if (s->pipe_size > 0) | |
464 | fprintf(f, | |
465 | "%sPipeSize: %zu\n", | |
466 | prefix, s->pipe_size); | |
467 | ||
468 | if (s->mark >= 0) | |
469 | fprintf(f, | |
470 | "%sMark: %i\n", | |
471 | prefix, s->mark); | |
472 | ||
916abb21 LP |
473 | if (s->mq_maxmsg > 0) |
474 | fprintf(f, | |
475 | "%sMessageQueueMaxMessages: %li\n", | |
476 | prefix, s->mq_maxmsg); | |
477 | ||
478 | if (s->mq_msgsize > 0) | |
479 | fprintf(f, | |
480 | "%sMessageQueueMessageSize: %li\n", | |
481 | prefix, s->mq_msgsize); | |
482 | ||
034c6ed7 | 483 | LIST_FOREACH(port, p, s->ports) { |
5cb5a6ff | 484 | |
542563ba LP |
485 | if (p->type == SOCKET_SOCKET) { |
486 | const char *t; | |
487 | int r; | |
e364ad06 | 488 | char *k = NULL; |
542563ba LP |
489 | |
490 | if ((r = socket_address_print(&p->address, &k)) < 0) | |
491 | t = strerror(-r); | |
492 | else | |
493 | t = k; | |
494 | ||
7a22745a | 495 | fprintf(f, "%s%s: %s\n", prefix, listen_lookup(socket_address_family(&p->address), p->address.type), t); |
542563ba | 496 | free(k); |
b0a3f2bc LP |
497 | } else if (p->type == SOCKET_SPECIAL) |
498 | fprintf(f, "%sListenSpecial: %s\n", prefix, p->path); | |
916abb21 LP |
499 | else if (p->type == SOCKET_MQUEUE) |
500 | fprintf(f, "%sListenMessageQueue: %s\n", prefix, p->path); | |
b0a3f2bc | 501 | else |
542563ba LP |
502 | fprintf(f, "%sListenFIFO: %s\n", prefix, p->path); |
503 | } | |
5cb5a6ff LP |
504 | |
505 | exec_context_dump(&s->exec_context, f, prefix); | |
506 | ||
e537352b | 507 | for (c = 0; c < _SOCKET_EXEC_COMMAND_MAX; c++) { |
c43d20a0 LP |
508 | if (!s->exec_command[c]) |
509 | continue; | |
5cb5a6ff | 510 | |
40d50879 | 511 | fprintf(f, "%s-> %s:\n", |
a16e1123 | 512 | prefix, socket_exec_command_to_string(c)); |
c43d20a0 LP |
513 | |
514 | exec_command_dump_list(s->exec_command[c], f, prefix2); | |
5cb5a6ff | 515 | } |
c43d20a0 | 516 | |
82ba9f08 | 517 | free(p2); |
5cb5a6ff LP |
518 | } |
519 | ||
4f2d528d LP |
520 | static int instance_from_socket(int fd, unsigned nr, char **instance) { |
521 | socklen_t l; | |
522 | char *r; | |
523 | union { | |
524 | struct sockaddr sa; | |
525 | struct sockaddr_un un; | |
526 | struct sockaddr_in in; | |
527 | struct sockaddr_in6 in6; | |
528 | struct sockaddr_storage storage; | |
529 | } local, remote; | |
530 | ||
531 | assert(fd >= 0); | |
532 | assert(instance); | |
533 | ||
534 | l = sizeof(local); | |
535 | if (getsockname(fd, &local.sa, &l) < 0) | |
536 | return -errno; | |
537 | ||
538 | l = sizeof(remote); | |
539 | if (getpeername(fd, &remote.sa, &l) < 0) | |
540 | return -errno; | |
541 | ||
542 | switch (local.sa.sa_family) { | |
543 | ||
544 | case AF_INET: { | |
545 | uint32_t | |
546 | a = ntohl(local.in.sin_addr.s_addr), | |
547 | b = ntohl(remote.in.sin_addr.s_addr); | |
548 | ||
549 | if (asprintf(&r, | |
b15bdda8 | 550 | "%u.%u.%u.%u:%u-%u.%u.%u.%u:%u", |
4f2d528d LP |
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) | |
555 | return -ENOMEM; | |
556 | ||
557 | break; | |
558 | } | |
559 | ||
560 | case AF_INET6: { | |
2b061f5a LP |
561 | static const char ipv4_prefix[] = { |
562 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF | |
563 | }; | |
564 | ||
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) { | |
567 | const uint8_t | |
568 | *a = local.in6.sin6_addr.s6_addr+12, | |
569 | *b = remote.in6.sin6_addr.s6_addr+12; | |
570 | ||
571 | if (asprintf(&r, | |
b15bdda8 | 572 | "%u.%u.%u.%u:%u-%u.%u.%u.%u:%u", |
2b061f5a LP |
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) | |
577 | return -ENOMEM; | |
578 | } else { | |
579 | char a[INET6_ADDRSTRLEN], b[INET6_ADDRSTRLEN]; | |
580 | ||
581 | if (asprintf(&r, | |
b15bdda8 | 582 | "%s:%u-%s:%u", |
2b061f5a LP |
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) | |
587 | return -ENOMEM; | |
588 | } | |
4f2d528d LP |
589 | |
590 | break; | |
591 | } | |
592 | ||
593 | case AF_UNIX: { | |
594 | struct ucred ucred; | |
595 | ||
596 | l = sizeof(ucred); | |
597 | if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l) < 0) | |
598 | return -errno; | |
599 | ||
600 | if (asprintf(&r, | |
bb00e604 | 601 | "%u-%lu-%lu", |
4f2d528d | 602 | nr, |
bb00e604 LP |
603 | (unsigned long) ucred.pid, |
604 | (unsigned long) ucred.uid) < 0) | |
4f2d528d LP |
605 | return -ENOMEM; |
606 | ||
607 | break; | |
608 | } | |
609 | ||
610 | default: | |
611 | assert_not_reached("Unhandled socket type."); | |
612 | } | |
613 | ||
614 | *instance = r; | |
615 | return 0; | |
616 | } | |
617 | ||
034c6ed7 | 618 | static void socket_close_fds(Socket *s) { |
83c60c9f LP |
619 | SocketPort *p; |
620 | ||
621 | assert(s); | |
622 | ||
034c6ed7 | 623 | LIST_FOREACH(port, p, s->ports) { |
83c60c9f LP |
624 | if (p->fd < 0) |
625 | continue; | |
626 | ||
acbb0225 | 627 | unit_unwatch_fd(UNIT(s), &p->fd_watch); |
a16e1123 LP |
628 | close_nointr_nofail(p->fd); |
629 | ||
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 | |
636 | * one! */ | |
9152c765 | 637 | |
83c60c9f LP |
638 | p->fd = -1; |
639 | } | |
640 | } | |
641 | ||
4fd5948e LP |
642 | static void socket_apply_socket_options(Socket *s, int fd) { |
643 | assert(s); | |
644 | assert(fd >= 0); | |
645 | ||
646 | if (s->keep_alive) { | |
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"); | |
650 | } | |
651 | ||
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"); | |
655 | ||
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"); | |
660 | } | |
661 | ||
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"); | |
666 | } | |
667 | ||
668 | if (s->mark >= 0) | |
669 | if (setsockopt(fd, SOL_SOCKET, SO_MARK, &s->mark, sizeof(s->mark)) < 0) | |
670 | log_warning("SO_MARK failed: %m"); | |
671 | ||
672 | if (s->ip_tos >= 0) | |
673 | if (setsockopt(fd, IPPROTO_IP, IP_TOS, &s->ip_tos, sizeof(s->ip_tos)) < 0) | |
674 | log_warning("IP_TOS failed: %m"); | |
675 | ||
46925ac5 LP |
676 | if (s->ip_ttl >= 0) { |
677 | int r, x; | |
678 | ||
679 | r = setsockopt(fd, IPPROTO_IP, IP_TTL, &s->ip_ttl, sizeof(s->ip_ttl)); | |
5bfcc1c6 FF |
680 | |
681 | if (socket_ipv6_is_supported()) | |
682 | x = setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &s->ip_ttl, sizeof(s->ip_ttl)); | |
683 | else { | |
684 | x = -1; | |
685 | errno = EAFNOSUPPORT; | |
686 | } | |
46925ac5 LP |
687 | |
688 | if (r < 0 && x < 0) | |
689 | log_warning("IP_TTL/IPV6_UNICAST_HOPS failed: %m"); | |
690 | } | |
cebf8b20 TT |
691 | |
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"); | |
4fd5948e LP |
695 | } |
696 | ||
b15bdda8 | 697 | static void socket_apply_fifo_options(Socket *s, int fd) { |
4fd5948e LP |
698 | assert(s); |
699 | assert(fd >= 0); | |
700 | ||
701 | if (s->pipe_size > 0) | |
702 | if (fcntl(fd, F_SETPIPE_SZ, s->pipe_size) < 0) | |
703 | log_warning("F_SETPIPE_SZ: %m"); | |
704 | } | |
705 | ||
b15bdda8 LP |
706 | static int fifo_address_create( |
707 | const char *path, | |
708 | mode_t directory_mode, | |
709 | mode_t socket_mode, | |
b15bdda8 LP |
710 | int *_fd) { |
711 | ||
7a58bfa4 | 712 | int fd = -1, r = 0; |
b15bdda8 LP |
713 | struct stat st; |
714 | mode_t old_mask; | |
715 | ||
716 | assert(path); | |
717 | assert(_fd); | |
718 | ||
719 | mkdir_parents(path, directory_mode); | |
720 | ||
c4e2ceae | 721 | if ((r = label_fifofile_set(path)) < 0) |
56cf987f | 722 | goto fail; |
b15bdda8 LP |
723 | |
724 | /* Enforce the right access mode for the fifo */ | |
725 | old_mask = umask(~ socket_mode); | |
726 | ||
727 | /* Include the original umask in our mask */ | |
728 | umask(~socket_mode | old_mask); | |
729 | ||
730 | r = mkfifo(path, socket_mode); | |
731 | umask(old_mask); | |
732 | ||
94bc2731 | 733 | if (r < 0 && errno != EEXIST) { |
b15bdda8 LP |
734 | r = -errno; |
735 | goto fail; | |
736 | } | |
737 | ||
738 | if ((fd = open(path, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW)) < 0) { | |
739 | r = -errno; | |
740 | goto fail; | |
741 | } | |
742 | ||
56cf987f | 743 | label_file_clear(); |
7a58bfa4 | 744 | |
b15bdda8 LP |
745 | if (fstat(fd, &st) < 0) { |
746 | r = -errno; | |
747 | goto fail; | |
748 | } | |
749 | ||
750 | if (!S_ISFIFO(st.st_mode) || | |
de0200fc | 751 | (st.st_mode & 0777) != (socket_mode & ~old_mask) || |
b15bdda8 LP |
752 | st.st_uid != getuid() || |
753 | st.st_gid != getgid()) { | |
754 | ||
755 | r = -EEXIST; | |
756 | goto fail; | |
757 | } | |
758 | ||
759 | *_fd = fd; | |
760 | return 0; | |
761 | ||
762 | fail: | |
56cf987f DW |
763 | label_file_clear(); |
764 | ||
b15bdda8 LP |
765 | if (fd >= 0) |
766 | close_nointr_nofail(fd); | |
767 | ||
768 | return r; | |
769 | } | |
770 | ||
b0a3f2bc LP |
771 | static int special_address_create( |
772 | const char *path, | |
773 | int *_fd) { | |
774 | ||
775 | int fd = -1, r = 0; | |
776 | struct stat st; | |
777 | ||
778 | assert(path); | |
779 | assert(_fd); | |
780 | ||
781 | if ((fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW)) < 0) { | |
782 | r = -errno; | |
783 | goto fail; | |
784 | } | |
785 | ||
786 | if (fstat(fd, &st) < 0) { | |
787 | r = -errno; | |
788 | goto fail; | |
789 | } | |
790 | ||
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)) { | |
793 | r = -EEXIST; | |
794 | goto fail; | |
795 | } | |
796 | ||
797 | *_fd = fd; | |
798 | return 0; | |
799 | ||
800 | fail: | |
801 | if (fd >= 0) | |
802 | close_nointr_nofail(fd); | |
803 | ||
804 | return r; | |
805 | } | |
806 | ||
916abb21 LP |
807 | static int mq_address_create( |
808 | const char *path, | |
809 | mode_t mq_mode, | |
810 | long maxmsg, | |
811 | long msgsize, | |
812 | int *_fd) { | |
813 | ||
814 | int fd = -1, r = 0; | |
815 | struct stat st; | |
816 | mode_t old_mask; | |
817 | struct mq_attr _attr, *attr = NULL; | |
818 | ||
819 | assert(path); | |
820 | assert(_fd); | |
821 | ||
822 | if (maxmsg > 0 && msgsize > 0) { | |
823 | zero(_attr); | |
824 | _attr.mq_flags = O_NONBLOCK; | |
825 | _attr.mq_maxmsg = maxmsg; | |
826 | _attr.mq_msgsize = msgsize; | |
827 | attr = &_attr; | |
828 | } | |
829 | ||
830 | /* Enforce the right access mode for the mq */ | |
831 | old_mask = umask(~ mq_mode); | |
832 | ||
833 | /* Include the original umask in our mask */ | |
834 | umask(~mq_mode | old_mask); | |
835 | ||
836 | fd = mq_open(path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_CREAT, mq_mode, attr); | |
837 | umask(old_mask); | |
838 | ||
839 | if (fd < 0 && errno != EEXIST) { | |
840 | r = -errno; | |
841 | goto fail; | |
842 | } | |
843 | ||
844 | if (fstat(fd, &st) < 0) { | |
845 | r = -errno; | |
846 | goto fail; | |
847 | } | |
848 | ||
849 | if ((st.st_mode & 0777) != (mq_mode & ~old_mask) || | |
850 | st.st_uid != getuid() || | |
851 | st.st_gid != getgid()) { | |
852 | ||
853 | r = -EEXIST; | |
854 | goto fail; | |
855 | } | |
856 | ||
857 | *_fd = fd; | |
858 | return 0; | |
859 | ||
860 | fail: | |
861 | if (fd >= 0) | |
862 | close_nointr_nofail(fd); | |
863 | ||
864 | return r; | |
865 | } | |
866 | ||
034c6ed7 | 867 | static int socket_open_fds(Socket *s) { |
83c60c9f LP |
868 | SocketPort *p; |
869 | int r; | |
56cf987f | 870 | char *label = NULL; |
049f8642 | 871 | bool know_label = false; |
83c60c9f LP |
872 | |
873 | assert(s); | |
874 | ||
034c6ed7 | 875 | LIST_FOREACH(port, p, s->ports) { |
83c60c9f | 876 | |
034c6ed7 LP |
877 | if (p->fd >= 0) |
878 | continue; | |
83c60c9f LP |
879 | |
880 | if (p->type == SOCKET_SOCKET) { | |
881 | ||
049f8642 LP |
882 | if (!know_label) { |
883 | ||
884 | if ((r = socket_instantiate_service(s)) < 0) | |
885 | return r; | |
886 | ||
cae18e21 | 887 | if (s->service && s->service->exec_command[SERVICE_EXEC_START]) |
a7444eda LP |
888 | if ((r = label_get_socket_label_from_exe(s->service->exec_command[SERVICE_EXEC_START]->path, &label)) < 0) { |
889 | if (r != -EPERM) | |
890 | return r; | |
891 | } | |
049f8642 LP |
892 | |
893 | know_label = true; | |
894 | } | |
895 | ||
b5a0699f LP |
896 | if ((r = socket_address_listen( |
897 | &p->address, | |
898 | s->backlog, | |
899 | s->bind_ipv6_only, | |
900 | s->bind_to_device, | |
4fd5948e | 901 | s->free_bind, |
6b6d2dee | 902 | s->transparent, |
b5a0699f LP |
903 | s->directory_mode, |
904 | s->socket_mode, | |
56cf987f | 905 | label, |
b5a0699f | 906 | &p->fd)) < 0) |
83c60c9f LP |
907 | goto rollback; |
908 | ||
4fd5948e LP |
909 | socket_apply_socket_options(s, p->fd); |
910 | ||
b0a3f2bc LP |
911 | } else if (p->type == SOCKET_SPECIAL) { |
912 | ||
913 | if ((r = special_address_create( | |
914 | p->path, | |
915 | &p->fd)) < 0) | |
916 | goto rollback; | |
917 | ||
b15bdda8 | 918 | } else if (p->type == SOCKET_FIFO) { |
83c60c9f | 919 | |
b15bdda8 LP |
920 | if ((r = fifo_address_create( |
921 | p->path, | |
922 | s->directory_mode, | |
923 | s->socket_mode, | |
b15bdda8 | 924 | &p->fd)) < 0) |
83c60c9f | 925 | goto rollback; |
83c60c9f | 926 | |
b15bdda8 | 927 | socket_apply_fifo_options(s, p->fd); |
916abb21 | 928 | } else if (p->type == SOCKET_MQUEUE) { |
83c60c9f | 929 | |
916abb21 LP |
930 | if ((r = mq_address_create( |
931 | p->path, | |
932 | s->socket_mode, | |
933 | s->mq_maxmsg, | |
934 | s->mq_msgsize, | |
935 | &p->fd)) < 0) | |
936 | goto rollback; | |
b15bdda8 LP |
937 | } else |
938 | assert_not_reached("Unknown port type"); | |
034c6ed7 LP |
939 | } |
940 | ||
56cf987f | 941 | label_free(label); |
034c6ed7 LP |
942 | return 0; |
943 | ||
944 | rollback: | |
945 | socket_close_fds(s); | |
56cf987f | 946 | label_free(label); |
034c6ed7 LP |
947 | return r; |
948 | } | |
949 | ||
950 | static void socket_unwatch_fds(Socket *s) { | |
951 | SocketPort *p; | |
9152c765 | 952 | |
034c6ed7 LP |
953 | assert(s); |
954 | ||
955 | LIST_FOREACH(port, p, s->ports) { | |
956 | if (p->fd < 0) | |
957 | continue; | |
958 | ||
acbb0225 | 959 | unit_unwatch_fd(UNIT(s), &p->fd_watch); |
83c60c9f | 960 | } |
034c6ed7 LP |
961 | } |
962 | ||
963 | static int socket_watch_fds(Socket *s) { | |
964 | SocketPort *p; | |
965 | int r; | |
966 | ||
967 | assert(s); | |
83c60c9f | 968 | |
034c6ed7 LP |
969 | LIST_FOREACH(port, p, s->ports) { |
970 | if (p->fd < 0) | |
971 | continue; | |
972 | ||
cabab516 | 973 | p->fd_watch.socket_accept = |
4f2d528d | 974 | s->accept && |
dd5ad9d4 | 975 | p->type == SOCKET_SOCKET && |
4f2d528d LP |
976 | socket_address_can_accept(&p->address); |
977 | ||
f94ea366 | 978 | if ((r = unit_watch_fd(UNIT(s), p->fd, EPOLLIN, &p->fd_watch)) < 0) |
034c6ed7 LP |
979 | goto fail; |
980 | } | |
83c60c9f | 981 | |
542563ba | 982 | return 0; |
83c60c9f | 983 | |
034c6ed7 LP |
984 | fail: |
985 | socket_unwatch_fds(s); | |
986 | return r; | |
987 | } | |
988 | ||
989 | static void socket_set_state(Socket *s, SocketState state) { | |
990 | SocketState old_state; | |
991 | assert(s); | |
992 | ||
993 | old_state = s->state; | |
994 | s->state = state; | |
995 | ||
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 && | |
80876c20 LP |
1002 | state != SOCKET_FINAL_SIGTERM && |
1003 | state != SOCKET_FINAL_SIGKILL) { | |
acbb0225 | 1004 | unit_unwatch_timer(UNIT(s), &s->timer_watch); |
5e94833f | 1005 | socket_unwatch_control_pid(s); |
034c6ed7 | 1006 | s->control_command = NULL; |
a16e1123 | 1007 | s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID; |
e537352b | 1008 | } |
034c6ed7 | 1009 | |
a16e1123 LP |
1010 | if (state != SOCKET_LISTENING) |
1011 | socket_unwatch_fds(s); | |
1012 | ||
034c6ed7 LP |
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); | |
1020 | ||
e537352b | 1021 | if (state != old_state) |
40d50879 | 1022 | log_debug("%s changed %s -> %s", |
a16e1123 LP |
1023 | s->meta.id, |
1024 | socket_state_to_string(old_state), | |
1025 | socket_state_to_string(state)); | |
acbb0225 | 1026 | |
e2f3b44c | 1027 | unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true); |
034c6ed7 LP |
1028 | } |
1029 | ||
a16e1123 LP |
1030 | static int socket_coldplug(Unit *u) { |
1031 | Socket *s = SOCKET(u); | |
1032 | int r; | |
1033 | ||
1034 | assert(s); | |
1035 | assert(s->state == SOCKET_DEAD); | |
1036 | ||
1037 | if (s->deserialized_state != s->state) { | |
1038 | ||
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) { | |
1047 | ||
1048 | if (s->control_pid <= 0) | |
1049 | return -EBADMSG; | |
1050 | ||
1051 | if ((r = unit_watch_pid(UNIT(s), s->control_pid)) < 0) | |
1052 | return r; | |
1053 | ||
1054 | if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0) | |
1055 | return r; | |
1056 | } | |
1057 | ||
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) | |
1065 | return r; | |
1066 | ||
1067 | if (s->deserialized_state == SOCKET_LISTENING) | |
1068 | if ((r = socket_watch_fds(s)) < 0) | |
1069 | return r; | |
1070 | ||
1071 | socket_set_state(s, s->deserialized_state); | |
1072 | } | |
1073 | ||
1074 | return 0; | |
1075 | } | |
1076 | ||
e537352b | 1077 | static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) { |
034c6ed7 LP |
1078 | pid_t pid; |
1079 | int r; | |
9e2f7c11 | 1080 | char **argv; |
034c6ed7 LP |
1081 | |
1082 | assert(s); | |
1083 | assert(c); | |
1084 | assert(_pid); | |
1085 | ||
e537352b LP |
1086 | if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0) |
1087 | goto fail; | |
034c6ed7 | 1088 | |
9e2f7c11 LP |
1089 | if (!(argv = unit_full_printf_strv(UNIT(s), c->argv))) { |
1090 | r = -ENOMEM; | |
1091 | goto fail; | |
1092 | } | |
1093 | ||
1094 | r = exec_spawn(c, | |
1095 | argv, | |
1096 | &s->exec_context, | |
1097 | NULL, 0, | |
1137a57c | 1098 | s->meta.manager->environment, |
9e2f7c11 LP |
1099 | true, |
1100 | true, | |
1e3ad081 | 1101 | true, |
4cd1fbcc LP |
1102 | s->meta.manager->confirm_spawn, |
1103 | s->meta.cgroup_bondings, | |
9e2f7c11 LP |
1104 | &pid); |
1105 | ||
1106 | strv_free(argv); | |
1107 | if (r < 0) | |
034c6ed7 LP |
1108 | goto fail; |
1109 | ||
87f0e418 | 1110 | if ((r = unit_watch_pid(UNIT(s), pid)) < 0) |
034c6ed7 LP |
1111 | /* FIXME: we need to do something here */ |
1112 | goto fail; | |
83c60c9f | 1113 | |
034c6ed7 LP |
1114 | *_pid = pid; |
1115 | ||
1116 | return 0; | |
1117 | ||
1118 | fail: | |
e537352b | 1119 | unit_unwatch_timer(UNIT(s), &s->timer_watch); |
83c60c9f LP |
1120 | |
1121 | return r; | |
542563ba LP |
1122 | } |
1123 | ||
034c6ed7 LP |
1124 | static void socket_enter_dead(Socket *s, bool success) { |
1125 | assert(s); | |
1126 | ||
1127 | if (!success) | |
1128 | s->failure = true; | |
1129 | ||
fdf20a31 | 1130 | socket_set_state(s, s->failure ? SOCKET_FAILED : SOCKET_DEAD); |
034c6ed7 LP |
1131 | } |
1132 | ||
80876c20 LP |
1133 | static void socket_enter_signal(Socket *s, SocketState state, bool success); |
1134 | ||
034c6ed7 LP |
1135 | static void socket_enter_stop_post(Socket *s, bool success) { |
1136 | int r; | |
1137 | assert(s); | |
1138 | ||
1139 | if (!success) | |
1140 | s->failure = true; | |
1141 | ||
5e94833f LP |
1142 | socket_unwatch_control_pid(s); |
1143 | ||
a16e1123 LP |
1144 | s->control_command_id = SOCKET_EXEC_STOP_POST; |
1145 | ||
80876c20 | 1146 | if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST])) { |
e537352b | 1147 | if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) |
034c6ed7 LP |
1148 | goto fail; |
1149 | ||
80876c20 LP |
1150 | socket_set_state(s, SOCKET_STOP_POST); |
1151 | } else | |
1152 | socket_enter_signal(s, SOCKET_FINAL_SIGTERM, true); | |
034c6ed7 LP |
1153 | |
1154 | return; | |
1155 | ||
1156 | fail: | |
6cf6bbc2 | 1157 | log_warning("%s failed to run 'stop-post' task: %s", s->meta.id, strerror(-r)); |
80876c20 | 1158 | socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false); |
034c6ed7 LP |
1159 | } |
1160 | ||
1161 | static void socket_enter_signal(Socket *s, SocketState state, bool success) { | |
1162 | int r; | |
ca949c9d LP |
1163 | Set *pid_set = NULL; |
1164 | bool wait_for_exit = false; | |
034c6ed7 LP |
1165 | |
1166 | assert(s); | |
1167 | ||
1168 | if (!success) | |
1169 | s->failure = true; | |
1170 | ||
2e22afe9 LP |
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; | |
034c6ed7 | 1173 | |
ca949c9d | 1174 | if (s->control_pid > 0) { |
cd25cce9 | 1175 | if (kill_and_sigcont(s->control_pid, sig) < 0 && errno != ESRCH) |
50159e6a | 1176 | |
ca949c9d LP |
1177 | log_warning("Failed to kill control process %li: %m", (long) s->control_pid); |
1178 | else | |
1179 | wait_for_exit = true; | |
034c6ed7 | 1180 | } |
50159e6a | 1181 | |
ca949c9d LP |
1182 | if (s->exec_context.kill_mode == KILL_CONTROL_GROUP) { |
1183 | ||
1184 | if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) { | |
1185 | r = -ENOMEM; | |
50159e6a LP |
1186 | goto fail; |
1187 | } | |
ca949c9d LP |
1188 | |
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) | |
1192 | goto fail; | |
1193 | ||
430c18ed | 1194 | if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, true, pid_set)) < 0) { |
ca949c9d LP |
1195 | if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) |
1196 | log_warning("Failed to kill control group: %s", strerror(-r)); | |
1197 | } else if (r > 0) | |
1198 | wait_for_exit = true; | |
1199 | ||
1200 | set_free(pid_set); | |
da19d5c1 | 1201 | pid_set = NULL; |
ca949c9d | 1202 | } |
d6ea93e3 | 1203 | } |
034c6ed7 | 1204 | |
ca949c9d | 1205 | if (wait_for_exit) { |
80876c20 LP |
1206 | if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0) |
1207 | goto fail; | |
d6ea93e3 | 1208 | |
80876c20 LP |
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); | |
1212 | else | |
034c6ed7 LP |
1213 | socket_enter_dead(s, true); |
1214 | ||
1215 | return; | |
1216 | ||
1217 | fail: | |
9e2f7c11 | 1218 | log_warning("%s failed to kill processes: %s", s->meta.id, strerror(-r)); |
034c6ed7 LP |
1219 | |
1220 | if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL) | |
1221 | socket_enter_stop_post(s, false); | |
1222 | else | |
1223 | socket_enter_dead(s, false); | |
ca949c9d LP |
1224 | |
1225 | if (pid_set) | |
1226 | set_free(pid_set); | |
034c6ed7 LP |
1227 | } |
1228 | ||
1229 | static void socket_enter_stop_pre(Socket *s, bool success) { | |
1230 | int r; | |
1231 | assert(s); | |
1232 | ||
1233 | if (!success) | |
1234 | s->failure = true; | |
1235 | ||
5e94833f LP |
1236 | socket_unwatch_control_pid(s); |
1237 | ||
a16e1123 LP |
1238 | s->control_command_id = SOCKET_EXEC_STOP_PRE; |
1239 | ||
80876c20 | 1240 | if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE])) { |
e537352b | 1241 | if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) |
034c6ed7 LP |
1242 | goto fail; |
1243 | ||
80876c20 LP |
1244 | socket_set_state(s, SOCKET_STOP_PRE); |
1245 | } else | |
034c6ed7 LP |
1246 | socket_enter_stop_post(s, true); |
1247 | ||
1248 | return; | |
1249 | ||
1250 | fail: | |
6cf6bbc2 | 1251 | log_warning("%s failed to run 'stop-pre' task: %s", s->meta.id, strerror(-r)); |
034c6ed7 LP |
1252 | socket_enter_stop_post(s, false); |
1253 | } | |
1254 | ||
e9af15c3 LP |
1255 | static void socket_enter_listening(Socket *s) { |
1256 | int r; | |
1257 | assert(s); | |
1258 | ||
1259 | if ((r = socket_watch_fds(s)) < 0) { | |
9e2f7c11 | 1260 | log_warning("%s failed to watch sockets: %s", s->meta.id, strerror(-r)); |
e9af15c3 LP |
1261 | goto fail; |
1262 | } | |
1263 | ||
1264 | socket_set_state(s, SOCKET_LISTENING); | |
1265 | return; | |
1266 | ||
1267 | fail: | |
1268 | socket_enter_stop_pre(s, false); | |
1269 | } | |
1270 | ||
034c6ed7 LP |
1271 | static void socket_enter_start_post(Socket *s) { |
1272 | int r; | |
1273 | assert(s); | |
1274 | ||
e9af15c3 | 1275 | if ((r = socket_open_fds(s)) < 0) { |
9e2f7c11 | 1276 | log_warning("%s failed to listen on sockets: %s", s->meta.id, strerror(-r)); |
034c6ed7 LP |
1277 | goto fail; |
1278 | } | |
1279 | ||
5e94833f LP |
1280 | socket_unwatch_control_pid(s); |
1281 | ||
a16e1123 LP |
1282 | s->control_command_id = SOCKET_EXEC_START_POST; |
1283 | ||
80876c20 | 1284 | if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) { |
e537352b | 1285 | if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) { |
6cf6bbc2 | 1286 | log_warning("%s failed to run 'start-post' task: %s", s->meta.id, strerror(-r)); |
034c6ed7 LP |
1287 | goto fail; |
1288 | } | |
1289 | ||
80876c20 LP |
1290 | socket_set_state(s, SOCKET_START_POST); |
1291 | } else | |
e9af15c3 | 1292 | socket_enter_listening(s); |
034c6ed7 LP |
1293 | |
1294 | return; | |
1295 | ||
1296 | fail: | |
1297 | socket_enter_stop_pre(s, false); | |
1298 | } | |
1299 | ||
1300 | static void socket_enter_start_pre(Socket *s) { | |
1301 | int r; | |
1302 | assert(s); | |
1303 | ||
5e94833f LP |
1304 | socket_unwatch_control_pid(s); |
1305 | ||
a16e1123 LP |
1306 | s->control_command_id = SOCKET_EXEC_START_PRE; |
1307 | ||
80876c20 | 1308 | if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE])) { |
e537352b | 1309 | if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) |
034c6ed7 LP |
1310 | goto fail; |
1311 | ||
80876c20 LP |
1312 | socket_set_state(s, SOCKET_START_PRE); |
1313 | } else | |
034c6ed7 LP |
1314 | socket_enter_start_post(s); |
1315 | ||
1316 | return; | |
1317 | ||
1318 | fail: | |
6cf6bbc2 | 1319 | log_warning("%s failed to run 'start-pre' task: %s", s->meta.id, strerror(-r)); |
034c6ed7 LP |
1320 | socket_enter_dead(s, false); |
1321 | } | |
1322 | ||
4f2d528d | 1323 | static void socket_enter_running(Socket *s, int cfd) { |
034c6ed7 | 1324 | int r; |
398ef8ba | 1325 | DBusError error; |
034c6ed7 LP |
1326 | |
1327 | assert(s); | |
398ef8ba | 1328 | dbus_error_init(&error); |
034c6ed7 | 1329 | |
ba3e67a7 LP |
1330 | /* We don't take connections anymore if we are supposed to |
1331 | * shut down anyway */ | |
18ffdfda | 1332 | if (unit_pending_inactive(UNIT(s))) { |
5d909e3e LP |
1333 | log_debug("Suppressing connection request on %s since unit stop is scheduled.", s->meta.id); |
1334 | ||
7c610628 LP |
1335 | if (cfd >= 0) |
1336 | close_nointr_nofail(cfd); | |
1337 | else { | |
1338 | /* Flush all sockets by closing and reopening them */ | |
1339 | socket_close_fds(s); | |
1340 | ||
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); | |
1344 | } | |
1345 | } | |
1346 | ||
ba3e67a7 LP |
1347 | return; |
1348 | } | |
1349 | ||
4f2d528d | 1350 | if (cfd < 0) { |
f976f3f6 LP |
1351 | bool pending = false; |
1352 | Meta *i; | |
1353 | ||
1354 | /* If there's already a start pending don't bother to | |
1355 | * do anything */ | |
1356 | LIST_FOREACH(units_per_type, i, s->meta.manager->units_per_type[UNIT_SERVICE]) { | |
1357 | Service *service = (Service *) i; | |
1358 | ||
1359 | if (!set_get(service->configured_sockets, s)) | |
1360 | continue; | |
1361 | ||
1362 | if (!unit_pending_active(UNIT(service))) | |
1363 | continue; | |
1364 | ||
1365 | pending = true; | |
1366 | break; | |
1367 | } | |
1368 | ||
1369 | if (!pending) | |
1370 | if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s->service), JOB_REPLACE, true, &error, NULL)) < 0) | |
1371 | goto fail; | |
4f2d528d LP |
1372 | |
1373 | socket_set_state(s, SOCKET_RUNNING); | |
1374 | } else { | |
b4f10a5e | 1375 | char *prefix, *instance = NULL, *name; |
b15bdda8 | 1376 | Service *service; |
4f2d528d | 1377 | |
6cf6bbc2 LP |
1378 | if (s->n_connections >= s->max_connections) { |
1379 | log_warning("Too many incoming connections (%u)", s->n_connections); | |
1380 | close_nointr_nofail(cfd); | |
1381 | return; | |
1382 | } | |
1383 | ||
b15bdda8 LP |
1384 | if ((r = socket_instantiate_service(s)) < 0) |
1385 | goto fail; | |
1386 | ||
1387 | if ((r = instance_from_socket(cfd, s->n_accepted, &instance)) < 0) | |
4f2d528d LP |
1388 | goto fail; |
1389 | ||
4cd1fbcc | 1390 | if (!(prefix = unit_name_to_prefix(s->meta.id))) { |
4f2d528d LP |
1391 | free(instance); |
1392 | r = -ENOMEM; | |
1393 | goto fail; | |
1394 | } | |
1395 | ||
1396 | name = unit_name_build(prefix, instance, ".service"); | |
1397 | free(prefix); | |
1398 | free(instance); | |
1399 | ||
b6dbbe1c | 1400 | if (!name) { |
4f2d528d | 1401 | r = -ENOMEM; |
b6dbbe1c LP |
1402 | goto fail; |
1403 | } | |
4f2d528d | 1404 | |
b15bdda8 LP |
1405 | if ((r = unit_add_name(UNIT(s->service), name)) < 0) { |
1406 | free(name); | |
4f2d528d | 1407 | goto fail; |
b15bdda8 LP |
1408 | } |
1409 | ||
1410 | service = s->service; | |
1411 | s->service = NULL; | |
1412 | s->n_accepted ++; | |
4f2d528d | 1413 | |
6c073082 LP |
1414 | service->meta.no_gc = false; |
1415 | ||
b15bdda8 LP |
1416 | unit_choose_id(UNIT(service), name); |
1417 | free(name); | |
1418 | ||
1419 | if ((r = service_set_socket_fd(service, cfd, s)) < 0) | |
4f2d528d LP |
1420 | goto fail; |
1421 | ||
1422 | cfd = -1; | |
6cf6bbc2 LP |
1423 | s->n_connections ++; |
1424 | ||
b15bdda8 | 1425 | if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(service), JOB_REPLACE, true, &error, NULL)) < 0) |
4f2d528d | 1426 | goto fail; |
c4e2ceae LP |
1427 | |
1428 | /* Notify clients about changed counters */ | |
1429 | unit_add_to_dbus_queue(UNIT(s)); | |
4f2d528d | 1430 | } |
034c6ed7 | 1431 | |
034c6ed7 LP |
1432 | return; |
1433 | ||
1434 | fail: | |
398ef8ba | 1435 | log_warning("%s failed to queue socket startup job: %s", s->meta.id, bus_error(&error, r)); |
80876c20 | 1436 | socket_enter_stop_pre(s, false); |
4f2d528d LP |
1437 | |
1438 | if (cfd >= 0) | |
1439 | close_nointr_nofail(cfd); | |
398ef8ba LP |
1440 | |
1441 | dbus_error_free(&error); | |
034c6ed7 LP |
1442 | } |
1443 | ||
1444 | static void socket_run_next(Socket *s, bool success) { | |
1445 | int r; | |
1446 | ||
1447 | assert(s); | |
1448 | assert(s->control_command); | |
1449 | assert(s->control_command->command_next); | |
1450 | ||
1451 | if (!success) | |
1452 | s->failure = true; | |
1453 | ||
5e94833f LP |
1454 | socket_unwatch_control_pid(s); |
1455 | ||
034c6ed7 LP |
1456 | s->control_command = s->control_command->command_next; |
1457 | ||
e537352b | 1458 | if ((r = socket_spawn(s, s->control_command, &s->control_pid)) < 0) |
034c6ed7 LP |
1459 | goto fail; |
1460 | ||
1461 | return; | |
1462 | ||
1463 | fail: | |
6cf6bbc2 | 1464 | log_warning("%s failed to run next task: %s", s->meta.id, strerror(-r)); |
80876c20 LP |
1465 | |
1466 | if (s->state == SOCKET_START_POST) | |
1467 | socket_enter_stop_pre(s, false); | |
034c6ed7 LP |
1468 | else if (s->state == SOCKET_STOP_POST) |
1469 | socket_enter_dead(s, false); | |
1470 | else | |
80876c20 | 1471 | socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false); |
034c6ed7 LP |
1472 | } |
1473 | ||
87f0e418 LP |
1474 | static int socket_start(Unit *u) { |
1475 | Socket *s = SOCKET(u); | |
83c60c9f LP |
1476 | |
1477 | assert(s); | |
1478 | ||
034c6ed7 LP |
1479 | /* We cannot fulfill this request right now, try again later |
1480 | * please! */ | |
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 || | |
80876c20 LP |
1485 | s->state == SOCKET_FINAL_SIGTERM || |
1486 | s->state == SOCKET_FINAL_SIGKILL) | |
034c6ed7 LP |
1487 | return -EAGAIN; |
1488 | ||
83c60c9f LP |
1489 | if (s->state == SOCKET_START_PRE || |
1490 | s->state == SOCKET_START_POST) | |
034c6ed7 | 1491 | return 0; |
83c60c9f | 1492 | |
034c6ed7 | 1493 | /* Cannot run this without the service being around */ |
4f2d528d | 1494 | if (s->service) { |
4ac9236f LP |
1495 | if (s->service->meta.load_state != UNIT_LOADED) { |
1496 | log_error("Socket service %s not loaded, refusing.", s->service->meta.id); | |
4f2d528d | 1497 | return -ENOENT; |
4ac9236f | 1498 | } |
4f2d528d | 1499 | |
35b8ca3a | 1500 | /* If the service is already active we cannot start the |
4f2d528d LP |
1501 | * socket */ |
1502 | if (s->service->state != SERVICE_DEAD && | |
fdf20a31 | 1503 | s->service->state != SERVICE_FAILED && |
4ac9236f LP |
1504 | s->service->state != SERVICE_AUTO_RESTART) { |
1505 | log_error("Socket service %s already active, refusing.", s->service->meta.id); | |
4f2d528d | 1506 | return -EBUSY; |
4ac9236f | 1507 | } |
7b4bf06b LP |
1508 | |
1509 | #ifdef HAVE_SYSV_COMPAT | |
1510 | if (s->service->sysv_path) { | |
1511 | log_error("Using SysV services for socket activation is not supported. Refusing."); | |
1512 | return -ENOENT; | |
1513 | } | |
1514 | #endif | |
4f2d528d | 1515 | } |
e537352b | 1516 | |
fdf20a31 | 1517 | assert(s->state == SOCKET_DEAD || s->state == SOCKET_FAILED); |
83c60c9f | 1518 | |
034c6ed7 LP |
1519 | s->failure = false; |
1520 | socket_enter_start_pre(s); | |
1521 | return 0; | |
1522 | } | |
83c60c9f | 1523 | |
87f0e418 LP |
1524 | static int socket_stop(Unit *u) { |
1525 | Socket *s = SOCKET(u); | |
034c6ed7 LP |
1526 | |
1527 | assert(s); | |
1528 | ||
e537352b LP |
1529 | /* Already on it */ |
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 || | |
80876c20 | 1534 | s->state == SOCKET_FINAL_SIGTERM || |
3f6c78dc | 1535 | s->state == SOCKET_FINAL_SIGKILL) |
e537352b LP |
1536 | return 0; |
1537 | ||
3f6c78dc LP |
1538 | /* If there's already something running we go directly into |
1539 | * kill mode. */ | |
1540 | if (s->state == SOCKET_START_PRE || | |
1541 | s->state == SOCKET_START_POST) { | |
1542 | socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, true); | |
1543 | return -EAGAIN; | |
1544 | } | |
1545 | ||
034c6ed7 | 1546 | assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING); |
83c60c9f | 1547 | |
034c6ed7 | 1548 | socket_enter_stop_pre(s, true); |
542563ba LP |
1549 | return 0; |
1550 | } | |
1551 | ||
a16e1123 LP |
1552 | static int socket_serialize(Unit *u, FILE *f, FDSet *fds) { |
1553 | Socket *s = SOCKET(u); | |
1554 | SocketPort *p; | |
1555 | int r; | |
1556 | ||
1557 | assert(u); | |
1558 | assert(f); | |
1559 | assert(fds); | |
1560 | ||
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); | |
1564 | ||
1565 | if (s->control_pid > 0) | |
5925dd3c | 1566 | unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid); |
a16e1123 LP |
1567 | |
1568 | if (s->control_command_id >= 0) | |
1569 | unit_serialize_item(u, f, "control-command", socket_exec_command_to_string(s->control_command_id)); | |
1570 | ||
1571 | LIST_FOREACH(port, p, s->ports) { | |
1572 | int copy; | |
1573 | ||
1574 | if (p->fd < 0) | |
1575 | continue; | |
1576 | ||
1577 | if ((copy = fdset_put_dup(fds, p->fd)) < 0) | |
1578 | return copy; | |
1579 | ||
1580 | if (p->type == SOCKET_SOCKET) { | |
1581 | char *t; | |
1582 | ||
1583 | if ((r = socket_address_print(&p->address, &t)) < 0) | |
1584 | return r; | |
1585 | ||
7a22745a LP |
1586 | if (socket_address_family(&p->address) == AF_NETLINK) |
1587 | unit_serialize_item_format(u, f, "netlink", "%i %s", copy, t); | |
1588 | else | |
1589 | unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t); | |
a16e1123 | 1590 | free(t); |
b0a3f2bc LP |
1591 | } else if (p->type == SOCKET_SPECIAL) |
1592 | unit_serialize_item_format(u, f, "special", "%i %s", copy, p->path); | |
1593 | else { | |
a16e1123 LP |
1594 | assert(p->type == SOCKET_FIFO); |
1595 | unit_serialize_item_format(u, f, "fifo", "%i %s", copy, p->path); | |
1596 | } | |
1597 | } | |
1598 | ||
1599 | return 0; | |
1600 | } | |
1601 | ||
1602 | static int socket_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) { | |
1603 | Socket *s = SOCKET(u); | |
a16e1123 LP |
1604 | |
1605 | assert(u); | |
1606 | assert(key); | |
1607 | assert(value); | |
1608 | assert(fds); | |
1609 | ||
1610 | if (streq(key, "state")) { | |
1611 | SocketState state; | |
1612 | ||
1613 | if ((state = socket_state_from_string(value)) < 0) | |
1614 | log_debug("Failed to parse state value %s", value); | |
1615 | else | |
1616 | s->deserialized_state = state; | |
1617 | } else if (streq(key, "failure")) { | |
1618 | int b; | |
1619 | ||
1620 | if ((b = parse_boolean(value)) < 0) | |
1621 | log_debug("Failed to parse failure value %s", value); | |
1622 | else | |
1623 | s->failure = b || s->failure; | |
1624 | ||
1625 | } else if (streq(key, "n-accepted")) { | |
1626 | unsigned k; | |
1627 | ||
e364ad06 | 1628 | if (safe_atou(value, &k) < 0) |
a16e1123 LP |
1629 | log_debug("Failed to parse n-accepted value %s", value); |
1630 | else | |
1631 | s->n_accepted += k; | |
1632 | } else if (streq(key, "control-pid")) { | |
5925dd3c | 1633 | pid_t pid; |
a16e1123 | 1634 | |
e364ad06 | 1635 | if (parse_pid(value, &pid) < 0) |
a16e1123 LP |
1636 | log_debug("Failed to parse control-pid value %s", value); |
1637 | else | |
5925dd3c | 1638 | s->control_pid = pid; |
a16e1123 LP |
1639 | } else if (streq(key, "control-command")) { |
1640 | SocketExecCommand id; | |
1641 | ||
1642 | if ((id = socket_exec_command_from_string(value)) < 0) | |
1643 | log_debug("Failed to parse exec-command value %s", value); | |
1644 | else { | |
1645 | s->control_command_id = id; | |
1646 | s->control_command = s->exec_command[id]; | |
1647 | } | |
1648 | } else if (streq(key, "fifo")) { | |
1649 | int fd, skip = 0; | |
1650 | SocketPort *p; | |
1651 | ||
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); | |
1654 | else { | |
1655 | ||
1656 | LIST_FOREACH(port, p, s->ports) | |
b0a3f2bc LP |
1657 | if (p->type == SOCKET_FIFO && |
1658 | streq_ptr(p->path, value+skip)) | |
1659 | break; | |
1660 | ||
1661 | if (p) { | |
1662 | if (p->fd >= 0) | |
1663 | close_nointr_nofail(p->fd); | |
1664 | p->fd = fdset_remove(fds, fd); | |
1665 | } | |
1666 | } | |
1667 | ||
1668 | } else if (streq(key, "special")) { | |
1669 | int fd, skip = 0; | |
1670 | SocketPort *p; | |
1671 | ||
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); | |
1674 | else { | |
1675 | ||
1676 | LIST_FOREACH(port, p, s->ports) | |
1677 | if (p->type == SOCKET_SPECIAL && | |
1678 | streq_ptr(p->path, value+skip)) | |
a16e1123 LP |
1679 | break; |
1680 | ||
1681 | if (p) { | |
1682 | if (p->fd >= 0) | |
1683 | close_nointr_nofail(p->fd); | |
1684 | p->fd = fdset_remove(fds, fd); | |
1685 | } | |
1686 | } | |
1687 | ||
1688 | } else if (streq(key, "socket")) { | |
27ca8d7a | 1689 | int fd, type, skip = 0; |
a16e1123 LP |
1690 | SocketPort *p; |
1691 | ||
27ca8d7a | 1692 | if (sscanf(value, "%i %i %n", &fd, &type, &skip) < 2 || fd < 0 || type < 0 || !fdset_contains(fds, fd)) |
a16e1123 LP |
1693 | log_debug("Failed to parse socket value %s", value); |
1694 | else { | |
1695 | ||
1696 | LIST_FOREACH(port, p, s->ports) | |
27ca8d7a | 1697 | if (socket_address_is(&p->address, value+skip, type)) |
a16e1123 LP |
1698 | break; |
1699 | ||
1700 | if (p) { | |
1701 | if (p->fd >= 0) | |
1702 | close_nointr_nofail(p->fd); | |
1703 | p->fd = fdset_remove(fds, fd); | |
1704 | } | |
1705 | } | |
1706 | ||
7a22745a LP |
1707 | } else if (streq(key, "netlink")) { |
1708 | int fd, skip = 0; | |
1709 | SocketPort *p; | |
1710 | ||
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); | |
1713 | else { | |
1714 | ||
1715 | LIST_FOREACH(port, p, s->ports) | |
1716 | if (socket_address_is_netlink(&p->address, value+skip)) | |
1717 | break; | |
1718 | ||
1719 | if (p) { | |
1720 | if (p->fd >= 0) | |
1721 | close_nointr_nofail(p->fd); | |
1722 | p->fd = fdset_remove(fds, fd); | |
1723 | } | |
1724 | } | |
1725 | ||
a16e1123 LP |
1726 | } else |
1727 | log_debug("Unknown serialization key '%s'", key); | |
1728 | ||
1729 | return 0; | |
1730 | } | |
1731 | ||
87f0e418 LP |
1732 | static UnitActiveState socket_active_state(Unit *u) { |
1733 | assert(u); | |
5cb5a6ff | 1734 | |
acbb0225 | 1735 | return state_translation_table[SOCKET(u)->state]; |
5cb5a6ff LP |
1736 | } |
1737 | ||
10a94420 LP |
1738 | static const char *socket_sub_state_to_string(Unit *u) { |
1739 | assert(u); | |
1740 | ||
a16e1123 | 1741 | return socket_state_to_string(SOCKET(u)->state); |
10a94420 LP |
1742 | } |
1743 | ||
6cf6bbc2 LP |
1744 | static bool socket_check_gc(Unit *u) { |
1745 | Socket *s = SOCKET(u); | |
1746 | ||
1747 | assert(u); | |
1748 | ||
1749 | return s->n_connections > 0; | |
1750 | } | |
1751 | ||
acbb0225 | 1752 | static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) { |
87f0e418 | 1753 | Socket *s = SOCKET(u); |
4f2d528d | 1754 | int cfd = -1; |
9152c765 | 1755 | |
034c6ed7 | 1756 | assert(s); |
8d567588 | 1757 | assert(fd >= 0); |
9152c765 | 1758 | |
871d7de4 LP |
1759 | if (s->state != SOCKET_LISTENING) |
1760 | return; | |
1761 | ||
9e2f7c11 | 1762 | log_debug("Incoming traffic on %s", u->meta.id); |
9152c765 | 1763 | |
4f2d528d | 1764 | if (events != EPOLLIN) { |
641e01dc LP |
1765 | |
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); | |
1768 | else | |
1769 | log_error("%s: Got unexpected poll event (0x%x) on socket.", u->meta.id, events); | |
1770 | ||
8d567588 | 1771 | goto fail; |
4f2d528d LP |
1772 | } |
1773 | ||
cabab516 | 1774 | if (w->socket_accept) { |
4f2d528d LP |
1775 | for (;;) { |
1776 | ||
1777 | if ((cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK)) < 0) { | |
1778 | ||
1779 | if (errno == EINTR) | |
1780 | continue; | |
1781 | ||
1782 | log_error("Failed to accept socket: %m"); | |
8d567588 | 1783 | goto fail; |
4f2d528d LP |
1784 | } |
1785 | ||
1786 | break; | |
1787 | } | |
4fd5948e LP |
1788 | |
1789 | socket_apply_socket_options(s, cfd); | |
4f2d528d | 1790 | } |
9152c765 | 1791 | |
4f2d528d | 1792 | socket_enter_running(s, cfd); |
8d567588 LP |
1793 | return; |
1794 | ||
1795 | fail: | |
1796 | socket_enter_stop_pre(s, false); | |
9152c765 LP |
1797 | } |
1798 | ||
87f0e418 LP |
1799 | static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) { |
1800 | Socket *s = SOCKET(u); | |
034c6ed7 | 1801 | bool success; |
5cb5a6ff LP |
1802 | |
1803 | assert(s); | |
034c6ed7 | 1804 | assert(pid >= 0); |
5cb5a6ff | 1805 | |
8c47c732 LP |
1806 | if (pid != s->control_pid) |
1807 | return; | |
542563ba | 1808 | |
034c6ed7 LP |
1809 | s->control_pid = 0; |
1810 | ||
8c47c732 | 1811 | success = is_clean_exit(code, status); |
8c47c732 | 1812 | |
b708e7ce | 1813 | if (s->control_command) { |
6ea832a2 | 1814 | exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status); |
a16e1123 | 1815 | |
b708e7ce LP |
1816 | if (s->control_command->ignore) |
1817 | success = true; | |
1818 | } | |
1819 | ||
92abbefb LP |
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); | |
b708e7ce | 1822 | s->failure = s->failure || !success; |
034c6ed7 | 1823 | |
a16e1123 LP |
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)); | |
034c6ed7 | 1826 | socket_run_next(s, success); |
acbb0225 | 1827 | } else { |
a16e1123 LP |
1828 | s->control_command = NULL; |
1829 | s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID; | |
1830 | ||
034c6ed7 LP |
1831 | /* No further commands for this step, so let's figure |
1832 | * out what to do next */ | |
5cb5a6ff | 1833 | |
a16e1123 | 1834 | log_debug("%s got final SIGCHLD for state %s", u->meta.id, socket_state_to_string(s->state)); |
acbb0225 | 1835 | |
034c6ed7 LP |
1836 | switch (s->state) { |
1837 | ||
1838 | case SOCKET_START_PRE: | |
1839 | if (success) | |
acbb0225 | 1840 | socket_enter_start_post(s); |
034c6ed7 | 1841 | else |
80876c20 | 1842 | socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false); |
034c6ed7 LP |
1843 | break; |
1844 | ||
1845 | case SOCKET_START_POST: | |
1846 | if (success) | |
e9af15c3 | 1847 | socket_enter_listening(s); |
034c6ed7 LP |
1848 | else |
1849 | socket_enter_stop_pre(s, false); | |
1850 | break; | |
1851 | ||
1852 | case SOCKET_STOP_PRE: | |
1853 | case SOCKET_STOP_PRE_SIGTERM: | |
1854 | case SOCKET_STOP_PRE_SIGKILL: | |
1855 | socket_enter_stop_post(s, success); | |
1856 | break; | |
1857 | ||
1858 | case SOCKET_STOP_POST: | |
80876c20 LP |
1859 | case SOCKET_FINAL_SIGTERM: |
1860 | case SOCKET_FINAL_SIGKILL: | |
034c6ed7 LP |
1861 | socket_enter_dead(s, success); |
1862 | break; | |
1863 | ||
1864 | default: | |
1865 | assert_not_reached("Uh, control process died at wrong time."); | |
1866 | } | |
1867 | } | |
c4e2ceae LP |
1868 | |
1869 | /* Notify clients about changed exit status */ | |
1870 | unit_add_to_dbus_queue(u); | |
034c6ed7 | 1871 | } |
5cb5a6ff | 1872 | |
acbb0225 | 1873 | static void socket_timer_event(Unit *u, uint64_t elapsed, Watch *w) { |
87f0e418 | 1874 | Socket *s = SOCKET(u); |
5cb5a6ff | 1875 | |
034c6ed7 LP |
1876 | assert(s); |
1877 | assert(elapsed == 1); | |
acbb0225 | 1878 | assert(w == &s->timer_watch); |
034c6ed7 LP |
1879 | |
1880 | switch (s->state) { | |
1881 | ||
1882 | case SOCKET_START_PRE: | |
9e2f7c11 | 1883 | log_warning("%s starting timed out. Terminating.", u->meta.id); |
80876c20 | 1884 | socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false); |
da19d5c1 | 1885 | break; |
80876c20 | 1886 | |
034c6ed7 | 1887 | case SOCKET_START_POST: |
9e2f7c11 | 1888 | log_warning("%s starting timed out. Stopping.", u->meta.id); |
034c6ed7 LP |
1889 | socket_enter_stop_pre(s, false); |
1890 | break; | |
1891 | ||
1892 | case SOCKET_STOP_PRE: | |
9e2f7c11 | 1893 | log_warning("%s stopping timed out. Terminating.", u->meta.id); |
034c6ed7 LP |
1894 | socket_enter_signal(s, SOCKET_STOP_PRE_SIGTERM, false); |
1895 | break; | |
1896 | ||
1897 | case SOCKET_STOP_PRE_SIGTERM: | |
ba035df2 LP |
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); | |
1901 | } else { | |
1902 | log_warning("%s stopping timed out. Skipping SIGKILL. Ignoring.", u->meta.id); | |
1903 | socket_enter_stop_post(s, false); | |
1904 | } | |
034c6ed7 LP |
1905 | break; |
1906 | ||
1907 | case SOCKET_STOP_PRE_SIGKILL: | |
9e2f7c11 | 1908 | log_warning("%s still around after SIGKILL. Ignoring.", u->meta.id); |
034c6ed7 LP |
1909 | socket_enter_stop_post(s, false); |
1910 | break; | |
1911 | ||
1912 | case SOCKET_STOP_POST: | |
9e2f7c11 | 1913 | log_warning("%s stopping timed out (2). Terminating.", u->meta.id); |
80876c20 | 1914 | socket_enter_signal(s, SOCKET_FINAL_SIGTERM, false); |
034c6ed7 LP |
1915 | break; |
1916 | ||
80876c20 | 1917 | case SOCKET_FINAL_SIGTERM: |
ba035df2 LP |
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); | |
1921 | } else { | |
1922 | log_warning("%s stopping timed out (2). Skipping SIGKILL. Ignoring.", u->meta.id); | |
1923 | socket_enter_dead(s, false); | |
1924 | } | |
034c6ed7 LP |
1925 | break; |
1926 | ||
80876c20 | 1927 | case SOCKET_FINAL_SIGKILL: |
fdf20a31 | 1928 | log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->meta.id); |
034c6ed7 LP |
1929 | socket_enter_dead(s, false); |
1930 | break; | |
1931 | ||
1932 | default: | |
1933 | assert_not_reached("Timeout at wrong time."); | |
1934 | } | |
5cb5a6ff LP |
1935 | } |
1936 | ||
44d8db9e LP |
1937 | int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) { |
1938 | int *rfds; | |
1939 | unsigned rn_fds, k; | |
1940 | SocketPort *p; | |
1941 | ||
1942 | assert(s); | |
1943 | assert(fds); | |
1944 | assert(n_fds); | |
1945 | ||
1946 | /* Called from the service code for requesting our fds */ | |
1947 | ||
1948 | rn_fds = 0; | |
1949 | LIST_FOREACH(port, p, s->ports) | |
1950 | if (p->fd >= 0) | |
1951 | rn_fds++; | |
1952 | ||
e364ad06 | 1953 | if (!(rfds = new(int, rn_fds))) |
44d8db9e LP |
1954 | return -ENOMEM; |
1955 | ||
1956 | k = 0; | |
1957 | LIST_FOREACH(port, p, s->ports) | |
1958 | if (p->fd >= 0) | |
1959 | rfds[k++] = p->fd; | |
1960 | ||
1961 | assert(k == rn_fds); | |
1962 | ||
1963 | *fds = rfds; | |
1964 | *n_fds = rn_fds; | |
1965 | ||
1966 | return 0; | |
1967 | } | |
1968 | ||
ceee3d82 LP |
1969 | void socket_notify_service_dead(Socket *s) { |
1970 | assert(s); | |
1971 | ||
6cf6bbc2 LP |
1972 | /* The service is dead. Dang! |
1973 | * | |
1974 | * This is strictly for one-instance-for-all-connections | |
1975 | * services. */ | |
ceee3d82 LP |
1976 | |
1977 | if (s->state == SOCKET_RUNNING) { | |
9e2f7c11 | 1978 | log_debug("%s got notified about service death.", s->meta.id); |
ceee3d82 LP |
1979 | socket_enter_listening(s); |
1980 | } | |
1981 | } | |
1982 | ||
6cf6bbc2 LP |
1983 | void socket_connection_unref(Socket *s) { |
1984 | assert(s); | |
1985 | ||
1986 | /* The service is dead. Yay! | |
1987 | * | |
35b8ca3a | 1988 | * This is strictly for one-instance-per-connection |
6cf6bbc2 LP |
1989 | * services. */ |
1990 | ||
1991 | assert(s->n_connections > 0); | |
1992 | s->n_connections--; | |
1993 | ||
1994 | log_debug("%s: One connection closed, %u left.", s->meta.id, s->n_connections); | |
1995 | } | |
1996 | ||
fdf20a31 | 1997 | static void socket_reset_failed(Unit *u) { |
5632e374 LP |
1998 | Socket *s = SOCKET(u); |
1999 | ||
2000 | assert(s); | |
2001 | ||
fdf20a31 | 2002 | if (s->state == SOCKET_FAILED) |
5632e374 LP |
2003 | socket_set_state(s, SOCKET_DEAD); |
2004 | ||
2005 | s->failure = false; | |
2006 | } | |
2007 | ||
8a0867d6 LP |
2008 | static int socket_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) { |
2009 | Socket *s = SOCKET(u); | |
2010 | int r = 0; | |
2011 | Set *pid_set = NULL; | |
2012 | ||
2013 | assert(s); | |
2014 | ||
2015 | if (who == KILL_MAIN) { | |
2016 | dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "Socket units have no main processes"); | |
2017 | return -EINVAL; | |
2018 | } | |
2019 | ||
2020 | if (s->control_pid <= 0 && who == KILL_CONTROL) { | |
2021 | dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill"); | |
2022 | return -ENOENT; | |
2023 | } | |
2024 | ||
2025 | if (s->control_pid > 0) | |
cd25cce9 | 2026 | if (kill(s->control_pid, signo) < 0) |
8a0867d6 LP |
2027 | r = -errno; |
2028 | ||
2029 | if (mode == KILL_CONTROL_GROUP) { | |
2030 | int q; | |
2031 | ||
2032 | if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) | |
2033 | return -ENOMEM; | |
2034 | ||
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) { | |
2038 | r = q; | |
2039 | goto finish; | |
2040 | } | |
2041 | ||
430c18ed | 2042 | if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0) |
8a0867d6 LP |
2043 | if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) |
2044 | r = q; | |
2045 | } | |
2046 | ||
2047 | finish: | |
2048 | if (pid_set) | |
2049 | set_free(pid_set); | |
2050 | ||
2051 | return r; | |
2052 | } | |
2053 | ||
a16e1123 LP |
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", | |
fdf20a31 | 2066 | [SOCKET_FAILED] = "failed" |
a16e1123 LP |
2067 | }; |
2068 | ||
2069 | DEFINE_STRING_TABLE_LOOKUP(socket_state, SocketState); | |
2070 | ||
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" | |
2076 | }; | |
2077 | ||
2078 | DEFINE_STRING_TABLE_LOOKUP(socket_exec_command, SocketExecCommand); | |
2079 | ||
87f0e418 | 2080 | const UnitVTable socket_vtable = { |
5cb5a6ff LP |
2081 | .suffix = ".socket", |
2082 | ||
034c6ed7 LP |
2083 | .init = socket_init, |
2084 | .done = socket_done, | |
a16e1123 LP |
2085 | .load = socket_load, |
2086 | ||
8a0867d6 LP |
2087 | .kill = socket_kill, |
2088 | ||
a16e1123 | 2089 | .coldplug = socket_coldplug, |
034c6ed7 | 2090 | |
5cb5a6ff LP |
2091 | .dump = socket_dump, |
2092 | ||
542563ba LP |
2093 | .start = socket_start, |
2094 | .stop = socket_stop, | |
5cb5a6ff | 2095 | |
a16e1123 LP |
2096 | .serialize = socket_serialize, |
2097 | .deserialize_item = socket_deserialize_item, | |
2098 | ||
5cb5a6ff | 2099 | .active_state = socket_active_state, |
10a94420 | 2100 | .sub_state_to_string = socket_sub_state_to_string, |
5cb5a6ff | 2101 | |
6cf6bbc2 LP |
2102 | .check_gc = socket_check_gc, |
2103 | ||
9152c765 | 2104 | .fd_event = socket_fd_event, |
034c6ed7 | 2105 | .sigchld_event = socket_sigchld_event, |
4139c1b2 LP |
2106 | .timer_event = socket_timer_event, |
2107 | ||
fdf20a31 | 2108 | .reset_failed = socket_reset_failed, |
5632e374 | 2109 | |
c4e2ceae LP |
2110 | .bus_interface = "org.freedesktop.systemd1.Socket", |
2111 | .bus_message_handler = bus_socket_message_handler, | |
2112 | .bus_invalidating_properties = bus_socket_invalidating_properties | |
5cb5a6ff | 2113 | }; |