diff options
author | dimitri staessens <[email protected]> | 2016-07-05 18:52:12 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2016-07-05 19:07:25 +0200 |
commit | bc9c60382b226e5a75a11a99364b9b799dc2b0c2 (patch) | |
tree | f9072634e81bc152c0ca52b927ab9984a845e0e8 /src/lib | |
parent | db96f7d488681be47abfeec6c636fd4159a37660 (diff) | |
download | ouroboros-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/lib')
-rw-r--r-- | src/lib/dev.c | 6 | ||||
-rw-r--r-- | src/lib/ipcp.c | 2 | ||||
-rw-r--r-- | src/lib/irm.c | 6 | ||||
-rw-r--r-- | src/lib/irmd_messages.proto | 4 | ||||
-rw-r--r-- | src/lib/shm_ap_rbuff.c | 4 | ||||
-rw-r--r-- | src/lib/shm_du_map.c | 12 |
6 files changed, 17 insertions, 17 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index 19bc90e5..d85afc45 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -93,7 +93,7 @@ int ap_init(char * ap_name) for (i = 0; i < AP_MAX_FLOWS; ++i) { _ap_instance->flows[i].rb = NULL; _ap_instance->flows[i].port_id = -1; - _ap_instance->flows[i].api = 0; /* API_INVALID */ + _ap_instance->flows[i].api = -1; } pthread_rwlock_init(&_ap_instance->flows_lock, NULL); @@ -397,7 +397,7 @@ int flow_dealloc(int fd) _ap_instance->flows[fd].port_id = -1; shm_ap_rbuff_close(_ap_instance->flows[fd].rb); _ap_instance->flows[fd].rb = NULL; - _ap_instance->flows[fd].api = 0; + _ap_instance->flows[fd].api = -1; bmp_release(_ap_instance->fds, fd); @@ -543,7 +543,7 @@ ssize_t flow_read(int fd, void * buf, size_t count) if (_ap_instance->flows[fd].oflags & FLOW_O_NONBLOCK) { idx = shm_ap_rbuff_read_port(_ap_instance->rb, - _ap_instance->flows[fd].port_id); + _ap_instance->flows[fd].port_id); } else { /* block */ while ((idx = shm_ap_rbuff_read_port(_ap_instance->rb, diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index b336155e..e4a82b60 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -103,7 +103,7 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t api, pid_t ipcp_create(enum ipcp_type ipcp_type) { - pid_t api = 0; + pid_t api = -1; char irmd_api[10]; size_t len = 0; char * ipcp_dir = "/sbin/"; diff --git a/src/lib/irm.c b/src/lib/irm.c index ee1851a3..4c71817d 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -67,7 +67,7 @@ int irm_destroy_ipcp(pid_t api) irm_msg_t * recv_msg = NULL; int ret = -1; - if (api == 0) + if (api == -1) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP; @@ -97,7 +97,7 @@ int irm_bootstrap_ipcp(pid_t api, irm_msg_t * recv_msg = NULL; int ret = -1; - if (api == 0 || conf == NULL) + if (api == -1 || conf == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; @@ -209,7 +209,7 @@ int irm_enroll_ipcp(pid_t api, irm_msg_t * recv_msg = NULL; int ret = -1; - if (api == 0 || dif_name == NULL) + if (api == -1 || dif_name == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP; diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index fa2ca258..315d6092 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -47,7 +47,7 @@ message irm_msg { required irm_msg_code code = 1; optional string ap_name = 2; optional string ae_name = 3; - optional uint32 api = 4; + optional sint32 api = 4; optional uint32 ipcp_type = 5; repeated string dif_name = 6; repeated string args = 7; @@ -56,6 +56,6 @@ message irm_msg { optional sint32 port_id = 10; optional dif_config_msg conf = 11; optional uint32 opts = 12; - repeated int32 apis = 13; + repeated sint32 apis = 13; optional sint32 result = 14; }; diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c index f54627b7..e90afe19 100644 --- a/src/lib/shm_ap_rbuff.c +++ b/src/lib/shm_ap_rbuff.c @@ -348,9 +348,9 @@ ssize_t shm_ap_rbuff_read_port(struct shm_ap_rbuff * rb, int port_id) pid_t shm_ap_rbuff_get_api(struct shm_ap_rbuff *rb) { - pid_t api = 0; + pid_t api = -1; if (rb == NULL) - return 0; + return -1; pthread_mutex_lock(rb->shm_mutex); api = rb->api; diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c index cf0bad19..6289857f 100644 --- a/src/lib/shm_du_map.c +++ b/src/lib/shm_du_map.c @@ -89,12 +89,12 @@ static void garbage_collect(struct shm_du_map * dum) { #ifdef SHM_DU_MAP_MULTI_BLOCK struct shm_du_buff * sdb; - while ((sdb = get_tail_ptr(dum))->dst_api == 0 && + while ((sdb = get_tail_ptr(dum))->dst_api == -1 && !shm_map_empty(dum)) *dum->ptr_tail = (*dum->ptr_tail + sdb->blocks) & (SHM_BLOCKS_IN_MAP - 1); #else - while (get_tail_ptr(dum)->dst_api == 0 && + while (get_tail_ptr(dum)->dst_api == -1 && !shm_map_empty(dum)) *dum->ptr_tail = (*dum->ptr_tail + 1) & (SHM_BLOCKS_IN_MAP - 1); @@ -110,7 +110,7 @@ static void clean_sdus(struct shm_du_map * dum, pid_t api) while (idx != *dum->ptr_head) { buf = idx_to_du_buff_ptr(dum, idx); if (buf->dst_api == api) - buf->dst_api = 0; + buf->dst_api = -1; #ifdef SHM_DU_MAP_MULTI_BLOCK idx = (idx + buf->blocks) & (SHM_BLOCKS_IN_MAP - 1); #else @@ -271,7 +271,7 @@ struct shm_du_map * shm_du_map_open() pid_t shm_du_map_owner(struct shm_du_map * dum) { if (dum == NULL) - return 0; + return -1; return *dum->api; } @@ -444,7 +444,7 @@ ssize_t shm_du_map_write(struct shm_du_map * dum, sdb = get_head_ptr(dum); sdb->size = 0; sdb->blocks = padblocks; - sdb->dst_api = 0; + sdb->dst_api = -1; sdb->du_head = 0; sdb->du_tail = 0; @@ -518,7 +518,7 @@ int shm_du_map_remove(struct shm_du_map * dum, ssize_t idx) return -1; } - idx_to_du_buff_ptr(dum, idx)->dst_api = 0; + idx_to_du_buff_ptr(dum, idx)->dst_api = -1; if (idx != *dum->ptr_tail) { pthread_mutex_unlock(dum->shm_mutex); |