Skip to content

Commit

Permalink
[arch/linux] use sigaction instead of signal
Browse files Browse the repository at this point in the history
also print message if sys_time timer couldn't be set up
  • Loading branch information
flixr committed Feb 23, 2015
1 parent b77c6a3 commit ed2eea2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions sw/airborne/arch/linux/mcu_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
#include "mcu_arch.h"

#if USE_LINUX_SIGNAL
#include "message_pragmas.h"
PRINT_CONFIG_MSG("Catching SIGINT. Press CTRL-C twice to stop program.")

/**
/*
* Handle linux signals by hand if the program is not launch
* by a shell already doing it
*/
Expand Down Expand Up @@ -61,7 +63,11 @@ static void sig_handler(int signo)

void mcu_arch_init(void)
{
if (signal(SIGINT, sig_handler) == SIG_ERR) {
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = &sig_handler;
if (sigaction(SIGINT, &sa, NULL) == -1) {
printf("Can't catch SIGINT\n");
}
}
Expand Down
6 changes: 5 additions & 1 deletion sw/airborne/arch/linux/mcu_periph/sys_time_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <sys/time.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>

#ifdef SYS_TIME_LED
#include "led.h"
Expand All @@ -45,7 +46,10 @@ void sys_time_arch_init(void)

memset(&sa, 0, sizeof(sa));
sa.sa_handler = &sys_tick_handler;
sigaction(SIGALRM, &sa, NULL);
if (sigaction(SIGALRM, &sa, NULL) == -1) {
printf("Couldn't set up sys_time timer!\n");
return;
}

// timer expires after sys_time.resolution sec
timer.it_value.tv_sec = 0;
Expand Down

0 comments on commit ed2eea2

Please sign in to comment.