Very few places actually check for errors from emit, and I actually see
the same endless loop from "sed (GNU sed) 4.4" on current Debian, so I'm
not sure this isn't Broken As Designed, but an endless loop spewing
"short write" (or saying nothing, in the case of GNU sed) really doesn't
feel like useful behavior in face of EPIPE, which really isn't going to
fix itself. Certainly not being able to run the sed tests to completion
is pretty annoying --- which is why, unless we remove this test as
invalid, we should probably also add a SKIP_HOST=1 to the "b loop" test.

Note that even with this fix you'll see the error twice:

  sed: short write: Broken pipe
  sed: short write: Broken pipe

Once from the first = command to fail, and then another from the !FLAG(n)
flush of the pattern space.
---
 tests/sed.test   | 2 --
 toys/posix/sed.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/tests/sed.test b/tests/sed.test
index 34dfa161..6b27fff8 100755
--- a/tests/sed.test
+++ b/tests/sed.test
@@ -72,8 +72,6 @@ testing "aci" \
  "sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \
  "one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \
  "one\ntwo\nthree\nfour\n"
-# TODO: next test is broken on new-ish debian/bash with never-ending
-# output of `sed: short write: Broken pipe`.
 testing "b loop" "sed ':woo;=;b woo' | head -n 5" '1\n1\n1\n1\n1\n' "" "X"
 testing "b skip" "sed -n '2b zap;d;:zap;p'" "two\n" "" "one\ntwo\nthree"
 testing "b end" "sed -n '2b;p'" "one\nthree" "" "one\ntwo\nthree"
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index 0be2165e..5e516249 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -600,7 +600,7 @@ writenow:
       }
     } else if (c=='=') {
       sprintf(toybuf, "%ld", TT.count);
-      emit(toybuf, strlen(toybuf), 1);
+      if (emit(toybuf, strlen(toybuf), 1)) break;
     }

     command = command->next;
-- 
2.20.1.791.gb4d0f1c61a-goog
From 5bdb5d1e8a58e9327c2ceb5401d95bb3e7e00173 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Tue, 12 Feb 2019 21:38:34 -0800
Subject: [PATCH] sed: fix endless loop in "b loop" test.

Very few places actually check for errors from emit, and I actually see
the same endless loop from "sed (GNU sed) 4.4" on current Debian, so I'm
not sure this isn't Broken As Designed, but an endless loop spewing
"short write" (or saying nothing, in the case of GNU sed) really doesn't
feel like useful behavior in face of EPIPE, which really isn't going to
fix itself. Certainly not being able to run the sed tests to completion
is pretty annoying --- which is why, unless we remove this test as
invalid, we should probably also add a SKIP_HOST=1 to the "b loop" test.

Note that even with this fix you'll see the error twice:

  sed: short write: Broken pipe
  sed: short write: Broken pipe

Once from the first = command to fail, and then another from the !FLAG(n)
flush of the pattern space.
---
 tests/sed.test   | 2 --
 toys/posix/sed.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/tests/sed.test b/tests/sed.test
index 34dfa161..6b27fff8 100755
--- a/tests/sed.test
+++ b/tests/sed.test
@@ -72,8 +72,6 @@ testing "aci" \
 	"sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \
 	"one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \
 	"one\ntwo\nthree\nfour\n"
-# TODO: next test is broken on new-ish debian/bash with never-ending
-# output of `sed: short write: Broken pipe`.
 testing "b loop" "sed ':woo;=;b woo' | head -n 5" '1\n1\n1\n1\n1\n' "" "X"
 testing "b skip" "sed -n '2b zap;d;:zap;p'" "two\n" "" "one\ntwo\nthree"
 testing "b end" "sed -n '2b;p'" "one\nthree" "" "one\ntwo\nthree"
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index 0be2165e..5e516249 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -600,7 +600,7 @@ writenow:
       }
     } else if (c=='=') {
       sprintf(toybuf, "%ld", TT.count);
-      emit(toybuf, strlen(toybuf), 1);
+      if (emit(toybuf, strlen(toybuf), 1)) break;
     }
 
     command = command->next;
-- 
2.20.1.791.gb4d0f1c61a-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to