summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/dir.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2017-01-04 11:35:18 +0100
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-01-04 11:35:18 +0100
commita241f53af601a8b9462b600a20381228f0f8e2e0 (patch)
tree3c8f23666da58259f67bc253314fa1e6952111e6 /src/ipcpd/normal/dir.c
parent004b586fd6b381fd1292aa276342163123be560a (diff)
parentf3fbf2c6093b293f995c4d784509577695e052b1 (diff)
downloadouroboros-a241f53af601a8b9462b600a20381228f0f8e2e0.tar.gz
ouroboros-a241f53af601a8b9462b600a20381228f0f8e2e0.zip
Merged in dstaesse/ouroboros/be-normal-refactor (pull request #331)
ipcpd: Refactor normal ipcp, initial commit
Diffstat (limited to 'src/ipcpd/normal/dir.c')
-rw-r--r--src/ipcpd/normal/dir.c49
1 files changed, 5 insertions, 44 deletions
diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c
index 47fb1f6e..c5bb03dd 100644
--- a/src/ipcpd/normal/dir.c
+++ b/src/ipcpd/normal/dir.c
@@ -1,5 +1,5 @@
/*
- * Ouroboros - Copyright (C) 2016
+ * Ouroboros - Copyright (C) 2016 - 2017
*
* DIF directory
*
@@ -26,7 +26,6 @@
#include <ouroboros/errno.h>
#include "dir.h"
-#include "ipcp.h"
#include "ro.h"
#include "pathname.h"
#include "ribmgr.h"
@@ -95,41 +94,27 @@ int dir_name_reg(char * name)
char * path;
uint64_t * addr;
- pthread_rwlock_rdlock(&ipcpi.state_lock);
-
- if (ipcp_get_state() != IPCP_OPERATIONAL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("IPCP is not in RUNNING state.");
- return -1;
- }
-
ro_attr_init(&attr);
attr.enrol_sync = true;
attr.recv_set = ALL_MEMBERS;
path = create_path(name);
- if (path == NULL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
+ if (path == NULL)
return -ENOMEM;
- }
addr = malloc(sizeof(*addr));
if (addr == NULL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
pathname_destroy(path);
return -ENOMEM;
}
*addr = ribmgr_address();
if (ro_create(path, &attr, (uint8_t *) addr, sizeof(*addr))) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
pathname_destroy(path);
LOG_ERR("Failed to create RIB object.");
return -1;
}
- pthread_rwlock_unlock(&ipcpi.state_lock);
-
LOG_DBG("Registered %s.", name);
pathname_destroy(path);
@@ -140,29 +125,16 @@ int dir_name_unreg(char * name)
{
char * path;
- pthread_rwlock_rdlock(&ipcpi.state_lock);
-
- if (ipcp_get_state() != IPCP_OPERATIONAL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
- LOG_ERR("IPCP is not in RUNNING state.");
- return -1;
- }
-
path = create_path(name);
- if (path == NULL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
+ if (path == NULL)
return -ENOMEM;
- }
if (ro_delete(path)) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
pathname_destroy(path);
LOG_ERR("No such RIB object exists.");
return -1;
}
- pthread_rwlock_unlock(&ipcpi.state_lock);
-
pathname_destroy(path);
return 0;
@@ -176,18 +148,9 @@ int dir_name_query(char * name)
uint64_t addr;
struct dt_const * dtc;
- pthread_rwlock_rdlock(&ipcpi.state_lock);
-
- if (ipcp_get_state() != IPCP_OPERATIONAL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
- return -1;
- }
-
path = create_path(name);
- if (path == NULL) {
- pthread_rwlock_unlock(&ipcpi.state_lock);
- return -1;
- }
+ if (path == NULL)
+ return -ENOMEM;
if (ro_exists(path)) {
if (ro_read(path, &ro_data) < 0) {
@@ -206,8 +169,6 @@ int dir_name_query(char * name)
ret = (addr == ribmgr_address()) ? -1 : 0;
}
- pthread_rwlock_unlock(&ipcpi.state_lock);
-
pathname_destroy(path);
return ret;