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

Damian Malarczyk via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 06:52:36 PDT 2022


dmcyk updated this revision to Diff 427304.
dmcyk added a comment.

- Check full error message


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/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,17 @@
+# 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.
+
+# UNSUPPORTED: system-windows
+
+# RUN: not %python %s llvm-nm llvm-nm 2>&1 | FileCheck %s
+# CHECK: error: write on a pipe with no reader
+
+import subprocess
+import sys
+
+with subprocess.Popen([sys.argv[1], sys.argv[2]], stdout=subprocess.PIPE) as process:
+  # Read single byte and immediately close pipe to trigger SIGPIPE.
+  process.stdout.read(1)
+  process.stdout.close()
+sys.exit(process.returncode)
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.427304.patch
Type: text/x-patch
Size: 1351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220505/8a852b85/attachment.bin>


More information about the llvm-commits mailing list