]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/socket: clean up socket peer handling a bit
authorMike Yuan <me@yhndnzj.com>
Sat, 23 Mar 2024 11:55:27 +0000 (19:55 +0800)
committerMike Yuan <me@yhndnzj.com>
Sat, 23 Mar 2024 17:08:40 +0000 (01:08 +0800)
Currently, SocketPeer object acquired through
socket_acquire_peer() are referenced twice
in socket_enter_running and service_set_socket_fd,
and the reference taken by former gets dropped
through _cleanup_. This is a bit confusing.
Let's just pass ownership instead.

src/core/service.c
src/core/socket.c

index cc6b6e6961cba4ecaaafab3a2928eec09ed0bc0b..953cb2934aacaf5fc5429bbe30e1e6fef46c91d8 100644 (file)
@@ -4760,7 +4760,7 @@ int service_set_socket_fd(
                                             "Failed to add After=/TriggeredBy= dependencies on socket unit: %m");
 
         s->socket_fd = fd;
-        s->socket_peer = socket_peer_ref(peer);
+        s->socket_peer = peer;
         s->socket_fd_selinux_context_net = selinux_context_net;
 
         unit_ref_set(&s->accept_socket, UNIT(s), UNIT(sock));
index 8b3aa88715105b88b13f388901700fef424c0cb1..2ce197e3287184ddc6e6db8610727ab6823a1656 100644 (file)
@@ -2364,7 +2364,10 @@ static void socket_enter_running(Socket *s, int cfd_in) {
                         goto fail;
                 }
 
-                TAKE_FD(cfd); /* We passed ownership of the fd to the service now. Forget it here. */
+                /* We passed ownership of the fd and socket peer to the service now. */
+                TAKE_FD(cfd);
+                TAKE_PTR(p);
+
                 s->n_connections++;
 
                 r = manager_add_job(UNIT(s)->manager, JOB_START, service, JOB_REPLACE, NULL, &error, NULL);