Subject: Runaway yes(1)
To: None <>
From: Jed Davis <>
List: tech-userlevel
Date: 11/17/2005 22:05:14

I feel that yes(1) should stop trying to write its message to stdout
if it encounters an error, rather than spinning forever accomplishing

This can occur if it's run in a pipeline with SIGPIPE ignored, perhaps
because some ancestor process set it that way to do socket I/O and
failed to reenable it before exec'ing.  (Yes, such programs should be
fixed, but that's not the point.)  A similar effect could be
encountered with a revoked tty.

No, this isn't terribly important, but I've attached a (tested, of
course) patch, which also fixes some style issues; so, all I need is
for someone with sufficient authority to say that I should or
shouldn't commit it.

Content-Type: text/x-patch
Content-Disposition: attachment; filename=yes.diff
Content-Description: Make yes(1) exit on write failure.

Index: yes.c
RCS file: /cvsroot/src/usr.bin/yes/yes.c,v
retrieving revision 1.6
diff -u -r1.6 yes.c
--- yes.c	7 Aug 2003 11:17:56 -0000	1.6
+++ yes.c	18 Nov 2005 02:47:04 -0000
@@ -43,17 +43,17 @@
 #endif /* not lint */
 #include <stdio.h>
-int main __P((int, char **));
+#include <stdlib.h>
-main(argc, argv)
-	int argc;
-	char **argv;
+main(int argc, char *argv[])
 	if (argc > 1)
-		for(;;)
-			(void)puts(argv[1]);
-	else for (;;)
-		(void)puts("y");
+		while (puts(argv[1]) >= 0)
+			continue;
+	else 
+		while (puts("y") >= 0)
+			continue;
+	return EXIT_FAILURE;


(let ((C call-with-current-continuation)) (apply (lambda (x y) (x y)) (map
((lambda (r) ((C C) (lambda (s) (r (lambda l (apply (s s) l))))))  (lambda
(f) (lambda (l) (if (null? l) C (lambda (k) (display (car l)) ((f (cdr l))
(C k)))))))    '((#\J #\d #\D #\v #\s) (#\e #\space #\a #\i #\newline)))))