]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Add a check for EINTR to accept() calls.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Tue, 9 Dec 2025 17:13:18 +0000 (17:13 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Tue, 9 Dec 2025 17:13:18 +0000 (17:13 +0000)
Makefile.am
ap2_event_receiver.c
ap2_rc_event_receiver.c
rtsp.c
utilities/network_utilities.c [new file with mode: 0644]
utilities/network_utilities.h [new file with mode: 0644]

index 35603caf7dcc047ffd4f280a4cfef1f8c9334af6..6325a4381da16146d0af34e29a54ceb364d8f3e6 100644 (file)
@@ -27,7 +27,7 @@ noinst_LIBRARIES =
 
 # See below for the flags for the test client program
 
-shairport_sync_SOURCES = utilities/debug.c shairport.c bonjour_strings.c rtsp.c mdns.c common.c rtp.c player.c audio.c loudness.c activity_monitor.c
+shairport_sync_SOURCES = shairport.c bonjour_strings.c rtsp.c mdns.c common.c rtp.c player.c audio.c loudness.c activity_monitor.c utilities/debug.c utilities/network_utilities.c
 
 if BUILD_FOR_DARWIN
   AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -Wno-deprecated-declarations -pthread -DSYSCONFDIR=\"$(sysconfdir)\"
index c4d939e8d04b3151af3493606438315ca56cd648..75371cbde58d7ff8ba266b3a68fc84d084efa649 100644 (file)
@@ -31,6 +31,7 @@
 #include "ptp-utilities.h"
 #include "rtsp.h"
 #include "utilities/structured_buffer.h"
+#include "utilities/network_utilities.h"
 
 void ap2_event_receiver_cleanup_handler(void *arg) {
   rtsp_conn_info *conn = (rtsp_conn_info *)arg;
@@ -108,7 +109,7 @@ void *ap2_event_receiver(void *arg) {
     memset(&remote_addr, 0, sizeof(remote_addr));
     socklen_t addr_size = sizeof(remote_addr);
 
-    int fd = accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
+    int fd = eintr_checked_accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
     debug(2,
           "Connection %d: ap2_event_receiver accepted a connection on socket %d and moved to a new "
           "socket %d.",
@@ -194,9 +195,11 @@ void *ap2_event_receiver(void *arg) {
       }
 
     } while (finished == 0);
+
     debug(3, "Connection %d: AP2 Event Receiver RTP thread starting \"normal\" exit.",
           conn->connection_number);
     pthread_cleanup_pop(1); // close the socket
+
     pthread_cleanup_pop(1); // do the cleanup
     pthread_cleanup_pop(1); // delete the structured buffer
     debug(2, "Connection %d: AP2 Event Receiver RTP thread \"normal\" exit.",
index 587d375cc6d2087d07090d39c745f1b0a535ae61..74d03327c75dbb5f4f7edb52ef5294d909b81db5 100644 (file)
@@ -29,6 +29,7 @@
 #include "player.h"
 #include "rtsp.h"
 #include "utilities/structured_buffer.h"
+#include "utilities/network_utilities.h"
 
 void ap2_rc_event_receiver_cleanup_handler(void *arg) {
   rtsp_conn_info *conn = (rtsp_conn_info *)arg;
@@ -58,7 +59,7 @@ void *ap2_rc_event_receiver(void *arg) {
     memset(&remote_addr, 0, sizeof(remote_addr));
     socklen_t addr_size = sizeof(remote_addr);
 
-    int fd = accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
+    int fd = eintr_checked_accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
     debug(2,
           "Connection %d: ap2_rc_event_receiver accepted a connection on socket %d and moved to a "
           "new "
diff --git a/rtsp.c b/rtsp.c
index 0b76004b8342ffc21c936d2a9e10d17ad2e7bfd1..30a7f54a9c7ea6f2e0700f291a190b0dbd7d3e4f 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
 #endif
 
 #include "mdns.h"
+#include "utilities/network_utilities.h"
 
 #define METADATA_SNDBUF (4 * 1024 * 1024)
 
@@ -457,7 +458,7 @@ play_lock_r get_play_lock(rtsp_conn_info *conn, int allow_session_interruption)
       // important -- demote the principal conn before cancelling it
       if (principal_conn->fd > 0) {
         debug(2,
-              "Connection %d: %s has acquired play_lock and is forcing termination of Connection "
+              "Connection %d: %s is acquiring play_lock and is forcing termination of Connection "
               "%d %s. Closing "
               "RTSP connection socket %d: "
               "from %s:%u to self at "
@@ -491,7 +492,7 @@ play_lock_r get_play_lock(rtsp_conn_info *conn, int allow_session_interruption)
 #endif
         response = play_lock_acquired_by_breaking_in;
       }
-      usleep(1000000); // don't know why this delay is needed.
+      // usleep(1000000); // don't know why this delay is needed.
     }
     if ((principal_conn != NULL) && (response != play_lock_already_acquired))
       debug(1, "Connection %d: %s has principal_conn.", conn->connection_number,
@@ -5410,7 +5411,7 @@ void *rtsp_listen_loop(__attribute((unused)) void *arg) {
 #endif
 
       socklen_t size_of_reply = sizeof(SOCKADDR);
-      conn->fd = accept(acceptfd, (struct sockaddr *)&conn->remote, &size_of_reply);
+      conn->fd = eintr_checked_accept(acceptfd, (struct sockaddr *)&conn->remote, &size_of_reply);
       if (conn->fd < 0) {
         debug(1, "Connection %d: New connection on port %d not accepted:", conn->connection_number,
               config.port);
diff --git a/utilities/network_utilities.c b/utilities/network_utilities.c
new file mode 100644 (file)
index 0000000..81c0169
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Network Utilities. This file is part of Shairport Sync.
+ * Copyright (c) Mike Brady 2014--2025
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include "network_utilities.h"
+
+int eintr_checked_accept(int sockfd, struct sockaddr *addr,
+                  socklen_t *addrlen) {
+  int response;
+  do {
+    response =  accept(sockfd, addr, addrlen);
+    
+    if (response == -1) {
+      char errorstring[1024];
+      strerror_r(errno, (char *)errorstring, sizeof(errorstring));
+      debug(1,
+        "error %d accept()ing a socketin ap2_event_receiver %d: \"%s\". Error %d is ignored.",
+        errno, errorstring, EINTR);
+    }
+    
+  } while((response == -1) && (errno == EINTR));
+  return response;
+}
\ No newline at end of file
diff --git a/utilities/network_utilities.h b/utilities/network_utilities.h
new file mode 100644 (file)
index 0000000..001a1c9
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef _NETWORK_UTILITIES_H
+#define _NETWORK_UTILITIES_H
+
+#include <sys/socket.h>
+
+#define restrict
+
+int eintr_checked_accept(int sockfd, struct sockaddr *addr,
+                  socklen_t *addrlen);
+#endif // _NETWORK_UTILITIES_H