Commit e62b5f05 authored by Alessandro Rubini's avatar Alessandro Rubini

arch-gnu-linux/posix-io.c: better error/exit

Trivial changes: exit code should not be 0 on error, we should exit
where we say so to the user and give more informative context.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 5708241c
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <time.h> #include <time.h>
#include <sys/timex.h> #include <sys/timex.h>
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
...@@ -12,9 +13,11 @@ ...@@ -12,9 +13,11 @@
const Integer32 PP_ADJ_FREQ_MAX = 512000; const Integer32 PP_ADJ_FREQ_MAX = 512000;
static void print_clock_gettime_err_msg(void) static void clock_fatal_error(char *context)
{ {
PP_PRINTF("clock_gettime() failed, exiting."); PP_PRINTF("failure in \"%s\": %s\n.Exiting.\n", context,
strerror(errno));
exit(1);
} }
void posix_puts(const char *s) void posix_puts(const char *s)
...@@ -45,10 +48,8 @@ void *posix_memset(void *s, int c, int count) ...@@ -45,10 +48,8 @@ void *posix_memset(void *s, int c, int count)
void posix_get_tstamp(TimeInternal *t) void posix_get_tstamp(TimeInternal *t)
{ {
struct timespec tp; struct timespec tp;
if (clock_gettime(CLOCK_REALTIME, &tp) < 0) { if (clock_gettime(CLOCK_REALTIME, &tp) < 0)
print_clock_gettime_err_msg(); clock_fatal_error("clock_gettime");
exit(0);
}
t->seconds = tp.tv_sec; t->seconds = tp.tv_sec;
t->nanoseconds = tp.tv_nsec; t->nanoseconds = tp.tv_nsec;
} }
...@@ -58,17 +59,13 @@ int32_t posix_set_tstamp(TimeInternal *t) ...@@ -58,17 +59,13 @@ int32_t posix_set_tstamp(TimeInternal *t)
struct timespec tp_orig; struct timespec tp_orig;
struct timespec tp; struct timespec tp;
if (clock_gettime(CLOCK_REALTIME, &tp_orig) < 0) { if (clock_gettime(CLOCK_REALTIME, &tp_orig) < 0)
print_clock_gettime_err_msg(); clock_fatal_error("clock_gettime");
exit(0);
}
tp.tv_sec = t->seconds; tp.tv_sec = t->seconds;
tp.tv_nsec = t->nanoseconds; tp.tv_nsec = t->nanoseconds;
if (clock_settime(CLOCK_REALTIME, &tp) < 0) { if (clock_settime(CLOCK_REALTIME, &tp) < 0)
print_clock_gettime_err_msg(); clock_fatal_error("clock_settime");
exit(0);
}
return tp.tv_sec - tp_orig.tv_sec; /* handle only sec field, since return tp.tv_sec - tp_orig.tv_sec; /* handle only sec field, since
* timer granularity is 1s */ * timer granularity is 1s */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment