]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2ca0435b | 2 | |
3f6fd1ba | 3 | #include <getopt.h> |
2ca0435b ZJS |
4 | #include <sys/epoll.h> |
5 | #include <sys/prctl.h> | |
6 | #include <sys/socket.h> | |
7 | #include <sys/wait.h> | |
3f6fd1ba | 8 | #include <unistd.h> |
2ca0435b | 9 | |
8dd4c05b | 10 | #include "sd-daemon.h" |
2ca0435b | 11 | |
b5efdb8a | 12 | #include "alloc-util.h" |
2b2fec7d | 13 | #include "errno-util.h" |
cf98937c | 14 | #include "escape.h" |
b5efdb8a | 15 | #include "fd-util.h" |
2ca0435b | 16 | #include "log.h" |
2ca0435b | 17 | #include "macro.h" |
294bf0c3 | 18 | #include "pretty-print.h" |
df0ff127 | 19 | #include "process-util.h" |
ce30c8dc | 20 | #include "signal-util.h" |
3f6fd1ba | 21 | #include "socket-util.h" |
07630cea | 22 | #include "string-util.h" |
3f6fd1ba | 23 | #include "strv.h" |
37ec0fdd | 24 | #include "terminal-util.h" |
ca78ad1d | 25 | #include "util.h" |
2ca0435b | 26 | |
1ace223c | 27 | static char **arg_listen = NULL; |
2ca0435b | 28 | static bool arg_accept = false; |
d31e430f | 29 | static int arg_socket_type = SOCK_STREAM; |
1ace223c SJ |
30 | static char **arg_args = NULL; |
31 | static char **arg_setenv = NULL; | |
cf98937c | 32 | static char **arg_fdnames = NULL; |
eef0a274 | 33 | static bool arg_inetd = false; |
2ca0435b ZJS |
34 | |
35 | static int add_epoll(int epoll_fd, int fd) { | |
30374ebe | 36 | struct epoll_event ev = { |
b1c05b98 ZJS |
37 | .events = EPOLLIN, |
38 | .data.fd = fd, | |
30374ebe | 39 | }; |
2ca0435b ZJS |
40 | |
41 | assert(epoll_fd >= 0); | |
42 | assert(fd >= 0); | |
43 | ||
b1c05b98 | 44 | if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) |
4a62c710 | 45 | return log_error_errno(errno, "Failed to add event on epoll fd:%d for fd:%d: %m", epoll_fd, fd); |
603938e0 LP |
46 | |
47 | return 0; | |
2ca0435b ZJS |
48 | } |
49 | ||
50 | static int open_sockets(int *epoll_fd, bool accept) { | |
30374ebe | 51 | char **address; |
29a5ca9b | 52 | int n, fd, r; |
2ca0435b | 53 | int count = 0; |
2ca0435b ZJS |
54 | |
55 | n = sd_listen_fds(true); | |
eb56eb9b MS |
56 | if (n < 0) |
57 | return log_error_errno(n, "Failed to read listening file descriptors from environment: %m"); | |
30374ebe LP |
58 | if (n > 0) { |
59 | log_info("Received %i descriptors via the environment.", n); | |
2ca0435b | 60 | |
30374ebe LP |
61 | for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { |
62 | r = fd_cloexec(fd, arg_accept); | |
63 | if (r < 0) | |
64 | return r; | |
2ca0435b | 65 | |
313cefa1 | 66 | count++; |
30374ebe | 67 | } |
2ca0435b ZJS |
68 | } |
69 | ||
c0997164 ZJS |
70 | /* Close logging and all other descriptors */ |
71 | if (arg_listen) { | |
72 | int except[3 + n]; | |
73 | ||
74 | for (fd = 0; fd < SD_LISTEN_FDS_START + n; fd++) | |
75 | except[fd] = fd; | |
76 | ||
77 | log_close(); | |
7acf581a ZJS |
78 | r = close_all_fds(except, 3 + n); |
79 | if (r < 0) | |
80 | return log_error_errno(r, "Failed to close all file descriptors: %m"); | |
c0997164 ZJS |
81 | } |
82 | ||
fff40a51 ZJS |
83 | /** Note: we leak some fd's on error here. I doesn't matter |
84 | * much, since the program will exit immediately anyway, but | |
85 | * would be a pain to fix. | |
86 | */ | |
87 | ||
2ca0435b | 88 | STRV_FOREACH(address, arg_listen) { |
1ace223c | 89 | fd = make_socket_fd(LOG_DEBUG, *address, arg_socket_type, (arg_accept * SOCK_CLOEXEC)); |
2ca0435b | 90 | if (fd < 0) { |
c0997164 | 91 | log_open(); |
23bbb0de | 92 | return log_error_errno(fd, "Failed to open '%s': %m", *address); |
2ca0435b ZJS |
93 | } |
94 | ||
175a3d25 | 95 | assert(fd == SD_LISTEN_FDS_START + count); |
313cefa1 | 96 | count++; |
2ca0435b ZJS |
97 | } |
98 | ||
c0997164 ZJS |
99 | if (arg_listen) |
100 | log_open(); | |
101 | ||
2ca0435b | 102 | *epoll_fd = epoll_create1(EPOLL_CLOEXEC); |
4a62c710 MS |
103 | if (*epoll_fd < 0) |
104 | return log_error_errno(errno, "Failed to create epoll object: %m"); | |
2ca0435b ZJS |
105 | |
106 | for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + count; fd++) { | |
30374ebe LP |
107 | _cleanup_free_ char *name = NULL; |
108 | ||
109 | getsockname_pretty(fd, &name); | |
2c408cb6 | 110 | log_info("Listening on %s as %i.", strna(name), fd); |
30374ebe | 111 | |
29a5ca9b | 112 | r = add_epoll(*epoll_fd, fd); |
2ca0435b ZJS |
113 | if (r < 0) |
114 | return r; | |
115 | } | |
116 | ||
117 | return count; | |
118 | } | |
119 | ||
1ace223c | 120 | static int exec_process(const char *name, char **argv, char **env, int start_fd, size_t n_fds) { |
30374ebe | 121 | |
30374ebe | 122 | _cleanup_strv_free_ char **envp = NULL; |
eef0a274 | 123 | _cleanup_free_ char *joined = NULL; |
da6053d0 | 124 | size_t n_env = 0, length; |
eef0a274 | 125 | const char *tocopy; |
eef0a274 LP |
126 | char **s; |
127 | int r; | |
128 | ||
baaa35ad ZJS |
129 | if (arg_inetd && n_fds != 1) |
130 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
131 | "--inetd only supported for single file descriptors."); | |
2ca0435b | 132 | |
892213bf | 133 | length = strv_length(arg_setenv); |
30374ebe | 134 | |
8dd4c05b LP |
135 | /* PATH, TERM, HOME, USER, LISTEN_FDS, LISTEN_PID, LISTEN_FDNAMES, NULL */ |
136 | envp = new0(char *, length + 8); | |
30374ebe LP |
137 | if (!envp) |
138 | return log_oom(); | |
5e65c93a | 139 | |
892213bf | 140 | STRV_FOREACH(s, arg_setenv) { |
eef0a274 | 141 | |
fa994f91 LP |
142 | if (strchr(*s, '=')) { |
143 | char *k; | |
144 | ||
145 | k = strdup(*s); | |
146 | if (!k) | |
147 | return log_oom(); | |
148 | ||
149 | envp[n_env++] = k; | |
150 | } else { | |
8dd4c05b | 151 | _cleanup_free_ char *p; |
fa994f91 | 152 | const char *n; |
8dd4c05b | 153 | |
b910cc72 | 154 | p = strjoin(*s, "="); |
5e65c93a ZJS |
155 | if (!p) |
156 | return log_oom(); | |
fa994f91 LP |
157 | |
158 | n = strv_find_prefix(env, p); | |
159 | if (!n) | |
160 | continue; | |
161 | ||
162 | envp[n_env] = strdup(n); | |
163 | if (!envp[n_env]) | |
164 | return log_oom(); | |
eef0a274 | 165 | |
313cefa1 | 166 | n_env++; |
5e65c93a ZJS |
167 | } |
168 | } | |
169 | ||
eef0a274 | 170 | FOREACH_STRING(tocopy, "TERM=", "PATH=", "USER=", "HOME=") { |
fa994f91 LP |
171 | const char *n; |
172 | ||
eef0a274 | 173 | n = strv_find_prefix(env, tocopy); |
fa994f91 LP |
174 | if (!n) |
175 | continue; | |
176 | ||
177 | envp[n_env] = strdup(n); | |
178 | if (!envp[n_env]) | |
179 | return log_oom(); | |
180 | ||
313cefa1 | 181 | n_env++; |
2ca0435b ZJS |
182 | } |
183 | ||
eef0a274 LP |
184 | if (arg_inetd) { |
185 | assert(n_fds == 1); | |
2ca0435b | 186 | |
2b33ab09 | 187 | r = rearrange_stdio(start_fd, start_fd, STDERR_FILENO); /* invalidates start_fd on success + error */ |
eef0a274 | 188 | if (r < 0) |
4355f1c9 | 189 | return log_error_errno(r, "Failed to move fd to stdin+stdout: %m"); |
8dd4c05b | 190 | |
eef0a274 LP |
191 | } else { |
192 | if (start_fd != SD_LISTEN_FDS_START) { | |
193 | assert(n_fds == 1); | |
194 | ||
b1c05b98 | 195 | if (dup2(start_fd, SD_LISTEN_FDS_START) < 0) |
eef0a274 LP |
196 | return log_error_errno(errno, "Failed to dup connection: %m"); |
197 | ||
198 | safe_close(start_fd); | |
199 | start_fd = SD_LISTEN_FDS_START; | |
200 | } | |
201 | ||
1ace223c | 202 | if (asprintf((char **) (envp + n_env++), "LISTEN_FDS=%zu", n_fds) < 0) |
8dd4c05b LP |
203 | return log_oom(); |
204 | ||
1ace223c | 205 | if (asprintf((char **) (envp + n_env++), "LISTEN_PID=" PID_FMT, getpid_cached()) < 0) |
eef0a274 | 206 | return log_oom(); |
8dd4c05b | 207 | |
cf98937c ZJS |
208 | if (arg_fdnames) { |
209 | _cleanup_free_ char *names = NULL; | |
210 | size_t len; | |
eef0a274 | 211 | char *e; |
cf98937c ZJS |
212 | |
213 | len = strv_length(arg_fdnames); | |
da6053d0 LP |
214 | if (len == 1) { |
215 | size_t i; | |
216 | ||
cf98937c ZJS |
217 | for (i = 1; i < n_fds; i++) { |
218 | r = strv_extend(&arg_fdnames, arg_fdnames[0]); | |
219 | if (r < 0) | |
220 | return log_error_errno(r, "Failed to extend strv: %m"); | |
221 | } | |
da6053d0 LP |
222 | } else if (len != n_fds) |
223 | log_warning("The number of fd names is different than number of fds: %zu vs %zu", len, n_fds); | |
eef0a274 | 224 | |
cf98937c ZJS |
225 | names = strv_join(arg_fdnames, ":"); |
226 | if (!names) | |
8dd4c05b | 227 | return log_oom(); |
eef0a274 | 228 | |
b910cc72 | 229 | e = strjoin("LISTEN_FDNAMES=", names); |
cf98937c ZJS |
230 | if (!e) |
231 | return log_oom(); | |
8dd4c05b | 232 | |
eef0a274 | 233 | envp[n_env++] = e; |
8dd4c05b | 234 | } |
8dd4c05b LP |
235 | } |
236 | ||
eef0a274 LP |
237 | joined = strv_join(argv, " "); |
238 | if (!joined) | |
2ca0435b ZJS |
239 | return log_oom(); |
240 | ||
eef0a274 | 241 | log_info("Execing %s (%s)", name, joined); |
2ca0435b | 242 | execvpe(name, argv, envp); |
30374ebe | 243 | |
eef0a274 | 244 | return log_error_errno(errno, "Failed to execp %s (%s): %m", name, joined); |
2ca0435b ZJS |
245 | } |
246 | ||
1ace223c | 247 | static int fork_and_exec_process(const char *child, char **argv, char **env, int fd) { |
eef0a274 | 248 | _cleanup_free_ char *joined = NULL; |
4c253ed1 LP |
249 | pid_t child_pid; |
250 | int r; | |
2ca0435b | 251 | |
eef0a274 LP |
252 | joined = strv_join(argv, " "); |
253 | if (!joined) | |
2ca0435b ZJS |
254 | return log_oom(); |
255 | ||
1ace223c SJ |
256 | r = safe_fork("(activate)", |
257 | FORK_RESET_SIGNALS | FORK_DEATHSIG | FORK_RLIMIT_NOFILE_SAFE | FORK_LOG, | |
258 | &child_pid); | |
4c253ed1 | 259 | if (r < 0) |
b6e1fff1 | 260 | return r; |
4c253ed1 LP |
261 | if (r == 0) { |
262 | /* In the child */ | |
eef0a274 | 263 | exec_process(child, argv, env, fd, 1); |
2ca0435b ZJS |
264 | _exit(EXIT_FAILURE); |
265 | } | |
266 | ||
4c253ed1 | 267 | log_info("Spawned %s (%s) as PID " PID_FMT ".", child, joined, child_pid); |
2ca0435b ZJS |
268 | return 0; |
269 | } | |
270 | ||
1ace223c | 271 | static int do_accept(const char *name, char **argv, char **envp, int fd) { |
30374ebe | 272 | _cleanup_free_ char *local = NULL, *peer = NULL; |
eef0a274 | 273 | _cleanup_close_ int fd_accepted = -1; |
2ca0435b | 274 | |
eef0a274 | 275 | fd_accepted = accept4(fd, NULL, NULL, 0); |
4ff9bc2e LP |
276 | if (fd_accepted < 0) { |
277 | if (ERRNO_IS_ACCEPT_AGAIN(errno)) | |
278 | return 0; | |
279 | ||
08719b64 | 280 | return log_error_errno(errno, "Failed to accept connection on fd:%d: %m", fd); |
4ff9bc2e | 281 | } |
2ca0435b | 282 | |
7ebd758c LP |
283 | (void) getsockname_pretty(fd_accepted, &local); |
284 | (void) getpeername_pretty(fd_accepted, true, &peer); | |
30374ebe | 285 | log_info("Connection from %s to %s", strna(peer), strna(local)); |
2ca0435b | 286 | |
eef0a274 | 287 | return fork_and_exec_process(name, argv, envp, fd_accepted); |
2ca0435b ZJS |
288 | } |
289 | ||
290 | /* SIGCHLD handler. */ | |
5488e52d | 291 | static void sigchld_hdl(int sig) { |
9d458c09 LP |
292 | PROTECT_ERRNO; |
293 | ||
5488e52d EV |
294 | for (;;) { |
295 | siginfo_t si; | |
296 | int r; | |
08719b64 | 297 | |
5488e52d | 298 | si.si_pid = 0; |
1ace223c | 299 | r = waitid(P_ALL, 0, &si, WEXITED | WNOHANG); |
5488e52d EV |
300 | if (r < 0) { |
301 | if (errno != ECHILD) | |
302 | log_error_errno(errno, "Failed to reap children: %m"); | |
303 | return; | |
304 | } | |
305 | if (si.si_pid == 0) | |
306 | return; | |
307 | ||
308 | log_info("Child %d died with code %d", si.si_pid, si.si_status); | |
309 | } | |
2ca0435b ZJS |
310 | } |
311 | ||
312 | static int install_chld_handler(void) { | |
08719b64 | 313 | static const struct sigaction act = { |
1ace223c | 314 | .sa_flags = SA_NOCLDSTOP | SA_RESTART, |
5488e52d | 315 | .sa_handler = sigchld_hdl, |
c0997164 | 316 | }; |
2ca0435b | 317 | |
b1c05b98 | 318 | if (sigaction(SIGCHLD, &act, 0) < 0) |
08719b64 LP |
319 | return log_error_errno(errno, "Failed to install SIGCHLD handler: %m"); |
320 | ||
321 | return 0; | |
2ca0435b ZJS |
322 | } |
323 | ||
37ec0fdd LP |
324 | static int help(void) { |
325 | _cleanup_free_ char *link = NULL; | |
326 | int r; | |
327 | ||
328 | r = terminal_urlify_man("systemd-socket-activate", "1", &link); | |
329 | if (r < 0) | |
330 | return log_oom(); | |
331 | ||
2ca0435b ZJS |
332 | printf("%s [OPTIONS...]\n\n" |
333 | "Listen on sockets and launch child on connection.\n\n" | |
334 | "Options:\n" | |
cf98937c ZJS |
335 | " -h --help Show this help and exit\n" |
336 | " --version Print version string and exit\n" | |
337 | " -l --listen=ADDR Listen for raw connections at ADDR\n" | |
338 | " -d --datagram Listen on datagram instead of stream socket\n" | |
339 | " --seqpacket Listen on SOCK_SEQPACKET instead of stream socket\n" | |
340 | " -a --accept Spawn separate child for each connection\n" | |
341 | " -E --setenv=NAME[=VALUE] Pass an environment variable to children\n" | |
342 | " --fdname=NAME[:NAME...] Specify names for file descriptors\n" | |
343 | " --inetd Enable inetd file descriptor passing protocol\n" | |
37ec0fdd LP |
344 | "\nNote: file descriptors from sd_listen_fds() will be passed through.\n" |
345 | "\nSee the %s for details.\n" | |
346 | , program_invocation_short_name | |
347 | , link | |
348 | ); | |
349 | ||
350 | return 0; | |
2ca0435b ZJS |
351 | } |
352 | ||
353 | static int parse_argv(int argc, char *argv[]) { | |
354 | enum { | |
355 | ARG_VERSION = 0x100, | |
8dd4c05b | 356 | ARG_FDNAME, |
d31e430f | 357 | ARG_SEQPACKET, |
eef0a274 | 358 | ARG_INETD, |
2ca0435b ZJS |
359 | }; |
360 | ||
361 | static const struct option options[] = { | |
892213bf ZJS |
362 | { "help", no_argument, NULL, 'h' }, |
363 | { "version", no_argument, NULL, ARG_VERSION }, | |
7b7afdfc | 364 | { "datagram", no_argument, NULL, 'd' }, |
d31e430f | 365 | { "seqpacket", no_argument, NULL, ARG_SEQPACKET }, |
892213bf ZJS |
366 | { "listen", required_argument, NULL, 'l' }, |
367 | { "accept", no_argument, NULL, 'a' }, | |
368 | { "setenv", required_argument, NULL, 'E' }, | |
8dd4c05b LP |
369 | { "environment", required_argument, NULL, 'E' }, /* legacy alias */ |
370 | { "fdname", required_argument, NULL, ARG_FDNAME }, | |
eef0a274 | 371 | { "inetd", no_argument, NULL, ARG_INETD }, |
eb9da376 | 372 | {} |
2ca0435b ZJS |
373 | }; |
374 | ||
8dd4c05b | 375 | int c, r; |
2ca0435b ZJS |
376 | |
377 | assert(argc >= 0); | |
378 | assert(argv); | |
379 | ||
b722348d | 380 | while ((c = getopt_long(argc, argv, "+hl:aE:d", options, NULL)) >= 0) |
1ace223c | 381 | switch (c) { |
2ca0435b | 382 | case 'h': |
37ec0fdd | 383 | return help(); |
2ca0435b ZJS |
384 | |
385 | case ARG_VERSION: | |
3f6fd1ba | 386 | return version(); |
2ca0435b | 387 | |
8dd4c05b LP |
388 | case 'l': |
389 | r = strv_extend(&arg_listen, optarg); | |
2ca0435b | 390 | if (r < 0) |
8dd4c05b | 391 | return log_oom(); |
2ca0435b ZJS |
392 | |
393 | break; | |
2ca0435b | 394 | |
7b7afdfc | 395 | case 'd': |
baaa35ad ZJS |
396 | if (arg_socket_type == SOCK_SEQPACKET) |
397 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
398 | "--datagram may not be combined with --seqpacket."); | |
d31e430f LP |
399 | |
400 | arg_socket_type = SOCK_DGRAM; | |
401 | break; | |
402 | ||
403 | case ARG_SEQPACKET: | |
baaa35ad ZJS |
404 | if (arg_socket_type == SOCK_DGRAM) |
405 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
406 | "--seqpacket may not be combined with --datagram."); | |
d31e430f LP |
407 | |
408 | arg_socket_type = SOCK_SEQPACKET; | |
7b7afdfc SS |
409 | break; |
410 | ||
2ca0435b ZJS |
411 | case 'a': |
412 | arg_accept = true; | |
413 | break; | |
414 | ||
8dd4c05b LP |
415 | case 'E': |
416 | r = strv_extend(&arg_setenv, optarg); | |
5e65c93a | 417 | if (r < 0) |
8dd4c05b | 418 | return log_oom(); |
5e65c93a ZJS |
419 | |
420 | break; | |
8dd4c05b | 421 | |
cf98937c ZJS |
422 | case ARG_FDNAME: { |
423 | _cleanup_strv_free_ char **names; | |
424 | char **s; | |
425 | ||
426 | names = strv_split(optarg, ":"); | |
427 | if (!names) | |
428 | return log_oom(); | |
429 | ||
430 | STRV_FOREACH(s, names) | |
431 | if (!fdname_is_valid(*s)) { | |
432 | _cleanup_free_ char *esc; | |
163c76c9 | 433 | |
cf98937c ZJS |
434 | esc = cescape(*s); |
435 | log_warning("File descriptor name \"%s\" is not valid.", esc); | |
436 | } | |
437 | ||
438 | /* Empty optargs means one empty name */ | |
439 | r = strv_extend_strv(&arg_fdnames, | |
440 | strv_isempty(names) ? STRV_MAKE("") : names, | |
441 | false); | |
442 | if (r < 0) | |
443 | return log_error_errno(r, "strv_extend_strv: %m"); | |
8dd4c05b | 444 | break; |
cf98937c | 445 | } |
5e65c93a | 446 | |
eef0a274 LP |
447 | case ARG_INETD: |
448 | arg_inetd = true; | |
449 | break; | |
450 | ||
2ca0435b ZJS |
451 | case '?': |
452 | return -EINVAL; | |
453 | ||
454 | default: | |
eb9da376 | 455 | assert_not_reached("Unhandled option"); |
2ca0435b ZJS |
456 | } |
457 | ||
baaa35ad ZJS |
458 | if (optind == argc) |
459 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
460 | "%s: command to execute is missing.", | |
461 | program_invocation_short_name); | |
2ca0435b | 462 | |
baaa35ad ZJS |
463 | if (arg_socket_type == SOCK_DGRAM && arg_accept) |
464 | return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | |
465 | "Datagram sockets do not accept connections. " | |
466 | "The --datagram and --accept options may not be combined."); | |
7b7afdfc | 467 | |
2ca0435b ZJS |
468 | arg_args = argv + optind; |
469 | ||
470 | return 1 /* work to do */; | |
471 | } | |
472 | ||
473 | int main(int argc, char **argv, char **envp) { | |
474 | int r, n; | |
475 | int epoll_fd = -1; | |
476 | ||
1a043959 | 477 | log_show_color(true); |
2ca0435b | 478 | log_parse_environment(); |
eceb8483 | 479 | log_open(); |
2ca0435b ZJS |
480 | |
481 | r = parse_argv(argc, argv); | |
482 | if (r <= 0) | |
483 | return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE; | |
484 | ||
485 | r = install_chld_handler(); | |
486 | if (r < 0) | |
487 | return EXIT_FAILURE; | |
488 | ||
489 | n = open_sockets(&epoll_fd, arg_accept); | |
490 | if (n < 0) | |
491 | return EXIT_FAILURE; | |
2c408cb6 LP |
492 | if (n == 0) { |
493 | log_error("No sockets to listen on specified or passed in."); | |
494 | return EXIT_FAILURE; | |
495 | } | |
2ca0435b | 496 | |
eceb8483 | 497 | for (;;) { |
2ca0435b ZJS |
498 | struct epoll_event event; |
499 | ||
b1c05b98 | 500 | if (epoll_wait(epoll_fd, &event, 1, -1) < 0) { |
2ca0435b ZJS |
501 | if (errno == EINTR) |
502 | continue; | |
503 | ||
56f64d95 | 504 | log_error_errno(errno, "epoll_wait() failed: %m"); |
2ca0435b ZJS |
505 | return EXIT_FAILURE; |
506 | } | |
507 | ||
2c408cb6 | 508 | log_info("Communication attempt on fd %i.", event.data.fd); |
2ca0435b | 509 | if (arg_accept) { |
d31e430f | 510 | r = do_accept(argv[optind], argv + optind, envp, event.data.fd); |
2ca0435b ZJS |
511 | if (r < 0) |
512 | return EXIT_FAILURE; | |
513 | } else | |
514 | break; | |
515 | } | |
516 | ||
da6053d0 | 517 | exec_process(argv[optind], argv + optind, envp, SD_LISTEN_FDS_START, (size_t) n); |
2ca0435b ZJS |
518 | |
519 | return EXIT_SUCCESS; | |
520 | } |