From 0f7c35900c3efc1c746f830f9304ab09b1afbc7d Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 28 Dec 2016 14:41:09 +0100 Subject: ipcpd: Rename normal/path to normal/pathname --- src/ipcpd/normal/CMakeLists.txt | 2 +- src/ipcpd/normal/dir.c | 2 +- src/ipcpd/normal/fmgr.c | 2 +- src/ipcpd/normal/path.c | 76 ----------------------------------------- src/ipcpd/normal/path.h | 34 ------------------ src/ipcpd/normal/pathname.c | 76 +++++++++++++++++++++++++++++++++++++++++ src/ipcpd/normal/pathname.h | 34 ++++++++++++++++++ src/ipcpd/normal/pol/flat.c | 2 +- src/ipcpd/normal/ribmgr.c | 2 +- 9 files changed, 115 insertions(+), 115 deletions(-) delete mode 100644 src/ipcpd/normal/path.c delete mode 100644 src/ipcpd/normal/path.h create mode 100644 src/ipcpd/normal/pathname.c create mode 100644 src/ipcpd/normal/pathname.h (limited to 'src') diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt index 5f85dd89..bdcb78ae 100644 --- a/src/ipcpd/normal/CMakeLists.txt +++ b/src/ipcpd/normal/CMakeLists.txt @@ -30,7 +30,7 @@ set(SOURCE_FILES fmgr.c frct.c main.c - path.c + pathname.c pff.c ribmgr.c shm_pci.c diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c index 905af2ed..47fb1f6e 100644 --- a/src/ipcpd/normal/dir.c +++ b/src/ipcpd/normal/dir.c @@ -28,7 +28,7 @@ #include "dir.h" #include "ipcp.h" #include "ro.h" -#include "path.h" +#include "pathname.h" #include "ribmgr.h" #include diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index 7917d61a..f7737b82 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -40,7 +40,7 @@ #include "ipcp.h" #include "shm_pci.h" #include "dir.h" -#include "path.h" +#include "pathname.h" #include "ro.h" #include "flow_alloc.pb-c.h" diff --git a/src/ipcpd/normal/path.c b/src/ipcpd/normal/path.c deleted file mode 100644 index ebd5719c..00000000 --- a/src/ipcpd/normal/path.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * Functions to construct pathnames - * - * Sander Vrijders - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#define OUROBOROS_PREFIX "pathnames" - -#include -#include -#include - -#include -#include -#include - -#include "path.h" - -char * pathname_create(const char * name) -{ - char * tmp; - - assert(name); - - tmp = malloc(strlen(name) + strlen(PATH_DELIMITER) + 1); - if (tmp == NULL) - return NULL; - - strcpy(tmp, PATH_DELIMITER); - strcat(tmp, name); - - return tmp; -} - -char * pathname_append(char * pname, - const char * name) -{ - char * tmp; - - assert(pname); - assert(name); - - tmp = malloc(strlen(pname) + - strlen(PATH_DELIMITER) + - strlen(name) + 1); - if (tmp == NULL) - return NULL; - - strcpy(tmp, pname); - strcat(tmp, PATH_DELIMITER); - strcat(tmp, name); - - free(pname); - - return tmp; -} - -void pathname_destroy(char * pname) -{ - free(pname); -} diff --git a/src/ipcpd/normal/path.h b/src/ipcpd/normal/path.h deleted file mode 100644 index 8689036f..00000000 --- a/src/ipcpd/normal/path.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * Functions to construct pathnames - * - * Sander Vrijders - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef OUROBOROS_IPCPD_NORMAL_PATH_H -#define OUROBOROS_IPCPD_NORMAL_PATH_H - -#define PATH_DELIMITER "/" - -char * pathname_create(const char * name); - -char * pathname_append(char * pname, - const char * name); - -void pathname_destroy(char * pname); - -#endif /* OUROBOROS_IPCPD_NORMAL_PATH_H */ diff --git a/src/ipcpd/normal/pathname.c b/src/ipcpd/normal/pathname.c new file mode 100644 index 00000000..cf6e08b0 --- /dev/null +++ b/src/ipcpd/normal/pathname.c @@ -0,0 +1,76 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Functions to construct pathnames + * + * Sander Vrijders + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define OUROBOROS_PREFIX "pathnames" + +#include +#include +#include + +#include +#include +#include + +#include "pathname.h" + +char * pathname_create(const char * name) +{ + char * tmp; + + assert(name); + + tmp = malloc(strlen(name) + strlen(PATH_DELIMITER) + 1); + if (tmp == NULL) + return NULL; + + strcpy(tmp, PATH_DELIMITER); + strcat(tmp, name); + + return tmp; +} + +char * pathname_append(char * pname, + const char * name) +{ + char * tmp; + + assert(pname); + assert(name); + + tmp = malloc(strlen(pname) + + strlen(PATH_DELIMITER) + + strlen(name) + 1); + if (tmp == NULL) + return NULL; + + strcpy(tmp, pname); + strcat(tmp, PATH_DELIMITER); + strcat(tmp, name); + + free(pname); + + return tmp; +} + +void pathname_destroy(char * pname) +{ + free(pname); +} diff --git a/src/ipcpd/normal/pathname.h b/src/ipcpd/normal/pathname.h new file mode 100644 index 00000000..dc91b7d9 --- /dev/null +++ b/src/ipcpd/normal/pathname.h @@ -0,0 +1,34 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Functions to construct pathnames + * + * Sander Vrijders + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef OUROBOROS_IPCPD_NORMAL_PATHNAME_H +#define OUROBOROS_IPCPD_NORMAL_PATHNAME_H + +#define PATH_DELIMITER "/" + +char * pathname_create(const char * name); + +char * pathname_append(char * pname, + const char * name); + +void pathname_destroy(char * pname); + +#endif /* OUROBOROS_IPCPD_NORMAL_PATHNAME_H */ diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c index 82c7db93..13eaf215 100644 --- a/src/ipcpd/normal/pol/flat.c +++ b/src/ipcpd/normal/pol/flat.c @@ -29,7 +29,7 @@ #include "shm_pci.h" #include "ribmgr.h" #include "ro.h" -#include "path.h" +#include "pathname.h" #include #include diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c index 15c3957f..d2ba8deb 100644 --- a/src/ipcpd/normal/ribmgr.c +++ b/src/ipcpd/normal/ribmgr.c @@ -42,7 +42,7 @@ #include "frct.h" #include "ipcp.h" #include "ro.h" -#include "path.h" +#include "pathname.h" #include "dir.h" #include "static_info.pb-c.h" -- cgit v1.2.3 From 9766166aa944fc6d8754f1b2c5262d7044690c50 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 28 Dec 2016 14:46:16 +0100 Subject: ipcpd: Wait for operational state to start fmgr The main thread will wait for the IPCP_OPERATIONAL state before starting the fmgr main thread by calling fmgr_init(), instead of the fmgr itself waiting for that state. --- src/ipcpd/normal/fmgr.c | 16 +++------------- src/ipcpd/normal/main.c | 12 +++++++----- 2 files changed, 10 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index f7737b82..d8190572 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -78,16 +78,8 @@ static void * fmgr_nm1_acceptor(void * o) (void) o; while (true) { - ipcp_wait_state(IPCP_OPERATIONAL, NULL); - - pthread_rwlock_rdlock(&ipcpi.state_lock); - - if (ipcp_get_state() == IPCP_SHUTDOWN) { - pthread_rwlock_unlock(&ipcpi.state_lock); + if (ipcp_get_state() == IPCP_SHUTDOWN) return 0; - } - - pthread_rwlock_unlock(&ipcpi.state_lock); fd = flow_accept(&ae_name, &qs); if (fd < 0) { @@ -594,8 +586,7 @@ int fmgr_np1_post_buf(cep_id_t cep_id, buffer_t * buf) return ret; } -int fmgr_np1_post_sdu(cep_id_t cep_id, - struct shm_du_buff * sdb) +int fmgr_np1_post_sdu(cep_id_t cep_id, struct shm_du_buff * sdb) { int fd; @@ -687,8 +678,7 @@ int fmgr_nm1_write_sdu(struct pci * pci, struct shm_du_buff * sdb) return 0; } -int fmgr_nm1_write_buf(struct pci * pci, - buffer_t * buf) +int fmgr_nm1_write_buf(struct pci * pci, buffer_t * buf) { buffer_t * buffer; diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 4eb708b4..34ba52da 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -215,22 +215,24 @@ int main(int argc, char * argv[]) pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); - if (fmgr_init()) { + if (ribmgr_init()) { + fmgr_fini(); ipcp_fini(); close_logfile(); exit(EXIT_FAILURE); } - if (ribmgr_init()) { + if (ipcp_create_r(getpid())) { + LOG_ERR("Failed to notify IRMd we are initialized."); fmgr_fini(); ipcp_fini(); close_logfile(); exit(EXIT_FAILURE); } - if (ipcp_create_r(getpid())) { - LOG_ERR("Failed to notify IRMd we are initialized."); - fmgr_fini(); + ipcp_wait_state(IPCP_OPERATIONAL, NULL); + + if (fmgr_init()) { ipcp_fini(); close_logfile(); exit(EXIT_FAILURE); -- cgit v1.2.3 From e8d6e91203b0521572b0ae32202e69944dde8f04 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 28 Dec 2016 16:02:57 +0100 Subject: ipcpd: Fix memleak in ribmgr --- src/ipcpd/normal/ribmgr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c index d2ba8deb..3b4a5784 100644 --- a/src/ipcpd/normal/ribmgr.c +++ b/src/ipcpd/normal/ribmgr.c @@ -971,18 +971,23 @@ static void * cdap_req_handler(void * o) if (opcode == CDAP_START) { if (ribmgr_cdap_start(instance, key, name)) LOG_WARN("CDAP start failed."); + free(name); continue; } else if (opcode == CDAP_STOP) { if (ribmgr_cdap_stop(instance, key, name)) LOG_WARN("CDAP stop failed."); + free(name); continue; } + assert(len > 0); + msg = ro_msg__unpack(NULL, len, data); if (msg == NULL) { cdap_reply_send(instance, key, -1, NULL, 0); LOG_WARN("Failed to unpack RO message"); + free(data); continue; } @@ -996,6 +1001,7 @@ static void * cdap_req_handler(void * o) ro_msg__free_unpacked(msg, NULL); cdap_reply_send(instance, key, 0, NULL, 0); LOG_DBG("Already received this RO."); + free(name); continue; } } @@ -1005,6 +1011,7 @@ static void * cdap_req_handler(void * o) if (ribmgr_cdap_create(instance, key, name, msg)) { LOG_WARN("CDAP create failed."); ro_msg__free_unpacked(msg, NULL); + free(name); continue; } } else if (opcode == CDAP_WRITE) { @@ -1012,24 +1019,28 @@ static void * cdap_req_handler(void * o) msg, flags)) { LOG_WARN("CDAP write failed."); ro_msg__free_unpacked(msg, NULL); + free(name); continue; } } else if (opcode == CDAP_DELETE) { if (ribmgr_cdap_delete(instance, key, name)) { LOG_WARN("CDAP delete failed."); ro_msg__free_unpacked(msg, NULL); + free(name); continue; } } else { LOG_INFO("Unsupported opcode received."); ro_msg__free_unpacked(msg, NULL); cdap_reply_send(instance, key, -1, NULL, 0); + free(name); continue; } if (ro_id_create(name, msg)) { LOG_WARN("Failed to create RO id."); ro_msg__free_unpacked(msg, NULL); + free(name); continue; } @@ -1050,6 +1061,7 @@ static void * cdap_req_handler(void * o) pthread_rwlock_unlock(&rib.flows_lock); } + free(name); ro_msg__free_unpacked(msg, NULL); } -- cgit v1.2.3