From 9beda12c4ce94fe44e32554ac61a32a3a500761a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Tue, 5 Sep 2017 10:11:23 +0200 Subject: [PATCH] fix compiler errors on OS X --- lib/api/actions/restart.c | 12 ++++++------ lib/io/raw.c | 1 + lib/nodes/Makefile.inc | 16 ++++++++++++++-- lib/nodes/file.c | 18 ++++++++++++------ lib/nodes/signal.c | 6 ++++-- lib/queue_signalled.c | 30 +++++++++++++++++------------- lib/sample.c | 4 ++-- 7 files changed, 56 insertions(+), 31 deletions(-) diff --git a/lib/api/actions/restart.c b/lib/api/actions/restart.c index b11bf5e64..73df73c35 100644 --- a/lib/api/actions/restart.c +++ b/lib/api/actions/restart.c @@ -31,10 +31,10 @@ static char *config; void api_restart_handler() { int ret; - + char *argv[] = { "villas-node", config, NULL }; - ret = execvpe("/proc/self/exe", argv, environ); + ret = execvp("/proc/self/exe", argv); if (ret) serror("Failed to restart"); } @@ -43,11 +43,11 @@ static int api_restart(struct api_action *h, json_t *args, json_t **resp, struct { int ret; json_error_t err; - + /* If no config is provided via request, we will use the previous one */ if (s->api->super_node->uri) config = strdup(s->api->super_node->uri); - + if (args) { ret = json_unpack_ex(args, &err, 0, "{ s?: s }", "config", &config); if (ret < 0) { @@ -64,7 +64,7 @@ static int api_restart(struct api_action *h, json_t *args, json_t **resp, struct /* We pass some env variables to the new process */ setenv("VILLAS_API_RESTART_COUNT", buf, 1); - + *resp = json_pack("{ s: i, s: s }", "restarts", cnt, "config", config @@ -74,7 +74,7 @@ static int api_restart(struct api_action *h, json_t *args, json_t **resp, struct ret = atexit(api_restart_handler); if (ret) return 0; - + /* Properly terminate current instance */ killme(SIGTERM); diff --git a/lib/io/raw.c b/lib/io/raw.c index c164d8f61..f526707df 100644 --- a/lib/io/raw.c +++ b/lib/io/raw.c @@ -24,6 +24,7 @@ #include "plugin.h" #include "utils.h" #include "io/raw.h" +#include "compat.h" /** Convert float to host byte order */ #define SWAP_FLT_TOH(o, n) ({ \ diff --git a/lib/nodes/Makefile.inc b/lib/nodes/Makefile.inc index e7f5f6a6a..b98e62864 100644 --- a/lib/nodes/Makefile.inc +++ b/lib/nodes/Makefile.inc @@ -20,10 +20,10 @@ # along with this program. If not, see . ################################################################################### -LIB_SRCS += $(addprefix lib/nodes/, cbuilder.c loopback.c) - ifeq ($(PLATFORM),Linux) WITH_FPGA ?= 1 + WITH_CBUILDER ?= 1 + WITH_LOOPBACK ?= 1 endif WITH_TEST_RTT ?= 0 @@ -37,6 +37,18 @@ WITH_NANOMSG ?= 1 WITH_SHMEM ?= 1 WITH_STATS ?= 1 +# Enabled loopback node-type +ifeq ($(WITH_LOOPBACK),1) + LIB_SRCS += lib/nodes/loopback.c + LIB_CFLAGS += -DWITH_LOOPBACK +endif + +# Enabled Cbuilder node-type +ifeq ($(WITH_CBUILDER),1) + LIB_SRCS += lib/nodes/cbuilder.c + LIB_CFLAGS += -DWITH_CBUILDER +endif + # Enable stats node-type ifeq ($(WITH_STATS),1) LIB_SRCS += lib/nodes/stats.c diff --git a/lib/nodes/file.c b/lib/nodes/file.c index cc0a44f25..b8a62c004 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -229,12 +229,18 @@ int file_start(struct node *n) struct sample s = { .capacity = 0 }; struct sample *smps[] = { &s }; - ret = io_scan(&f->io, smps, 1); - if (ret != 1) - error("Failed to read first timestamp of node %s", node_name(n)); - - f->first = s.ts.origin; - f->offset = file_calc_offset(&f->first, &f->epoch, f->epoch_mode); + if (io_eof(&f->io)) { + warn("Empty file"); + } + else { + ret = io_scan(&f->io, smps, 1); + if (ret == 1) { + f->first = s.ts.origin; + f->offset = file_calc_offset(&f->first, &f->epoch, f->epoch_mode); + } + else + warn("Failed to read first timestamp of node %s", node_name(n)); + } } io_rewind(&f->io); diff --git a/lib/nodes/signal.c b/lib/nodes/signal.c index 1c9cfe6a3..1b2838a26 100644 --- a/lib/nodes/signal.c +++ b/lib/nodes/signal.c @@ -157,10 +157,12 @@ check: if (optarg == endptr) type = argv[optind]; - s->type = signal_lookup_type(type); - if (s->type == -1) + int t = signal_lookup_type(type); + if (t == -1) error("Invalid signal type: %s", type); + s->type = t; + /* We know the expected number of values. */ n->samplelen = s->values; diff --git a/lib/queue_signalled.c b/lib/queue_signalled.c index 2d22927b3..957c47ed1 100644 --- a/lib/queue_signalled.c +++ b/lib/queue_signalled.c @@ -31,7 +31,7 @@ static void queue_signalled_cleanup(void *p) { struct queue_signalled *qs = p; - + if (qs->mode == QUEUE_SIGNALLED_PTHREAD) pthread_mutex_unlock(&qs->pthread.mutex); } @@ -39,9 +39,9 @@ static void queue_signalled_cleanup(void *p) int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memtype *mem, int flags) { int ret; - + qs->mode = flags & QUEUE_SIGNALLED_MASK; - + if (qs->mode == 0) { #ifdef __linux__ if (flags & QUEUE_SIGNALLED_PROCESS_SHARED) @@ -60,7 +60,7 @@ int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memtype if (qs->mode == QUEUE_SIGNALLED_PTHREAD) { pthread_condattr_t cvattr; pthread_mutexattr_t mtattr; - + pthread_mutexattr_init(&mtattr); pthread_condattr_init(&cvattr); @@ -98,7 +98,7 @@ int queue_signalled_destroy(struct queue_signalled *qs) ret = queue_destroy(&qs->queue); if (ret < 0) return ret; - + if (qs->mode == QUEUE_SIGNALLED_PTHREAD) { pthread_cond_destroy(&qs->pthread.ready); pthread_mutex_destroy(&qs->pthread.mutex); @@ -121,12 +121,12 @@ int queue_signalled_destroy(struct queue_signalled *qs) int queue_signalled_push(struct queue_signalled *qs, void *ptr) { - int ret, pushed; + int pushed; pushed = queue_push(&qs->queue, ptr); if (pushed < 0) return pushed; - + if (qs->mode == QUEUE_SIGNALLED_PTHREAD) { pthread_mutex_lock(&qs->pthread.mutex); pthread_cond_broadcast(&qs->pthread.ready); @@ -137,6 +137,7 @@ int queue_signalled_push(struct queue_signalled *qs, void *ptr) } #ifdef __linux__ else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { + int ret; uint64_t incr = 1; ret = write(qs->eventfd, &incr, sizeof(incr)); if (ret < 0) @@ -151,7 +152,7 @@ int queue_signalled_push(struct queue_signalled *qs, void *ptr) int queue_signalled_push_many(struct queue_signalled *qs, void *ptr[], size_t cnt) { - int ret, pushed; + int pushed; pushed = queue_push_many(&qs->queue, ptr, cnt); if (pushed < 0) @@ -167,6 +168,7 @@ int queue_signalled_push_many(struct queue_signalled *qs, void *ptr[], size_t cn } #ifdef __linux__ else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { + int ret; uint64_t incr = 1; ret = write(qs->eventfd, &incr, sizeof(incr)); if (ret < 0) @@ -181,7 +183,7 @@ int queue_signalled_push_many(struct queue_signalled *qs, void *ptr[], size_t cn int queue_signalled_pull(struct queue_signalled *qs, void **ptr) { - int ret, pulled = 0; + int pulled = 0; /* Make sure that qs->mutex is unlocked if this thread gets cancelled. */ pthread_cleanup_push(queue_signalled_cleanup, qs); @@ -200,6 +202,7 @@ int queue_signalled_pull(struct queue_signalled *qs, void **ptr) continue; /* Try again */ #ifdef __linux__ else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { + int ret; uint64_t cntr; ret = read(qs->eventfd, &cntr, sizeof(cntr)); if (ret < 0) @@ -221,7 +224,7 @@ int queue_signalled_pull(struct queue_signalled *qs, void **ptr) int queue_signalled_pull_many(struct queue_signalled *qs, void *ptr[], size_t cnt) { - int ret, pulled = 0; + int pulled = 0; /* Make sure that qs->mutex is unlocked if this thread gets cancelled. */ pthread_cleanup_push(queue_signalled_cleanup, qs); @@ -240,6 +243,7 @@ int queue_signalled_pull_many(struct queue_signalled *qs, void *ptr[], size_t cn continue; /* Try again */ #ifdef __linux__ else if (qs->mode == QUEUE_SIGNALLED_EVENTFD) { + int ret; uint64_t cntr; ret = read(qs->eventfd, &cntr, sizeof(cntr)); if (ret < 0) @@ -253,7 +257,7 @@ int queue_signalled_pull_many(struct queue_signalled *qs, void *ptr[], size_t cn if (qs->mode == QUEUE_SIGNALLED_PTHREAD) pthread_mutex_unlock(&qs->pthread.mutex); - + pthread_cleanup_pop(0); return pulled; @@ -267,7 +271,7 @@ int queue_signalled_close(struct queue_signalled *qs) pthread_mutex_lock(&qs->pthread.mutex); ret = queue_close(&qs->queue); - + if (qs->mode == QUEUE_SIGNALLED_PTHREAD) { pthread_cond_broadcast(&qs->pthread.ready); pthread_mutex_unlock(&qs->pthread.mutex); @@ -300,6 +304,6 @@ int queue_signalled_fd(struct queue_signalled *qs) #endif default: { } } - + return -1; } diff --git a/lib/sample.c b/lib/sample.c index 580f04159..596a63230 100644 --- a/lib/sample.c +++ b/lib/sample.c @@ -151,7 +151,7 @@ int sample_cmp(struct sample *a, struct sample *b, double epsilon, int flags) } if (a->format != b->format) { - printf("format: %#lx != %#lx\n", a->format, b->format); + printf("format: %#llx != %#llx\n", a->format, b->format); return 6; } @@ -166,7 +166,7 @@ int sample_cmp(struct sample *a, struct sample *b, double epsilon, int flags) case SAMPLE_DATA_FORMAT_INT: if (a->data[i].i != b->data[i].i) { - printf("data[%d].i: %ld != %ld\n", i, a->data[i].i, b->data[i].i); + printf("data[%d].i: %lld != %lld\n", i, a->data[i].i, b->data[i].i); return 5; } break;