From 2fb11492864a773a5d643435e3cbc41c1a560563 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Mon, 25 Sep 2017 11:11:48 +0200 Subject: Untested userfriendliness improvement for timeouts Will be merged into the master branch after some testing. --- src/config.c | 170 +++++++++++++++++++++++++++++++++++++++++++++-------------- src/config.h | 10 ---- 2 files changed, 131 insertions(+), 49 deletions(-) diff --git a/src/config.c b/src/config.c index bb78779..6243db2 100644 --- a/src/config.c +++ b/src/config.c @@ -244,11 +244,10 @@ static int read_axis_options return -1; } -/* static int parse_timeout_option ( struct relabsd_config * const conf, - FILE * const f + const char * const param ) { int valc, timeout_msec; @@ -258,7 +257,7 @@ static int parse_timeout_option errno = 0; - valc = fscanf(f, "%d", &timeout_msec); + valc = scanf(param, "%d", &timeout_msec); if (valc == EOF) { @@ -266,14 +265,14 @@ static int parse_timeout_option { RELABSD_S_FATAL ( - "[CONFIG] Unexpected end of file while reading timeout option." + "Unexpected end of file while reading timeout option." ); } else { RELABSD_FATAL ( - "[CONFIG] An error occured while reading timeout option: %s.", + "An error occured while reading timeout option: %s.", strerror(errno) ); } @@ -286,7 +285,7 @@ static int parse_timeout_option { RELABSD_S_FATAL ( - "[CONFIG] Invalid parameter count for timeout option (1 expected)." + "Invalid parameter count for timeout option (1 int expected)." ); errno = prev_errno; @@ -294,6 +293,15 @@ static int parse_timeout_option return -1; } + if (timeout_msec <= 0) + { + RELABSD_FATAL + ( + "Illegal value for timeout \"%d\": accepted range is [1, %d].", + timeout_msec, + INT_MAX + ); + } memset((void *) &(conf->timeout), 0, sizeof(struct timeval)); conf->timeout.tv_sec = (time_t) (timeout_msec / 1000); @@ -306,7 +314,6 @@ static int parse_timeout_option return 0; } -*/ /* * Returns -1 on (fatal) error, @@ -521,6 +528,27 @@ static int read_config_file return 0; } +static void print_usage +( + const char * const exec +) +{ + RELABSD_FATAL + ( + "USAGE: %s input_device config_file [