const SocketAddress *address,
const char *label) {
- _cleanup_(pidref_done) PidRef pid = PIDREF_NULL;
- _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
- int fd, r;
+ int r;
assert(s);
assert(address);
if (!fork_needed(address, s)) {
/* Shortcut things... */
- fd = socket_address_listen_do(s, address, label);
- if (fd < 0)
- return log_address_error_errno(UNIT(s), address, fd, "Failed to create listening socket (%s): %m");
+ r = socket_address_listen_do(s, address, label);
+ if (r < 0)
+ return log_address_error_errno(UNIT(s), address, r, "Failed to create listening socket (%s): %m");
- return fd;
+ return r;
}
r = unit_setup_exec_runtime(UNIT(s));
}
}
+ _cleanup_(pidref_done) PidRef pid = PIDREF_NULL;
+ _cleanup_close_pair_ int pair[2] = EBADF_PAIR;
+ _cleanup_close_ int fd = -EBADF;
+
if (socketpair(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0, pair) < 0)
return log_unit_error_errno(UNIT(s), errno, "Failed to create communication channel: %m");
/* We synchronously wait for the helper, as it shouldn't be slow */
r = pidref_wait_for_terminate_and_check("(sd-listen)", &pid, WAIT_LOG_ABNORMAL);
- if (r < 0) {
- safe_close(fd);
+ if (r < 0)
return r;
- }
if (fd < 0)
return log_address_error_errno(UNIT(s), address, fd, "Failed to receive listening socket (%s): %m");
- return fd;
+ return TAKE_FD(fd);
}
static int socket_open_fds(Socket *orig_s) {
/* If we received no fd, we got EIO here. If this happens with a process exit code of EXIT_SUCCESS
* this is a spurious accept(), let's convert that back to EAGAIN here. */
- if (cfd == -EIO)
+ if (cfd == -EIO && r == EXIT_SUCCESS)
return -EAGAIN;
if (cfd < 0)
return log_unit_error_errno(UNIT(s), cfd, "Failed to receive connection socket: %m");