replace 1 with EXIT_FAILURE in all err calls

This commit is contained in:
Ludwig Ortmann 2013-11-20 15:25:11 +01:00
parent 3ca8181c73
commit 3a04671912
6 changed files with 41 additions and 39 deletions

View File

@ -30,6 +30,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <signal.h> #include <signal.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
#include <err.h> #include <err.h>
#include "hwtimer.h" #include "hwtimer.h"
@ -118,7 +119,7 @@ void schedule_timer(void)
* are set at all */ * are set at all */
if (native_hwtimer_isset[next_timer] == 1) { if (native_hwtimer_isset[next_timer] == 1) {
if (setitimer(ITIMER_REAL, &native_hwtimer[next_timer], NULL) == -1) { if (setitimer(ITIMER_REAL, &native_hwtimer[next_timer], NULL) == -1) {
err(1, "schedule_timer"); err(EXIT_FAILURE, "schedule_timer");
} }
else { else {
DEBUG("schedule_timer(): set next timer.\n"); DEBUG("schedule_timer(): set next timer.\n");
@ -237,7 +238,7 @@ unsigned long hwtimer_arch_now(void)
#else #else
if (clock_gettime(CLOCK_MONOTONIC, &t) == -1) { if (clock_gettime(CLOCK_MONOTONIC, &t) == -1) {
err(1, "hwtimer_arch_now: clock_gettime"); err(EXIT_FAILURE, "hwtimer_arch_now: clock_gettime");
} }
#endif #endif

View File

@ -74,7 +74,7 @@ void print_thread_sigmask(ucontext_t *cp)
sigset_t *p = &cp->uc_sigmask; sigset_t *p = &cp->uc_sigmask;
if (sigemptyset(p) == -1) { if (sigemptyset(p) == -1) {
err(1, "print_thread_sigmask: sigemptyset"); err(EXIT_FAILURE, "print_thread_sigmask: sigemptyset");
} }
for (int i = 1; i < (NSIG); i++) { for (int i = 1; i < (NSIG); i++) {
@ -113,15 +113,15 @@ void native_print_signals()
puts("native signals:\n"); puts("native signals:\n");
if (sigemptyset(&p) == -1) { if (sigemptyset(&p) == -1) {
err(1, "native_print_signals: sigemptyset"); err(EXIT_FAILURE, "native_print_signals: sigemptyset");
} }
if (sigpending(&p) == -1) { if (sigpending(&p) == -1) {
err(1, "native_print_signals: sigpending"); err(EXIT_FAILURE, "native_print_signals: sigpending");
} }
if (sigprocmask(SIG_SETMASK, NULL, &q) == -1) { if (sigprocmask(SIG_SETMASK, NULL, &q) == -1) {
err(1, "native_print_signals(): sigprocmask"); err(EXIT_FAILURE, "native_print_signals(): sigprocmask");
} }
for (int i = 1; i < (NSIG); i++) { for (int i = 1; i < (NSIG); i++) {
@ -158,21 +158,21 @@ unsigned disableIRQ(void)
} }
if (sigfillset(&mask) == -1) { if (sigfillset(&mask) == -1) {
err(1, "disableIRQ(): sigfillset"); err(EXIT_FAILURE, "disableIRQ(): sigfillset");
} }
if (native_interrupts_enabled == 1) { if (native_interrupts_enabled == 1) {
DEBUG("sigprocmask(..native_sig_set)\n"); DEBUG("sigprocmask(..native_sig_set)\n");
if (sigprocmask(SIG_SETMASK, &mask, &native_sig_set) == -1) { if (sigprocmask(SIG_SETMASK, &mask, &native_sig_set) == -1) {
err(1, "disableIRQ(): sigprocmask"); err(EXIT_FAILURE, "disableIRQ(): sigprocmask");
} }
} }
else { else {
DEBUG("sigprocmask()\n"); DEBUG("sigprocmask()\n");
if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) { if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
err(1, "disableIRQ(): sigprocmask()"); err(EXIT_FAILURE, "disableIRQ(): sigprocmask()");
} }
} }
@ -200,7 +200,7 @@ unsigned enableIRQ(void)
} }
if (sigprocmask(SIG_SETMASK, &native_sig_set, NULL) == -1) { if (sigprocmask(SIG_SETMASK, &native_sig_set, NULL) == -1) {
err(1, "enableIRQ(): sigprocmask()"); err(EXIT_FAILURE, "enableIRQ(): sigprocmask()");
} }
prev_state = native_interrupts_enabled; prev_state = native_interrupts_enabled;
@ -257,7 +257,7 @@ int _native_popsig(void)
} }
if (nread == -1) { if (nread == -1) {
err(1, "_native_popsig(): real_read()"); err(EXIT_FAILURE, "_native_popsig(): real_read()");
} }
return sig; return sig;
@ -310,7 +310,7 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
/* save the signal */ /* save the signal */
if (real_write(_sig_pipefd[1], &sig, sizeof(int)) == -1) { if (real_write(_sig_pipefd[1], &sig, sizeof(int)) == -1) {
err(1, "native_isr_entry(): real_write()"); err(EXIT_FAILURE, "native_isr_entry(): real_write()");
} }
_native_sigpend++; _native_sigpend++;
//real_write(STDOUT_FILENO, "sigpend\n", 8); //real_write(STDOUT_FILENO, "sigpend\n", 8);
@ -374,7 +374,7 @@ int register_interrupt(int sig, void (*handler)(void))
DEBUG("XXX: register_interrupt()\n"); DEBUG("XXX: register_interrupt()\n");
if (sigdelset(&native_sig_set, sig)) { if (sigdelset(&native_sig_set, sig)) {
err(1, "register_interrupt: sigdelset"); err(EXIT_FAILURE, "register_interrupt: sigdelset");
} }
native_irq_handlers[sig].func = handler; native_irq_handlers[sig].func = handler;
@ -382,13 +382,13 @@ int register_interrupt(int sig, void (*handler)(void))
sa.sa_sigaction = native_isr_entry; sa.sa_sigaction = native_isr_entry;
if (sigemptyset(&sa.sa_mask) == -1) { if (sigemptyset(&sa.sa_mask) == -1) {
err(1, "register_interrupt: sigemptyset"); err(EXIT_FAILURE, "register_interrupt: sigemptyset");
} }
sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK; sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
if (sigaction(sig, &sa, NULL)) { if (sigaction(sig, &sa, NULL)) {
err(1, "register_interrupt: sigaction"); err(EXIT_FAILURE, "register_interrupt: sigaction");
} }
return 0; return 0;
@ -406,7 +406,7 @@ int unregister_interrupt(int sig)
DEBUG("XXX: unregister_interrupt()\n"); DEBUG("XXX: unregister_interrupt()\n");
if (sigaddset(&native_sig_set, sig) == -1) { if (sigaddset(&native_sig_set, sig) == -1) {
err(1, "unregister_interrupt: sigaddset"); err(EXIT_FAILURE, "unregister_interrupt: sigaddset");
} }
native_irq_handlers[sig].func = NULL; native_irq_handlers[sig].func = NULL;
@ -414,13 +414,13 @@ int unregister_interrupt(int sig)
sa.sa_handler = SIG_IGN; sa.sa_handler = SIG_IGN;
if (sigemptyset(&sa.sa_mask) == -1) { if (sigemptyset(&sa.sa_mask) == -1) {
err(1, "unregister_interrupt: sigemptyset"); err(EXIT_FAILURE, "unregister_interrupt: sigemptyset");
} }
sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK; sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
if (sigaction(sig, &sa, NULL)) { if (sigaction(sig, &sa, NULL)) {
err(1, "unregister_interrupt: sigaction"); err(EXIT_FAILURE, "unregister_interrupt: sigaction");
} }
return 0; return 0;
@ -461,34 +461,34 @@ void native_interrupt_init(void)
sa.sa_sigaction = native_isr_entry; sa.sa_sigaction = native_isr_entry;
if (sigemptyset(&sa.sa_mask) == -1) { if (sigemptyset(&sa.sa_mask) == -1) {
err(1, "native_interrupt_init: sigemptyset"); err(EXIT_FAILURE, "native_interrupt_init: sigemptyset");
} }
sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK; sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
/* /*
if (sigemptyset(&native_sig_set) == -1) { if (sigemptyset(&native_sig_set) == -1) {
err(1, "native_interrupt_init: sigemptyset"); err(EXIT_FAILURE, "native_interrupt_init: sigemptyset");
} }
*/ */
if (sigprocmask(SIG_SETMASK, NULL, &native_sig_set) == -1) { if (sigprocmask(SIG_SETMASK, NULL, &native_sig_set) == -1) {
err(1, "native_interrupt_init(): sigprocmask"); err(EXIT_FAILURE, "native_interrupt_init(): sigprocmask");
} }
if (sigdelset(&native_sig_set, SIGUSR1) == -1) { if (sigdelset(&native_sig_set, SIGUSR1) == -1) {
err(1, "native_interrupt_init: sigdelset"); err(EXIT_FAILURE, "native_interrupt_init: sigdelset");
} }
if (sigaction(SIGUSR1, &sa, NULL)) { if (sigaction(SIGUSR1, &sa, NULL)) {
err(1, "native_interrupt_init: sigaction"); err(EXIT_FAILURE, "native_interrupt_init: sigaction");
} }
if (getcontext(&native_isr_context) == -1) { if (getcontext(&native_isr_context) == -1) {
err(1, "native_isr_entry(): getcontext()"); err(EXIT_FAILURE, "native_isr_entry(): getcontext()");
} }
if (sigfillset(&(native_isr_context.uc_sigmask)) == -1) { if (sigfillset(&(native_isr_context.uc_sigmask)) == -1) {
err(1, "native_isr_entry(): sigfillset()"); err(EXIT_FAILURE, "native_isr_entry(): sigfillset()");
} }
native_isr_context.uc_stack.ss_sp = __isr_stack; native_isr_context.uc_stack.ss_sp = __isr_stack;
@ -502,7 +502,7 @@ void native_interrupt_init(void)
sigstk.ss_flags = 0; sigstk.ss_flags = 0;
if (sigaltstack(&sigstk, NULL) < 0) { if (sigaltstack(&sigstk, NULL) < 0) {
err(1, "main: sigaltstack"); err(EXIT_FAILURE, "main: sigaltstack");
} }
makecontext(&native_isr_context, native_irq_handler, 0); makecontext(&native_isr_context, native_irq_handler, 0);
@ -510,7 +510,7 @@ void native_interrupt_init(void)
_native_in_syscall = 0; _native_in_syscall = 0;
if (pipe(_sig_pipefd) == -1) { if (pipe(_sig_pipefd) == -1) {
err(1, "native_interrupt_init(): pipe()"); err(EXIT_FAILURE, "native_interrupt_init(): pipe()");
} }
/* allow for ctrl+c to shut down gracefully */ /* allow for ctrl+c to shut down gracefully */

