[PATCH] D45636: Make InterruptHandler non-blocking for Fuchsia

Aaron Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 13 14:24:54 PDT 2018


aarongreen created this revision.
aarongreen added reviewers: phosek, kcc.
Herald added subscribers: Sanitizers, llvm-commits.

The initial naive approach to simulate SIGINT on Fuchsia was to getchar and look for ETX.  This caused the InterruptHandler thread to lock stdin, preventing musl's exit() from being able to close the stdio descriptors and complete.  This change uses select() instead.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D45636

Files:
  lib/fuzzer/FuzzerUtilFuchsia.cpp


Index: lib/fuzzer/FuzzerUtilFuchsia.cpp
===================================================================
--- lib/fuzzer/FuzzerUtilFuchsia.cpp
+++ lib/fuzzer/FuzzerUtilFuchsia.cpp
@@ -45,8 +45,16 @@
 }
 
 void InterruptHandler() {
+  struct timeval timeout;
+  timeout.tv_sec= 1;
+  timeout.tv_usec= 0;
+  fd_set readfds;
   // Ctrl-C sends ETX in Zircon.
-  while (getchar() != 0x03);
+  do {
+    FD_ZERO(&readfds);
+    FD_SET(STDIN_FILENO, &readfds);
+    select(STDIN_FILENO + 1, &readfds, nullptr, nullptr, &timeout);
+  } while(!FD_ISSET(STDIN_FILENO, &readfds) || getchar() != 0x03);
   Fuzzer::StaticInterruptCallback();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45636.142467.patch
Type: text/x-patch
Size: 637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180413/337d943b/attachment.bin>


More information about the llvm-commits mailing list