5#include <winpr/atexit.h>
7#include <winpr/debug.h>
8#include <winpr/assert.h>
10#include <freerdp/log.h>
11#include <freerdp/utils/signal.h>
13#include "platform_signal.h"
15#define TAG FREERDP_TAG("utils.signal.posix")
21 EnterCriticalSection(&signal_lock);
26 LeaveCriticalSection(&signal_lock);
29const char* strsignal(
int signum)
43 CASE_STR(SIGABRT_COMPAT);
48static void fatal_handler(
int signum)
50 static BOOL recursive = FALSE;
56 WLog_ERR(TAG,
"Caught signal '%s' [%d]", strsignal(signum), signum);
58 winpr_log_backtrace(TAG, WLOG_ERROR, 20);
64static const int term_signals[] = { SIGINT, SIGTERM };
66static const int fatal_signals[] = { SIGABRT, SIGFPE, SIGILL, SIGSEGV };
68static BOOL register_handlers(
const int* signals,
size_t count,
void (*handler)(
int))
70 WINPR_ASSERT(signals || (count == 0));
71 WINPR_ASSERT(handler);
73 for (
size_t x = 0; x < count; x++)
75 (void)signal(signals[x], handler);
81static void unregister_handlers(
const int* signals,
size_t count)
83 WINPR_ASSERT(signals || (count == 0));
85 for (
size_t x = 0; x < count; x++)
87 (void)signal(signals[x], SIG_IGN);
91static void unregister_all_handlers(
void)
93 unregister_handlers(fatal_signals, ARRAYSIZE(fatal_signals));
94 unregister_handlers(term_signals, ARRAYSIZE(term_signals));
95 DeleteCriticalSection(&signal_lock);
98int freerdp_handle_signals(
void)
101 InitializeCriticalSection(&signal_lock);
105 WLog_DBG(TAG,
"Registering signal hook...");
107 (void)winpr_atexit(unregister_all_handlers);
108 if (!register_handlers(fatal_signals, ARRAYSIZE(fatal_signals), fatal_handler))
110 if (!register_handlers(term_signals, ARRAYSIZE(term_signals), fsig_term_handler))
113 fsig_handlers_registered =
true;