OmniSciDB  2e3a973ef4
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 
21 #include "Logger/Logger.h"
22 
25  std::signal(SIGTERM, shutdownSubsystemsAndExit);
26  std::signal(SIGSEGV, shutdownSubsystemsAndExit);
27  std::signal(SIGABRT, shutdownSubsystemsAndExit);
29  }
30 }
31 
33  std::function<void()> shutdown_callback) {
34  shutdown_callbacks_.emplace_back(shutdown_callback);
35 }
36 
38  LOG(ERROR) << "Interrupt signal (" << signal_number << ") received.";
39 
40  // Perform additional shutdowns
41  for (auto& callback : shutdown_callbacks_) {
42  callback();
43  }
44 
45  // Shutdown logging force a flush
47 
48  // Terminate program
49  if (signal_number == SIGTERM) {
50  std::exit(EXIT_SUCCESS);
51  } else {
52  std::exit(signal_number);
53  }
54 }
55 
57 std::vector<std::function<void()>> TestProcessSignalHandler::shutdown_callbacks_{};
static void shutdownSubsystemsAndExit(int signal_number)
#define LOG(tag)
Definition: Logger.h:188
static void addShutdownCallback(std::function< void()> shutdown_callback)
void shutdown()
Definition: Logger.cpp:314
static std::vector< std::function< void()> > shutdown_callbacks_