]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
socket: make all sockets non-blocking
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 23 Jul 2019 13:09:24 +0000 (15:09 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 24 Jul 2019 08:21:14 +0000 (10:21 +0200)
All networking code in chronyd (NTP server/client, signd client, cmdmon
server) assumes sending a message will not block, but only the signd
client actually checks for a write event and only the NTP server
requests a non-blocking socket. The cmdmon server and NTP client
(if using one socket for all servers) might be blocked.

chronyc doesn't need a non-blocking socket, but it is not expected to
block as it sends only one message at a time.

Prefer dropped messages over blocking in all cases. Remove the
SCK_FLAG_NONBLOCK flag and make all sockets non-blocking.

ntp_io.c
socket.c
socket.h

index 584795638fab02a2d0006417775b25ad38e83e9c..f947237d1fcc29509af18acec3a047ca217b8a65 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -98,7 +98,7 @@ open_socket(int family, int local_port, int client_only, IPSockAddr *remote_addr
 
   sock_flags = SCK_FLAG_RX_DEST_ADDR | SCK_FLAG_PRIV_BIND;
   if (!client_only)
-    sock_flags |= SCK_FLAG_NONBLOCK | SCK_FLAG_BROADCAST;
+    sock_flags |= SCK_FLAG_BROADCAST;
 
   sock_fd = SCK_OpenUdpSocket(remote_addr, &local_addr, sock_flags);
   if (sock_fd < 0) {
index 5a2a51140c5bc357ce88b075e447ff1a2a100be8..7d28d7a1f0a3f3d1ecb1916f0bae4786370109c1 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -160,8 +160,8 @@ open_socket(int domain, int type, int flags)
     return INVALID_SOCK_FD;
   }
 
-  /* Enable non-blocking mode if requested */
-  if (flags & SCK_FLAG_NONBLOCK && fcntl(sock_fd, F_SETFL, O_NONBLOCK)) {
+  /* Enable non-blocking mode */
+  if (fcntl(sock_fd, F_SETFL, O_NONBLOCK)) {
     DEBUG_LOG("Could not set O_NONBLOCK : %s", strerror(errno));
     close(sock_fd);
     return INVALID_SOCK_FD;
index 54ec5a6ea7f2914371b1a43c10dd9a4b7dccd02b..b3949188ca3cb5a32a147afc5709a9ebbc5b568f 100644 (file)
--- a/socket.h
+++ b/socket.h
@@ -31,7 +31,6 @@
 #include "addressing.h"
 
 /* Flags for opening sockets */
-#define SCK_FLAG_NONBLOCK 1
 #define SCK_FLAG_BROADCAST 2
 #define SCK_FLAG_RX_DEST_ADDR 4
 #define SCK_FLAG_ALL_PERMISSIONS 8