Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit 162f2a8

Browse files
committed
Ignore JVM signal handler for SIGINT.
Signed-off-by: ienkovich <[email protected]>
1 parent 0b38686 commit 162f2a8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

omniscidb/Calcite/CalciteJNI.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include <jni.h>
2525
#include <filesystem>
2626

27+
#ifndef _WIN32
28+
#include <signal.h>
29+
#endif
30+
2731
using namespace std::string_literals;
2832

2933
namespace {
@@ -677,17 +681,27 @@ void CalciteMgr::setRuntimeExtensionFunctions(const std::vector<ExtensionFunctio
677681
CalciteMgr::CalciteMgr(const std::string& udf_filename,
678682
size_t calcite_max_mem_mb,
679683
const std::string& log_dir) {
680-
// todo: should register an exit handler for ctrl + c
681684
worker_ =
682685
std::thread(&CalciteMgr::worker, this, udf_filename, calcite_max_mem_mb, log_dir);
683686
}
684687

685688
void CalciteMgr::worker(const std::string& udf_filename,
686689
size_t calcite_max_mem_mb,
687690
const std::string& log_dir) {
691+
// Don't allow JVM to override SIGINT handler to have proper Ctrl + C behavior.
692+
// Store the current handler and restore it after JVM initialization.
693+
#ifndef _WIN32
694+
struct sigaction old_sigint_action;
695+
sigaction(SIGINT, nullptr, &old_sigint_action);
696+
#endif
697+
688698
auto calcite_jni =
689699
std::make_unique<CalciteJNI>(udf_filename, calcite_max_mem_mb, log_dir);
690700

701+
#ifndef _WIN32
702+
sigaction(SIGINT, &old_sigint_action, nullptr);
703+
#endif
704+
691705
std::unique_lock<std::mutex> lock(queue_mutex_);
692706
while (true) {
693707
worker_cv_.wait(lock, [this] { return !queue_.empty() || should_exit_; });

0 commit comments

Comments
 (0)