Commit 8d03dee9 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use MSG_NOSIGNAL in send()/sendto()/sendmsg()

This avoids SIGPIPE firing when writing to a remote-closed connection-
oriented socket (it is useless for datagram sockets or on Windows
though). SIGPIPE is blocked ins VLC, but not necessarily in LibVLC.

The problem remains for write() on broken pipe and sockets.
parent 3d94da0d
......@@ -68,7 +68,7 @@ static inline int is_allowed_port (uint16_t port)
static inline int send_err (int fd, int err)
{
return send (fd, &err, sizeof (err), 0) == sizeof (err) ? 0 : -1;
return send(fd, &err, sizeof (err), MSG_NOSIGNAL) == sizeof (err) ? 0 : -1;
}
/**
......@@ -99,7 +99,7 @@ static int send_fd (int p, int fd)
memcpy (CMSG_DATA (cmsg), &fd, sizeof (fd));
hdr.msg_controllen = cmsg->cmsg_len;
return sendmsg (p, &hdr, 0) == sizeof (val) ? 0 : -1;
return sendmsg(p, &hdr, MSG_NOSIGNAL) == sizeof (val) ? 0 : -1;
}
......
......@@ -78,6 +78,10 @@ struct msghdr
# undef IPV6_JOIN_GROUP
#endif
#ifndef MSG_NOSIGNAL
# define MSG_NOSIGNAL 0
#endif
VLC_API int vlc_socket (int, int, int, bool nonblock) VLC_USED;
struct sockaddr;
......
......@@ -294,7 +294,8 @@ static int vlclua_net_send( lua_State *L )
const char *psz_buffer = luaL_checklstring( L, 2, &i_len );
i_len = luaL_optint( L, 3, i_len );
lua_pushinteger( L, (fd != -1) ? send( fd, psz_buffer, i_len, 0 ) : -1 );
lua_pushinteger( L,
(fd != -1) ? send( fd, psz_buffer, i_len, MSG_NOSIGNAL ) : -1 );
return 1;
}
......
......@@ -1278,7 +1278,7 @@ ssize_t httpd_NetSend (httpd_client_t *cl, const uint8_t *p, size_t i_len)
p_tls = cl->p_tls;
do
val = p_tls ? tls_Send(p_tls, p, i_len)
: send (cl->fd, p, i_len, 0);
: send (cl->fd, p, i_len, MSG_NOSIGNAL);
while (val == -1 && errno == EINTR);
return val;
}
......
......@@ -166,7 +166,7 @@ int rootwrap_bind (int family, int socktype, int protocol,
memcpy (&ss, addr, (alen > sizeof (ss)) ? sizeof (ss) : alen);
pthread_mutex_lock (&mutex);
if (send (sock, &ss, sizeof (ss), 0) != sizeof (ss))
if (send (sock, &ss, sizeof (ss), MSG_NOSIGNAL) != sizeof (ss))
{
pthread_mutex_unlock (&mutex);
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment