]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/socket: trivial coding style cleanups
authorMike Yuan <me@yhndnzj.com>
Mon, 16 Dec 2024 00:29:35 +0000 (01:29 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 17 May 2025 11:43:20 +0000 (12:43 +0100)
(cherry picked from commit 2fbdfe0b0d355d0bd6ea8b93a000f92bc7f5fe5f)
(cherry picked from commit 7f3bc9fef15ef7ba3cf8458c7841760ba3036e89)

src/core/socket.c
src/core/socket.h

index da635f90410f583c2d6b9a6343e98b4a1e86e0ac..792527696e14c4dbbe8c55bc9dad851038fb594a 100644 (file)
@@ -75,7 +75,6 @@ static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
 
 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,
@@ -355,11 +354,13 @@ static int socket_add_extras(Socket *s) {
         return 0;
 }
 
-static const char *socket_find_symlink_target(Socket *s) {
+static const charsocket_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) {
 
@@ -372,7 +373,7 @@ static const char *socket_find_symlink_target(Socket *s) {
                         break;
 
                 default:
-                        break;
+                        f = NULL;
                 }
 
                 if (f) {
@@ -469,7 +470,7 @@ static int socket_load(Unit *u) {
         return socket_verify(s);
 }
 
-static SocketPeer *socket_peer_dup(const SocketPeer *q) {
+static SocketPeersocket_peer_dup(const SocketPeer *q) {
         SocketPeer *p;
 
         assert(q);
@@ -488,7 +489,7 @@ static SocketPeer *socket_peer_dup(const SocketPeer *q) {
         return p;
 }
 
-static SocketPeer *socket_peer_free(SocketPeer *p) {
+static SocketPeersocket_peer_free(SocketPeer *p) {
         assert(p);
 
         if (p->socket)
@@ -564,7 +565,6 @@ static const char* listen_lookup(int family, int type) {
                 return "ListenSequentialPacket";
 
         assert_not_reached();
-        return NULL;
 }
 
 static void socket_dump(Unit *u, FILE *f, const char *prefix) {
@@ -960,7 +960,7 @@ static void socket_close_fds(Socket *s) {
                         break;
 
                 default:
-                        break;
+                        ;
                 }
         }
 
@@ -971,6 +971,8 @@ static void socket_close_fds(Socket *s) {
         /* 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;
 
@@ -1282,7 +1284,6 @@ static int socket_symlink(Socket *s) {
                 (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
@@ -1291,7 +1292,6 @@ static int socket_symlink(Socket *s) {
                         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);
@@ -1611,8 +1611,6 @@ static int socket_address_listen_in_cgroup(
         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_(mac_selinux_freep) char *label = NULL;
@@ -1668,7 +1666,7 @@ static int socket_open_fds(Socket *orig_s) {
 
                         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:
@@ -1678,7 +1676,7 @@ static int socket_open_fds(Socket *orig_s) {
                                         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);
@@ -1692,7 +1690,7 @@ static int socket_open_fds(Socket *orig_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: {
@@ -1716,12 +1714,13 @@ static int socket_open_fds(Socket *orig_s) {
 
                         break;
                 }
+
                 default:
                         assert_not_reached();
                 }
         }
 
-        s = NULL;
+        TAKE_PTR(s);
         return 0;
 }
 
@@ -2105,7 +2104,6 @@ static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) {
                 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) {
@@ -2159,6 +2157,21 @@ static void socket_enter_stop_pre(Socket *s, SocketResult f) {
                 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;
 
@@ -2263,21 +2276,6 @@ static void socket_enter_start_pre(Socket *s) {
                 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. */
index 5e3929c5fa78370b4430bd4442e4b37caba77c0d..ac1202b75a306990315801fe823ff6b648a2d6fc 100644 (file)
@@ -177,7 +177,7 @@ int socket_collect_fds(Socket *s, int **ret);
 /* Called from the service code when a per-connection service ended */
 void socket_connection_unref(Socket *s);
 
-SocketPort *socket_port_free(SocketPort *p);
+SocketPortsocket_port_free(SocketPort *p);
 DEFINE_TRIVIAL_CLEANUP_FUNC(SocketPort*, socket_port_free);
 
 void socket_free_ports(Socket *s);