OmniSciDB  bf83d84833
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestProcessSignalHandler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, 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  */
17 
18 #include <csignal>
19 #include <cstdlib>
20 #include <iostream>
21 
22 #include "Logger/Logger.h"
23 
26  std::signal(SIGTERM, shutdownSubsystemsAndExit);
27  std::signal(SIGSEGV, shutdownSubsystemsAndExit);
28  std::signal(SIGABRT, shutdownSubsystemsAndExit);
30  }
31 }
32 
34  std::function<void()> shutdown_callback) {
35  shutdown_callbacks_.emplace_back(shutdown_callback);
36 }
37 
39  std::cerr << __func__ << ": Interrupt signal (" << signal_number << ") received."
40  << std::endl;
41 
42  // Perform additional shutdowns
43  for (auto& callback : shutdown_callbacks_) {
44  callback();
45  }
46 
47  // Shutdown logging force a flush
49 
50  // Terminate program
51  // TODO: Why convert SIGTERM to EXIT_SUCCESS?
52  int const exit_code = signal_number == SIGTERM ? EXIT_SUCCESS : signal_number;
53 #ifdef __APPLE__
54  std::exit(exit_code);
55 #else
56  std::quick_exit(exit_code);
57 #endif
58 }
59 
61 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:314
static std::vector< std::function< void()> > shutdown_callbacks_