Skip to content

Commit 85e3962

Browse files
force termination (SIGINT,SIGTERM) after 1s
1 parent c0dd413 commit 85e3962

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static volatile bool terminate = false;
1717
*/
1818
static void sig_term_handler(int) {
1919
terminate = true;
20-
alarm(1);
20+
alarm(1); // force termination after 1 second
2121
}
2222

2323
/*! \brief main function
@@ -41,6 +41,11 @@ int main(int argc, char **argv) {
4141
exit(EX_OSERR);
4242
}
4343

44+
if (signal(SIGALRM, [](int) { exit(EX_OK); })) {
45+
perror("Failed to establish signal handler");
46+
exit(EX_OSERR);
47+
}
48+
4449
// all command line arguments
4550
options.add_options()("d,device", "mandatory: serial device", cxxopts::value<std::string>());
4651
options.add_options()("i,id", "mandatory: modbus RTU slave id", cxxopts::value<int>());

0 commit comments

Comments
 (0)