Skip to content

Commit 2f1dd2e

Browse files
committed
implement NO_SIGNAL env and better signal report
1 parent e42469d commit 2f1dd2e

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/cli/console.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,26 +259,48 @@ void TerminateConsoleDontWait() {
259259
es::Print("\033[?25h"); // Enable cursor
260260
}
261261

262+
const char *SignalName(int sig) {
263+
switch (sig) {
264+
case SIGTERM:
265+
return "(SIGTERM)";
266+
case SIGABRT:
267+
return "(SIGABRT)";
268+
case SIGINT:
269+
return "(SIGINT) ";
270+
case SIGSEGV:
271+
return "(SIGSEGV)";
272+
#ifdef SIGBUS
273+
case SIGBUS:
274+
return "(SIGBUS) ";
275+
#endif
276+
default:
277+
return " ";
278+
}
279+
}
280+
262281
void InitConsole() {
263282
es::Print("\033[?25l"); // Disable cursor
264283
es::print::AddQueuer(ReceiveQueue);
265284
logger = std::thread{MakeLogger};
266285
pthread_setname_np(logger.native_handle(), "console_logger");
267286
auto terminate = [](int sig) {
268287
TerminateConsoleDontWait();
269-
printf("+------------------------------------------------+\n");
270-
printf("| APPLICATION HAVE CLOSED UNEXPECTEDLY, CODE: %.2i |\n", sig);
271-
printf("+------------------------------------------------+\n");
288+
printf("+----------------------------------------------------------+\n");
289+
printf("| APPLICATION HAVE CLOSED UNEXPECTEDLY, CODE: %.2i %s |\n", sig,
290+
SignalName(sig));
291+
printf("+----------------------------------------------------------+\n");
272292
std::exit(sig);
273293
};
274294

275-
std::signal(SIGTERM, terminate);
276-
std::signal(SIGABRT, terminate);
277-
std::signal(SIGINT, terminate);
278-
std::signal(SIGSEGV, terminate);
295+
if (!getenv("NO_SIGNAL")) {
296+
std::signal(SIGTERM, terminate);
297+
std::signal(SIGABRT, terminate);
298+
std::signal(SIGINT, terminate);
299+
std::signal(SIGSEGV, terminate);
279300
#ifdef SIGBUS
280-
std::signal(SIGBUS, terminate);
301+
std::signal(SIGBUS, terminate);
281302
#endif
303+
}
282304
}
283305

284306
void TerminateConsole() {

0 commit comments

Comments
 (0)