socket: make all sockets non-blocking

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.
This commit is contained in:
Miroslav Lichvar 2019-07-23 15:09:24 +02:00
parent d78680912e
commit 4d26cfc92b
3 changed files with 3 additions and 4 deletions

View file

@ -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; sock_flags = SCK_FLAG_RX_DEST_ADDR | SCK_FLAG_PRIV_BIND;
if (!client_only) 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); sock_fd = SCK_OpenUdpSocket(remote_addr, &local_addr, sock_flags);
if (sock_fd < 0) { if (sock_fd < 0) {

View file

@ -160,8 +160,8 @@ open_socket(int domain, int type, int flags)
return INVALID_SOCK_FD; return INVALID_SOCK_FD;
} }
/* Enable non-blocking mode if requested */ /* Enable non-blocking mode */
if (flags & SCK_FLAG_NONBLOCK && fcntl(sock_fd, F_SETFL, O_NONBLOCK)) { if (fcntl(sock_fd, F_SETFL, O_NONBLOCK)) {
DEBUG_LOG("Could not set O_NONBLOCK : %s", strerror(errno)); DEBUG_LOG("Could not set O_NONBLOCK : %s", strerror(errno));
close(sock_fd); close(sock_fd);
return INVALID_SOCK_FD; return INVALID_SOCK_FD;

View file

@ -31,7 +31,6 @@
#include "addressing.h" #include "addressing.h"
/* Flags for opening sockets */ /* Flags for opening sockets */
#define SCK_FLAG_NONBLOCK 1
#define SCK_FLAG_BROADCAST 2 #define SCK_FLAG_BROADCAST 2
#define SCK_FLAG_RX_DEST_ADDR 4 #define SCK_FLAG_RX_DEST_ADDR 4
#define SCK_FLAG_ALL_PERMISSIONS 8 #define SCK_FLAG_ALL_PERMISSIONS 8