From 929e74568e3bb499ef14a265f49fdb974c684f1c Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Tue, 15 May 2018 04:23:48 +0000 Subject: [PATCH] [NFC] pull a function into its own lambda As requested in D46858, pulling this function into its own lambda makes it easier to read that part of the code and reason as to what's going on because the scope it can be called from is extremely limited. We want to keep it as a function because it's called from the two subsequent lines. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332325 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Unix/Signals.inc | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index 33edc2a5d4d..d828674de49 100644 --- a/lib/Support/Unix/Signals.inc +++ b/lib/Support/Unix/Signals.inc @@ -101,23 +101,6 @@ static struct { } RegisteredSignalInfo[array_lengthof(IntSigs) + array_lengthof(KillSigs)]; -static void RegisterHandler(int Signal) { - assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) && - "Out of space for signal handlers!"); - - struct sigaction NewHandler; - - NewHandler.sa_handler = SignalHandler; - NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK; - sigemptyset(&NewHandler.sa_mask); - - // Install the new handler, save the old one in RegisteredSignalInfo. - sigaction(Signal, &NewHandler, - &RegisteredSignalInfo[NumRegisteredSignals].SA); - RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal; - ++NumRegisteredSignals; -} - #if defined(HAVE_SIGALTSTACK) // Hold onto both the old and new alternate signal stack so that it's not // reported as a leak. We don't make any attempt to remove our alt signal @@ -159,8 +142,27 @@ static void RegisterHandlers() { // be able to reliably handle signals due to stack overflow. CreateSigAltStack(); - for (auto S : IntSigs) RegisterHandler(S); - for (auto S : KillSigs) RegisterHandler(S); + auto registerHandler = [&](int Signal) { + assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) && + "Out of space for signal handlers!"); + + struct sigaction NewHandler; + + NewHandler.sa_handler = SignalHandler; + NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK; + sigemptyset(&NewHandler.sa_mask); + + // Install the new handler, save the old one in RegisteredSignalInfo. + sigaction(Signal, &NewHandler, + &RegisteredSignalInfo[NumRegisteredSignals].SA); + RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal; + ++NumRegisteredSignals; + }; + + for (auto S : IntSigs) + registerHandler(S); + for (auto S : KillSigs) + registerHandler(S); } static void UnregisterHandlers() { -- 2.11.0