static int socket_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static int socket_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
-static void flush_ports(Socket *s);
static bool SOCKET_STATE_WITH_PROCESS(SocketState state) {
return IN_SET(state,
return 0;
}
-static const char *socket_find_symlink_target(Socket *s) {
+static const char* socket_find_symlink_target(Socket *s) {
const char *found = NULL;
+ assert(s);
+
LIST_FOREACH(port, p, s->ports) {
- const char *f = NULL;
+ const char *f;
switch (p->type) {
break;
default:
- break;
+ f = NULL;
}
if (f) {
return socket_verify(s);
}
-static SocketPeer *socket_peer_dup(const SocketPeer *q) {
+static SocketPeer* socket_peer_dup(const SocketPeer *q) {
SocketPeer *p;
assert(q);
return p;
}
-static SocketPeer *socket_peer_free(SocketPeer *p) {
+static SocketPeer* socket_peer_free(SocketPeer *p) {
assert(p);
if (p->socket)
return "ListenSequentialPacket";
assert_not_reached();
- return NULL;
}
static void socket_dump(Unit *u, FILE *f, const char *prefix) {
break;
default:
- break;
+ ;
}
}
/* Note that we don't return NULL here, since s has not been freed. */
}
+DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(Socket*, socket_close_fds, NULL);
+
static void socket_apply_socket_options(Socket *s, SocketPort *p, int fd) {
int r;
(void) mkdir_parents_label(*i, s->directory_mode);
r = symlink_idempotent(p, *i, false);
-
if (r == -EEXIST && s->remove_on_stop) {
/* If there's already something where we want to create the symlink, and the destructive
* RemoveOnStop= mode is set, then we might as well try to remove what already exists and try
if (unlink(*i) >= 0)
r = symlink_idempotent(p, *i, false);
}
-
if (r < 0)
log_unit_warning_errno(UNIT(s), r, "Failed to create symlink %s %s %s, ignoring: %m",
p, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), *i);
return fd;
}
-DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(Socket *, socket_close_fds, NULL);
-
static int socket_open_fds(Socket *orig_s) {
_cleanup_(socket_close_fdsp) Socket *s = orig_s;
_cleanup_freecon_ char *label = NULL;
p->fd = special_address_create(p->path, s->writable);
if (p->fd < 0)
- return log_unit_error_errno(UNIT(s), p->fd, "Failed to open special file %s: %m", p->path);
+ return log_unit_error_errno(UNIT(s), p->fd, "Failed to open special file '%s': %m", p->path);
break;
case SOCKET_FIFO:
s->directory_mode,
s->socket_mode);
if (p->fd < 0)
- return log_unit_error_errno(UNIT(s), p->fd, "Failed to open FIFO %s: %m", p->path);
+ return log_unit_error_errno(UNIT(s), p->fd, "Failed to open FIFO '%s': %m", p->path);
socket_apply_fifo_options(s, p->fd);
socket_symlink(s);
s->mq_maxmsg,
s->mq_msgsize);
if (p->fd < 0)
- return log_unit_error_errno(UNIT(s), p->fd, "Failed to open message queue %s: %m", p->path);
+ return log_unit_error_errno(UNIT(s), p->fd, "Failed to open message queue '%s': %m", p->path);
break;
case SOCKET_USB_FUNCTION: {
break;
}
+
default:
assert_not_reached();
}
}
- s = NULL;
+ TAKE_PTR(s);
return 0;
}
log_unit_warning_errno(UNIT(s), r, "Failed to kill processes: %m");
goto fail;
}
-
if (r > 0) {
r = socket_arm_timer(s, /* relative= */ true, s->timeout_usec);
if (r < 0) {
socket_enter_stop_post(s, SOCKET_SUCCESS);
}
+static void flush_ports(Socket *s) {
+ assert(s);
+
+ /* Flush all incoming traffic, regardless if actual bytes or new connections, so that this socket isn't busy
+ * anymore */
+
+ LIST_FOREACH(port, p, s->ports) {
+ if (p->fd < 0)
+ continue;
+
+ (void) flush_accept(p->fd);
+ (void) flush_fd(p->fd);
+ }
+}
+
static void socket_enter_listening(Socket *s) {
int r;
socket_enter_start_chown(s);
}
-static void flush_ports(Socket *s) {
- assert(s);
-
- /* Flush all incoming traffic, regardless if actual bytes or new connections, so that this socket isn't busy
- * anymore */
-
- LIST_FOREACH(port, p, s->ports) {
- if (p->fd < 0)
- continue;
-
- (void) flush_accept(p->fd);
- (void) flush_fd(p->fd);
- }
-}
-
static void socket_enter_running(Socket *s, int cfd_in) {
/* Note that this call takes possession of the connection fd passed. It either has to assign it
* somewhere or close it. */