Add main loop and signal handler
This commit is contained in:
parent
948c3971ee
commit
fffd1c3fff
26
main.c
26
main.c
@ -16,12 +16,38 @@
|
||||
* <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static bool exit_requested = false;
|
||||
|
||||
void handle_exit_signal(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
exit_requested = true;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
if (signal(SIGTERM, handle_exit_signal) == SIG_ERR) {
|
||||
fprintf(stderr, "Failed to register SIGTERM signal handler\n");
|
||||
return 1;
|
||||
}
|
||||
if (signal(SIGINT, handle_exit_signal) == SIG_ERR) {
|
||||
fprintf(stderr, "Failed to register SIGINT signal handler\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (!exit_requested) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
printf("After loop\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user