From 6785ca65ab48f1a29914c1784a24009964ec4720 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Thu, 9 Feb 2017 16:49:56 +0100 Subject: ipcpd, lib: Report IPCP creation failure The IPCP will now respond with an ipcp_create_r message when it fails, informing the IRMd. Also adds some const qualifiers in the public headers and fixes some formatting in dev.c. --- include/ouroboros/dev.h | 16 +++--- include/ouroboros/fcntl.h | 4 +- include/ouroboros/fqueue.h | 4 +- include/ouroboros/ipcp-dev.h | 3 +- include/ouroboros/irm.h | 48 ++++++++--------- include/ouroboros/shm_rdrbuff.h | 4 +- include/ouroboros/utils.h | 10 ++++ src/ipcpd/local/main.c | 5 +- src/ipcpd/normal/main.c | 6 ++- src/ipcpd/normal/pol/flat.c | 10 +--- src/ipcpd/shim-eth-llc/main.c | 5 +- src/ipcpd/shim-udp/main.c | 5 +- src/irmd/main.c | 8 ++- src/lib/dev.c | 115 ++++++++++++++++++++++++++++------------ src/lib/irm.c | 81 +++++++++++++++------------- src/lib/shm_rdrbuff.c | 4 +- 16 files changed, 201 insertions(+), 127 deletions(-) diff --git a/include/ouroboros/dev.h b/include/ouroboros/dev.h index 8ac38124..1d2a2533 100644 --- a/include/ouroboros/dev.h +++ b/include/ouroboros/dev.h @@ -30,7 +30,7 @@ #define UNKNOWN_AE "__UNKNOWN_AE__" /* These calls should be removed once we write the ouroboros OS. */ -int ap_init(char * ap_name); +int ap_init(const char * ap_name); void ap_fini(void); @@ -43,19 +43,19 @@ int flow_alloc_resp(int fd, /* * Returns flow descriptor (> 0). - * On returning, qos will contain the actual supplied QoS. + * On returning, spec will contain the actual supplied QoS. */ -int flow_alloc(char * dst_name, - char * src_ae_name, - qosspec_t * spec); +int flow_alloc(const char * dst_name, + const char * src_ae_name, + qosspec_t * spec); int flow_alloc_res(int fd); int flow_dealloc(int fd); -ssize_t flow_write(int fd, - void * buf, - size_t count); +ssize_t flow_write(int fd, + const void * buf, + size_t count); ssize_t flow_read(int fd, void * buf, diff --git a/include/ouroboros/fcntl.h b/include/ouroboros/fcntl.h index ad968a1d..7ee4229e 100644 --- a/include/ouroboros/fcntl.h +++ b/include/ouroboros/fcntl.h @@ -41,8 +41,8 @@ int flow_set_flags(int fd, int flow_get_flags(int fd); -int flow_set_timeout(int fd, - struct timespec * to); +int flow_set_timeout(int fd, + const struct timespec * to); int flow_get_timeout(int fd, struct timespec * to); diff --git a/include/ouroboros/fqueue.h b/include/ouroboros/fqueue.h index 254648e6..fdd2cbfb 100644 --- a/include/ouroboros/fqueue.h +++ b/include/ouroboros/fqueue.h @@ -47,8 +47,8 @@ void flow_set_zero(flow_set_t * set); int flow_set_add(flow_set_t * set, int fd); -bool flow_set_has(flow_set_t * set, - int fd); +bool flow_set_has(const flow_set_t * set, + int fd); void flow_set_del(flow_set_t * set, int fd); diff --git a/include/ouroboros/ipcp-dev.h b/include/ouroboros/ipcp-dev.h index d4e174fb..81aca1d7 100644 --- a/include/ouroboros/ipcp-dev.h +++ b/include/ouroboros/ipcp-dev.h @@ -26,7 +26,8 @@ #ifndef OUROBOROS_IPCP_DEV_H #define OUROBOROS_IPCP_DEV_H -int ipcp_create_r(pid_t api); +int ipcp_create_r(pid_t api, + int result); int ipcp_flow_req_arr(pid_t api, char * dst_name, diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h index 79e3e7c9..07052727 100644 --- a/include/ouroboros/irm.h +++ b/include/ouroboros/irm.h @@ -26,42 +26,42 @@ #include #include -pid_t irm_create_ipcp(char * name, +pid_t irm_create_ipcp(const char * name, enum ipcp_type ipcp_type); int irm_destroy_ipcp(pid_t api); /* apis is an out-parameter */ -ssize_t irm_list_ipcps(char * name, - pid_t ** apis); +ssize_t irm_list_ipcps(const char * name, + pid_t ** apis); -int irm_enroll_ipcp(pid_t api, - char * dif_name); +int irm_enroll_ipcp(pid_t api, + const char * dif_name); -int irm_bootstrap_ipcp(pid_t api, - struct dif_config * conf); +int irm_bootstrap_ipcp(pid_t api, + const struct dif_config * conf); -int irm_bind_ap(char * ap, - char * name, - uint16_t opts, - int argc, - char ** argv); +int irm_bind_ap(const char * ap, + const char * name, + uint16_t opts, + int argc, + char ** argv); -int irm_unbind_ap(char * ap, - char * name); +int irm_unbind_ap(const char * ap, + const char * name); -int irm_bind_api(pid_t api, - char * name); +int irm_bind_api(pid_t api, + const char * name); -int irm_unbind_api(pid_t api, - char * name); +int irm_unbind_api(pid_t api, + const char * name); -int irm_reg(char * name, - char ** difs, - size_t difs_size); +int irm_reg(const char * name, + char ** difs, + size_t len); -int irm_unreg(char * name, - char ** difs, - size_t difs_size); +int irm_unreg(const char * name, + char ** difs, + size_t len); #endif /* OUROBOROS_IRM_H */ diff --git a/include/ouroboros/shm_rdrbuff.h b/include/ouroboros/shm_rdrbuff.h index 2e23381b..73d6bfbc 100644 --- a/include/ouroboros/shm_rdrbuff.h +++ b/include/ouroboros/shm_rdrbuff.h @@ -49,13 +49,13 @@ void shm_rdrbuff_wait_full(struct shm_rdrbuff * rdrb); ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, size_t headspace, size_t tailspace, - uint8_t * data, + const uint8_t * data, size_t data_len); ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, size_t headspace, size_t tailspace, - uint8_t * data, + const uint8_t * data, size_t data_len); ssize_t shm_rdrbuff_read(uint8_t ** dst, diff --git a/include/ouroboros/utils.h b/include/ouroboros/utils.h index 52873a7e..29fb4367 100644 --- a/include/ouroboros/utils.h +++ b/include/ouroboros/utils.h @@ -46,4 +46,14 @@ char * strdup(const char * src); /* gets the application name */ char * path_strip(char * src); +/* destroy a ** */ +#define freepp(type, ptr, len) \ + do { \ + if (len == 0) \ + break; \ + while (len > 0) \ + free(((type **) ptr)[--len]); \ + free(ptr); \ + } while (0); + #endif /* OUROBOROS_UTILS_H */ diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index b49e1612..ccbd6acb 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -353,11 +353,13 @@ int main(int argc, if (ipcp_init(argc, argv, THIS_TYPE, &local_ops) < 0) { log_err("Failed to init IPCP."); + ipcp_create_r(getpid(), -1); exit(EXIT_FAILURE); } if (local_data_init() < 0) { log_err("Failed to init local data."); + ipcp_create_r(getpid(), -1); ipcp_fini(); exit(EXIT_FAILURE); } @@ -366,6 +368,7 @@ int main(int argc, if (ipcp_boot() < 0) { log_err("Failed to boot IPCP."); + ipcp_create_r(getpid(), -1); local_data_fini(); ipcp_fini(); exit(EXIT_FAILURE); @@ -373,7 +376,7 @@ int main(int argc, pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); - if (ipcp_create_r(getpid())) { + if (ipcp_create_r(getpid(), 0)) { log_err("Failed to notify IRMd we are initialized."); ipcp_set_state(IPCP_NULL); ipcp_shutdown(); diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 2b30dba3..b69bfe28 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -459,17 +459,20 @@ int main(int argc, if (ipcp_init(argc, argv, THIS_TYPE, &normal_ops) < 0) { log_err("Failed to create instance."); + ipcp_create_r(getpid(), -1); exit(EXIT_FAILURE); } if (irm_bind_api(getpid(), ipcpi.name)) { log_err("Failed to bind AP name."); + ipcp_create_r(getpid(), -1); ipcp_fini(); exit(EXIT_FAILURE); } if (rib_init()) { log_err("Failed to initialize RIB."); + ipcp_create_r(getpid(), -1); irm_unbind_api(getpid(), ipcpi.name); ipcp_fini(); exit(EXIT_FAILURE); @@ -479,6 +482,7 @@ int main(int argc, if (ipcp_boot() < 0) { log_err("Failed to boot IPCP."); + ipcp_create_r(getpid(), -1); rib_fini(); irm_unbind_api(getpid(), ipcpi.name); ipcp_fini(); @@ -487,7 +491,7 @@ int main(int argc, pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); - if (ipcp_create_r(getpid())) { + if (ipcp_create_r(getpid(), 0)) { log_err("Failed to notify IRMd we are initialized."); ipcp_set_state(IPCP_NULL); ipcp_shutdown(); diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c index 9ffeb5c7..61b0110c 100644 --- a/src/ipcpd/normal/pol/flat.c +++ b/src/ipcpd/normal/pol/flat.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "ipcp.h" @@ -46,15 +47,6 @@ static void addr_name(char * name, sprintf(name, "%8x", (uint32_t) (addr)); } -#define freepp(type, ptr, len) \ - do { \ - if (len == 0) \ - break; \ - while (len > 0) \ - free(((type **) ptr)[--len]); \ - free(ptr); \ - } while (0); - static int addr_taken(char * name, char ** members, size_t len) diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index 35ec0297..15482f87 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -1129,11 +1129,13 @@ int main(int argc, if (ipcp_init(argc, argv, THIS_TYPE, ð_llc_ops) < 0) { log_err("Failed to init IPCP."); + ipcp_create_r(getpid(), -1); exit(EXIT_FAILURE); } if (eth_llc_data_init() < 0) { log_err("Failed to init shim-eth-llc data."); + ipcp_create_r(getpid(), -1); ipcp_fini(); exit(EXIT_FAILURE); } @@ -1143,6 +1145,7 @@ int main(int argc, if (ipcp_boot() < 0) { log_err("Failed to boot IPCP."); + ipcp_create_r(getpid(), -1); eth_llc_data_fini(); ipcp_fini(); exit(EXIT_FAILURE); @@ -1150,7 +1153,7 @@ int main(int argc, pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); - if (ipcp_create_r(getpid())) { + if (ipcp_create_r(getpid(), 0)) { log_err("Failed to notify IRMd we are initialized."); ipcp_set_state(IPCP_NULL); ipcp_shutdown(); diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index 2a73077c..47628a3e 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -1196,11 +1196,13 @@ int main(int argc, if (ipcp_init(argc, argv, THIS_TYPE, &udp_ops) < 0) { log_err("Failed to init IPCP."); + ipcp_create_r(getpid(), -1); exit(EXIT_FAILURE); } if (udp_data_init() < 0) { log_err("Failed to init shim-udp data."); + ipcp_create_r(getpid(), -1); ipcp_fini(); exit(EXIT_FAILURE); } @@ -1210,6 +1212,7 @@ int main(int argc, if (ipcp_boot() < 0) { log_err("Failed to boot IPCP."); + ipcp_create_r(getpid(), -1); udp_data_fini(); ipcp_fini(); exit(EXIT_FAILURE); @@ -1217,7 +1220,7 @@ int main(int argc, pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); - if (ipcp_create_r(getpid())) { + if (ipcp_create_r(getpid(), 0)) { log_err("Failed to notify IRMd we are initialized."); ipcp_set_state(IPCP_NULL); ipcp_shutdown(); diff --git a/src/irmd/main.c b/src/irmd/main.c index c029b4cf..74cb8359 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -303,10 +303,14 @@ static pid_t create_ipcp(char * name, return api->pid; } -static int create_ipcp_r(pid_t api) +static int create_ipcp_r(pid_t api, + int result) { struct list_head * pos = NULL; + if (result != 0) + return result; + pthread_rwlock_rdlock(&irmd->state_lock); pthread_rwlock_rdlock(&irmd->reg_lock); @@ -1821,7 +1825,7 @@ void * mainloop(void * o) break; case IRM_MSG_CODE__IPCP_CREATE_R: ret_msg.has_result = true; - ret_msg.result = create_ipcp_r(msg->api); + ret_msg.result = create_ipcp_r(msg->api, msg->result); break; case IRM_MSG_CODE__IRM_DESTROY_IPCP: ret_msg.has_result = true; diff --git a/src/lib/dev.c b/src/lib/dev.c index eefb9b18..38f7cddf 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -87,7 +87,8 @@ static void port_destroy(struct port * p) pthread_mutex_unlock(&p->state_lock); } -static void port_set_state(struct port * p, enum port_state state) +static void port_set_state(struct port * p, + enum port_state state) { pthread_mutex_lock(&p->state_lock); @@ -169,7 +170,8 @@ static qoscube_t spec_to_cube(qosspec_t * spec) } /* FIXME: fill real spec */ -static void fill_qosspec(qosspec_t * spec, qoscube_t cube) +static void fill_qosspec(qosspec_t * spec, + qoscube_t cube) { assert(spec); @@ -235,14 +237,13 @@ static void reset_flow(int fd) ai.flows[fd].cube = QOS_CUBE_BE; } -int ap_init(char * ap_name) +int ap_init(const char * ap_name) { int i = 0; - ap_name = path_strip(ap_name); + assert(ai.ap_name == NULL); ai.api = getpid(); - ai.ap_name = ap_name; ai.daf_name = NULL; ai.fds = bmp_create(AP_MAX_FLOWS, 0); @@ -300,6 +301,28 @@ int ap_init(char * ap_name) return -1; } + if (ap_name != NULL) { + ai.ap_name = strdup(path_strip((char *) ap_name)); + if (ai.ap_name == NULL) { + free(ai.flows); + shm_rdrbuff_close(ai.rdrb); + shm_flow_set_destroy(ai.fqset); + bmp_destroy(ai.fqueues); + bmp_destroy(ai.fds); + return -ENOMEM; + } + + if (api_announce((char *) ai.ap_name)) { + free(ai.ap_name); + free(ai.flows); + shm_rdrbuff_close(ai.rdrb); + shm_flow_set_destroy(ai.fqset); + bmp_destroy(ai.fqueues); + bmp_destroy(ai.fds); + return -1; + } + } + for (i = 0; i < IRMD_MAX_FLOWS; ++i) { ai.ports[i].state = PORT_ID_PENDING; pthread_mutex_init(&ai.ports[i].state_lock, NULL); @@ -309,9 +332,6 @@ int ap_init(char * ap_name) pthread_rwlock_init(&ai.flows_lock, NULL); pthread_rwlock_init(&ai.data_lock, NULL); - if (ap_name != NULL) - return api_announce(ap_name); - return 0; } @@ -323,11 +343,15 @@ void ap_fini() bmp_destroy(ai.fds); bmp_destroy(ai.fqueues); + shm_flow_set_destroy(ai.fqset); if (ai.daf_name != NULL) free(ai.daf_name); + if (ai.ap_name != NULL) + free(ai.ap_name); + pthread_rwlock_rdlock(&ai.flows_lock); for (i = 0; i < AP_MAX_FLOWS; ++i) { @@ -358,7 +382,8 @@ void ap_fini() pthread_rwlock_destroy(&ai.data_lock); } -int flow_accept(char ** ae_name, qosspec_t * spec) +int flow_accept(char ** ae_name, + qosspec_t * spec) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -452,7 +477,8 @@ int flow_accept(char ** ae_name, qosspec_t * spec) return fd; } -int flow_alloc_resp(int fd, int response) +int flow_alloc_resp(int fd, + int response) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -499,7 +525,9 @@ int flow_alloc_resp(int fd, int response) return ret; } -int flow_alloc(char * dst_name, char * src_ae_name, qosspec_t * spec) +int flow_alloc(const char * dst_name, + const char * src_ae_name, + qosspec_t * spec) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -512,8 +540,8 @@ int flow_alloc(char * dst_name, char * src_ae_name, qosspec_t * spec) src_ae_name = UNKNOWN_AE; msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC; - msg.dst_name = dst_name; - msg.ae_name = src_ae_name; + msg.dst_name = (char *) dst_name; + msg.ae_name = (char *) src_ae_name; msg.has_api = true; msg.has_qoscube = true; msg.qoscube = spec_to_cube(spec); @@ -678,7 +706,8 @@ int flow_dealloc(int fd) return 0; } -int flow_set_flags(int fd, int flags) +int flow_set_flags(int fd, + int flags) { int old; @@ -731,7 +760,8 @@ int flow_get_flags(int fd) return old; } -int flow_get_timeout(int fd, struct timespec * timeo) +int flow_get_timeout(int fd, + struct timespec * timeo) { int ret = 0; @@ -758,7 +788,8 @@ int flow_get_timeout(int fd, struct timespec * timeo) return ret; } -int flow_set_timeout(int fd, struct timespec * timeo) +int flow_set_timeout(int fd, + const struct timespec * timeo) { if (fd < 0 || fd >= AP_MAX_FLOWS) return -EINVAL; @@ -785,7 +816,8 @@ int flow_set_timeout(int fd, struct timespec * timeo) return 0; } -int flow_get_qosspec(int fd, qosspec_t * spec) +int flow_get_qosspec(int fd, + qosspec_t * spec) { if (fd < 0 || fd >= AP_MAX_FLOWS || spec == NULL) return -EINVAL; @@ -807,7 +839,9 @@ int flow_get_qosspec(int fd, qosspec_t * spec) return 0; } -ssize_t flow_write(int fd, void * buf, size_t count) +ssize_t flow_write(int fd, + const void * buf, + size_t count) { ssize_t idx; @@ -882,7 +916,9 @@ ssize_t flow_write(int fd, void * buf, size_t count) return 0; } -ssize_t flow_read(int fd, void * buf, size_t count) +ssize_t flow_read(int fd, + void * buf, + size_t count) { ssize_t idx = -1; ssize_t n; @@ -1002,7 +1038,8 @@ void flow_set_zero(struct flow_set * set) pthread_rwlock_unlock(&ai.data_lock); } -int flow_set_add(struct flow_set * set, int fd) +int flow_set_add(struct flow_set * set, + int fd) { int ret; @@ -1020,7 +1057,8 @@ int flow_set_add(struct flow_set * set, int fd) return ret; } -void flow_set_del(struct flow_set * set, int fd) +void flow_set_del(struct flow_set * set, + int fd) { if (set == NULL) return; @@ -1035,7 +1073,8 @@ void flow_set_del(struct flow_set * set, int fd) pthread_rwlock_unlock(&ai.data_lock); } -bool flow_set_has(struct flow_set * set, int fd) +bool flow_set_has(const struct flow_set * set, + int fd) { bool ret = false; @@ -1112,7 +1151,8 @@ int flow_event_wait(struct flow_set * set, /* ipcp-dev functions */ -int np1_flow_alloc(pid_t n_api, int port_id) +int np1_flow_alloc(pid_t n_api, + int port_id) { int fd; @@ -1195,15 +1235,18 @@ int np1_flow_resp(int port_id) return fd; } -int ipcp_create_r(pid_t api) +int ipcp_create_r(pid_t api, + int result) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - msg.code = IRM_MSG_CODE__IPCP_CREATE_R; - msg.has_api = true; - msg.api = api; + msg.code = IRM_MSG_CODE__IPCP_CREATE_R; + msg.has_api = true; + msg.api = api; + msg.has_result = true; + msg.result = result; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -1320,7 +1363,8 @@ int ipcp_flow_req_arr(pid_t api, return fd; } -int ipcp_flow_alloc_reply(int fd, int response) +int ipcp_flow_alloc_reply(int fd, + int response) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -1354,7 +1398,8 @@ int ipcp_flow_alloc_reply(int fd, int response) return ret; } -int ipcp_flow_read(int fd, struct shm_du_buff ** sdb) +int ipcp_flow_read(int fd, + struct shm_du_buff ** sdb) { ssize_t idx = -1; int port_id = -1; @@ -1389,7 +1434,8 @@ int ipcp_flow_read(int fd, struct shm_du_buff ** sdb) return 0; } -int ipcp_flow_write(int fd, struct shm_du_buff * sdb) +int ipcp_flow_write(int fd, + struct shm_du_buff * sdb) { size_t idx; @@ -1442,7 +1488,8 @@ int ipcp_flow_fini(int fd) return 0; } -int ipcp_flow_get_qoscube(int fd, qoscube_t * cube) +int ipcp_flow_get_qoscube(int fd, + qoscube_t * cube) { if (fd < 0 || fd >= AP_MAX_FLOWS || cube == NULL) return -EINVAL; @@ -1479,7 +1526,8 @@ ssize_t local_flow_read(int fd) return ret; } -int local_flow_write(int fd, size_t idx) +int local_flow_write(int fd, + size_t idx) { if (fd < 0) return -EINVAL; @@ -1503,7 +1551,8 @@ int local_flow_write(int fd, size_t idx) return 0; } -int ipcp_read_shim(int fd, struct shm_du_buff ** sdb) +int ipcp_read_shim(int fd, + struct shm_du_buff ** sdb) { ssize_t idx; diff --git a/src/lib/irm.c b/src/lib/irm.c index 477547a2..b610a59e 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -31,7 +31,7 @@ #include #include -pid_t irm_create_ipcp(char * name, +pid_t irm_create_ipcp(const char * name, enum ipcp_type ipcp_type) { irm_msg_t msg = IRM_MSG__INIT; @@ -39,7 +39,7 @@ pid_t irm_create_ipcp(char * name, int ret = -1; msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; - msg.dst_name = name; + msg.dst_name = (char *) name; msg.has_ipcp_type = true; msg.ipcp_type = ipcp_type; @@ -86,8 +86,8 @@ int irm_destroy_ipcp(pid_t api) return ret; } -int irm_bootstrap_ipcp(pid_t api, - struct dif_config * conf) +int irm_bootstrap_ipcp(pid_t api, + const struct dif_config * conf) { irm_msg_t msg = IRM_MSG__INIT; dif_config_msg_t config = DIF_CONFIG_MSG__INIT; @@ -161,8 +161,8 @@ int irm_bootstrap_ipcp(pid_t api, return ret; } -ssize_t irm_list_ipcps(char * name, - pid_t ** apis) +ssize_t irm_list_ipcps(const char * name, + pid_t ** apis) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -173,7 +173,7 @@ ssize_t irm_list_ipcps(char * name, return -EINVAL; msg.code = IRM_MSG_CODE__IRM_LIST_IPCPS; - msg.dst_name = name; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { @@ -202,8 +202,8 @@ ssize_t irm_list_ipcps(char * name, return nr; } -int irm_enroll_ipcp(pid_t api, - char * dif_name) +int irm_enroll_ipcp(pid_t api, + const char * dif_name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -220,7 +220,7 @@ int irm_enroll_ipcp(pid_t api, if (msg.dif_name == NULL) return -ENOMEM; - msg.dif_name[0] = dif_name; + msg.dif_name[0] = (char *) dif_name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { @@ -240,7 +240,7 @@ int irm_enroll_ipcp(pid_t api, return ret; } -static int check_ap(char * ap_name) +static int check_ap(const char * ap_name) { struct stat s; @@ -265,6 +265,8 @@ static int check_ap_path(char ** ap_name) bool perm = true; int ret = 0; + assert(ap_name); + if (*ap_name == NULL || path == NULL) return -EINVAL; @@ -320,11 +322,11 @@ static int check_ap_path(char ** ap_name) return -ENOENT; } -int irm_bind_ap(char * ap, - char * name, - uint16_t opts, - int argc, - char ** argv) +int irm_bind_ap(const char * ap, + const char * name, + uint16_t opts, + int argc, + char ** argv) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -344,12 +346,12 @@ int irm_bind_ap(char * ap, } msg.code = IRM_MSG_CODE__IRM_BIND_AP; - msg.dst_name = name; + msg.dst_name = (char *) name; msg.ap_name = full_ap_name; if (argv != NULL) { msg.n_args = argc; - msg.args = argv; + msg.args = (char **) argv; } msg.has_opts = true; @@ -373,7 +375,8 @@ int irm_bind_ap(char * ap, return ret; } -int irm_bind_api(pid_t api, char * name) +int irm_bind_api(pid_t api, + const char * name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -385,7 +388,7 @@ int irm_bind_api(pid_t api, char * name) msg.code = IRM_MSG_CODE__IRM_BIND_API; msg.has_api = true; msg.api = api; - msg.dst_name = name; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -402,7 +405,8 @@ int irm_bind_api(pid_t api, char * name) return ret; } -int irm_unbind_ap(char * ap, char * name) +int irm_unbind_ap(const char * ap, + const char * name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -412,8 +416,8 @@ int irm_unbind_ap(char * ap, char * name) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_UNBIND_AP; - msg.ap_name = ap; - msg.dst_name = name; + msg.ap_name = (char *) ap; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -430,7 +434,8 @@ int irm_unbind_ap(char * ap, char * name) return ret; } -int irm_unbind_api(pid_t api, char * name) +int irm_unbind_api(pid_t api, + const char * name) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; @@ -442,7 +447,7 @@ int irm_unbind_api(pid_t api, char * name) msg.code = IRM_MSG_CODE__IRM_UNBIND_API; msg.has_api = true; msg.api = api; - msg.dst_name = name; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -459,23 +464,23 @@ int irm_unbind_api(pid_t api, char * name) return ret; } -int irm_reg(char * name, - char ** difs, - size_t difs_size) +int irm_reg(const char * name, + char ** difs, + size_t len) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - if (name == NULL || difs == NULL || difs_size == 0) + if (name == NULL || difs == NULL || len == 0) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_REG; - msg.dst_name = name; + msg.dst_name = (char *) name; msg.dif_name = difs; - msg.n_dif_name = difs_size; + msg.n_dif_name = len; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) @@ -493,23 +498,23 @@ int irm_reg(char * name, } -int irm_unreg(char * name, - char ** difs, - size_t difs_size) +int irm_unreg(const char * name, + char ** difs, + size_t len) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; int ret = -1; - if (name == NULL || difs == NULL || difs_size == 0) + if (name == NULL || difs == NULL || len == 0) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_UNREG; - msg.dst_name = name; + msg.dst_name = (char *) name; - msg.dif_name = difs; - msg.n_dif_name = difs_size; + msg.dif_name = (char **) difs; + msg.n_dif_name = len; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index 55047aa5..eb51a278 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -321,7 +321,7 @@ void shm_rdrbuff_destroy(struct shm_rdrbuff * rdrb) ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, size_t headspace, size_t tailspace, - uint8_t * data, + const uint8_t * data, size_t len) { struct shm_du_buff * sdb; @@ -400,7 +400,7 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, size_t headspace, size_t tailspace, - uint8_t * data, + const uint8_t * data, size_t len) { struct shm_du_buff * sdb; -- cgit v1.2.3