Re: r247839: broken pipe - for top, sudo and ports

From: Jilles Tjoelker <jilles_at_stack.nl>
Date: Wed, 6 Mar 2013 22:24:08 +0100
On Tue, Mar 05, 2013 at 08:59:09PM +0100, Hartmann, O. wrote:
> A "truss top" reveals this, is this of help?

> [...]
> stat("/etc/nsswitch.conf",{ mode=-rw-r--r--
> ,inode=162310,size=1007,blksize=32768 }) = 0 (0x0)
> stat("/etc/nsswitch.conf",{ mode=-rw-r--r--
> ,inode=162310,size=1007,blksize=32768 }) = 0 (0x0)
> stat("/etc/nsswitch.conf",{ mode=-rw-r--r--
> ,inode=162310,size=1007,blksize=32768 }) = 0 (0x0)
> stat("/etc/nsswitch.conf",{ mode=-rw-r--r--
> ,inode=162310,size=1007,blksize=32768 }) = 0 (0x0)
> stat("/etc/nsswitch.conf",{ mode=-rw-r--r--
> ,inode=162310,size=1007,blksize=32768 }) = 0 (0x0)
> socket(PF_LOCAL,SOCK_STREAM,0)                   = 4 (0x4)
> connect(4,{ AF_UNIX "/var/run/nscd" },15)        = 0 (0x0)
> fcntl(4,F_SETFL,O_NONBLOCK)                      = 0 (0x0)
> kqueue(0x80183b000,0x80122fc58,0x10,0x80062b308,0x80183b010,0x2) = 5 (0x5)
> kevent(5,{0x4,EVFILT_WRITE,EV_ADD,0,0x0,0x0},1,0x0,0,0x0) = 0 (0x0)
> kqueue(0x5,0x7fffffffd2e0,0x1,0x0,0x0,0x0)       = 6 (0x6)
> kevent(6,{0x4,EVFILT_READ,EV_ADD,0,0x0,0x0},1,0x0,0,0x0) = 0 (0x0)
> kevent(5,{0x4,EVFILT_WRITE,EV_ADD,1,0x4,0x0},1,0x0,0,0x0) = 0 (0x0)
> kevent(5,0x0,0,{0x4,EVFILT_WRITE,EV_EOF,0,0x2000,0x0},1,0x0) = 1 (0x1)
> sendmsg(0x4,0x7fffffffd290,0x0,0x1,0x1,0x0)      ERR#32 'Broken pipe'
> SIGNAL 13 (SIGPIPE)
> process exit, rval = 0

Apparently there is a bug that causes nscd to close the connection
immediately but even then it is wrong that this terminates the calling
program with SIGPIPE.

The below patch prevents the SIGPIPE but cannot revive the connection to
nscd. This may cause numeric UIDs in top or increase the load on the
directory server. It is compile tested only.

Index: lib/libc/net/nscachedcli.c
===================================================================
--- lib/libc/net/nscachedcli.c	(revision 247710)
+++ lib/libc/net/nscachedcli.c	(working copy)
_at__at_ -75,9 +75,9 _at__at_
 		nevents = _kevent(connection->write_queue, NULL, 0, &eventlist,
 		    1, &timeout);
 		if ((nevents == 1) && (eventlist.filter == EVFILT_WRITE)) {
-			s_result = _write(connection->sockfd, data + result,
+			s_result = send(connection->sockfd, data + result,
 			    eventlist.data < data_size - result ?
-			    eventlist.data : data_size - result);
+			    eventlist.data : data_size - result, MSG_NOSIGNAL);
 			if (s_result == -1)
 				return (-1);
 			else
_at__at_ -175,8 +175,8 _at__at_
 	nevents = _kevent(connection->write_queue, NULL, 0, &eventlist, 1,
 	    NULL);
 	if (nevents == 1 && eventlist.filter == EVFILT_WRITE) {
-		result = (_sendmsg(connection->sockfd, &cred_hdr, 0) == -1) ?
-		    -1 : 0;
+		result = (_sendmsg(connection->sockfd, &cred_hdr,
+		    MSG_NOSIGNAL) == -1) ?  -1 : 0;
 		EV_SET(&eventlist, connection->sockfd, EVFILT_WRITE, EV_ADD,
 		    0, 0, NULL);
 		_kevent(connection->write_queue, &eventlist, 1, NULL, 0, NULL);

-- 
Jilles Tjoelker
Received on Wed Mar 06 2013 - 20:24:10 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:35 UTC