From 9b33cea0f7a50e4c484a9acb3ada0c1218cd3fcb Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Fri, 5 Jul 2024 09:07:32 -0400 Subject: [PATCH] module-rtp: Minor robustness improvement to PTP socket reading Mark socket as CLOEXEC like we do everything else, log when we flush stale data, and check for errors in the while loop. --- src/modules/module-rtp-sap.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/module-rtp-sap.c b/src/modules/module-rtp-sap.c index ff98ca489..5f860aaae 100644 --- a/src/modules/module-rtp-sap.c +++ b/src/modules/module-rtp-sap.c @@ -376,7 +376,7 @@ static bool is_multicast(struct sockaddr *sa, socklen_t salen) static int make_unix_socket(const char *path) { struct sockaddr_un addr; - spa_autoclose int fd = socket(AF_UNIX, SOCK_DGRAM, 0); + spa_autoclose int fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (fd < 0) { pw_log_warn("Failed to create PTP management socket"); return -1; @@ -529,9 +529,11 @@ static void update_ts_refclk(struct impl *impl) // Read if something is left in the socket int avail; - ioctl(impl->ptp_fd, FIONREAD, &avail); uint8_t tmp; - while (avail--) read(impl->ptp_fd, &tmp, 1); + + ioctl(impl->ptp_fd, FIONREAD, &avail); + pw_log_debug("Flushing stale data: %u bytes", avail); + while (avail-- && read(impl->ptp_fd, &tmp, 1)); struct ptp_management_msg req; spa_zero(req);