diff --git a/lib/hooks/jitter_calc.c b/lib/hooks/jitter_calc.c index 23ef825ed..b33ea2903 100644 --- a/lib/hooks/jitter_calc.c +++ b/lib/hooks/jitter_calc.c @@ -73,7 +73,7 @@ int hook_jitter_ts(struct hook *h, struct sample *smps[], size_t *cnt) D(i,j) = (Rj-Ri)-(Sj-Si) = (Rj-Sj)-(Ri-Si) J(i) = J(i-1)+(|D(i-1,i)|-J(i-1))/16 */ - jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE] = jitter_val[curr_count] + (abs(curr_delay_us) - jitter_val[curr_count])/16; + jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE] = jitter_val[curr_count] + (labs(curr_delay_us) - jitter_val[curr_count])/16; stats("%s: jitter=%" PRId64 " usec, moving average=%" PRId64 " usec, moving variance=%" PRId64 " usec", __FUNCTION__, jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE], moving_avg[curr_count], moving_var[curr_count]); diff --git a/lib/mapping.c b/lib/mapping.c index 823459077..ae0896d17 100644 --- a/lib/mapping.c +++ b/lib/mapping.c @@ -30,6 +30,7 @@ int mapping_entry_parse_str(struct mapping_entry *e, const char *str) { + int id; char *cpy, *type, *field, *subfield, *end; cpy = strdup(str); @@ -56,10 +57,12 @@ int mapping_entry_parse_str(struct mapping_entry *e, const char *str) if (end) goto invalid_format; - e->stats.id = stats_lookup_id(field); - if (e->stats.id < 0) + id = stats_lookup_id(field); + if (id < 0) goto invalid_format; + e->stats.id = id; + if (!strcmp(subfield, "total")) e->stats.type = MAPPING_STATS_TYPE_TOTAL; else if (!strcmp(subfield, "last")) diff --git a/lib/nodes/file.c b/lib/nodes/file.c index 3f31e2b70..428390bcf 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -87,26 +87,21 @@ static struct timespec file_calc_read_offset(const struct timespec *first, const switch (mode) { case FILE_EPOCH_DIRECT: /* read first value at now + epoch */ offset = time_diff(first, &now); - offset = time_add(&offset, epoch); - break; + return time_add(&offset, epoch); case FILE_EPOCH_WAIT: /* read first value at now + first + epoch */ offset = now; return time_add(&now, epoch); - break; case FILE_EPOCH_RELATIVE: /* read first value at first + epoch */ return *epoch; - break; case FILE_EPOCH_ABSOLUTE: /* read first value at f->read_epoch */ return time_diff(first, epoch); - break; - default: { } + default: + return (struct timespec) { 0 }; } - - return offset; } int file_parse(struct node *n, config_setting_t *cfg) diff --git a/lib/nodes/signal.c b/lib/nodes/signal.c index 2994c5f4c..e5304f924 100644 --- a/lib/nodes/signal.c +++ b/lib/nodes/signal.c @@ -49,14 +49,17 @@ int signal_parse(struct node *n, config_setting_t *cfg) { struct signal *s = n->_vd; + int ret; const char *type; if (!config_setting_lookup_string(cfg, "signal", &type)) s->type = SIGNAL_TYPE_MIXED; else { - s->type = signal_lookup_type(type); - if (s->type == -1) + ret = signal_lookup_type(type); + if (ret == -1) cerror(cfg, "Unknown signal type '%s'", type); + + s->type = ret; } if (!config_setting_lookup_bool(cfg, "realtime", &s->rt)) @@ -85,6 +88,7 @@ int signal_parse(struct node *n, config_setting_t *cfg) int signal_parse_cli(struct node *n, int argc, char *argv[]) { + int ret; char *type; struct signal *s = n->_vd; @@ -139,10 +143,12 @@ check: if (optarg == endptr) type = argv[optind]; - s->type = signal_lookup_type(type); - if (s->type == -1) + ret = signal_lookup_type(type); + if (ret == -1) error("Invalid signal type: %s", type); + s->type = ret; + return 0; } diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index 144c637e8..7240c9beb 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -375,7 +375,7 @@ int websocket_deinit() /* Wait for all connections to be closed */ while (list_length(&connections) > 0) - sleep(0.2); + usleep(0.2*1e6); list_destroy(&connections, (dtor_cb_t) websocket_destination_destroy, true); diff --git a/lib/queue.c b/lib/queue.c index 96e82993d..2ca6c86c1 100644 --- a/lib/queue.c +++ b/lib/queue.c @@ -188,7 +188,7 @@ int queue_pull_many(struct queue *q, void *ptr[], size_t cnt) int queue_close(struct queue *q) { - int expected = STATE_INITIALIZED; + enum state expected = STATE_INITIALIZED; if (atomic_compare_exchange_weak_explicit(&q->state, &expected, STATE_STOPPED, memory_order_relaxed, memory_order_relaxed)) return 0;