View File

@ -66,7 +66,7 @@ void _native_lpm_sleep()
} }
else if (errno != EINTR) { else if (errno != EINTR) {
/* select failed for reason other than signal */ /* select failed for reason other than signal */
err(1, "lpm_set(): select()"); err(EXIT_FAILURE, "lpm_set(): select()");
} }
/* otherwise select was interrupted because of a signal, continue below */ /* otherwise select was interrupted because of a signal, continue below */

View File

@ -88,7 +88,7 @@ char *thread_stack_init(void (*task_func)(void), void *stack_start, int stacksiz
#endif #endif
if (getcontext(p) == -1) { if (getcontext(p) == -1) {
err(1, "thread_stack_init(): getcontext()"); err(EXIT_FAILURE, "thread_stack_init(): getcontext()");
} }
p->uc_stack.ss_sp = stk; p->uc_stack.ss_sp = stk;
@ -97,7 +97,7 @@ char *thread_stack_init(void (*task_func)(void), void *stack_start, int stacksiz
p->uc_link = &end_context; p->uc_link = &end_context;
if (sigemptyset(&(p->uc_sigmask)) == -1) { if (sigemptyset(&(p->uc_sigmask)) == -1) {
err(1, "thread_stack_init(): sigemptyset()"); err(EXIT_FAILURE, "thread_stack_init(): sigemptyset()");
} }
makecontext(p, task_func, 0); makecontext(p, task_func, 0);
@ -123,7 +123,7 @@ void isr_cpu_switch_context_exit(void)
_native_in_isr = 0; _native_in_isr = 0;
if (setcontext(ctx) == -1) { if (setcontext(ctx) == -1) {
err(1, "cpu_switch_context_exit(): setcontext():"); err(EXIT_FAILURE, "cpu_switch_context_exit(): setcontext():");
} }
} }
@ -137,7 +137,7 @@ void cpu_switch_context_exit()
native_isr_context.uc_stack.ss_flags = 0; native_isr_context.uc_stack.ss_flags = 0;
makecontext(&native_isr_context, isr_cpu_switch_context_exit, 0); makecontext(&native_isr_context, isr_cpu_switch_context_exit, 0);
if (setcontext(&native_isr_context) == -1) { if (setcontext(&native_isr_context) == -1) {
err(1, "cpu_switch_context_exit: swapcontext"); err(EXIT_FAILURE, "cpu_switch_context_exit: swapcontext");
} }
} }
else { else {
@ -157,7 +157,7 @@ void isr_thread_yield()
native_interrupts_enabled = 1; native_interrupts_enabled = 1;
_native_in_isr = 0; _native_in_isr = 0;
if (setcontext(ctx) == -1) { if (setcontext(ctx) == -1) {
err(1, "isr_thread_yield(): setcontext()"); err(EXIT_FAILURE, "isr_thread_yield(): setcontext()");
} }
} }
@ -172,7 +172,7 @@ void thread_yield()
native_isr_context.uc_stack.ss_flags = 0; native_isr_context.uc_stack.ss_flags = 0;
makecontext(&native_isr_context, isr_thread_yield, 0); makecontext(&native_isr_context, isr_thread_yield, 0);
if (swapcontext(ctx, &native_isr_context) == -1) { if (swapcontext(ctx, &native_isr_context) == -1) {
err(1, "thread_yield: swapcontext"); err(EXIT_FAILURE, "thread_yield: swapcontext");
} }
eINT(); eINT();
} }
@ -184,7 +184,7 @@ void thread_yield()
void native_cpu_init() void native_cpu_init()
{ {
if (getcontext(&end_context) == -1) { if (getcontext(&end_context) == -1) {
err(1, "end_context(): getcontext()"); err(EXIT_FAILURE, "end_context(): getcontext()");
} }
end_context.uc_stack.ss_sp = __end_stack; end_context.uc_stack.ss_sp = __end_stack;

View File

@ -246,12 +246,12 @@ int tap_init(char *name)
#ifndef __MACH__ /* tuntap signalled IO not working in OSX */ #ifndef __MACH__ /* tuntap signalled IO not working in OSX */
/* configure fds to send signals on io */ /* configure fds to send signals on io */
if (fcntl(_native_tap_fd, F_SETOWN, getpid()) == -1) { if (fcntl(_native_tap_fd, F_SETOWN, getpid()) == -1) {
err(1, "tap_init(): fcntl(F_SETOWN)"); err(EXIT_FAILURE, "tap_init(): fcntl(F_SETOWN)");
} }
/* set file access mode to nonblocking */ /* set file access mode to nonblocking */
if (fcntl(_native_tap_fd, F_SETFL, O_NONBLOCK|O_ASYNC) == -1) { if (fcntl(_native_tap_fd, F_SETFL, O_NONBLOCK|O_ASYNC) == -1) {
err(1, "tap_init(): fcntl(F_SETFL)"); err(EXIT_FAILURE, "tap_init(): fcntl(F_SETFL)");
} }
#endif /* OSX */ #endif /* OSX */

View File

@ -19,6 +19,7 @@
*/ */
#include <time.h> #include <time.h>
#include <stdlib.h>
#include <err.h> #include <err.h>
#include "debug.h" #include "debug.h"
@ -65,7 +66,7 @@ void rtc_get_localtime(struct tm *localt)
t = time(NULL); t = time(NULL);
if (localtime_r(&t, localt) == NULL) { if (localtime_r(&t, localt) == NULL) {
err(1, "rtc_get_localtime: localtime_r"); err(EXIT_FAILURE, "rtc_get_localtime: localtime_r");
} }
_native_syscall_leave(); _native_syscall_leave();
} }
@ -76,7 +77,7 @@ time_t rtc_time(struct timeval *time)
if (native_rtc_enabled == 1) { if (native_rtc_enabled == 1) {
_native_syscall_enter(); _native_syscall_enter();
if (gettimeofday(time, NULL) == -1) { if (gettimeofday(time, NULL) == -1) {
err(1, "rtc_time: gettimeofday"); err(EXIT_FAILURE, "rtc_time: gettimeofday");
} }
_native_syscall_leave(); _native_syscall_leave();
} }