OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestProcessSignalHandler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <csignal>
20 #include <cstdlib>
21 #include <iostream>
22 
23 #include "Logger/Logger.h"
24 
27  std::signal(SIGTERM, shutdownSubsystemsAndExit);
28  std::signal(SIGSEGV, shutdownSubsystemsAndExit);
29  std::signal(SIGABRT, shutdownSubsystemsAndExit);
31  }
32 }
33 
35  std::function<void()> shutdown_callback) {
36  shutdown_callbacks_.emplace_back(shutdown_callback);
37 }
38 
40  std::cerr << __func__ << ": Interrupt signal (" << signal_number << ") received."
41  << std::endl;
42 
43  // Perform additional shutdowns
44  for (auto& callback : shutdown_callbacks_) {
45  callback();
46  }
47 
48  // Shutdown logging force a flush
50 
51  // Terminate program
52  // TODO: Why convert SIGTERM to EXIT_SUCCESS?
53  int const exit_code = signal_number == SIGTERM ? EXIT_SUCCESS : signal_number;
54 #ifdef __APPLE__
55  std::exit(exit_code);
56 #else
57  std::quick_exit(exit_code);
58 #endif
59 }
60 
62 std::vector<std::function<void()>> TestProcessSignalHandler::shutdown_callbacks_{};
static void shutdownSubsystemsAndExit(int signal_number)
static void addShutdownCallback(std::function< void()> shutdown_callback)
void shutdown()
Definition: Logger.cpp:401
static std::vector< std::function< void()> > shutdown_callbacks_