flush_ports: flush POSIX message queues properly

On Linux, read() on a message queue descriptor returns the message
queue statistics, not the actual message queue data.  We need to use
mq_receive() to drain the queues instead.

Fixes a problem where a POSIX message queue socket unit with messages
in the queue at shutdown time could result in a hang on reboot/shutdown.
This commit is contained in:
Todd C. Miller
2025-05-08 02:37:45 +09:00
committed by Yu Watanabe
parent 676fb42aae
commit ffb6adb763
3 changed files with 56 additions and 2 deletions
+1
View File
@@ -199,6 +199,7 @@ int receive_many_fds(int transport_fd, int **ret_fds_array, size_t *ret_n_fds_ar
ssize_t next_datagram_size_fd(int fd);
int flush_accept(int fd);
ssize_t flush_mqueue(int fd);
#define CMSG_FOREACH(cmsg, mh) \
for ((cmsg) = CMSG_FIRSTHDR(mh); (cmsg); (cmsg) = CMSG_NXTHDR((mh), (cmsg)))