3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-22 00:26:38 +00:00

Fix SIGINT handler to use sigaction with SA_ONSTACK flag

Related to #7305

Update SIGINT signal handler to use `sigaction` with `SA_ONSTACK` flag.

* Replace `signal` function with `sigaction` function in `src/util/scoped_ctrl_c.cpp` to register the SIGINT handler.
* Set the `SA_ONSTACK` flag for the SIGINT signal handler in `src/util/scoped_ctrl_c.cpp`.
* Update `on_ctrl_c` function to use `sigaction` in `src/util/scoped_ctrl_c.cpp`.
* Modify `scoped_ctrl_c` struct in `src/util/scoped_ctrl_c.h` to include `struct sigaction m_old_action` instead of `void (STD_CALL *m_old_handler)(int)`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Z3Prover/z3/issues/7305?shareId=XXXX-XXXX-XXXX-XXXX).
This commit is contained in:
Nikolaj Bjorner 2024-07-26 23:22:53 -07:00
parent 1e6b13741c
commit 62b530e945
2 changed files with 9 additions and 8 deletions

View file

@ -26,11 +26,10 @@ static void on_ctrl_c(int) {
g_obj->m_cancel_eh(CTRL_C_EH_CALLER);
if (g_obj->m_once) {
g_obj->m_first = false;
signal(SIGINT, on_ctrl_c); // re-install the handler
}
}
else {
signal(SIGINT, g_obj->m_old_handler);
sigaction(SIGINT, &g_obj->m_old_action, nullptr);
raise(SIGINT);
}
}
@ -43,15 +42,17 @@ scoped_ctrl_c::scoped_ctrl_c(event_handler & eh, bool once, bool enabled):
m_old_scoped_ctrl_c(g_obj) {
if (m_enabled) {
g_obj = this;
m_old_handler = signal(SIGINT, on_ctrl_c);
struct sigaction sa;
sa.sa_handler = on_ctrl_c;
sa.sa_flags = SA_ONSTACK;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, &m_old_action);
}
}
scoped_ctrl_c::~scoped_ctrl_c() {
if (m_enabled) {
g_obj = m_old_scoped_ctrl_c;
if (m_old_handler != SIG_ERR) {
signal(SIGINT, m_old_handler);
}
sigaction(SIGINT, &m_old_action, nullptr);
}
}

View file

@ -20,13 +20,14 @@ Revision History:
#include "util/event_handler.h"
#include "util/util.h"
#include <signal.h>
struct scoped_ctrl_c {
event_handler & m_cancel_eh;
bool m_first;
bool m_once;
bool m_enabled;
void (STD_CALL *m_old_handler)(int);
struct sigaction m_old_action;
scoped_ctrl_c * m_old_scoped_ctrl_c;
public:
// If once == true, then the cancel_eh is invoked only at the first Ctrl-C.
@ -36,4 +37,3 @@ public:
~scoped_ctrl_c();
void reset() { m_first = true; }
};