Rename a pipe method, add docs
[carla.git] / source / utils / CarlaProcessUtils.cpp
blob49f6b877d279b35ee6762d1a97225944b9f4e9e3
1 /*
2 * Carla process utils
3 * Copyright (C) 2019-2022 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "CarlaProcessUtils.hpp"
20 // --------------------------------------------------------------------------------------------------------------------
21 // process utility classes
23 #if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
24 ScopedAbortCatcher::ScopedAbortCatcher()
26 s_triggered = false;
27 s_oldsig = ::setjmp(s_env) == 0
28 ? std::signal(SIGABRT, sig_handler)
29 : nullptr;
32 ScopedAbortCatcher::~ScopedAbortCatcher()
34 if (s_oldsig != nullptr && ! s_triggered)
35 std::signal(SIGABRT, s_oldsig);
38 bool ScopedAbortCatcher::s_triggered = false;
40 jmp_buf ScopedAbortCatcher::s_env;
41 sig_t ScopedAbortCatcher::s_oldsig;
43 void ScopedAbortCatcher::sig_handler(const int signum)
45 CARLA_SAFE_ASSERT_INT2_RETURN(signum == SIGABRT, signum, SIGABRT,);
47 s_triggered = true;
48 std::signal(signum, s_oldsig);
49 std::longjmp(s_env, 1);
51 #endif
53 // --------------------------------------------------------------------------------------------------------------------
55 CarlaSignalRestorer::CarlaSignalRestorer()
57 #if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
58 carla_zeroStructs(sigs, 16);
60 for (int i=0; i < 16; ++i)
61 ::sigaction(i+1, nullptr, &sigs[i]);
62 #endif
65 CarlaSignalRestorer::~CarlaSignalRestorer()
67 #if !(defined(CARLA_OS_WASM) || defined(CARLA_OS_WIN))
68 for (int i=0; i < 16; ++i)
69 ::sigaction(i+1, &sigs[i], nullptr);
70 #endif
73 // --------------------------------------------------------------------------------------------------------------------