From d32f138d30afe2f2f823e1a252e074fbd0f3e950 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Thu, 24 Mar 2016 21:03:58 +0000 Subject: [PATCH] [libFuzzer] handle SIGTERM git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264338 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Fuzzer/FuzzerDriver.cpp | 1 + lib/Fuzzer/FuzzerFlags.def | 1 + lib/Fuzzer/FuzzerInternal.h | 1 + lib/Fuzzer/FuzzerUtil.cpp | 1 + 4 files changed, 4 insertions(+) diff --git a/lib/Fuzzer/FuzzerDriver.cpp b/lib/Fuzzer/FuzzerDriver.cpp index a31d306b668..9be1b7fff67 100644 --- a/lib/Fuzzer/FuzzerDriver.cpp +++ b/lib/Fuzzer/FuzzerDriver.cpp @@ -338,6 +338,7 @@ static int FuzzerDriver(const std::vector &Args, if (Flags.handle_ill) SetSigIllHandler(); if (Flags.handle_fpe) SetSigFpeHandler(); if (Flags.handle_int) SetSigIntHandler(); + if (Flags.handle_term) SetSigTermHandler(); if (DoPlainRun) { Options.SaveArtifacts = false; diff --git a/lib/Fuzzer/FuzzerFlags.def b/lib/Fuzzer/FuzzerFlags.def index 20ffa321d25..4504cffd7f3 100644 --- a/lib/Fuzzer/FuzzerFlags.def +++ b/lib/Fuzzer/FuzzerFlags.def @@ -75,6 +75,7 @@ FUZZER_FLAG_INT(handle_abrt, 1, "If 1, try to intercept SIGABRT.") FUZZER_FLAG_INT(handle_ill, 1, "If 1, try to intercept SIGILL.") FUZZER_FLAG_INT(handle_fpe, 1, "If 1, try to intercept SIGFPE.") FUZZER_FLAG_INT(handle_int, 1, "If 1, try to intercept SIGINT.") +FUZZER_FLAG_INT(handle_term, 1, "If 1, try to intercept SIGTERM.") FUZZER_FLAG_INT(close_fd_mask, 0, "If 1, close stdout at startup; " "if 2, close stderr; if 3, close both.") diff --git a/lib/Fuzzer/FuzzerInternal.h b/lib/Fuzzer/FuzzerInternal.h index 2ff131902b4..7200cbe9d3d 100644 --- a/lib/Fuzzer/FuzzerInternal.h +++ b/lib/Fuzzer/FuzzerInternal.h @@ -92,6 +92,7 @@ void SetSigAbrtHandler(); void SetSigIllHandler(); void SetSigFpeHandler(); void SetSigIntHandler(); +void SetSigTermHandler(); std::string Base64(const Unit &U); int ExecuteCommand(const std::string &Command); size_t GetPeakRSSMb(); diff --git a/lib/Fuzzer/FuzzerUtil.cpp b/lib/Fuzzer/FuzzerUtil.cpp index 84c4983f991..d5335616a83 100644 --- a/lib/Fuzzer/FuzzerUtil.cpp +++ b/lib/Fuzzer/FuzzerUtil.cpp @@ -106,6 +106,7 @@ void SetSigAbrtHandler() { SetSigaction(SIGABRT, CrashHandler); } void SetSigIllHandler() { SetSigaction(SIGILL, CrashHandler); } void SetSigFpeHandler() { SetSigaction(SIGFPE, CrashHandler); } void SetSigIntHandler() { SetSigaction(SIGINT, InterruptHandler); } +void SetSigTermHandler() { SetSigaction(SIGTERM, InterruptHandler); } int NumberOfCpuCores() { FILE *F = popen("nproc", "r");