From e7e5729f46812929e2acbde19d99eea7e7929670 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 22 Oct 2016 15:19:31 +0200 Subject: lib: Fix wrong comparison FLOW_O_RDONLY is 0, so the previous statement would always be false. --- src/lib/dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/dev.c b/src/lib/dev.c index 86a5913e..f737b74c 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -699,7 +699,7 @@ ssize_t flow_write(int fd, void * buf, size_t count) return -ENOTALLOC; } - if (ai.flows[fd].oflags & FLOW_O_RDONLY) { + if ((ai.flows[fd].oflags & FLOW_O_ACCMODE) == FLOW_O_RDONLY) { pthread_rwlock_unlock(&ai.flows_lock); pthread_rwlock_unlock(&ai.data_lock); return -EPERM; @@ -1257,7 +1257,7 @@ int ipcp_flow_write(int fd, struct shm_du_buff * sdb) pthread_rwlock_rdlock(&ai.data_lock); pthread_rwlock_rdlock(&ai.flows_lock); - if (ai.flows[fd].oflags & FLOW_O_RDONLY) { + if ((ai.flows[fd].oflags & FLOW_O_ACCMODE) == FLOW_O_RDONLY) { pthread_rwlock_unlock(&ai.flows_lock); pthread_rwlock_unlock(&ai.data_lock); return -EPERM; -- cgit v1.2.3 From dc41c0ebfae020368ccf832f0fe0528ceb137f2c Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 22 Oct 2016 15:35:26 +0200 Subject: irmd, tools: Fix missing initializers The BSD compiler requires explicit initializers for all fields with the -Wmissing-field-initializers flag enabled On branch be-fix-build # Changes to be committed: # modified: src/irmd/main.c # modified: src/tools/irm/irm.c # modified: src/tools/irm/irm_bind.c # modified: src/tools/irm/irm_ipcp.c # modified: src/tools/irm/irm_unbind.c # # Untracked files: # killouroboros.sh # start.sh # --- src/irmd/main.c | 4 +++- src/tools/irm/irm.c | 14 +++++++------- src/tools/irm/irm_bind.c | 2 +- src/tools/irm/irm_ipcp.c | 12 ++++++------ src/tools/irm/irm_unbind.c | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/irmd/main.c b/src/irmd/main.c index 4dee4b91..390681a8 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1993,7 +1993,7 @@ void * mainloop(void * o) static int irm_create(void) { - struct stat st = {0}; + struct stat st; struct timeval timeout = {(IRMD_ACCEPT_TIMEOUT / 1000), (IRMD_ACCEPT_TIMEOUT % 1000) * 1000}; @@ -2001,6 +2001,8 @@ static int irm_create(void) if (irmd == NULL) return -ENOMEM; + memset(&st, 0, sizeof(st)); + irmd->state = IRMD_NULL; if (pthread_rwlock_init(&irmd->state_lock, NULL)) { diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index be758098..320ce97a 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -47,13 +47,13 @@ static const struct cmd { const char * cmd; int (* func)(int argc, char ** argv); } cmds[] = { - { "ipcp", ipcp_cmd }, - { "bind", bind_cmd }, - { "unbind", unbind_cmd }, - { "register", do_register }, - { "unregister", do_unregister }, - { "help", do_help }, - { 0 } + { "ipcp", ipcp_cmd }, + { "bind", bind_cmd }, + { "unbind", unbind_cmd }, + { "register", do_register }, + { "unregister", do_unregister }, + { "help", do_help }, + { NULL, NULL } }; static int do_cmd(const char * argv0, diff --git a/src/tools/irm/irm_bind.c b/src/tools/irm/irm_bind.c index bb441573..aafa2f75 100644 --- a/src/tools/irm/irm_bind.c +++ b/src/tools/irm/irm_bind.c @@ -51,7 +51,7 @@ static const struct cmd { { "api", do_bind_api }, { "ipcp", do_bind_ipcp }, { "help", do_help }, - { 0 } + { NULL, NULL } }; static int do_cmd(const char * argv0, diff --git a/src/tools/irm/irm_ipcp.c b/src/tools/irm/irm_ipcp.c index 795281bb..004bbbe0 100644 --- a/src/tools/irm/irm_ipcp.c +++ b/src/tools/irm/irm_ipcp.c @@ -45,12 +45,12 @@ static const struct cmd { const char * cmd; int (* func)(int argc, char ** argv); } cmds[] = { - { "create", do_create_ipcp }, - { "destroy", do_destroy_ipcp }, - { "bootstrap", do_bootstrap_ipcp }, - { "enroll", do_enroll_ipcp }, - { "help", do_help }, - { 0 } + { "create", do_create_ipcp }, + { "destroy", do_destroy_ipcp }, + { "bootstrap", do_bootstrap_ipcp }, + { "enroll", do_enroll_ipcp }, + { "help", do_help }, + { NULL, NULL } }; static int do_cmd(const char * argv0, diff --git a/src/tools/irm/irm_unbind.c b/src/tools/irm/irm_unbind.c index 5d167e1c..a6b27907 100644 --- a/src/tools/irm/irm_unbind.c +++ b/src/tools/irm/irm_unbind.c @@ -51,7 +51,7 @@ static const struct cmd { { "api", do_unbind_api }, { "ipcp", do_unbind_ipcp }, { "help", do_help }, - { 0 } + { NULL, NULL } }; static int do_cmd(const char * argv0, int argc, char ** argv) -- cgit v1.2.3 From 2bc5cafc514ab92c389ce0d7dd376f89dfa7bb8e Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 22 Oct 2016 16:12:29 +0200 Subject: lib: Revert bad fqueue modification An untested (and wrong) modification to the fqueue was mistakenly added to a previous commit. This corrects the bad code. --- src/lib/dev.c | 3 ++- src/lib/shm_flow_set.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/dev.c b/src/lib/dev.c index f737b74c..41841988 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -960,12 +960,13 @@ int flow_event_wait(struct flow_set * set, if (fq->fqsize > 0) return 0; + assert(!fq->next); + ret = shm_flow_set_wait(ai.fqset, set->idx, fq->fqueue, timeout); if (ret == -ETIMEDOUT) return -ETIMEDOUT; fq->fqsize = ret; - fq->next = 0; return 0; } diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c index f68773aa..3b1af83f 100644 --- a/src/lib/shm_flow_set.c +++ b/src/lib/shm_flow_set.c @@ -356,6 +356,7 @@ ssize_t shm_flow_set_wait(const struct shm_flow_set * shm_set, assert(shm_set); assert(idx < AP_MAX_FQUEUES); + assert(fqueue); #ifdef __APPLE__ pthread_mutex_lock(shm_set->lock); @@ -397,10 +398,11 @@ ssize_t shm_flow_set_wait(const struct shm_flow_set * shm_set, memcpy(fqueue, fqueue_ptr(shm_set, idx), shm_set->heads[idx] * sizeof(int)); + ret = shm_set->heads[idx]; shm_set->heads[idx] = 0; } pthread_cleanup_pop(true); - return 0; + return ret; } -- cgit v1.2.3 From 4bb18901fa222dc686886e7736e9935cfa1a4672 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 22 Oct 2016 16:18:58 +0200 Subject: lib: Fix closing applications with active flows The rdrbuff was previously closed before the remaining SDUs were removed. --- src/lib/dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/dev.c b/src/lib/dev.c index 41841988..cac3ca37 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -276,7 +276,6 @@ void ap_fini() bmp_destroy(ai.fds); bmp_destroy(ai.fqueues); shm_flow_set_destroy(ai.fqset); - shm_rdrbuff_close(ai.rdrb); if (ai.daf_name != NULL) free(ai.daf_name); @@ -303,6 +302,8 @@ void ap_fini() pthread_cond_destroy(&ai.ports[i].state_cond); } + shm_rdrbuff_close(ai.rdrb); + free(ai.flows); free(ai.ports); -- cgit v1.2.3