[vlc-commits] Use MSG_NOSIGNAL in send()/sendto()/sendmsg()

Rémi Denis-Courmont git at videolan.org
Sun May 17 10:02:31 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun May 17 10:58:38 2015 +0300| [8d03dee93cc5a9598e0485344a3ec237d4ae8846] | committer: 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8d03dee93cc5a9598e0485344a3ec237d4ae8846
---

 bin/rootwrap.c         |    4 ++--
 include/vlc_network.h  |    4 ++++
 modules/lua/libs/net.c |    3 ++-
 src/network/httpd.c    |    2 +-
 src/network/rootbind.c |    2 +-
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/bin/rootwrap.c b/bin/rootwrap.c
index 37d8839..6e49ee8 100644
--- a/bin/rootwrap.c
+++ b/bin/rootwrap.c
@@ -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;
 }
 
 
diff --git a/include/vlc_network.h b/include/vlc_network.h
index b6bd56c..c66e2d1 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -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;
diff --git a/modules/lua/libs/net.c b/modules/lua/libs/net.c
index 4d6e87b..f34c010 100644
--- a/modules/lua/libs/net.c
+++ b/modules/lua/libs/net.c
@@ -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;
 }
 
diff --git a/src/network/httpd.c b/src/network/httpd.c
index 3d31da5..2af6b4e 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -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;
 }
diff --git a/src/network/rootbind.c b/src/network/rootbind.c
index 89d9328..9c24c97 100644
--- a/src/network/rootbind.c
+++ b/src/network/rootbind.c
@@ -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;



More information about the vlc-commits mailing list