Skip to content

Commit 9accea0

Browse files
force termination (SIGINT, SIGTERM) after 1s
1 parent 7d14a0a commit 9accea0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static int socket = -1;
2121
static void sig_term_handler(int) {
2222
if (socket != -1) close(socket);
2323
terminate = true;
24+
alarm(1); // force termination after 1s
2425
}
2526

2627
/*! \brief main function
@@ -44,6 +45,11 @@ int main(int argc, char **argv) {
4445
exit(EX_OSERR);
4546
}
4647

48+
if (signal(SIGALRM, [](int) { exit(EX_OK); })) {
49+
perror("Failed to establish signal handler");
50+
exit(EX_OSERR);
51+
}
52+
4753
// all command line arguments
4854
// clang-format off
4955
options.add_options()("i,ip",

0 commit comments

Comments
 (0)