[PATCH] D124607: Add an error message to the default SIGPIPE handler

Damian Malarczyk via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 04:05:18 PDT 2022


dmcyk updated this revision to Diff 426960.
dmcyk added a comment.
Herald added subscribers: rupprecht, MaskRay.

- Add llvm-nm test case for SIGPIPE handler


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124607/new/

https://reviews.llvm.org/D124607

Files:
  llvm/lib/Support/Unix/Signals.inc
  llvm/test/tools/llvm-nm/Inputs/unix03-sigpipe-exit.sh
  llvm/test/tools/llvm-nm/unix03-sigpipe-exit.test


Index: llvm/test/tools/llvm-nm/unix03-sigpipe-exit.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-nm/unix03-sigpipe-exit.test
@@ -0,0 +1,9 @@
+# Test that when nm tries to write to a closed stdout it will finish with
+# a non-zero exit code and an error message on stderr.
+# This is required for UNIX03 conformance.
+
+RUN: sh %S/Inputs/unix03-sigpipe-exit.sh llvm-nm > %t.stdout 2> %t.stderr
+RUN: FileCheck --check-prefix=STDOUT --input-file=%t.stdout %s
+RUN: FileCheck --check-prefix=STDERR --input-file=%t.stderr %s
+STDOUT-NOT: exitstatus 0
+STDERR: write on a pipe with no reader
Index: llvm/test/tools/llvm-nm/Inputs/unix03-sigpipe-exit.sh
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-nm/Inputs/unix03-sigpipe-exit.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+NM_CMD=${1:-nm}
+exec 3>&1
+(
+	# sleep first, so that true can finish running before nm does.
+	# Because true finishes earlier, stdout for nm will be closed and nm will
+	# receive SIGPIPE signal when writing to or flushing stdout.
+	sleep 2
+	$NM_CMD $(which $NM_CMD)
+	echo exitstatus $? >&3
+) | true
Index: llvm/lib/Support/Unix/Signals.inc
===================================================================
--- llvm/lib/Support/Unix/Signals.inc
+++ llvm/lib/Support/Unix/Signals.inc
@@ -432,6 +432,10 @@
 }
 
 void llvm::sys::DefaultOneShotPipeSignalHandler() {
+  // UNIX03 conformance requires a non-zero exit code and an error message
+  // to stderr when writing to a closed stdout fails.
+  errs() << "error: write on a pipe with no reader\n";
+
   // Send a special return code that drivers can check for, from sysexits.h.
   exit(EX_IOERR);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124607.426960.patch
Type: text/x-patch
Size: 1744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220504/aca81136/attachment.bin>


More information about the llvm-commits mailing list