Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Feb 2003 04:40:34 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Alexander Leidinger <Alexander@Leidinger.net>
Cc:        current@FreeBSD.ORG, <phk@FreeBSD.ORG>
Subject:   Re: Do we still have a FIFO / named pipe problem?
Message-ID:  <20030210033714.O1731-100000@gamplex.bde.org>
In-Reply-To: <20030209170616.2e4e3635.Alexander@Leidinger.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 9 Feb 2003, Alexander Leidinger wrote:

> ports/mail/gensig has a problem. It is supposed to create a named pipe
> (~/.signature) and wait for an application to read from the pipe. It
> allows to have a random signature on every mail. On 4.x and on 5-current
> from last year it works as expected. But since the end of the last year
> or the begin of this year it doesn't anymore. gensig daemonizes itself
> fills the named pipe and then terminates. The content of the named pipe
> stays the same for every mail (no wonder, gensig is gone).

Blocking opens of named pipes for writing were broken in:

% RCS file: /home/ncvs/src/sys/fs/fifofs/fifo_vnops.c,v
% Working file: fifo_vnops.c
% head: 1.81
% ...
% ----------------------------
% revision 1.79
% date: 2002/12/29 10:32:16;  author: phk;  state: Exp;  lines: +6 -1
% There is some sort of race/deadlock which I have not identified
% here.  It manifests itself by sendmail hanging in "fifoow" during
% boot on a diskless machine with sendmail disabled.
%
% Giving the sleep a 1sec timout breaks the deadlock, but does not solve
% the underlying problem.
%
% XXX comment applied.
% ----------------------------

This change makes such opens bogusly time out after 1 second (unless
there is already a writer).

There seems to be a race in fifo_open(): opens for read don't terminate
the wait if the reader goes away before the opener looks.  It is not
clear if sendmail is affected by this race or one of its own.

Untested fix for this and rev.1.79, and for a similar race in blocking
opens of named pipes for reading:

%%%
Index: fifo_vnops.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/fifofs/fifo_vnops.c,v
retrieving revision 1.81
diff -u -2 -r1.81 fifo_vnops.c
--- fifo_vnops.c	13 Jan 2003 00:28:57 -0000	1.81
+++ fifo_vnops.c	9 Feb 2003 17:32:16 -0000
@@ -227,5 +227,5 @@
 	}
 	if ((ap->a_mode & FREAD) && (ap->a_mode & O_NONBLOCK) == 0) {
-		while (fip->fi_writers == 0) {
+		if (fip->fi_writers == 0) {
 			VOP_UNLOCK(vp, 0, td);
 			error = tsleep((caddr_t)&fip->fi_readers,
@@ -234,4 +234,9 @@
 			if (error)
 				goto bad;
+			/*
+			 * We must have got woken up because we had a writer.
+			 * That (and not still having one) is the condition
+			 * that we must wait for.
+			 */
 		}
 	}
@@ -243,16 +248,16 @@
 			}
 		} else {
-			while (fip->fi_readers == 0) {
+			if (fip->fi_readers == 0) {
 				VOP_UNLOCK(vp, 0, td);
-				/*
-				 * XXX: Some race I havn't located is solved
-				 * by timing out after a sec.  Race seen when
-				 * sendmail hangs here during boot /phk
-				 */
 				error = tsleep((caddr_t)&fip->fi_writers,
-				    PCATCH | PSOCK, "fifoow", hz);
+				    PCATCH | PSOCK, "fifoow", 0);
 				vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
 				if (error)
 					goto bad;
+				/*
+				 * We must have got woken up because we had
+				 * a reader.  That (and not still having one)
+				 * is the condition that we must wait for.
+				 */
 			}
 		}
%%%

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030210033714.O1731-100000>