Skip to content

Commit b15490c

Browse files
committed
sd-daemon: Replace SO_LINGER with shutdown() + recv()
Let's shutdown the write end and wait for EOF from the other side before continuing to make sure that the receiver has received all data we sent on the socket. (cherry picked from commit 13b67b6)
1 parent 97ad9a3 commit b15490c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libsystemd/sd-daemon/sd-daemon.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,19 @@ static int pid_notify_with_fds_internal(
594594
}
595595
} while (!iovec_increment(msghdr.msg_iov, msghdr.msg_iovlen, n));
596596

597+
if (address.sockaddr.sa.sa_family == AF_VSOCK && IN_SET(type, SOCK_STREAM, SOCK_SEQPACKET)) {
598+
/* For AF_VSOCK, we need to close the socket to signal the end of the message. */
599+
if (shutdown(fd, SHUT_WR) < 0)
600+
return log_error_errno(errno, "Failed to shutdown notify socket: %m");
601+
602+
char buf[1];
603+
n = recv(fd, buf, sizeof(buf), MSG_NOSIGNAL);
604+
if (n > 0)
605+
return log_error_errno(errno, "Unexpectedly received data on notify socket: %m");
606+
if (n < 0)
607+
return log_error_errno(errno, "Failed to wait for EOF on notify socket: %m");
608+
}
609+
597610
return 1;
598611
}
599612

0 commit comments

Comments
 (0)