When writing to a tty would block, wall(1) attempts to fork a child process
which will block for up to 5 minutes trying to deliver the message. This
doesn't actually work because an incorrect usage of fnctl leaves non-blocking
mode on.

fcntl(fd, O_NONBLOCK, &off)? Not even close! fcntl is not setsockopt...

FreeBSD fixed this bug 7 years ago. NetBSD picked up the fix 4 years ago. If
we go next we can still beat OpenBSD. (But for them it actually worked before
the fix, at least part of the time, because their O_NONBLOCK==F_SETFL).

I've also enjoyed reading the parts of ttymsg.c that have been rewritten more
clumsily than the BSD original because "Linux doesn't have snprintf".

The FreeBSD commit diff:
http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/wall/ttymsg.c.diff?r1=1.4;r2=1.5
applies, after removing the hunk containing the rcsid, to
util-linux-ng/login-utils/ttymsg.c; here's a copy for your convenience:

--- src/usr.bin/wall/ttymsg.c   1999/08/28 01:07:31     1.4
+++ src/usr.bin/wall/ttymsg.c   2000/06/09 19:38:28     1.5
@@ -120,7 +120,7 @@ ttymsg(iov, iovcnt, line, tmout)
                        continue;
                }
                if (errno == EWOULDBLOCK) {
-                       int cpid, off = 0;
+                       int cpid;
 
                        if (forked) {
                                (void) close(fd);
@@ -143,7 +143,7 @@ ttymsg(iov, iovcnt, line, tmout)
                        (void) signal(SIGTERM, SIG_DFL); /* XXX */
                        (void) sigsetmask(0);
                        (void) alarm((u_int)tmout);
-                       (void) fcntl(fd, O_NONBLOCK, &off);
+                       (void) fcntl(fd, F_SETFL, 0);   /* clear O_NONBLOCK */
                        continue;
                }
                /*
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to