summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-07-05 18:52:12 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-07-05 19:07:25 +0200
commitbc9c60382b226e5a75a11a99364b9b799dc2b0c2 (patch)
treef9072634e81bc152c0ca52b927ab9984a845e0e8 /src/irmd
parentdb96f7d488681be47abfeec6c636fd4159a37660 (diff)
downloadouroboros-bc9c60382b226e5a75a11a99364b9b799dc2b0c2.tar.gz
ouroboros-bc9c60382b226e5a75a11a99364b9b799dc2b0c2.zip
lib: Change invalid pid to -1
The stack used pid 0 (the scheduler) to indicate an invalid process instance, probably as a leftover from the deprecated application process instance id. Using -1 is a better solution. Fixes #16.
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/main.c20
-rw-r--r--src/irmd/registry.c13
2 files changed, 16 insertions, 17 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 8475839b..de100cf8 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -51,8 +51,6 @@
#include <pthread.h>
#include <sys/stat.h>
-#define API_INVALID 0
-
#define IRMD_CLEANUP_TIMER ((IRMD_FLOW_TIMEOUT / 20) * MILLION) /* ns */
struct ipcp_entry {
@@ -114,9 +112,9 @@ static struct port_map_entry * port_map_entry_create()
if (e == NULL)
return NULL;
- e->n_api = 0;
- e->n_1_api = 0;
- e->port_id = 0;
+ e->n_api = -1;
+ e->n_1_api = -1;
+ e->port_id = -1;
e->state = FLOW_NULL;
if (pthread_cond_init(&e->res_signal, NULL)) {
@@ -256,7 +254,7 @@ static pid_t get_ipcp_by_dst_name(char * dst_name,
}
}
- return 0;
+ return -1;
}
static pid_t create_ipcp(char * name,
@@ -269,7 +267,7 @@ static pid_t create_ipcp(char * name,
if (instance->state != IRMD_RUNNING) {
pthread_rwlock_unlock(&instance->state_lock);
- return 0;
+ return -1;
}
api = ipcp_create(ipcp_type);
@@ -456,6 +454,9 @@ static int bind_name(char * name,
char ** argv_dup = NULL;
char * apn = path_strip(ap_name);
+ if (name == NULL || ap_name == NULL)
+ return -EINVAL;
+
pthread_rwlock_rdlock(&instance->state_lock);
if (instance->state != IRMD_RUNNING) {
@@ -578,6 +579,9 @@ static int ap_reg(char * name,
struct reg_entry * reg = NULL;
struct list_head * pos = NULL;
+ if (name == NULL || difs == NULL || len == 0 || difs[0] == NULL)
+ return -EINVAL;
+
pthread_rwlock_rdlock(&instance->state_lock);
if (instance->state != IRMD_RUNNING) {
@@ -1113,7 +1117,7 @@ static struct port_map_entry * flow_req_arr(pid_t api,
case REG_NAME_FLOW_ACCEPT:
pme->n_api = reg_entry_resolve_api(rne);
- if (pme->n_api == 0) {
+ if (pme->n_api == -1) {
pthread_rwlock_unlock(&instance->reg_lock);
pthread_rwlock_unlock(&instance->state_lock);
LOG_ERR("Invalid api returned.");
diff --git a/src/irmd/registry.c b/src/irmd/registry.c
index 063309a4..a4e2fcfa 100644
--- a/src/irmd/registry.c
+++ b/src/irmd/registry.c
@@ -290,7 +290,7 @@ pid_t reg_entry_resolve_api(struct reg_entry * e)
return r->api;
}
- return 0;
+ return -1;
}
char ** reg_entry_resolve_auto(struct reg_entry * e)
@@ -498,7 +498,7 @@ struct reg_instance * registry_add_ap_instance(struct list_head * registry,
struct reg_entry * e = NULL;
struct reg_instance * i = NULL;
- if (name == NULL || api == 0)
+ if (name == NULL || api == -1)
return NULL;
e = registry_get_entry_by_name(registry, name);
@@ -507,11 +507,6 @@ struct reg_instance * registry_add_ap_instance(struct list_head * registry,
return NULL;
}
- if (api == 0) {
- LOG_DBG("Invalid api.");
- return NULL;
- }
-
if (reg_entry_has_api(e, api)) {
LOG_DBG("Instance already registered with this name.");
return NULL;
@@ -546,8 +541,8 @@ int registry_remove_ap_instance(struct list_head * registry,
struct reg_entry * e = NULL;
struct reg_instance * i = NULL;
- if (name == NULL || api == 0)
- return -1;
+ if (name == NULL || api == -1)
+ return -EINVAL;
e = registry_get_entry_by_name(registry, name);
if (e == NULL) {