diff options
author | Dimitri Staessens <dimitri.staessens@ugent.be> | 2017-12-02 14:01:03 +0100 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-12-02 14:56:20 +0100 |
commit | 9b8a3e11c558877c09416991ff1ec840fea6d0ab (patch) | |
tree | f2faf7a4ab45687782a010fb6e48829e8ee1bdeb /src/lib | |
parent | f43e5e2329fb798047d15dd0748e5eef3359c966 (diff) | |
download | ouroboros-9b8a3e11c558877c09416991ff1ec840fea6d0ab.tar.gz ouroboros-9b8a3e11c558877c09416991ff1ec840fea6d0ab.zip |
lib, tools: Rename application process and instance
This refactors ouroboros to use "program" instead of "application
process" and "process" instead of "application process instance" to
align with current naming in current Operating Systems courses instead
of the ISO nomenclature adopted by RINA. This change permeates through
the entire implementation. Also contains some minor other refactors.
Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be>
Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/lib/config.h.in | 6 | ||||
-rw-r--r-- | src/lib/dev.c | 118 | ||||
-rw-r--r-- | src/lib/hashtable.c | 2 | ||||
-rw-r--r-- | src/lib/ipcpd_messages.proto | 2 | ||||
-rw-r--r-- | src/lib/irm.c | 201 | ||||
-rw-r--r-- | src/lib/irmd_messages.proto | 16 | ||||
-rw-r--r-- | src/lib/lockfile.c | 20 | ||||
-rw-r--r-- | src/lib/shm_flow_set.c | 46 | ||||
-rw-r--r-- | src/lib/shm_rbuff.c | 27 | ||||
-rw-r--r-- | src/lib/shm_rbuff_ll.c | 2 | ||||
-rw-r--r-- | src/lib/shm_rbuff_pthr.c | 2 | ||||
-rw-r--r-- | src/lib/shm_rdrbuff.c | 8 | ||||
-rw-r--r-- | src/lib/sockets.c | 18 |
14 files changed, 240 insertions, 234 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index db99bc97..2460ce41 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -140,11 +140,11 @@ set(SHM_BUFFER_SIZE ${SHM_BUFFER_EXPR} CACHE STRING "Number of blocks in SDU buffer, must be a power of 2") set(SYS_MAX_FLOWS 10240 CACHE STRING "Maximum number of total flows for this system") -set(AP_MAX_FLOWS 4096 CACHE STRING +set(PROG_MAX_FLOWS 4096 CACHE STRING "Maximum number of flows in an application") -set(AP_RES_FDS 64 CACHE STRING +set(PROG_RES_FDS 64 CACHE STRING "Number of reserved flow descriptors per application") -set(AP_MAX_FQUEUES 32 CACHE STRING +set(PROG_MAX_FQUEUES 32 CACHE STRING "Maximum number of flow sets per application") set(DU_BUFF_HEADSPACE 128 CACHE STRING "Bytes of headspace to reserve for future headers") diff --git a/src/lib/config.h.in b/src/lib/config.h.in index 40ac945d..b4b973f2 100644 --- a/src/lib/config.h.in +++ b/src/lib/config.h.in @@ -53,9 +53,9 @@ #define PTHREAD_COND_CLOCK @PTHREAD_COND_CLOCK@ -#define AP_MAX_FLOWS @AP_MAX_FLOWS@ -#define AP_RES_FDS @AP_RES_FDS@ -#define AP_MAX_FQUEUES @AP_MAX_FQUEUES@ +#define PROG_MAX_FLOWS @PROG_MAX_FLOWS@ +#define PROG_RES_FDS @PROG_RES_FDS@ +#define PROG_MAX_FQUEUES @PROG_MAX_FQUEUES@ #define DU_BUFF_HEADSPACE @DU_BUFF_HEADSPACE@ #define DU_BUFF_TAILSPACE @DU_BUFF_TAILSPACE@ diff --git a/src/lib/dev.c b/src/lib/dev.c index a577ca80..3fca56a1 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -93,7 +93,7 @@ struct flow { qoscube_t cube; qosspec_t spec; - pid_t api; + pid_t pid; bool snd_timesout; bool rcv_timesout; @@ -104,8 +104,8 @@ struct flow { }; struct { - char * ap_name; - pid_t api; + char * prog; + pid_t pid; struct shm_rdrbuff * rdrb; struct shm_flow_set * fqset; @@ -198,17 +198,17 @@ static enum port_state port_wait_assign(int port_id) return state; } -static int api_announce(char * ap_name) +static int proc_announce(char * prog) { - irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; - msg.code = IRM_MSG_CODE__IRM_API_ANNOUNCE; - msg.has_api = true; + msg.code = IRM_MSG_CODE__IRM_PROC_ANNOUNCE; + msg.has_pid = true; - msg.api = ai.api; - msg.ap_name = ap_name; + msg.pid = ai.pid; + msg.prog_name = prog; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) { @@ -230,7 +230,7 @@ static void flow_clear(int fd) memset(&ai.flows[fd], 0, sizeof(ai.flows[fd])); ai.flows[fd].port_id = -1; - ai.flows[fd].api = -1; + ai.flows[fd].pid = -1; ai.flows[fd].cube = QOS_CUBE_BE; } @@ -259,7 +259,7 @@ static void flow_fini(int fd) } static int flow_init(int port_id, - pid_t api, + pid_t pid, qoscube_t qc) { int fd; @@ -273,21 +273,21 @@ static int flow_init(int port_id, goto fail_fds; } - ai.flows[fd].rx_rb = shm_rbuff_open(ai.api, port_id); + ai.flows[fd].rx_rb = shm_rbuff_open(ai.pid, port_id); if (ai.flows[fd].rx_rb == NULL) goto fail; - ai.flows[fd].tx_rb = shm_rbuff_open(api, port_id); + ai.flows[fd].tx_rb = shm_rbuff_open(pid, port_id); if (ai.flows[fd].tx_rb == NULL) goto fail; - ai.flows[fd].set = shm_flow_set_open(api); + ai.flows[fd].set = shm_flow_set_open(pid); if (ai.flows[fd].set == NULL) goto fail; ai.flows[fd].port_id = port_id; ai.flows[fd].oflags = FLOWFDEFAULT; - ai.flows[fd].api = api; + ai.flows[fd].pid = pid; ai.flows[fd].cube = qc; ai.flows[fd].spec = qos_cube_to_spec(qc); @@ -320,24 +320,24 @@ static void init(int argc, char ** argv, char ** envp) { - const char * ap_name = argv[0]; + const char * prog = argv[0]; int i; (void) argc; (void) envp; - assert(ai.ap_name == NULL); + assert(ai.prog == NULL); if (check_python(argv[0])) - ap_name = argv[1]; + prog = argv[1]; - ai.api = getpid(); + ai.pid = getpid(); - ai.fds = bmp_create(AP_MAX_FLOWS - AP_RES_FDS, AP_RES_FDS); + ai.fds = bmp_create(PROG_MAX_FLOWS - PROG_RES_FDS, PROG_RES_FDS); if (ai.fds == NULL) goto fail_fds; - ai.fqueues = bmp_create(AP_MAX_FQUEUES, 0); + ai.fqueues = bmp_create(PROG_MAX_FQUEUES, 0); if (ai.fqueues == NULL) goto fail_fqueues; @@ -349,23 +349,23 @@ static void init(int argc, if (ai.rdrb == NULL) goto fail_rdrb; - ai.flows = malloc(sizeof(*ai.flows) * AP_MAX_FLOWS); + ai.flows = malloc(sizeof(*ai.flows) * PROG_MAX_FLOWS); if (ai.flows == NULL) goto fail_flows; - for (i = 0; i < AP_MAX_FLOWS; ++i) + for (i = 0; i < PROG_MAX_FLOWS; ++i) flow_clear(i); ai.ports = malloc(sizeof(*ai.ports) * SYS_MAX_FLOWS); if (ai.ports == NULL) goto fail_ports; - if (ap_name != NULL) { - ai.ap_name = strdup(path_strip((char *) ap_name)); - if (ai.ap_name == NULL) - goto fail_ap_name; + if (prog != NULL) { + ai.prog = strdup(path_strip((char *) prog)); + if (ai.prog == NULL) + goto fail_prog; - if (api_announce((char *) ai.ap_name)) + if (proc_announce((char *) ai.prog)) goto fail_announce; } @@ -402,8 +402,8 @@ static void init(int argc, for (i = 0; i < SYS_MAX_FLOWS; ++i) pthread_mutex_destroy(&ai.ports[i].state_lock); fail_announce: - free(ai.ap_name); - fail_ap_name: + free(ai.prog); + fail_prog: free(ai.ports); fail_ports: free(ai.flows); @@ -433,12 +433,12 @@ static void fini(void) shm_flow_set_destroy(ai.fqset); - if (ai.ap_name != NULL) - free(ai.ap_name); + if (ai.prog != NULL) + free(ai.prog); pthread_rwlock_wrlock(&ai.lock); - for (i = 0; i < AP_MAX_FLOWS; ++i) { + for (i = 0; i < PROG_MAX_FLOWS; ++i) { if (ai.flows[i].port_id != -1) { ssize_t idx; while ((idx = shm_rbuff_read(ai.flows[i].rx_rb)) >= 0) @@ -487,8 +487,8 @@ int flow_accept(qosspec_t * qs, int fd = -1; msg.code = IRM_MSG_CODE__IRM_FLOW_ACCEPT; - msg.has_api = true; - msg.api = ai.api; + msg.has_pid = true; + msg.pid = ai.pid; if (timeo != NULL) { msg.has_timeo_sec = true; @@ -512,13 +512,13 @@ int flow_accept(qosspec_t * qs, return res; } - if (!recv_msg->has_api || !recv_msg->has_port_id || + if (!recv_msg->has_pid || !recv_msg->has_port_id || !recv_msg->has_qoscube) { irm_msg__free_unpacked(recv_msg, NULL); return -EIRMD; } - fd = flow_init(recv_msg->port_id, recv_msg->api, recv_msg->qoscube); + fd = flow_init(recv_msg->port_id, recv_msg->pid, recv_msg->qoscube); irm_msg__free_unpacked(recv_msg, NULL); @@ -557,9 +557,9 @@ int flow_alloc(const char * dst_name, msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC; msg.dst_name = (char *) dst_name; - msg.has_api = true; + msg.has_pid = true; msg.has_qoscube = true; - msg.api = ai.api; + msg.pid = ai.pid; if (qs != NULL) qc = qos_spec_to_cube(*qs); @@ -588,12 +588,12 @@ int flow_alloc(const char * dst_name, return res; } - if (!recv_msg->has_api || !recv_msg->has_port_id) { + if (!recv_msg->has_pid || !recv_msg->has_port_id) { irm_msg__free_unpacked(recv_msg, NULL); return -EIRMD; } - fd = flow_init(recv_msg->port_id, recv_msg->api, qc); + fd = flow_init(recv_msg->port_id, recv_msg->pid, qc); irm_msg__free_unpacked(recv_msg, NULL); @@ -627,8 +627,8 @@ int flow_dealloc(int fd) msg.code = IRM_MSG_CODE__IRM_FLOW_DEALLOC; msg.has_port_id = true; - msg.has_api = true; - msg.api = ai.api; + msg.has_pid = true; + msg.pid = ai.pid; pthread_rwlock_rdlock(&ai.lock); @@ -672,7 +672,7 @@ int fccntl(int fd, uint32_t tx_acl; struct flow * flow; - if (fd < 0 || fd >= AP_MAX_FLOWS) + if (fd < 0 || fd >= PROG_MAX_FLOWS) return -EBADF; flow = &ai.flows[fd]; @@ -807,7 +807,7 @@ ssize_t flow_write(int fd, if (buf == NULL) return 0; - if (fd < 0 || fd > AP_MAX_FLOWS) + if (fd < 0 || fd > PROG_MAX_FLOWS) return -EBADF; flow = &ai.flows[fd]; @@ -876,7 +876,7 @@ ssize_t flow_read(int fd, struct flow * flow; bool noblock; - if (fd < 0 || fd > AP_MAX_FLOWS) + if (fd < 0 || fd > PROG_MAX_FLOWS) return -EBADF; flow = &ai.flows[fd]; @@ -998,7 +998,7 @@ int fset_add(struct flow_set * set, size_t sdus; size_t i; - if (set == NULL || fd < 0 || fd > AP_MAX_FLOWS) + if (set == NULL || fd < 0 || fd > PROG_MAX_FLOWS) return -EINVAL; pthread_rwlock_wrlock(&ai.lock); @@ -1017,7 +1017,7 @@ int fset_add(struct flow_set * set, void fset_del(struct flow_set * set, int fd) { - if (set == NULL || fd < 0 || fd > AP_MAX_FLOWS) + if (set == NULL || fd < 0 || fd > PROG_MAX_FLOWS) return; pthread_rwlock_wrlock(&ai.lock); @@ -1111,11 +1111,11 @@ int fevent(struct flow_set * set, /* ipcp-dev functions. */ -int np1_flow_alloc(pid_t n_api, +int np1_flow_alloc(pid_t n_pid, int port_id, qoscube_t qc) { - return flow_init(port_id, n_api, qc); + return flow_init(port_id, n_pid, qc); } int np1_flow_dealloc(int port_id) @@ -1147,7 +1147,7 @@ int np1_flow_resp(int port_id) return fd; } -int ipcp_create_r(pid_t api, +int ipcp_create_r(pid_t pid, int result) { irm_msg_t msg = IRM_MSG__INIT; @@ -1155,8 +1155,8 @@ int ipcp_create_r(pid_t api, int ret = -1; msg.code = IRM_MSG_CODE__IPCP_CREATE_R; - msg.has_api = true; - msg.api = api; + msg.has_pid = true; + msg.pid = pid; msg.has_result = true; msg.result = result; @@ -1175,7 +1175,7 @@ int ipcp_create_r(pid_t api, return ret; } -int ipcp_flow_req_arr(pid_t api, +int ipcp_flow_req_arr(pid_t pid, const uint8_t * dst, size_t len, qoscube_t qc) @@ -1188,8 +1188,8 @@ int ipcp_flow_req_arr(pid_t api, return -EINVAL; msg.code = IRM_MSG_CODE__IPCP_FLOW_REQ_ARR; - msg.has_api = true; - msg.api = api; + msg.has_pid = true; + msg.pid = pid; msg.has_hash = true; msg.hash.len = len; msg.hash.data = (uint8_t *) dst; @@ -1201,7 +1201,7 @@ int ipcp_flow_req_arr(pid_t api, if (recv_msg == NULL) return -EIRMD; - if (!recv_msg->has_port_id || !recv_msg->has_api) { + if (!recv_msg->has_port_id || !recv_msg->has_pid) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -1211,7 +1211,7 @@ int ipcp_flow_req_arr(pid_t api, return -1; } - fd = flow_init(recv_msg->port_id, recv_msg->api, qc); + fd = flow_init(recv_msg->port_id, recv_msg->pid, qc); irm_msg__free_unpacked(recv_msg, NULL); diff --git a/src/lib/hashtable.c b/src/lib/hashtable.c index 16de8bc9..f3f3a64d 100644 --- a/src/lib/hashtable.c +++ b/src/lib/hashtable.c @@ -127,7 +127,7 @@ static uint64_t hash(uint64_t key) static uint64_t calc_key(struct htable * table, uint64_t key) { - if (table->hash_key == true) + if (table->hash_key) key = hash(key); return (key & (table->buckets_size - 1)); diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto index adf0737f..2f4e5b26 100644 --- a/src/lib/ipcpd_messages.proto +++ b/src/lib/ipcpd_messages.proto @@ -46,7 +46,7 @@ message ipcp_msg { optional string dst_name = 5; optional uint32 qoscube = 6; optional ipcp_config_msg conf = 7; - optional int32 api = 8; + optional int32 pid = 8; optional dif_info_msg dif_info = 9; optional int32 response = 10; optional string comp_name = 11; diff --git a/src/lib/irm.c b/src/lib/irm.c index 0b949e5a..e323ee28 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -36,20 +36,23 @@ pid_t irm_create_ipcp(const char * name, enum ipcp_type ipcp_type) { - irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; - msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; - msg.dst_name = (char *) name; + if (name == NULL) + return -EINVAL; + + msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; + msg.dst_name = (char *) name; msg.has_ipcp_type = true; - msg.ipcp_type = ipcp_type; + msg.ipcp_type = ipcp_type; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -60,24 +63,24 @@ pid_t irm_create_ipcp(const char * name, return ret; } -int irm_destroy_ipcp(pid_t api) +int irm_destroy_ipcp(pid_t pid) { - irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; - if (api == -1) + if (pid < 0) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_DESTROY_IPCP; - msg.has_api = true; - msg.api = api; + msg.has_pid = true; + msg.pid = pid; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -88,7 +91,7 @@ int irm_destroy_ipcp(pid_t api) return ret; } -int irm_bootstrap_ipcp(pid_t api, +int irm_bootstrap_ipcp(pid_t pid, const struct ipcp_config * conf) { irm_msg_t msg = IRM_MSG__INIT; @@ -97,12 +100,12 @@ int irm_bootstrap_ipcp(pid_t api, irm_msg_t * recv_msg = NULL; int ret = -1; - if (api == -1 || conf == NULL) + if (pid == -1 || conf == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP; - msg.has_api = true; - msg.api = api; + msg.has_pid = true; + msg.pid = pid; config.dif_info = &dif_info; msg.conf = &config; @@ -146,7 +149,7 @@ int irm_bootstrap_ipcp(pid_t api, if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -EIRMD; } @@ -157,7 +160,7 @@ int irm_bootstrap_ipcp(pid_t api, return ret; } -int irm_connect_ipcp(pid_t api, +int irm_connect_ipcp(pid_t pid, const char * dst, const char * component) { @@ -168,14 +171,14 @@ int irm_connect_ipcp(pid_t api, msg.code = IRM_MSG_CODE__IRM_CONNECT_IPCP; msg.dst_name = (char *) dst; msg.comp_name = (char *) component; - msg.has_api = true; - msg.api = api; + msg.has_pid = true; + msg.pid = pid; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -EIRMD; } @@ -186,7 +189,7 @@ int irm_connect_ipcp(pid_t api, return ret; } -int irm_disconnect_ipcp(pid_t api, +int irm_disconnect_ipcp(pid_t pid, const char * dst, const char * component) { @@ -197,14 +200,14 @@ int irm_disconnect_ipcp(pid_t api, msg.code = IRM_MSG_CODE__IRM_DISCONNECT_IPCP; msg.dst_name = (char *) dst; msg.comp_name = (char *) component; - msg.has_api = true; - msg.api = api; + msg.has_pid = true; + msg.pid = pid; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -EIRMD; } @@ -216,14 +219,14 @@ int irm_disconnect_ipcp(pid_t api, } ssize_t irm_list_ipcps(const char * name, - pid_t ** apis) + pid_t ** pids) { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; size_t nr = 0; size_t i; - if (apis == NULL) + if (pids == NULL) return -EINVAL; msg.code = IRM_MSG_CODE__IRM_LIST_IPCPS; @@ -233,41 +236,41 @@ ssize_t irm_list_ipcps(const char * name, if (recv_msg == NULL) return -EIRMD; - if (recv_msg->apis == NULL) { + if (recv_msg->pids == NULL) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } - nr = recv_msg->n_apis; - *apis = malloc(nr * sizeof(pid_t)); - if (*apis == NULL) { + nr = recv_msg->n_pids; + *pids = malloc(nr * sizeof(pid_t)); + if (*pids == NULL) { irm_msg__free_unpacked(recv_msg, NULL); return -ENOMEM; } for (i = 0; i < nr; i++) - (*apis)[i] = recv_msg->apis[i]; + (*pids)[i] = recv_msg->pids[i]; irm_msg__free_unpacked(recv_msg, NULL); return nr; } -int irm_enroll_ipcp(pid_t api, +int irm_enroll_ipcp(pid_t pid, const char * dif_name) { - irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; - if (api == -1 || dif_name == NULL) + if (pid == -1 || dif_name == NULL) return -EINVAL; - msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP; - msg.has_api = true; - msg.api = api; + msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP; + msg.has_pid = true; + msg.pid = pid; msg.n_dif_name = 1; - msg.dif_name = malloc(sizeof(*(msg.dif_name))); + msg.dif_name = malloc(sizeof(*(msg.dif_name))); if (msg.dif_name == NULL) return -ENOMEM; @@ -279,7 +282,7 @@ int irm_enroll_ipcp(pid_t api, return -EIRMD; } - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -291,11 +294,11 @@ int irm_enroll_ipcp(pid_t api, return ret; } -static int check_ap(const char * ap_name) +static int check_prog(const char * prog) { struct stat s; - if (stat(ap_name, &s) != 0) + if (stat(prog, &s) != 0) return -ENOENT; if (!(s.st_mode & S_IXUSR)) @@ -304,7 +307,7 @@ static int check_ap(const char * ap_name) return 0; } -static int check_ap_path(char ** ap_name) +static int check_prog_path(char ** prog) { char * path = getenv("PATH"); char * path_end = path + strlen(path) + 1; @@ -316,23 +319,23 @@ static int check_ap_path(char ** ap_name) bool perm = true; int ret = 0; - assert(ap_name); + assert(prog); - if (*ap_name == NULL || path == NULL) + if (*prog == NULL || path == NULL) return -EINVAL; - if (!strlen(path) || strchr(*ap_name, '/') != NULL) { - if ((ret = check_ap(*ap_name)) < 0) + if (!strlen(path) || strchr(*prog, '/') != NULL) { + if ((ret = check_prog(*prog)) < 0) return ret; return 0; } - tmp = malloc(strlen(path) + strlen(*ap_name) + 2); + tmp = malloc(strlen(path) + strlen(*prog) + 2); if (tmp == NULL) return -ENOMEM; tstop = tmp + strlen(path) + 1; - strcpy(tstop--, *ap_name); + strcpy(tstop--, *prog); while (pstop < path_end) { pstart = pstop; @@ -349,17 +352,17 @@ static int check_ap_path(char ** ap_name) strcpy(tstart, pstart); *tstop = '/'; - if ((ret = check_ap(tstart)) < 0) { + if ((ret = check_prog(tstart)) < 0) { if (ret == -EPERM) perm = false; continue; } - free(*ap_name); - *ap_name = strdup(tstart); + free(*prog); + *prog = strdup(tstart); free(tmp); - if (*ap_name == NULL) + if (*prog == NULL) return -ENOMEM; return 0; @@ -372,32 +375,32 @@ static int check_ap_path(char ** ap_name) return -ENOENT; } -int irm_bind_ap(const char * ap, - const char * name, - uint16_t opts, - int argc, - char ** argv) +int irm_bind_program(const char * prog, + const char * name, + uint16_t opts, + int argc, + char ** argv) { - irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - int ret = -1; - char * full_ap_name; + int ret = -1; + char * full_name; - if (ap == NULL || name == NULL) + if (prog == NULL || name == NULL) return -EINVAL; - full_ap_name = strdup(ap); - if (full_ap_name == NULL) + full_name = strdup(prog); + if (full_name == NULL) return -ENOMEM; - if ((ret = check_ap_path(&full_ap_name)) < 0) { - free(full_ap_name); + if ((ret = check_prog_path(&full_name)) < 0) { + free(full_name); return ret; } - msg.code = IRM_MSG_CODE__IRM_BIND_AP; - msg.dst_name = (char *) name; - msg.ap_name = full_ap_name; + msg.code = IRM_MSG_CODE__IRM_BIND_PROGRAM; + msg.dst_name = (char *) name; + msg.prog_name = full_name; if (argv != NULL) { msg.n_args = argc; @@ -409,12 +412,12 @@ int irm_bind_ap(const char * ap, recv_msg = send_recv_irm_msg(&msg); - free(full_ap_name); + free(full_name); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -425,26 +428,26 @@ int irm_bind_ap(const char * ap, return ret; } -int irm_bind_api(pid_t api, - const char * name) +int irm_bind_process(pid_t pid, + const char * name) { - irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; if (name == NULL) return -EINVAL; - msg.code = IRM_MSG_CODE__IRM_BIND_API; - msg.has_api = true; - msg.api = api; + msg.code = IRM_MSG_CODE__IRM_BIND_PROCESS; + msg.has_pid = true; + msg.pid = pid; msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -455,25 +458,25 @@ int irm_bind_api(pid_t api, return ret; } -int irm_unbind_ap(const char * ap, - const char * name) +int irm_unbind_program(const char * prog, + const char * name) { - irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; if (name == NULL) return -EINVAL; - msg.code = IRM_MSG_CODE__IRM_UNBIND_AP; - msg.ap_name = (char *) ap; - msg.dst_name = (char *) name; + msg.code = IRM_MSG_CODE__IRM_UNBIND_PROGRAM; + msg.prog_name = (char *) prog; + msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -484,26 +487,26 @@ int irm_unbind_ap(const char * ap, return ret; } -int irm_unbind_api(pid_t api, - const char * name) +int irm_unbind_process(pid_t pid, + const char * name) { - irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - int ret = -1; + int ret = -1; if (name == NULL) return -EINVAL; - msg.code = IRM_MSG_CODE__IRM_UNBIND_API; - msg.has_api = true; - msg.api = api; + msg.code = IRM_MSG_CODE__IRM_UNBIND_PROCESS; + msg.has_pid = true; + msg.pid = pid; msg.dst_name = (char *) name; recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -536,7 +539,7 @@ int irm_reg(const char * name, if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -570,7 +573,7 @@ int irm_unreg(const char * name, if (recv_msg == NULL) return -EIRMD; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index f3e79a43..bb2be55b 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -33,11 +33,11 @@ enum irm_msg_code { IRM_ENROLL_IPCP = 6; IRM_CONNECT_IPCP = 7; IRM_DISCONNECT_IPCP = 8; - IRM_BIND_AP = 9; - IRM_UNBIND_AP = 10; - IRM_API_ANNOUNCE = 11; - IRM_BIND_API = 12; - IRM_UNBIND_API = 13; + IRM_BIND_PROGRAM = 9; + IRM_UNBIND_PROGRAM = 10; + IRM_PROC_ANNOUNCE = 11; + IRM_BIND_PROCESS = 12; + IRM_UNBIND_PROCESS = 13; IRM_REG = 14; IRM_UNREG = 15; IRM_FLOW_ALLOC = 16; @@ -50,8 +50,8 @@ enum irm_msg_code { message irm_msg { required irm_msg_code code = 1; - optional string ap_name = 2; - optional sint32 api = 3; + optional string prog_name = 2; + optional sint32 pid = 3; optional uint32 ipcp_type = 4; repeated string dif_name = 5; repeated string args = 6; @@ -62,7 +62,7 @@ message irm_msg { optional sint32 qoscube = 11; optional ipcp_config_msg conf = 12; optional uint32 opts = 13; - repeated sint32 apis = 14; + repeated sint32 pids = 14; optional uint32 timeo_sec = 15; optional uint32 timeo_nsec = 16; optional string comp_name = 17; diff --git a/src/lib/lockfile.c b/src/lib/lockfile.c index 4a3dcb91..0d1bcd17 100644 --- a/src/lib/lockfile.c +++ b/src/lib/lockfile.c @@ -38,7 +38,7 @@ #define LF_SIZE (sizeof(pid_t)) struct lockfile { - pid_t * api; + pid_t * pid; }; struct lockfile * lockfile_create() { @@ -63,7 +63,7 @@ struct lockfile * lockfile_create() { return NULL; } - lf->api = mmap(NULL, + lf->pid = mmap(NULL, LF_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, @@ -71,13 +71,13 @@ struct lockfile * lockfile_create() { close (fd); - if (lf->api == MAP_FAILED) { + if (lf->pid == MAP_FAILED) { shm_unlink(SHM_LOCKFILE_NAME); free(lf); return NULL; } - *lf->api = getpid(); + *lf->pid = getpid(); return lf; } @@ -94,7 +94,7 @@ struct lockfile * lockfile_open() { return NULL; } - lf->api = mmap(NULL, + lf->pid = mmap(NULL, LF_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, @@ -102,7 +102,7 @@ struct lockfile * lockfile_open() { close(fd); - if (lf->api == MAP_FAILED) { + if (lf->pid == MAP_FAILED) { shm_unlink(SHM_LOCKFILE_NAME); free(lf); return NULL; @@ -115,7 +115,7 @@ void lockfile_close(struct lockfile * lf) { assert(lf); - munmap(lf->api, LF_SIZE); + munmap(lf->pid, LF_SIZE); free(lf); } @@ -124,10 +124,10 @@ void lockfile_destroy(struct lockfile * lf) { assert(lf); - if (getpid() != *lf->api && kill(*lf->api, 0) == 0) + if (getpid() != *lf->pid && kill(*lf->pid, 0) == 0) return; - munmap(lf->api, LF_SIZE); + munmap(lf->pid, LF_SIZE); shm_unlink(SHM_LOCKFILE_NAME); @@ -138,5 +138,5 @@ pid_t lockfile_owner(struct lockfile * lf) { assert(lf); - return *lf->api; + return *lf->pid; } diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c index 78fdce36..15192fd8 100644 --- a/src/lib/shm_flow_set.c +++ b/src/lib/shm_flow_set.c @@ -56,10 +56,10 @@ #define FQUEUESIZE ((SHM_BUFFER_SIZE) * sizeof(int)) -#define SHM_FLOW_SET_FILE_SIZE (SYS_MAX_FLOWS * sizeof(ssize_t) \ - + AP_MAX_FQUEUES * sizeof(size_t) \ - + AP_MAX_FQUEUES * sizeof(pthread_cond_t) \ - + AP_MAX_FQUEUES * FQUEUESIZE \ +#define SHM_FLOW_SET_FILE_SIZE (SYS_MAX_FLOWS * sizeof(ssize_t) \ + + PROG_MAX_FQUEUES * sizeof(size_t) \ + + PROG_MAX_FQUEUES * sizeof(pthread_cond_t) \ + + PROG_MAX_FQUEUES * FQUEUESIZE \ + sizeof(pthread_mutex_t)) #define fqueue_ptr(fs, idx) (fs->fqueues + (SHM_BUFFER_SIZE) * idx) @@ -71,7 +71,7 @@ struct shm_flow_set { int * fqueues; pthread_mutex_t * lock; - pid_t api; + pid_t pid; }; struct shm_flow_set * shm_flow_set_create() @@ -124,10 +124,10 @@ struct shm_flow_set * shm_flow_set_create() set->mtable = shm_base; set->heads = (size_t *) (set->mtable + SYS_MAX_FLOWS); - set->conds = (pthread_cond_t *)(set->heads + AP_MAX_FQUEUES); - set->fqueues = (int *) (set->conds + AP_MAX_FQUEUES); + set->conds = (pthread_cond_t *)(set->heads + PROG_MAX_FQUEUES); + set->fqueues = (int *) (set->conds + PROG_MAX_FQUEUES); set->lock = (pthread_mutex_t *) - (set->fqueues + AP_MAX_FQUEUES * (SHM_BUFFER_SIZE)); + (set->fqueues + PROG_MAX_FQUEUES * (SHM_BUFFER_SIZE)); pthread_mutexattr_init(&mattr); #ifdef HAVE_ROBUST_MUTEX @@ -141,7 +141,7 @@ struct shm_flow_set * shm_flow_set_create() #ifndef __APPLE__ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK); #endif - for (i = 0; i < AP_MAX_FQUEUES; ++i) { + for (i = 0; i < PROG_MAX_FQUEUES; ++i) { set->heads[i] = 0; pthread_cond_init(&set->conds[i], &cattr); } @@ -149,19 +149,19 @@ struct shm_flow_set * shm_flow_set_create() for (i = 0; i < SYS_MAX_FLOWS; ++i) set->mtable[i] = -1; - set->api = getpid(); + set->pid = getpid(); return set; } -struct shm_flow_set * shm_flow_set_open(pid_t api) +struct shm_flow_set * shm_flow_set_open(pid_t pid) { struct shm_flow_set * set; ssize_t * shm_base; char fn[FN_MAX_CHARS]; int shm_fd; - sprintf(fn, SHM_FLOW_SET_PREFIX "%d", api); + sprintf(fn, SHM_FLOW_SET_PREFIX "%d", pid); set = malloc(sizeof(*set)); if (set == NULL) @@ -190,12 +190,12 @@ struct shm_flow_set * shm_flow_set_open(pid_t api) set->mtable = shm_base; set->heads = (size_t *) (set->mtable + SYS_MAX_FLOWS); - set->conds = (pthread_cond_t *)(set->heads + AP_MAX_FQUEUES); - set->fqueues = (int *) (set->conds + AP_MAX_FQUEUES); + set->conds = (pthread_cond_t *)(set->heads + PROG_MAX_FQUEUES); + set->fqueues = (int *) (set->conds + PROG_MAX_FQUEUES); set->lock = (pthread_mutex_t *) - (set->fqueues + AP_MAX_FQUEUES * (SHM_BUFFER_SIZE)); + (set->fqueues + PROG_MAX_FQUEUES * (SHM_BUFFER_SIZE)); - set->api = api; + set->pid = pid; return set; } @@ -207,7 +207,7 @@ void shm_flow_set_destroy(struct shm_flow_set * set) assert(set); - if (set->api != getpid()) { + if (set->pid != getpid()) { lf = lockfile_open(); if (lf == NULL) return; @@ -220,7 +220,7 @@ void shm_flow_set_destroy(struct shm_flow_set * set) } } - sprintf(fn, SHM_FLOW_SET_PREFIX "%d", set->api); + sprintf(fn, SHM_FLOW_SET_PREFIX "%d", set->pid); munmap(set->mtable, SHM_FLOW_SET_FILE_SIZE); shm_unlink(fn); @@ -243,7 +243,7 @@ void shm_flow_set_zero(struct shm_flow_set * set, ssize_t i = 0; assert(set); - assert(idx < AP_MAX_FQUEUES); + assert(idx < PROG_MAX_FQUEUES); pthread_mutex_lock(set->lock); @@ -263,7 +263,7 @@ int shm_flow_set_add(struct shm_flow_set * set, { assert(set); assert(!(port_id < 0) && port_id < SYS_MAX_FLOWS); - assert(idx < AP_MAX_FQUEUES); + assert(idx < PROG_MAX_FQUEUES); pthread_mutex_lock(set->lock); @@ -285,7 +285,7 @@ void shm_flow_set_del(struct shm_flow_set * set, { assert(set); assert(!(port_id < 0) && port_id < SYS_MAX_FLOWS); - assert(idx < AP_MAX_FQUEUES); + assert(idx < PROG_MAX_FQUEUES); pthread_mutex_lock(set->lock); @@ -303,7 +303,7 @@ int shm_flow_set_has(struct shm_flow_set * set, assert(set); assert(!(port_id < 0) && port_id < SYS_MAX_FLOWS); - assert(idx < AP_MAX_FQUEUES); + assert(idx < PROG_MAX_FQUEUES); pthread_mutex_lock(set->lock); @@ -345,7 +345,7 @@ ssize_t shm_flow_set_wait(const struct shm_flow_set * set, ssize_t ret = 0; assert(set); - assert(idx < AP_MAX_FQUEUES); + assert(idx < PROG_MAX_FQUEUES); assert(fqueue); #ifndef HAVE_ROBUST_MUTEX diff --git a/src/lib/shm_rbuff.c b/src/lib/shm_rbuff.c index 00f0b92b..db957168 100644 --- a/src/lib/shm_rbuff.c +++ b/src/lib/shm_rbuff.c @@ -45,7 +45,7 @@ #define FN_MAX_CHARS 255 -#define SHM_RB_FILE_SIZE ((SHM_BUFFER_SIZE) * sizeof(ssize_t) \ +#define SHM_RB_FILE_SIZE ((SHM_BUFFER_SIZE) * sizeof(ssize_t) \ + 3 * sizeof(size_t) \ + sizeof(pthread_mutex_t) \ + 2 * sizeof (pthread_cond_t)) @@ -65,7 +65,7 @@ struct shm_rbuff { pthread_mutex_t * lock; /* lock all free space in shm */ pthread_cond_t * add; /* SDU arrived */ pthread_cond_t * del; /* SDU removed */ - pid_t api; /* api of the owner */ + pid_t pid; /* pid of the owner */ int port_id; /* port_id of the flow */ }; @@ -80,14 +80,16 @@ void shm_rbuff_close(struct shm_rbuff * rb) #define MM_FLAGS (PROT_READ | PROT_WRITE) -struct shm_rbuff * rbuff_create(pid_t api, int port_id, int flags) +struct shm_rbuff * rbuff_create(pid_t pid, + int port_id, + int flags) { struct shm_rbuff * rb; int fd; ssize_t * shm_base; char fn[FN_MAX_CHARS]; - sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", api, port_id); + sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", pid, port_id); rb = malloc(sizeof(*rb)); if (rb == NULL) @@ -113,9 +115,8 @@ struct shm_rbuff * rbuff_create(pid_t api, int port_id, int flags) rb->lock = (pthread_mutex_t *) (rb->acl + 1); rb->add = (pthread_cond_t *) (rb->lock + 1); rb->del = rb->add + 1; - - rb->api = api; - rb->port_id = port_id; + rb->pid = pid; + rb->port_id = port_id; return rb; @@ -129,7 +130,8 @@ struct shm_rbuff * rbuff_create(pid_t api, int port_id, int flags) return NULL; } -struct shm_rbuff * shm_rbuff_create(pid_t api, int port_id) +struct shm_rbuff * shm_rbuff_create(pid_t pid, + int port_id) { struct shm_rbuff * rb; pthread_mutexattr_t mattr; @@ -138,7 +140,7 @@ struct shm_rbuff * shm_rbuff_create(pid_t api, int port_id) mask = umask(0); - rb = rbuff_create(api, port_id, O_CREAT | O_EXCL | O_RDWR); + rb = rbuff_create(pid, port_id, O_CREAT | O_EXCL | O_RDWR); umask(mask); @@ -172,7 +174,7 @@ struct shm_rbuff * shm_rbuff_create(pid_t api, int port_id) *rb->head = 0; *rb->tail = 0; - rb->api = api; + rb->pid = pid; rb->port_id = port_id; pthread_mutexattr_destroy(&mattr); @@ -194,9 +196,10 @@ struct shm_rbuff * shm_rbuff_create(pid_t api, int port_id) return NULL; } -struct shm_rbuff * shm_rbuff_open(pid_t api, int port_id) +struct shm_rbuff * shm_rbuff_open(pid_t pid, + int port_id) { - return rbuff_create(api, port_id, O_RDWR); + return rbuff_create(pid, port_id, O_RDWR); } #if (defined(SHM_RBUFF_LOCKLESS) && \ diff --git a/src/lib/shm_rbuff_ll.c b/src/lib/shm_rbuff_ll.c index 6ac9af47..d38ee0e4 100644 --- a/src/lib/shm_rbuff_ll.c +++ b/src/lib/shm_rbuff_ll.c @@ -29,7 +29,7 @@ void shm_rbuff_destroy(struct shm_rbuff * rb) assert(rb); - sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", rb->api, rb->port_id); + sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", rb->pid, rb->port_id); shm_rbuff_close(rb); diff --git a/src/lib/shm_rbuff_pthr.c b/src/lib/shm_rbuff_pthr.c index 565bb1fa..51ef6495 100644 --- a/src/lib/shm_rbuff_pthr.c +++ b/src/lib/shm_rbuff_pthr.c @@ -33,7 +33,7 @@ void shm_rbuff_destroy(struct shm_rbuff * rb) pthread_mutex_unlock(rb->lock); #endif - sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", rb->api, rb->port_id); + sprintf(fn, SHM_RBUFF_PREFIX "%d.%d", rb->pid, rb->port_id); shm_rbuff_close(rb); diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index 4c00c74d..4145115a 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -103,7 +103,7 @@ struct shm_rdrbuff { pthread_mutex_t * lock; /* lock all free space in shm */ pthread_cond_t * full; /* flag when full */ pthread_cond_t * healthy; /* flag when SDU is read */ - pid_t * api; /* api of the irmd owner */ + pid_t * pid; /* pid of the irmd owner */ }; static void garbage_collect(struct shm_rdrbuff * rdrb) @@ -148,7 +148,7 @@ void shm_rdrbuff_destroy(struct shm_rdrbuff * rdrb) assert(rdrb); - if (getpid() != *rdrb->api && kill(*rdrb->api, 0) == 0) + if (getpid() != *rdrb->pid && kill(*rdrb->pid, 0) == 0) return; shm_rdrbuff_close(rdrb); @@ -197,7 +197,7 @@ static struct shm_rdrbuff * rdrb_create(int flags) rdrb->lock = (pthread_mutex_t *) (rdrb->tail + 1); rdrb->full = (pthread_cond_t *) (rdrb->lock + 1); rdrb->healthy = rdrb->full + 1; - rdrb->api = (pid_t *) (rdrb->healthy + 1); + rdrb->pid = (pid_t *) (rdrb->healthy + 1); free(shm_rdrb_fn); @@ -257,7 +257,7 @@ struct shm_rdrbuff * shm_rdrbuff_create() *rdrb->head = 0; *rdrb->tail = 0; - *rdrb->api = getpid(); + *rdrb->pid = getpid(); pthread_mutexattr_destroy(&mattr); pthread_condattr_destroy(&cattr); diff --git a/src/lib/sockets.c b/src/lib/sockets.c index 42676d11..d811a826 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -125,19 +125,19 @@ irm_msg_t * send_recv_irm_msg(irm_msg_t * msg) return recv_msg; } -char * ipcp_sock_path(pid_t api) +char * ipcp_sock_path(pid_t pid) { char * full_name = NULL; - char * api_string = NULL; + char * pid_string = NULL; size_t len = 0; char * delim = "_"; - len = n_digits(api); - api_string = malloc(len + 1); - if (api_string == NULL) + len = n_digits(pid); + pid_string = malloc(len + 1); + if (pid_string == NULL) return NULL; - sprintf(api_string, "%d", api); + sprintf(pid_string, "%d", pid); len += strlen(IPCP_SOCK_PATH_PREFIX); len += strlen(delim); @@ -145,16 +145,16 @@ char * ipcp_sock_path(pid_t api) full_name = malloc(len + 1); if (full_name == NULL) { - free(api_string); + free(pid_string); return NULL; } strcpy(full_name, IPCP_SOCK_PATH_PREFIX); strcat(full_name, delim); - strcat(full_name, api_string); + strcat(full_name, pid_string); strcat(full_name, SOCK_PATH_SUFFIX); - free(api_string); + free(pid_string); return full_name; } |