diff options
67 files changed, 1204 insertions, 1177 deletions
diff --git a/doc/man/flow_alloc.3 b/doc/man/flow_alloc.3 index cc505df6..1b3c232c 100644 --- a/doc/man/flow_alloc.3 +++ b/doc/man/flow_alloc.3 @@ -2,13 +2,12 @@ .\" Dimitri Staessens <dimitri.staessens@ugent.be> .\" Sander Vrijders <sander.vrijders@ugent.be> -.TH FLOW_ALLOC 3 2017-04-10 Ouroboros "Ouroboros Programmer's Manual" +.TH FLOW_ALLOC 3 2017-12-02 Ouroboros "Ouroboros Programmer's Manual" .SH NAME flow_accept, flow_alloc, flow_dealloc \- allocate and free resources -to support Inter-Process Communication between application process -instances +to support Inter-Process Communication .SH SYNOPSIS @@ -31,24 +30,23 @@ to support Inter-Process Communication (IPC). Such a collection of allocated system and network resources is referred to as a flow. A flow has a certain Quality of Service (QoS) associated with it. -The \fBflow_accept\fR() function blocks the calling thread waiting -for an incoming request to allocate a flow. If \fBqosspec_t * \fIqs\fR -is not NULL, the value of \fIqs\fR will be updated to reflect the -actual QoS provided by the IPC facility for the accepted flow. Which -flows this application will accept is configured outside of the -program. For an explanation on configuring which flows an application -should accept, see \fBirm\fR(8). +The \fBflow_accept\fR() function blocks the calling thread waiting for +an incoming request to allocate a flow. If \fBqosspec_t * \fIqs\fR is +not NULL, the value of \fIqs\fR will be updated to reflect the actual +QoS provided by the IPC facility for the accepted flow. Which flows +this process will accept is configured through the IRMd. For an +explanation on configuring which flows an application should accept, +see \fBirm\fR(8). The \fBflow_alloc\fR() function requests to allocate system and/or network resources to support Inter-Process Communication between the -calling application and one or more application process instances -accepting flows for \fBchar * \fIdst_name\fR, which cannot be NULL. -The \fBflow_alloc\fR() call can specify a certain minimum \fBqosspec_t -* \fIqs\fR that has to be guaranteed by the IPC facility allocating -the resources. This can be NULL if there is no QoS to be guaranteed -(best effort service). If \fIqs\fR is not NULL, the value of \fIqs\fR -will be updated to reflect the actual QoS provided by the IPC -facility. +calling application and one or more processes accepting flows for +\fBchar * \fIdst_name\fR, which cannot be NULL. The +\fBflow_alloc\fR() call can specify a certain minimum \fBqosspec_t * +\fIqs\fR that has to be guaranteed by the IPC facility allocating the +resources. This can be NULL if there is no QoS to be guaranteed (best +effort service). If \fIqs\fR is not NULL, the value of \fIqs\fR will +be updated to reflect the actual QoS provided by the IPC facility. The \fBflow_accept\fR() and \fBflow_alloc\fR() take a \fBconst struct timespec * \fItimeo\fR to specify a timeout. If \fItimeo\fR is NULL, diff --git a/doc/man/ouroboros-glossary.7 b/doc/man/ouroboros-glossary.7 index cb397c76..5f9425f6 100644 --- a/doc/man/ouroboros-glossary.7 +++ b/doc/man/ouroboros-glossary.7 @@ -2,7 +2,7 @@ .\" Dimitri Staessens <dimitri.staessens@ugent.be> .\" Sander Vrijders <sander.vrijders@ugent.be> -.TH OUROBOROS-GLOSSARY 7 2017-10-15 Ouroboros "Ouroboros User Manual" +.TH OUROBOROS-GLOSSARY 7 2017-12-02 Ouroboros "Ouroboros User Manual" .SH NAME @@ -65,11 +65,11 @@ that DIF. .PP flow .RS 4 -the system and network resources over which two application processes -can send information. A flow is an abstraction of the actual -underlying IPC mechanism and has a quality of service (QoS) associated -with it, which reflects externally measurable quantities such as -delay, jitter, bandwidth, loss and bit error rate. +the system and network resources over which two processes can send +information. A flow is an abstraction of the actual underlying IPC +mechanism and has a quality of service (QoS) associated with it, which +reflects externally measurable quantities such as delay, jitter, +bandwidth, loss and bit error rate. .RE .PP diff --git a/doc/man/ouroboros-tutorial.7 b/doc/man/ouroboros-tutorial.7 index 792b3056..8e135e23 100644 --- a/doc/man/ouroboros-tutorial.7 +++ b/doc/man/ouroboros-tutorial.7 @@ -2,7 +2,7 @@ .\" Dimitri Staessens <dimitri.staessens@ugent.be> .\" Sander Vrijders <sander.vrijders@ugent.be> -.TH OUROBOROS-TUTORIAL 7 2017-10-15 Ouroboros "Ouroboros User Manual" +.TH OUROBOROS-TUTORIAL 7 2017-12-02 Ouroboros "Ouroboros User Manual" .SH NAME @@ -89,7 +89,7 @@ $ oping -l & .br [1] 24063 .br -$ irm bind api 24063 name my.oping.server +$ irm bind process 24063 name my.oping.server .RE With the server up and running, let's connect a client and send 3 @@ -130,9 +130,9 @@ resources (port_id's 0 and 1) are released. .br ==23918== irmd(II): Flow on port_id 0 allocated. .br -==23918== irmd(II): Completed deallocation of port_id 0 by AP-I 23932. +==23918== irmd(II): Completed deallocation of port_id 0 by process 23932. .br -==23918== irmd(II): Completed deallocation of port_id 1 by AP-I 23932. +==23918== irmd(II): Completed deallocation of port_id 1 by process 23932. .RE .SH TERMINOLOGY diff --git a/doc/man/ouroboros.8 b/doc/man/ouroboros.8 index 394625fa..634eb3f7 100644 --- a/doc/man/ouroboros.8 +++ b/doc/man/ouroboros.8 @@ -2,7 +2,7 @@ .\" Dimitri Staessens <dimitri.staessens@ugent.be> .\" Sander Vrijders <sander.vrijders@ugent.be> -.TH OUROBOROS 8 2017-10-15 Ouroboros "Ouroboros User Manual" +.TH OUROBOROS 8 2017-12-02 Ouroboros "Ouroboros User Manual" .SH NAME @@ -233,7 +233,7 @@ same DIF. .SH IRM COMMANDS .PP -\fBirm bind\fR ap \fiprogram\fR name \fIname\fR [[\fIauto\fR] -- \ +\fBirm bind\fR program \fiprogram\fR name \fIname\fR [[\fIauto\fR] -- \ [\fIparam\fR] [\fIparam\fR] ... [\fIparam\fR]] .RS 4 bind a program \fIprogram\fR, referenced by its binary, to a certain @@ -248,7 +248,7 @@ application when it is started. .RE .PP -\fBirm bind\fR api \fIpid\fR name \fIname\fR +\fBirm bind\fR process \fIpid\fR name \fIname\fR .RS 4 bind a process \fIpid\fR to a certain name. If \fIname\fR is registered in a DIF, the process \fIpid\fR will accept flows for that name. @@ -263,7 +263,7 @@ shorthand for binding the pid of \fipcp\fR. .RE .PP -\fBirm unbind\fR ap \fIprogram\fR name \fIname\fR +\fBirm unbind\fR program \fIprogram\fR name \fIname\fR .RS 4 remove the binding between \fIprogram\fR and \fIname\fR. Instances of \fIprogram\fR will not accept future flow allocation requests for @@ -271,7 +271,7 @@ remove the binding between \fIprogram\fR and \fIname\fR. Instances of .RE .PP -\fBirm unbind\fR api \fIpid\fR name \fIname\fR +\fBirm unbind\fR process \fIpid\fR name \fIname\fR .RS 4 remove the binding between \fIpid\fR and \fIname\fR. The process \fIpid\fR will not accept future flow allocation requests for diff --git a/include/ouroboros/ipcp-dev.h b/include/ouroboros/ipcp-dev.h index 70c604eb..af771fc9 100644 --- a/include/ouroboros/ipcp-dev.h +++ b/include/ouroboros/ipcp-dev.h @@ -25,10 +25,10 @@ #ifndef OUROBOROS_IPCP_DEV_H #define OUROBOROS_IPCP_DEV_H -int ipcp_create_r(pid_t api, +int ipcp_create_r(pid_t pid, int result); -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 cube); diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h index dc723fc0..514351b7 100644 --- a/include/ouroboros/irm.h +++ b/include/ouroboros/irm.h @@ -33,48 +33,47 @@ #define MGMT_AE "Management" /* Name binding options. */ -#define BIND_AP_AUTO 0x01 -#define BIND_AP_UNIQUE 0x02 +#define BIND_AUTO 0x01 __BEGIN_DECLS pid_t irm_create_ipcp(const char * name, enum ipcp_type ipcp_type); -int irm_destroy_ipcp(pid_t api); +int irm_destroy_ipcp(pid_t pid); -/* apis is an out-parameter */ +/* pids is an out-parameter */ ssize_t irm_list_ipcps(const char * name, - pid_t ** apis); + pid_t ** pids); -int irm_enroll_ipcp(pid_t api, +int irm_enroll_ipcp(pid_t pid, const char * dif_name); -int irm_bootstrap_ipcp(pid_t api, +int irm_bootstrap_ipcp(pid_t pid, const struct ipcp_config * conf); -int irm_connect_ipcp(pid_t api, +int irm_connect_ipcp(pid_t pid, const char * component, const char * dst); -int irm_disconnect_ipcp(pid_t api, +int irm_disconnect_ipcp(pid_t pid, const char * component, const char * dst); -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); -int irm_unbind_ap(const char * ap, - const char * name); +int irm_unbind_program(const char * progr, + const char * name); -int irm_bind_api(pid_t api, - const char * name); +int irm_bind_process(pid_t pid, + const char * name); -int irm_unbind_api(pid_t api, - const char * name); +int irm_unbind_process(pid_t pid, + const char * name); int irm_reg(const char * name, char ** difs, diff --git a/include/ouroboros/np1_flow.h b/include/ouroboros/np1_flow.h index 3231a397..c47f8e1f 100644 --- a/include/ouroboros/np1_flow.h +++ b/include/ouroboros/np1_flow.h @@ -27,7 +27,7 @@ #include <unistd.h> -int np1_flow_alloc(pid_t n_api, +int np1_flow_alloc(pid_t n_pid, int port_id, qoscube_t qc); diff --git a/include/ouroboros/shm_flow_set.h b/include/ouroboros/shm_flow_set.h index be2f836b..ec9ef63d 100644 --- a/include/ouroboros/shm_flow_set.h +++ b/include/ouroboros/shm_flow_set.h @@ -33,7 +33,7 @@ struct shm_flow_set * shm_flow_set_create(void); void shm_flow_set_destroy(struct shm_flow_set * set); -struct shm_flow_set * shm_flow_set_open(pid_t api); +struct shm_flow_set * shm_flow_set_open(pid_t pid); void shm_flow_set_close(struct shm_flow_set * set); diff --git a/include/ouroboros/shm_rbuff.h b/include/ouroboros/shm_rbuff.h index af50aada..d33af473 100644 --- a/include/ouroboros/shm_rbuff.h +++ b/include/ouroboros/shm_rbuff.h @@ -34,10 +34,10 @@ struct shm_rbuff; -struct shm_rbuff * shm_rbuff_create(pid_t api, +struct shm_rbuff * shm_rbuff_create(pid_t pid, int port_id); -struct shm_rbuff * shm_rbuff_open(pid_t api, +struct shm_rbuff * shm_rbuff_open(pid_t pid, int port_id); void shm_rbuff_close(struct shm_rbuff * rb); diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index c0f5d8c7..3f2e71aa 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -45,7 +45,7 @@ typedef IpcpMsg ipcp_msg_t; #define IPCP_MSG_BUF_SIZE IRM_MSG_BUF_SIZE /* Returns the full socket path of an IPCP */ -char * ipcp_sock_path(pid_t api); +char * ipcp_sock_path(pid_t pid); int server_socket_open(char * file_name); diff --git a/src/ipcpd/config.h.in b/src/ipcpd/config.h.in index 39be449d..322c6856 100644 --- a/src/ipcpd/config.h.in +++ b/src/ipcpd/config.h.in @@ -23,12 +23,13 @@ #define PTHREAD_COND_CLOCK @PTHREAD_COND_CLOCK@ #define SYS_MAX_FLOWS @SYS_MAX_FLOWS@ -#define AP_RES_FDS @AP_RES_FDS@ -#define AP_MAX_FLOWS @AP_MAX_FLOWS@ +#define PROG_RES_FDS @PROG_RES_FDS@ +#define PROG_MAX_FLOWS @PROG_MAX_FLOWS@ #define IPCP_ACCEPT_TIMEOUT @IPCP_ACCEPT_TIMEOUT@ #define SOCKET_TIMEOUT @SOCKET_TIMEOUT@ +#define CONNECT_TIMEOUT @CONNECT_TIMEOUT@ #define SHM_BUFFER_SIZE @SHM_BUFFER_SIZE@ diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index ba89e2cc..42064817 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -62,7 +62,7 @@ void ipcp_sig_handler(int sig, case SIGTERM: case SIGHUP: case SIGQUIT: - if (info->si_pid == ipcpi.irmd_api) { + if (info->si_pid == ipcpi.irmd_pid) { if (ipcp_get_state() == IPCP_INIT) ipcp_set_state(IPCP_NULL); @@ -407,7 +407,7 @@ static void * mainloop(void * o) break; } - fd = np1_flow_alloc(msg->api, + fd = np1_flow_alloc(msg->pid, msg->port_id, msg->qoscube); if (fd < 0) { @@ -526,11 +526,11 @@ static int parse_args(int argc, if (!(argc == 4 || argc == 3)) return -1; - /* argument 1: api of irmd */ + /* argument 1: pid of irmd */ if (atoi(argv[1]) == 0) return -1; - ipcpi.irmd_api = atoi(argv[1]); + ipcpi.irmd_pid = atoi(argv[1]); /* argument 2: IPCP name */ ipcpi.name = argv[2]; diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h index 62fb310a..fbc44e5d 100644 --- a/src/ipcpd/ipcp.h +++ b/src/ipcpd/ipcp.h @@ -73,7 +73,7 @@ struct ipcp_ops { #define ipcp_dir_hash_len() (hash_len(ipcpi.dir_hash_algo)) struct ipcp { - int irmd_api; + pid_t irmd_pid; char * name; enum ipcp_type type; diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 684949d9..dc998965 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -139,7 +139,7 @@ static int ipcp_local_bootstrap(const struct ipcp_config * conf) return -1; } - log_info("Bootstrapped local IPCP with api %d.", getpid()); + log_info("Bootstrapped local IPCP with pid %d.", getpid()); return 0; } diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c index f99f7072..5692a699 100644 --- a/src/ipcpd/normal/dt.c +++ b/src/ipcpd/normal/dt.c @@ -61,7 +61,7 @@ struct { struct routing_i * routing[QOS_CUBE_MAX]; struct bmp * res_fds; - struct ae_info aes[AP_RES_FDS]; + struct ae_info aes[PROG_RES_FDS]; pthread_rwlock_t lock; pthread_t listener; @@ -127,7 +127,7 @@ static void sdu_handler(int fd, } else { dt_pci_shrink(sdb); - if (dt_pci.fd > AP_RES_FDS) { + if (dt_pci.fd > PROG_RES_FDS) { if (ipcp_flow_write(dt_pci.fd, sdb)) ipcp_sdb_release(sdb); return; @@ -225,7 +225,7 @@ int dt_init(enum pol_routing pr, goto fail_rwlock_init; } - dt.res_fds = bmp_create(AP_RES_FDS, 0); + dt.res_fds = bmp_create(PROG_RES_FDS, 0); if (dt.res_fds == NULL) goto fail_res_fds; diff --git a/src/ipcpd/normal/fa.c b/src/ipcpd/normal/fa.c index e684abd2..6b8c65aa 100644 --- a/src/ipcpd/normal/fa.c +++ b/src/ipcpd/normal/fa.c @@ -50,8 +50,8 @@ typedef FlowAllocMsg flow_alloc_msg_t; struct { pthread_rwlock_t flows_lock; - int r_fd[AP_MAX_FLOWS]; - uint64_t r_addr[AP_MAX_FLOWS]; + int r_fd[PROG_MAX_FLOWS]; + uint64_t r_addr[PROG_MAX_FLOWS]; int fd; struct sdu_sched * sdu_sched; @@ -188,7 +188,7 @@ int fa_init(void) { int i; - for (i = 0; i < AP_MAX_FLOWS; ++i) + for (i = 0; i < PROG_MAX_FLOWS; ++i) destroy_conn(i); if (pthread_rwlock_init(&fa.flows_lock, NULL)) diff --git a/src/ipcpd/normal/pol/graph.c b/src/ipcpd/normal/pol/graph.c index a0af19f9..c3b5f976 100644 --- a/src/ipcpd/normal/pol/graph.c +++ b/src/ipcpd/normal/pol/graph.c @@ -359,7 +359,7 @@ static int get_min_vertex(struct graph * graph, *v = NULL; list_for_each(p, &graph->vertices) { - if (used[i] == true) { + if (used[i]) { i++; continue; } @@ -592,9 +592,9 @@ int graph_routing_table_lfa(struct graph * graph, struct list_head * table) { int * s_dist; - int * n_dist[AP_MAX_FLOWS]; - uint64_t addrs[AP_MAX_FLOWS]; - int n_index[AP_MAX_FLOWS]; + int * n_dist[PROG_MAX_FLOWS]; + uint64_t addrs[PROG_MAX_FLOWS]; + int n_index[PROG_MAX_FLOWS]; struct list_head * p; struct list_head * q; struct vertex * v; @@ -609,7 +609,7 @@ int graph_routing_table_lfa(struct graph * graph, pthread_mutex_lock(&graph->lock); - for (j = 0; j < AP_MAX_FLOWS; j++) { + for (j = 0; j < PROG_MAX_FLOWS; j++) { n_dist[i] = NULL; n_index[i] = -1; addrs[i] = -1; diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index 3979328c..00c72069 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -416,7 +416,7 @@ static void * calculate_pff(void * o) struct list_head table; struct list_head * p; struct list_head * q; - int fds[AP_MAX_FLOWS]; + int fds[PROG_MAX_FLOWS]; instance = (struct routing_i *) o; diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index 2dd56856..cd245323 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -1107,7 +1107,7 @@ static int eth_llc_ipcp_bootstrap(const struct ipcp_config * conf) goto fail_sdu_writer; } - log_dbg("Bootstrapped shim IPCP over Ethernet with LLC with api %d.", + log_dbg("Bootstrapped shim IPCP over Ethernet with LLC with pid %d.", getpid()); return 0; diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index f8248f86..4fafc4de 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -631,7 +631,7 @@ static int ipcp_udp_bootstrap(const struct ipcp_config * conf) goto fail_sduloop; } - log_dbg("Bootstrapped shim IPCP over UDP with api %d.", getpid()); + log_dbg("Bootstrapped shim IPCP over UDP with pid %d.", getpid()); log_dbg("Bound to IP address %s.", ipstr); log_dbg("DNS server address is %s.", dnsstr); @@ -654,7 +654,7 @@ static int ipcp_udp_bootstrap(const struct ipcp_config * conf) /* NOTE: Disgusted with this crap */ static int ddns_send(char * cmd) { - pid_t api = -1; + pid_t pid = -1; int wstatus; int pipe_fd[2]; char * argv[] = {NSUPDATE_EXEC, 0}; @@ -665,13 +665,13 @@ static int ddns_send(char * cmd) return -1; } - api = fork(); - if (api == -1) { + pid = fork(); + if (pid == -1) { log_err("Failed to fork."); return -1; } - if (api == 0) { + if (pid == 0) { close(pipe_fd[1]); dup2(pipe_fd[0], 0); execve(argv[0], &argv[0], envp); @@ -685,9 +685,8 @@ static int ddns_send(char * cmd) return -1; } - waitpid(api, &wstatus, 0); - if (WIFEXITED(wstatus) == true && - WEXITSTATUS(wstatus) == 0) + waitpid(pid, &wstatus, 0); + if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0) log_dbg("Succesfully communicated with DNS server."); else log_err("Failed to register with DNS server."); @@ -699,7 +698,7 @@ static int ddns_send(char * cmd) static uint32_t ddns_resolve(char * name, uint32_t dns_addr) { - pid_t api = -1; + pid_t pid = -1; int wstatus; int pipe_fd[2]; char dnsstr[INET_ADDRSTRLEN]; @@ -718,13 +717,13 @@ static uint32_t ddns_resolve(char * name, return 0; } - api = fork(); - if (api == -1) { + pid = fork(); + if (pid == -1) { log_err("Failed to fork."); return 0; } - if (api == 0) { + if (pid == 0) { char * argv[] = {NSLOOKUP_EXEC, name, dnsstr, 0}; char * envp[] = {0}; @@ -744,9 +743,8 @@ static uint32_t ddns_resolve(char * name, close(pipe_fd[0]); - waitpid(api, &wstatus, 0); - if (WIFEXITED(wstatus) == true && - WEXITSTATUS(wstatus) == 0) + waitpid(pid, &wstatus, 0); + if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0) log_dbg("Succesfully communicated with nslookup."); else log_err("Failed to resolve DNS address."); diff --git a/src/irmd/CMakeLists.txt b/src/irmd/CMakeLists.txt index 51b6f965..51423621 100644 --- a/src/irmd/CMakeLists.txt +++ b/src/irmd/CMakeLists.txt @@ -30,8 +30,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" set(SOURCE_FILES # Add source files here - api_table.c - apn_table.c + proc_table.c + prog_table.c ipcp.c irm_flow.c main.c diff --git a/src/irmd/api_table.h b/src/irmd/api_table.h deleted file mode 100644 index 1fb2e285..00000000 --- a/src/irmd/api_table.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * The IPC Resource Manager - Application Instance Table - * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> - * - * 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., http://www.fsf.org/about/contact/. - */ - -#ifndef OUROBOROS_IRMD_API_TABLE_H -#define OUROBOROS_IRMD_API_TABLE_H - -#include "time.h" -#include "utils.h" - -#include <unistd.h> -#include <pthread.h> - -enum api_state { - API_NULL = 0, - API_INIT, - API_SLEEP, - API_WAKE, - API_DESTROY -}; - -struct api_entry { - struct list_head next; - pid_t api; - char * apn; /* application process instantiated */ - char * daf_name; /* DAF this AP-I belongs to */ - struct list_head names; /* names for which api accepts flows */ - - struct reg_entry * re; /* reg_entry for which a flow arrived */ - - /* The process will block on this */ - enum api_state state; - pthread_cond_t cond; - pthread_mutex_t lock; -}; - -struct api_entry * api_entry_create(pid_t api, - char * apn); - -void api_entry_destroy(struct api_entry * e); - -int api_entry_sleep(struct api_entry * e, - struct timespec * timeo); - -void api_entry_wake(struct api_entry * e, - struct reg_entry * re); - -void api_entry_cancel(struct api_entry * e); - -int api_entry_add_name(struct api_entry * e, - char * name); - -void api_entry_del_name(struct api_entry * e, - const char * name); - -int api_table_add(struct list_head * api_table, - struct api_entry * e); - -void api_table_del(struct list_head * api_table, - pid_t api); - -struct api_entry * api_table_get(struct list_head * api_table, - pid_t api); - -#endif /* OUROBOROS_IRMD_API_TABLE_H */ diff --git a/src/irmd/apn_table.h b/src/irmd/apn_table.h deleted file mode 100644 index 0daff929..00000000 --- a/src/irmd/apn_table.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * The IPC Resource Manager - Application Process Names Table - * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> - * - * 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., http://www.fsf.org/about/contact/. - */ - -#ifndef OUROBOROS_IRMD_APN_TABLE_H -#define OUROBOROS_IRMD_APN_TABLE_H - -#include <ouroboros/list.h> - -#include <unistd.h> -#include <stdint.h> - -struct apn_entry { - struct list_head next; - char * apn; /* name for irmd */ - char * ap; /* name of binary */ - uint32_t flags; - char ** argv; - struct list_head names; /* names that all instances will listen for */ -}; - -struct apn_entry * apn_entry_create(char * apn, - char * ap, - uint32_t flags, - char ** argv); - -void apn_entry_destroy(struct apn_entry * e); - -int apn_entry_add_name(struct apn_entry * e, - char * name); - -void apn_entry_del_name(struct apn_entry * e, - char * name); - -int apn_table_add(struct list_head * apn_table, - struct apn_entry * e); - -void apn_table_del(struct list_head * apn_table, - char * ap); - -struct apn_entry * apn_table_get(struct list_head * apn_table, - char * ap); - -struct apn_entry * apn_table_get_by_apn(struct list_head * apn_table, - char * apn); - -#endif /* OUROBOROS_IRMD_APN_TABLE_H */ diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c index 497bff9f..d2eaa947 100644 --- a/src/irmd/ipcp.c +++ b/src/irmd/ipcp.c @@ -48,7 +48,7 @@ static void close_ptr(void * o) close(*(int *) o); } -ipcp_msg_t * send_recv_ipcp_msg(pid_t api, +ipcp_msg_t * send_recv_ipcp_msg(pid_t pid, ipcp_msg_t * msg) { int sockfd = 0; @@ -58,10 +58,10 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, ipcp_msg_t * recv_msg = NULL; struct timeval tv; - if (kill(api, 0) < 0) + if (kill(pid, 0) < 0) return NULL; - sock_path = ipcp_sock_path(api); + sock_path = ipcp_sock_path(pid); if (sock_path == NULL) return NULL; @@ -128,10 +128,10 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, pid_t ipcp_create(const char * name, enum ipcp_type ipcp_type) { - pid_t api = -1; + pid_t pid = -1; char * ipcp_dir = "/sbin/"; char * exec_name = NULL; - char irmd_api[10]; + char irmd_pid[10]; char full_name[256]; char * argv[5]; @@ -157,16 +157,16 @@ pid_t ipcp_create(const char * name, return -1; } - sprintf(irmd_api, "%u", getpid()); + sprintf(irmd_pid, "%u", getpid()); - api = fork(); - if (api == -1) { + pid = fork(); + if (pid == -1) { log_err("Failed to fork"); - return api; + return pid; } - if (api != 0) - return api; + if (pid != 0) + return pid; strcpy(full_name, INSTALL_PREFIX); strcat(full_name, ipcp_dir); @@ -174,7 +174,7 @@ pid_t ipcp_create(const char * name, /* log_file to be placed at the end */ argv[0] = full_name; - argv[1] = irmd_api; + argv[1] = irmd_pid; argv[2] = (char *) name; if (log_syslog) argv[3] = "1"; @@ -190,9 +190,9 @@ pid_t ipcp_create(const char * name, exit(EXIT_FAILURE); } -int ipcp_destroy(pid_t api) +int ipcp_destroy(pid_t pid) { - if (kill(api, SIGTERM)) { + if (kill(pid, SIGTERM)) { log_err("Failed to destroy IPCP"); return -1; } @@ -200,7 +200,7 @@ int ipcp_destroy(pid_t api) return 0; } -int ipcp_bootstrap(pid_t api, +int ipcp_bootstrap(pid_t pid, ipcp_config_msg_t * conf, struct dif_info * info) { @@ -214,11 +214,11 @@ int ipcp_bootstrap(pid_t api, msg.code = IPCP_MSG_CODE__IPCP_BOOTSTRAP; msg.conf = conf; - recv_msg = send_recv_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return -EIPCP; } @@ -243,7 +243,7 @@ int ipcp_bootstrap(pid_t api, return ret; } -int ipcp_enroll(pid_t api, +int ipcp_enroll(pid_t pid, const char * dst, struct dif_info * info) { @@ -257,11 +257,11 @@ int ipcp_enroll(pid_t api, msg.code = IPCP_MSG_CODE__IPCP_ENROLL; msg.dst_name = (char *) dst; - recv_msg = send_recv_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return -EIPCP; } @@ -285,7 +285,7 @@ int ipcp_enroll(pid_t api, return 0; } -int ipcp_connect(pid_t api, +int ipcp_connect(pid_t pid, const char * dst, const char * component) { @@ -296,14 +296,14 @@ int ipcp_connect(pid_t api, msg.code = IPCP_MSG_CODE__IPCP_CONNECT; 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_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return -EIPCP; } @@ -314,7 +314,7 @@ int ipcp_connect(pid_t api, return ret; } -int ipcp_disconnect(pid_t api, +int ipcp_disconnect(pid_t pid, const char * dst, const char * component) { @@ -325,14 +325,14 @@ int ipcp_disconnect(pid_t api, msg.code = IPCP_MSG_CODE__IPCP_DISCONNECT; 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_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return -EIPCP; } @@ -343,7 +343,7 @@ int ipcp_disconnect(pid_t api, return ret; } -int ipcp_reg(pid_t api, +int ipcp_reg(pid_t pid, const uint8_t * hash, size_t len) { @@ -358,11 +358,11 @@ int ipcp_reg(pid_t api, msg.hash.len = len; msg.hash.data = (uint8_t *)hash; - recv_msg = send_recv_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return -EIPCP; } @@ -373,7 +373,7 @@ int ipcp_reg(pid_t api, return ret; } -int ipcp_unreg(pid_t api, +int ipcp_unreg(pid_t pid, const uint8_t * hash, size_t len) { @@ -386,11 +386,11 @@ int ipcp_unreg(pid_t api, msg.hash.len = len; msg.hash.data = (uint8_t *) hash; - recv_msg = send_recv_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return -EIPCP; } @@ -401,7 +401,7 @@ int ipcp_unreg(pid_t api, return ret; } -int ipcp_query(pid_t api, +int ipcp_query(pid_t pid, const uint8_t * hash, size_t len) { @@ -414,11 +414,11 @@ int ipcp_query(pid_t api, msg.hash.len = len; msg.hash.data = (uint8_t *) hash; - recv_msg = send_recv_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return -EIPCP; } @@ -429,9 +429,9 @@ int ipcp_query(pid_t api, return ret; } -int ipcp_flow_alloc(pid_t api, +int ipcp_flow_alloc(pid_t pid, int port_id, - pid_t n_api, + pid_t n_pid, const uint8_t * dst, size_t len, qoscube_t cube) @@ -445,15 +445,15 @@ int ipcp_flow_alloc(pid_t api, msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC; msg.has_port_id = true; msg.port_id = port_id; - msg.has_api = true; - msg.api = n_api; + msg.has_pid = true; + msg.pid = n_pid; msg.has_hash = true; msg.hash.len = len; msg.hash.data = (uint8_t *) dst; msg.has_qoscube = true; msg.qoscube = cube; - recv_msg = send_recv_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; @@ -468,9 +468,9 @@ int ipcp_flow_alloc(pid_t api, return ret; } -int ipcp_flow_alloc_resp(pid_t api, +int ipcp_flow_alloc_resp(pid_t pid, int port_id, - pid_t n_api, + pid_t n_pid, int response) { ipcp_msg_t msg = IPCP_MSG__INIT; @@ -480,16 +480,16 @@ int ipcp_flow_alloc_resp(pid_t api, msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP; msg.has_port_id = true; msg.port_id = port_id; - msg.has_api = true; - msg.api = n_api; + msg.has_pid = true; + msg.pid = n_pid; msg.has_response = true; msg.response = response; - recv_msg = send_recv_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return -EIPCP; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return -EIPCP; } @@ -500,7 +500,7 @@ int ipcp_flow_alloc_resp(pid_t api, return ret; } -int ipcp_flow_dealloc(pid_t api, +int ipcp_flow_dealloc(pid_t pid, int port_id) { ipcp_msg_t msg = IPCP_MSG__INIT; @@ -511,11 +511,11 @@ int ipcp_flow_dealloc(pid_t api, msg.has_port_id = true; msg.port_id = port_id; - recv_msg = send_recv_ipcp_msg(api, &msg); + recv_msg = send_recv_ipcp_msg(pid, &msg); if (recv_msg == NULL) return 0; - if (recv_msg->has_result == false) { + if (!recv_msg->has_result) { ipcp_msg__free_unpacked(recv_msg, NULL); return 0; } diff --git a/src/irmd/ipcp.h b/src/irmd/ipcp.h index 9c861cde..3797e628 100644 --- a/src/irmd/ipcp.h +++ b/src/irmd/ipcp.h @@ -32,49 +32,49 @@ pid_t ipcp_create(const char * name, enum ipcp_type ipcp_type); -int ipcp_destroy(pid_t api); +int ipcp_destroy(pid_t pid); -int ipcp_enroll(pid_t api, +int ipcp_enroll(pid_t pid, const char * dst, struct dif_info * info); -int ipcp_bootstrap(pid_t api, +int ipcp_bootstrap(pid_t pid, ipcp_config_msg_t * conf, struct dif_info * info); -int ipcp_connect(pid_t api, +int ipcp_connect(pid_t pid, const char * dst, const char * component); -int ipcp_disconnect(pid_t api, +int ipcp_disconnect(pid_t pid, const char * dst, const char * component); -int ipcp_reg(pid_t api, +int ipcp_reg(pid_t pid, const uint8_t * hash, size_t len); -int ipcp_unreg(pid_t api, +int ipcp_unreg(pid_t pid, const uint8_t * hash, size_t len); -int ipcp_query(pid_t api, +int ipcp_query(pid_t pid, const uint8_t * hash, size_t len); -int ipcp_flow_alloc(pid_t api, +int ipcp_flow_alloc(pid_t pid, int port_id, - pid_t n_api, + pid_t n_pid, const uint8_t * dst, size_t len, qoscube_t qos); -int ipcp_flow_alloc_resp(pid_t api, +int ipcp_flow_alloc_resp(pid_t pid, int port_id, - pid_t n_api, + pid_t n_pid, int response); -int ipcp_flow_dealloc(pid_t api, +int ipcp_flow_dealloc(pid_t pid, int port_id); #endif /* OUROBOROS_IRMD_IPCP_H */ diff --git a/src/irmd/irm_flow.c b/src/irmd/irm_flow.c index 2b7f8de7..cc7b91ab 100644 --- a/src/irmd/irm_flow.c +++ b/src/irmd/irm_flow.c @@ -36,8 +36,8 @@ #include <stdbool.h> #include <assert.h> -struct irm_flow * irm_flow_create(pid_t n_api, - pid_t n_1_api, +struct irm_flow * irm_flow_create(pid_t n_pid, + pid_t n_1_pid, int port_id, qoscube_t qc) { @@ -58,20 +58,20 @@ struct irm_flow * irm_flow_create(pid_t n_api, if (pthread_mutex_init(&f->state_lock, NULL)) goto fail_mutex; - f->n_api = n_api; - f->n_1_api = n_1_api; + f->n_pid = n_pid; + f->n_1_pid = n_1_pid; f->port_id = port_id; f->qc = qc; - f->n_rb = shm_rbuff_create(n_api, port_id); + f->n_rb = shm_rbuff_create(n_pid, port_id); if (f->n_rb == NULL) { - log_err("Could not create ringbuffer for AP-I %d.", n_api); + log_err("Could not create ringbuffer for process %d.", n_pid); goto fail_n_rbuff; } - f->n_1_rb = shm_rbuff_create(n_1_api, port_id); + f->n_1_rb = shm_rbuff_create(n_1_pid, port_id); if (f->n_1_rb == NULL) { - log_err("Could not create ringbuffer for AP-I %d.", n_1_api); + log_err("Could not create ringbuffer for process %d.", n_1_pid); goto fail_n_1_rbuff; } diff --git a/src/irmd/irm_flow.h b/src/irmd/irm_flow.h index 3a302b02..906e5651 100644 --- a/src/irmd/irm_flow.h +++ b/src/irmd/irm_flow.h @@ -45,8 +45,8 @@ struct irm_flow { int port_id; qoscube_t qc; - pid_t n_api; - pid_t n_1_api; + pid_t n_pid; + pid_t n_1_pid; struct shm_rbuff * n_rb; struct shm_rbuff * n_1_rb; @@ -58,8 +58,8 @@ struct irm_flow { pthread_mutex_t state_lock; }; -struct irm_flow * irm_flow_create(pid_t n_api, - pid_t n_1_api, +struct irm_flow * irm_flow_create(pid_t n_pid, + pid_t n_1_pid, int port_id, qoscube_t qc); diff --git a/src/irmd/main.c b/src/irmd/main.c index f9438b9b..7b4ad9d8 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -46,7 +46,7 @@ #include "utils.h" #include "registry.h" #include "irm_flow.h" -#include "api_table.h" +#include "proc_table.h" #include "ipcp.h" #include <sys/socket.h> @@ -78,7 +78,7 @@ struct ipcp_entry { struct list_head next; char * name; - pid_t api; + pid_t pid; enum ipcp_type type; enum hash_algo dir_hash_algo; char * dif_name; @@ -106,9 +106,9 @@ struct { struct list_head ipcps; /* list of ipcps in system */ - struct list_head api_table; /* ap instances */ - struct list_head apn_table; /* ap names known */ - struct list_head spawned_apis; /* child ap instances */ + struct list_head proc_table; /* processes */ + struct list_head prog_table; /* programs known */ + struct list_head spawned_pids; /* child processes */ pthread_rwlock_t reg_lock; /* lock for registration info */ struct bmp * port_ids; /* port_ids for flows */ @@ -181,13 +181,13 @@ static struct irm_flow * get_irm_flow(int port_id) return NULL; } -static struct irm_flow * get_irm_flow_n(pid_t n_api) +static struct irm_flow * get_irm_flow_n(pid_t n_pid) { struct list_head * pos = NULL; list_for_each(pos, &irmd.irm_flows) { struct irm_flow * e = list_entry(pos, struct irm_flow, next); - if (e->n_api == n_api && + if (e->n_pid == n_pid && irm_flow_get_state(e) == FLOW_ALLOC_PENDING) return e; } @@ -229,13 +229,13 @@ static void ipcp_entry_destroy(struct ipcp_entry * e) free(e); } -static struct ipcp_entry * get_ipcp_entry_by_api(pid_t api) +static struct ipcp_entry * get_ipcp_entry_by_pid(pid_t pid) { struct list_head * p = NULL; list_for_each(p, &irmd.ipcps) { struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next); - if (api == e->api) + if (pid == e->pid) return e; } @@ -261,13 +261,13 @@ static struct ipcp_entry * get_ipcp_by_dst_name(const char * name, struct list_head * p; struct list_head * h; uint8_t * hash; - pid_t api; + pid_t pid; pthread_rwlock_rdlock(&irmd.reg_lock); list_for_each_safe(p, h, &irmd.ipcps) { struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next); - if (e->dif_name == NULL || e->api == src) + if (e->dif_name == NULL || e->pid == src) continue; hash = malloc(IPCP_HASH_LEN(e)); @@ -276,11 +276,11 @@ static struct ipcp_entry * get_ipcp_by_dst_name(const char * name, str_hash(e->dir_hash_algo, hash, name); - api = e->api; + pid = e->pid; pthread_rwlock_unlock(&irmd.reg_lock); - if (ipcp_query(api, hash, IPCP_HASH_LEN(e)) == 0) { + if (ipcp_query(pid, hash, IPCP_HASH_LEN(e)) == 0) { free(hash); return e; } @@ -298,7 +298,7 @@ static struct ipcp_entry * get_ipcp_by_dst_name(const char * name, static pid_t create_ipcp(char * name, enum ipcp_type ipcp_type) { - struct pid_el * api = NULL; + struct pid_el * ppid = NULL; struct ipcp_entry * tmp = NULL; struct list_head * p = NULL; struct ipcp_entry * entry = NULL; @@ -309,8 +309,8 @@ static pid_t create_ipcp(char * name, (SOCKET_TIMEOUT % 1000) * MILLION}; pid_t ipcp_pid; - api = malloc(sizeof(*api)); - if (api == NULL) + ppid = malloc(sizeof(*ppid)); + if (ppid == NULL) return -ENOMEM; pthread_rwlock_wrlock(&irmd.reg_lock); @@ -318,15 +318,15 @@ static pid_t create_ipcp(char * name, entry = get_ipcp_entry_by_name(name); if (entry != NULL) { pthread_rwlock_unlock(&irmd.reg_lock); - free(api); + free(ppid); log_err("IPCP by that name already exists."); return -1; } - api->pid = ipcp_create(name, ipcp_type); - if (api->pid == -1) { + ppid->pid = ipcp_create(name, ipcp_type); + if (ppid->pid == -1) { pthread_rwlock_unlock(&irmd.reg_lock); - free(api); + free(ppid); log_err("Failed to create IPCP."); return -1; } @@ -334,17 +334,17 @@ static pid_t create_ipcp(char * name, tmp = ipcp_entry_create(); if (tmp == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); - free(api); + free(ppid); return -1; } list_head_init(&tmp->next); tmp->name = strdup(name); - if (tmp->name == NULL) { + if (tmp->name == NULL) { ipcp_entry_destroy(tmp); pthread_rwlock_unlock(&irmd.reg_lock); - free(api); + free(ppid); return -1; } @@ -359,12 +359,12 @@ static pid_t create_ipcp(char * name, pthread_mutex_init(&tmp->init_lock, NULL); - tmp->api = api->pid; + tmp->pid = ppid->pid; tmp->dif_name = NULL; tmp->type = ipcp_type; tmp->init_state = IPCP_BOOT; tmp->dir_hash_algo = -1; - ipcp_pid = tmp->api; + ipcp_pid = tmp->pid; list_for_each(p, &irmd.ipcps) { struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next); @@ -374,7 +374,7 @@ static pid_t create_ipcp(char * name, list_add_tail(&tmp->next, p); - list_add(&api->next, &irmd.spawned_apis); + list_add(&ppid->next, &irmd.spawned_pids); pthread_rwlock_unlock(&irmd.reg_lock); @@ -389,7 +389,7 @@ static pid_t create_ipcp(char * name, &dl); if (ret == -ETIMEDOUT) { - kill(tmp->api, SIGKILL); + kill(tmp->pid, SIGKILL); tmp->init_state = IPCP_NULL; pthread_cond_signal(&tmp->init_cond); pthread_mutex_unlock(&tmp->init_lock); @@ -404,7 +404,7 @@ static pid_t create_ipcp(char * name, return ipcp_pid; } -static int create_ipcp_r(pid_t api, +static int create_ipcp_r(pid_t pid, int result) { struct list_head * pos = NULL; @@ -418,7 +418,7 @@ static int create_ipcp_r(pid_t api, struct ipcp_entry * e = list_entry(pos, struct ipcp_entry, next); - if (e->api == api) { + if (e->pid == pid) { pthread_mutex_lock(&e->init_lock); e->init_state = IPCP_LIVE; pthread_cond_broadcast(&e->init_cond); @@ -431,21 +431,21 @@ static int create_ipcp_r(pid_t api, return 0; } -static void clear_spawned_api(pid_t api) +static void clear_spawned_process(pid_t pid) { struct list_head * pos = NULL; struct list_head * n = NULL; - list_for_each_safe(pos, n, &(irmd.spawned_apis)) { + list_for_each_safe(pos, n, &(irmd.spawned_pids)) { struct pid_el * a = list_entry(pos, struct pid_el, next); - if (api == a->pid) { + if (pid == a->pid) { list_del(&a->next); free(a); } } } -static int destroy_ipcp(pid_t api) +static int destroy_ipcp(pid_t pid) { struct list_head * pos = NULL; struct list_head * n = NULL; @@ -456,14 +456,14 @@ static int destroy_ipcp(pid_t api) struct ipcp_entry * tmp = list_entry(pos, struct ipcp_entry, next); - if (api == tmp->api) { - clear_spawned_api(api); - if (ipcp_destroy(api)) + if (pid == tmp->pid) { + clear_spawned_process(pid); + if (ipcp_destroy(pid)) log_err("Could not destroy IPCP."); list_del(&tmp->next); ipcp_entry_destroy(tmp); - log_info("Destroyed IPCP %d.", api); + log_info("Destroyed IPCP %d.", pid); } } @@ -472,7 +472,7 @@ static int destroy_ipcp(pid_t api) return 0; } -static int bootstrap_ipcp(pid_t api, +static int bootstrap_ipcp(pid_t pid, ipcp_config_msg_t * conf) { struct ipcp_entry * entry = NULL; @@ -480,7 +480,7 @@ static int bootstrap_ipcp(pid_t api, pthread_rwlock_wrlock(&irmd.reg_lock); - entry = get_ipcp_entry_by_api(api); + entry = get_ipcp_entry_by_pid(pid); if (entry == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); log_err("No such IPCP."); @@ -493,7 +493,7 @@ static int bootstrap_ipcp(pid_t api, return -1; } - if (ipcp_bootstrap(entry->api, conf, &info)) { + if (ipcp_bootstrap(entry->pid, conf, &info)) { pthread_rwlock_unlock(&irmd.reg_lock); log_err("Could not bootstrap IPCP."); return -1; @@ -511,12 +511,12 @@ static int bootstrap_ipcp(pid_t api, pthread_rwlock_unlock(&irmd.reg_lock); log_info("Bootstrapped IPCP %d in DIF %s.", - api, conf->dif_info->dif_name); + pid, conf->dif_info->dif_name); return 0; } -static int enroll_ipcp(pid_t api, +static int enroll_ipcp(pid_t pid, char * dst_name) { struct ipcp_entry * entry = NULL; @@ -524,7 +524,7 @@ static int enroll_ipcp(pid_t api, pthread_rwlock_wrlock(&irmd.reg_lock); - entry = get_ipcp_entry_by_api(api); + entry = get_ipcp_entry_by_pid(pid); if (entry == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); log_err("No such IPCP."); @@ -539,14 +539,14 @@ static int enroll_ipcp(pid_t api, pthread_rwlock_unlock(&irmd.reg_lock); - if (ipcp_enroll(api, dst_name, &info) < 0) { - log_err("Could not enroll IPCP %d.", api); + if (ipcp_enroll(pid, dst_name, &info) < 0) { + log_err("Could not enroll IPCP %d.", pid); return -1; } pthread_rwlock_wrlock(&irmd.reg_lock); - entry = get_ipcp_entry_by_api(api); + entry = get_ipcp_entry_by_pid(pid); if (entry == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); log_err("No such IPCP."); @@ -565,12 +565,12 @@ static int enroll_ipcp(pid_t api, pthread_rwlock_unlock(&irmd.reg_lock); log_info("Enrolled IPCP %d in DIF %s.", - api, info.dif_name); + pid, info.dif_name); return 0; } -static int connect_ipcp(pid_t api, +static int connect_ipcp(pid_t pid, const char * dst, const char * component) { @@ -578,7 +578,7 @@ static int connect_ipcp(pid_t api, pthread_rwlock_rdlock(&irmd.reg_lock); - entry = get_ipcp_entry_by_api(api); + entry = get_ipcp_entry_by_pid(pid); if (entry == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); log_err("No such IPCP."); @@ -595,18 +595,18 @@ static int connect_ipcp(pid_t api, log_dbg("Connecting %s to %s.", component, dst); - if (ipcp_connect(api, dst, component)) { + if (ipcp_connect(pid, dst, component)) { log_err("Could not connect IPCP."); return -EPERM; } log_info("Established %s connection between IPCP %d and %s.", - component, api, dst); + component, pid, dst); return 0; } -static int disconnect_ipcp(pid_t api, +static int disconnect_ipcp(pid_t pid, const char * dst, const char * component) { @@ -614,7 +614,7 @@ static int disconnect_ipcp(pid_t api, pthread_rwlock_rdlock(&irmd.reg_lock); - entry = get_ipcp_entry_by_api(api); + entry = get_ipcp_entry_by_pid(pid); if (entry == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); log_err("No such IPCP."); @@ -629,80 +629,80 @@ static int disconnect_ipcp(pid_t api, pthread_rwlock_unlock(&irmd.reg_lock); - if (ipcp_disconnect(api, dst, component)) { + if (ipcp_disconnect(pid, dst, component)) { log_err("Could not disconnect IPCP."); return -EPERM; } log_info("%s connection between IPCP %d and %s torn down.", - component, api, dst); + component, pid, dst); return 0; } -static int bind_ap(char * ap, - char * name, - uint16_t flags, - int argc, - char ** argv) +static int bind_program(char * prog, + char * name, + uint16_t flags, + int argc, + char ** argv) { - char * aps; - char * apn; + char * progs; + char * progn; char ** argv_dup = NULL; int i; char * name_dup = NULL; - struct apn_entry * e = NULL; + struct prog_entry * e = NULL; struct reg_entry * re = NULL; - if (ap == NULL || name == NULL) + if (prog == NULL || name == NULL) return -EINVAL; pthread_rwlock_wrlock(&irmd.reg_lock); - e = apn_table_get(&irmd.apn_table, path_strip(ap)); + e = prog_table_get(&irmd.prog_table, path_strip(prog)); if (e == NULL) { - aps = strdup(path_strip(ap)); - if (aps == NULL) { + progs = strdup(path_strip(prog)); + if (progs == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); return -ENOMEM; } - apn = strdup(name); - if (apn == NULL) { + progn = strdup(name); + if (progn == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); - free(aps); + free(progs); return -ENOMEM; } - if ((flags & BIND_AP_AUTO) && argc) { - /* We need to duplicate argv and set argv[0] to ap. */ + if ((flags & BIND_AUTO) && argc) { + /* We need to duplicate argv and set argv[0] to prog. */ argv_dup = malloc((argc + 2) * sizeof(*argv_dup)); - argv_dup[0] = strdup(ap); + argv_dup[0] = strdup(prog); for (i = 1; i <= argc; ++i) { argv_dup[i] = strdup(argv[i - 1]); if (argv_dup[i] == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); argvfree(argv_dup); - log_err("Failed to bind ap %s to %s.", - ap, name); - free(aps); - free(apn); + log_err("Failed to bind program %s to %s.", + prog, name); + free(progs); + free(progn); return -ENOMEM; } } argv_dup[argc + 1] = NULL; } - e = apn_entry_create(apn, aps, flags, argv_dup); + e = prog_entry_create(progn, progs, flags, argv_dup); if (e == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); - free(aps); - free(apn); + free(progs); + free(progn); argvfree(argv_dup); return -ENOMEM; } - apn_table_add(&irmd.apn_table, e); + prog_table_add(&irmd.prog_table, e); } @@ -712,7 +712,7 @@ static int bind_ap(char * ap, return -ENOMEM; } - if (apn_entry_add_name(e, name_dup)) { + if (prog_entry_add_name(e, name_dup)) { log_err("Failed adding name."); pthread_rwlock_unlock(&irmd.reg_lock); free(name_dup); @@ -720,21 +720,21 @@ static int bind_ap(char * ap, } re = registry_get_entry(&irmd.registry, name); - if (re != NULL && reg_entry_add_apn(re, e) < 0) - log_err("Failed adding AP %s for name %s.", ap, name); + if (re != NULL && reg_entry_add_prog(re, e) < 0) + log_err("Failed adding program %s for name %s.", prog, name); pthread_rwlock_unlock(&irmd.reg_lock); - log_info("Bound AP %s to name %s.", ap, name); + log_info("Bound program %s to name %s.", prog, name); return 0; } -static int bind_api(pid_t api, - char * name) +static int bind_process(pid_t pid, + char * name) { char * name_dup = NULL; - struct api_entry * e = NULL; + struct proc_entry * e = NULL; struct reg_entry * re = NULL; if (name == NULL) @@ -742,9 +742,9 @@ static int bind_api(pid_t api, pthread_rwlock_wrlock(&irmd.reg_lock); - e = api_table_get(&irmd.api_table, api); + e = proc_table_get(&irmd.proc_table, pid); if (e == NULL) { - log_err("AP-I %d does not exist.", api); + log_err("Process %d does not exist.", pid); pthread_rwlock_unlock(&irmd.reg_lock); return -1; } @@ -755,85 +755,85 @@ static int bind_api(pid_t api, return -ENOMEM; } - if (api_entry_add_name(e, name_dup)) { + if (proc_entry_add_name(e, name_dup)) { pthread_rwlock_unlock(&irmd.reg_lock); - log_err("Failed to add name %s to api %d.", name, api); + log_err("Failed to add name %s to process %d.", name, pid); free(name_dup); return -1; } re = registry_get_entry(&irmd.registry, name); - if (re != NULL && reg_entry_add_api(re, api) < 0) - log_err("Failed adding AP-I %d for name %s.", api, name); + if (re != NULL && reg_entry_add_pid(re, pid) < 0) + log_err("Failed adding process %d for name %s.", pid, name); pthread_rwlock_unlock(&irmd.reg_lock); - log_info("Bound AP-I %d to name %s.", api, name); + log_info("Bound process %d to name %s.", pid, name); return 0; } -static int unbind_ap(char * ap, - char * name) +static int unbind_program(char * prog, + char * name) { struct reg_entry * e; - if (ap == NULL) + if (prog == NULL) return -EINVAL; pthread_rwlock_wrlock(&irmd.reg_lock); if (name == NULL) - apn_table_del(&irmd.apn_table, ap); + prog_table_del(&irmd.prog_table, prog); else { - struct apn_entry * e = apn_table_get(&irmd.apn_table, ap); - apn_entry_del_name(e, name); + struct prog_entry * e = prog_table_get(&irmd.prog_table, prog); + prog_entry_del_name(e, name); } e = registry_get_entry(&irmd.registry, name); if (e != NULL) - reg_entry_del_apn(e, ap); + reg_entry_del_prog(e, prog); pthread_rwlock_unlock(&irmd.reg_lock); - if (name == NULL) - log_info("AP %s removed.", ap); + if (name == NULL) + log_info("Program %s unbound.", prog); else - log_info("All names matching %s cleared for %s.", name, ap); + log_info("All names matching %s unbound for %s.", name, prog); return 0; } -static int unbind_api(pid_t api, - const char * name) +static int unbind_process(pid_t pid, + const char * name) { struct reg_entry * e; pthread_rwlock_wrlock(&irmd.reg_lock); if (name == NULL) - api_table_del(&irmd.api_table, api); + proc_table_del(&irmd.proc_table, pid); else { - struct api_entry * e = api_table_get(&irmd.api_table, api); - api_entry_del_name(e, name); + struct proc_entry * e = proc_table_get(&irmd.proc_table, pid); + proc_entry_del_name(e, name); } e = registry_get_entry(&irmd.registry, name); if (e != NULL) - reg_entry_del_api(e, api); + reg_entry_del_pid(e, pid); pthread_rwlock_unlock(&irmd.reg_lock); - if (name == NULL) - log_info("AP-I %d removed.", api); + if (name == NULL) + log_info("Process %d unbound.", pid); else - log_info("All names matching %s cleared for %d.", name, api); + log_info("All names matching %s unbound for %d.", name, pid); return 0; } static ssize_t list_ipcps(char * name, - pid_t ** apis) + pid_t ** pids) { struct list_head * pos = NULL; size_t count = 0; @@ -853,8 +853,8 @@ static ssize_t list_ipcps(char * name, return 0; } - *apis = malloc(count * sizeof(pid_t)); - if (*apis == NULL) { + *pids = malloc(count * sizeof(**pids)); + if (*pids == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); return -1; } @@ -863,7 +863,7 @@ static ssize_t list_ipcps(char * name, struct ipcp_entry * tmp = list_entry(pos, struct ipcp_entry, next); if (wildcard_match(name, tmp->name) == 0) - (*apis)[i++] = tmp->api; + (*pids)[i++] = tmp->pid; } pthread_rwlock_unlock(&irmd.reg_lock); @@ -900,28 +900,28 @@ static int name_reg(const char * name, return -1; } - /* check the tables for client APs */ - list_for_each(p, &irmd.api_table) { + /* check the tables for client programs */ + list_for_each(p, &irmd.proc_table) { struct list_head * q; - struct api_entry * e = - list_entry(p, struct api_entry, next); + struct proc_entry * e = + list_entry(p, struct proc_entry, next); list_for_each(q, &e->names) { struct str_el * s = list_entry(q, struct str_el, next); if (!strcmp(s->str, name)) - reg_entry_add_api(re, e->api); + reg_entry_add_pid(re, e->pid); } } - list_for_each(p, &irmd.apn_table) { + list_for_each(p, &irmd.prog_table) { struct list_head * q; - struct apn_entry * e = - list_entry(p, struct apn_entry, next); + struct prog_entry * e = + list_entry(p, struct prog_entry, next); list_for_each(q, &e->names) { struct str_el * s = list_entry(q, struct str_el, next); if (!strcmp(s->str, name)) - reg_entry_add_apn(re, e); + reg_entry_add_prog(re, e); } } } @@ -933,7 +933,7 @@ static int name_reg(const char * name, for (i = 0; i < len; ++i) { uint8_t * hash; - pid_t api; + pid_t pid; size_t len; if (wildcard_match(difs[i], e->dif_name)) @@ -945,15 +945,15 @@ static int name_reg(const char * name, str_hash(e->dir_hash_algo, hash, name); - api = e->api; + pid = e->pid; len = IPCP_HASH_LEN(e); pthread_rwlock_unlock(&irmd.reg_lock); - if (ipcp_reg(api, hash, len)) { + if (ipcp_reg(pid, hash, len)) { log_err("Could not register " HASH_FMT " with IPCP %d.", - HASH_VAL(hash), api); + HASH_VAL(hash), pid); pthread_rwlock_wrlock(&irmd.reg_lock); free(hash); break; @@ -1005,7 +1005,7 @@ static int name_unreg(const char * name, for (i = 0; i < len; ++i) { uint8_t * hash; - pid_t api; + pid_t pid; size_t len; if (wildcard_match(difs[i], e->dif_name)) @@ -1017,14 +1017,14 @@ static int name_unreg(const char * name, str_hash(e->dir_hash_algo, hash, name); - api = e->api; + pid = e->pid; len = IPCP_HASH_LEN(e); pthread_rwlock_unlock(&irmd.reg_lock); - if (ipcp_unreg(api, hash, len)) { + if (ipcp_unreg(pid, hash, len)) { log_err("Could not unregister %s with IPCP %d.", - name, api); + name, pid); pthread_rwlock_wrlock(&irmd.reg_lock); free(hash); break; @@ -1048,32 +1048,32 @@ static int name_unreg(const char * name, return (ret > 0 ? 0 : -1); } -static int api_announce(pid_t api, - char * apn) +static int proc_announce(pid_t pid, + char * prog) { - struct api_entry * e = NULL; - struct apn_entry * a = NULL; - char * apn_dup; - if (apn == NULL) + struct proc_entry * e = NULL; + struct prog_entry * a = NULL; + char * prog_dup; + if (prog == NULL) return -EINVAL; - apn_dup = strdup(apn); - if (apn_dup == NULL) { + prog_dup = strdup(prog); + if (prog_dup == NULL) { return -ENOMEM; } - e = api_entry_create(api, apn_dup); + e = proc_entry_create(pid, prog_dup); if (e == NULL) { return -ENOMEM; } pthread_rwlock_wrlock(&irmd.reg_lock); - api_table_add(&irmd.api_table, e); + proc_table_add(&irmd.proc_table, e); - /* Copy listen names from apn if it exists. */ + /* Copy listen names from program if it exists. */ - a = apn_table_get(&irmd.apn_table, e->apn); + a = prog_table_get(&irmd.prog_table, e->prog); if (a != NULL) { struct list_head * p; list_for_each(p, &a->names) { @@ -1092,8 +1092,8 @@ static int api_announce(pid_t api, } list_add(&n->next, &e->names); - log_dbg("AP-I %d inherits listen name %s from AP %s.", - api, n->str, e->apn); + log_dbg("Process %d inherits name %s from program %s.", + pid, n->str, e->prog); } } @@ -1102,43 +1102,43 @@ static int api_announce(pid_t api, return 0; } -static int flow_accept(pid_t api, +static int flow_accept(pid_t pid, struct timespec * timeo, struct irm_flow ** fl) { - struct irm_flow * f = NULL; - struct api_entry * e = NULL; - struct reg_entry * re = NULL; - struct list_head * p = NULL; + struct irm_flow * f = NULL; + struct proc_entry * e = NULL; + struct reg_entry * re = NULL; + struct list_head * p = NULL; - pid_t api_n1; - pid_t api_n; + pid_t pid_n1; + pid_t pid_n; int port_id; int ret; pthread_rwlock_wrlock(&irmd.reg_lock); - e = api_table_get(&irmd.api_table, api); + e = proc_table_get(&irmd.proc_table, pid); if (e == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); - log_err("Unknown instance %d calling accept.", api); + log_err("Unknown process %d calling accept.", pid); return -EINVAL; } - log_dbg("New instance (%d) of %s added.", api, e->apn); - log_dbg("This instance accepts flows for:"); + log_dbg("New instance (%d) of %s added.", pid, e->prog); + log_dbg("This process accepts flows for:"); list_for_each(p, &e->names) { struct str_el * s = list_entry(p, struct str_el, next); log_dbg(" %s", s->str); re = registry_get_entry(&irmd.registry, s->str); if (re != NULL) - reg_entry_add_api(re, api); + reg_entry_add_pid(re, pid); } pthread_rwlock_unlock(&irmd.reg_lock); - ret = api_entry_sleep(e, timeo); + ret = proc_entry_sleep(e, timeo); if (ret == -ETIMEDOUT) return -ETIMEDOUT; @@ -1152,28 +1152,28 @@ static int flow_accept(pid_t api, pthread_rwlock_rdlock(&irmd.flows_lock); - f = get_irm_flow_n(api); + f = get_irm_flow_n(pid); if (f == NULL) { pthread_rwlock_unlock(&irmd.flows_lock); log_warn("Port_id was not created yet."); return -EPERM; } - api_n = f->n_api; - api_n1 = f->n_1_api; + pid_n = f->n_pid; + pid_n1 = f->n_1_pid; port_id = f->port_id; pthread_rwlock_unlock(&irmd.flows_lock); pthread_rwlock_rdlock(&irmd.reg_lock); - e = api_table_get(&irmd.api_table, api); + e = proc_table_get(&irmd.proc_table, pid); if (e == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); pthread_rwlock_wrlock(&irmd.flows_lock); list_del(&f->next); bmp_release(irmd.port_ids, f->port_id); pthread_rwlock_unlock(&irmd.flows_lock); - ipcp_flow_alloc_resp(api_n1, port_id, api_n, -1); + ipcp_flow_alloc_resp(pid_n1, port_id, pid_n, -1); clear_irm_flow(f); irm_flow_set_state(f, FLOW_NULL); irm_flow_destroy(f); @@ -1193,7 +1193,7 @@ static int flow_accept(pid_t api, list_del(&f->next); bmp_release(irmd.port_ids, f->port_id); pthread_rwlock_unlock(&irmd.flows_lock); - ipcp_flow_alloc_resp(api_n1, port_id, api_n, -1); + ipcp_flow_alloc_resp(pid_n1, port_id, pid_n, -1); clear_irm_flow(f); irm_flow_set_state(f, FLOW_NULL); irm_flow_destroy(f); @@ -1201,11 +1201,11 @@ static int flow_accept(pid_t api, return -EPERM; } - registry_del_api(&irmd.registry, api); + registry_del_process(&irmd.registry, pid); pthread_rwlock_unlock(&irmd.reg_lock); - if (ipcp_flow_alloc_resp(api_n1, port_id, api_n, 0)) { + if (ipcp_flow_alloc_resp(pid_n1, port_id, pid_n, 0)) { pthread_rwlock_wrlock(&irmd.flows_lock); list_del(&f->next); pthread_rwlock_unlock(&irmd.flows_lock); @@ -1225,7 +1225,7 @@ static int flow_accept(pid_t api, return 0; } -static int flow_alloc(pid_t api, +static int flow_alloc(pid_t pid, const char * dst, qoscube_t cube, struct timespec * timeo, @@ -1237,7 +1237,7 @@ static int flow_alloc(pid_t api, int state; uint8_t * hash; - ipcp = get_ipcp_by_dst_name(dst, api); + ipcp = get_ipcp_by_dst_name(dst, pid); if (ipcp == NULL) { log_info("Destination %s unreachable.", dst); return -1; @@ -1251,7 +1251,7 @@ static int flow_alloc(pid_t api, return -EBADF; } - f = irm_flow_create(api, ipcp->api, port_id, cube); + f = irm_flow_create(pid, ipcp->pid, port_id, cube); if (f == NULL) { bmp_release(irmd.port_ids, port_id); pthread_rwlock_unlock(&irmd.flows_lock); @@ -1272,7 +1272,7 @@ static int flow_alloc(pid_t api, str_hash(ipcp->dir_hash_algo, hash, dst); - if (ipcp_flow_alloc(ipcp->api, port_id, api, hash, + if (ipcp_flow_alloc(ipcp->pid, port_id, pid, hash, IPCP_HASH_LEN(ipcp), cube)) { /* sanitizer cleans this */ log_info("Flow_allocation failed."); @@ -1302,10 +1302,10 @@ static int flow_alloc(pid_t api, return 0; } -static int flow_dealloc(pid_t api, +static int flow_dealloc(pid_t pid, int port_id) { - pid_t n_1_api = -1; + pid_t n_1_pid = -1; int ret = 0; struct irm_flow * f = NULL; @@ -1315,69 +1315,69 @@ static int flow_dealloc(pid_t api, f = get_irm_flow(port_id); if (f == NULL) { pthread_rwlock_unlock(&irmd.flows_lock); - log_dbg("Deallocate unknown port %d by %d.", port_id, api); + log_dbg("Deallocate unknown port %d by %d.", port_id, pid); return 0; } - if (api == f->n_api) { - f->n_api = -1; - n_1_api = f->n_1_api; - } else if (api == f->n_1_api) { - f->n_1_api = -1; + if (pid == f->n_pid) { + f->n_pid = -1; + n_1_pid = f->n_1_pid; + } else if (pid == f->n_1_pid) { + f->n_1_pid = -1; } else { pthread_rwlock_unlock(&irmd.flows_lock); - log_dbg("Dealloc called by wrong AP-I."); + log_dbg("Dealloc called by wrong process."); return -EPERM; } if (irm_flow_get_state(f) == FLOW_DEALLOC_PENDING) { list_del(&f->next); - if ((kill(f->n_api, 0) < 0 && f->n_1_api == -1) || - (kill(f->n_1_api, 0) < 0 && f->n_api == -1)) + if ((kill(f->n_pid, 0) < 0 && f->n_1_pid == -1) || + (kill(f->n_1_pid, 0) < 0 && f->n_pid == -1)) irm_flow_set_state(f, FLOW_NULL); clear_irm_flow(f); irm_flow_destroy(f); bmp_release(irmd.port_ids, port_id); - log_info("Completed deallocation of port_id %d by AP-I %d.", - port_id, api); + log_info("Completed deallocation of port_id %d by process %d.", + port_id, pid); } else { irm_flow_set_state(f, FLOW_DEALLOC_PENDING); - log_dbg("Partial deallocation of port_id %d by AP-I %d.", - port_id, api); + log_dbg("Partial deallocation of port_id %d by process %d.", + port_id, pid); } pthread_rwlock_unlock(&irmd.flows_lock); - if (n_1_api != -1) - ret = ipcp_flow_dealloc(n_1_api, port_id); + if (n_1_pid != -1) + ret = ipcp_flow_dealloc(n_1_pid, port_id); return ret; } static pid_t auto_execute(char ** argv) { - pid_t api; + pid_t pid; struct stat s; if (stat(argv[0], &s) != 0) { - log_warn("Application %s does not exist.", argv[0]); + log_warn("Program %s does not exist.", argv[0]); return -1; } if (!(s.st_mode & S_IXUSR)) { - log_warn("Application %s is not executable.", argv[0]); + log_warn("Program %s is not executable.", argv[0]); return -1; } - api = fork(); - if (api == -1) { + pid = fork(); + if (pid == -1) { log_err("Failed to fork"); - return api; + return pid; } - if (api != 0) { - log_info("Instantiated %s as AP-I %d.", argv[0], api); - return api; + if (pid != 0) { + log_info("Instantiated %s as process %d.", argv[0], pid); + return pid; } execv(argv[0], argv); @@ -1387,29 +1387,29 @@ static pid_t auto_execute(char ** argv) exit(EXIT_FAILURE); } -static struct irm_flow * flow_req_arr(pid_t api, +static struct irm_flow * flow_req_arr(pid_t pid, const uint8_t * hash, qoscube_t cube) { - struct reg_entry * re = NULL; - struct apn_entry * a = NULL; - struct api_entry * e = NULL; - struct irm_flow * f = NULL; + struct reg_entry * re = NULL; + struct prog_entry * a = NULL; + struct proc_entry * e = NULL; + struct irm_flow * f = NULL; - struct pid_el * c_api; + struct pid_el * c_pid; struct ipcp_entry * ipcp; - pid_t h_api = -1; + pid_t h_pid = -1; int port_id = -1; struct timespec wt = {IRMD_REQ_ARR_TIMEOUT / 1000, (IRMD_REQ_ARR_TIMEOUT % 1000) * MILLION}; log_dbg("Flow req arrived from IPCP %d for " HASH_FMT ".", - api, HASH_VAL(hash)); + pid, HASH_VAL(hash)); pthread_rwlock_rdlock(&irmd.reg_lock); - ipcp = get_ipcp_entry_by_api(api); + ipcp = get_ipcp_entry_by_pid(pid); if (ipcp == NULL) { log_err("IPCP died."); return NULL; @@ -1427,9 +1427,9 @@ static struct irm_flow * flow_req_arr(pid_t api, pthread_rwlock_unlock(&irmd.reg_lock); - /* Give the AP a bit of slop time to call accept */ + /* Give the process a bit of slop time to call accept */ if (reg_entry_leave_state(re, REG_NAME_IDLE, &wt) == -1) { - log_err("No APs for " HASH_FMT ".", HASH_VAL(hash)); + log_err("No processes for " HASH_FMT ".", HASH_VAL(hash)); return NULL; } @@ -1438,29 +1438,29 @@ static struct irm_flow * flow_req_arr(pid_t api, switch (reg_entry_get_state(re)) { case REG_NAME_IDLE: pthread_rwlock_unlock(&irmd.reg_lock); - log_err("No APs for " HASH_FMT ".", HASH_VAL(hash)); + log_err("No processes for " HASH_FMT ".", HASH_VAL(hash)); return NULL; case REG_NAME_AUTO_ACCEPT: - c_api = malloc(sizeof(*c_api)); - if (c_api == NULL) { + c_pid = malloc(sizeof(*c_pid)); + if (c_pid == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); return NULL; } reg_entry_set_state(re, REG_NAME_AUTO_EXEC); - a = apn_table_get_by_apn(&irmd.apn_table, - reg_entry_get_apn(re)); + a = prog_table_get_by_progn(&irmd.prog_table, + reg_entry_get_prog(re)); - if (a == NULL || (c_api->pid = auto_execute(a->argv)) < 0) { + if (a == NULL || (c_pid->pid = auto_execute(a->argv)) < 0) { reg_entry_set_state(re, REG_NAME_AUTO_ACCEPT); pthread_rwlock_unlock(&irmd.reg_lock); - log_err("Could not get start apn for reg_entry %s.", + log_err("Could not start program for reg_entry %s.", re->name); - free(c_api); + free(c_pid); return NULL; } - list_add(&c_api->next, &irmd.spawned_apis); + list_add(&c_pid->next, &irmd.spawned_pids); pthread_rwlock_unlock(&irmd.reg_lock); @@ -1470,10 +1470,10 @@ static struct irm_flow * flow_req_arr(pid_t api, pthread_rwlock_wrlock(&irmd.reg_lock); /* FALLTHRU */ case REG_NAME_FLOW_ACCEPT: - h_api = reg_entry_get_api(re); - if (h_api == -1) { + h_pid = reg_entry_get_pid(re); + if (h_pid == -1) { pthread_rwlock_unlock(&irmd.reg_lock); - log_err("Invalid api returned."); + log_err("Invalid process id returned."); return NULL; } @@ -1492,7 +1492,7 @@ static struct irm_flow * flow_req_arr(pid_t api, return NULL; } - f = irm_flow_create(h_api, api, port_id, cube); + f = irm_flow_create(h_pid, pid, port_id, cube); if (f == NULL) { bmp_release(irmd.port_ids, port_id); pthread_rwlock_unlock(&irmd.flows_lock); @@ -1507,7 +1507,7 @@ static struct irm_flow * flow_req_arr(pid_t api, reg_entry_set_state(re, REG_NAME_FLOW_ARRIVED); - e = api_table_get(&irmd.api_table, h_api); + e = proc_table_get(&irmd.proc_table, h_pid); if (e == NULL) { pthread_rwlock_unlock(&irmd.reg_lock); pthread_rwlock_wrlock(&irmd.flows_lock); @@ -1515,12 +1515,12 @@ static struct irm_flow * flow_req_arr(pid_t api, bmp_release(irmd.port_ids, f->port_id); list_del(&f->next); pthread_rwlock_unlock(&irmd.flows_lock); - log_err("Could not get api table entry for %d.", h_api); + log_err("Could not get process table entry for %d.", h_pid); irm_flow_destroy(f); return NULL; } - api_entry_wake(e, re); + proc_entry_wake(e, re); pthread_rwlock_unlock(&irmd.reg_lock); @@ -1580,26 +1580,26 @@ static void irm_fini(void) ipcp_entry_destroy(e); } - list_for_each(p, &irmd.spawned_apis) { + list_for_each(p, &irmd.spawned_pids) { struct pid_el * e = list_entry(p, struct pid_el, next); if (kill(e->pid, SIGTERM)) log_dbg("Could not send kill signal to %d.", e->pid); } - list_for_each_safe(p, h, &irmd.spawned_apis) { + list_for_each_safe(p, h, &irmd.spawned_pids) { struct pid_el * e = list_entry(p, struct pid_el, next); int status; if (waitpid(e->pid, &status, 0) < 0) log_dbg("Error waiting for %d to exit.", e->pid); list_del(&e->next); - registry_del_api(&irmd.registry, e->pid); + registry_del_process(&irmd.registry, e->pid); free(e); } - list_for_each_safe(p, h, &irmd.apn_table) { - struct apn_entry * e = list_entry(p, struct apn_entry, next); + list_for_each_safe(p, h, &irmd.prog_table) { + struct prog_entry * e = list_entry(p, struct prog_entry, next); list_del(&e->next); - apn_entry_destroy(e); + prog_entry_destroy(e); } registry_destroy(&irmd.registry); @@ -1667,13 +1667,13 @@ void * shm_sanitize(void * o) list_for_each(p, &irmd.irm_flows) { struct irm_flow * f = list_entry(p, struct irm_flow, next); - if (kill(f->n_api, 0) < 0) { + if (kill(f->n_pid, 0) < 0) { while ((idx = shm_rbuff_read(f->n_rb)) >= 0) shm_rdrbuff_remove(irmd.rdrb, idx); continue; } - if (kill(f->n_1_api, 0) < 0) { + if (kill(f->n_1_pid, 0) < 0) { while ((idx = shm_rbuff_read(f->n_1_rb)) >= 0) shm_rdrbuff_remove(irmd.rdrb, idx); continue; @@ -1707,7 +1707,7 @@ void * irm_sanitize(void * o) pthread_rwlock_wrlock(&irmd.reg_lock); - list_for_each_safe(p, h, &irmd.spawned_apis) { + list_for_each_safe(p, h, &irmd.spawned_pids) { struct pid_el * e = list_entry(p, struct pid_el, next); waitpid(e->pid, &s, WNOHANG); if (kill(e->pid, 0) >= 0) @@ -1717,22 +1717,22 @@ void * irm_sanitize(void * o) free(e); } - list_for_each_safe(p, h, &irmd.api_table) { - struct api_entry * e = - list_entry(p, struct api_entry, next); - if (kill(e->api, 0) >= 0) + list_for_each_safe(p, h, &irmd.proc_table) { + struct proc_entry * e = + list_entry(p, struct proc_entry, next); + if (kill(e->pid, 0) >= 0) continue; - log_dbg("Dead AP-I removed: %d.", e->api); + log_dbg("Dead process removed: %d.", e->pid); list_del(&e->next); - api_entry_destroy(e); + proc_entry_destroy(e); } list_for_each_safe(p, h, &irmd.ipcps) { struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next); - if (kill(e->api, 0) >= 0) + if (kill(e->pid, 0) >= 0) continue; - log_dbg("Dead IPCP removed: %d.", e->api); + log_dbg("Dead IPCP removed: %d.", e->pid); list_del(&e->next); ipcp_entry_destroy(e); } @@ -1742,12 +1742,12 @@ void * irm_sanitize(void * o) struct list_head * h2; struct reg_entry * e = list_entry(p, struct reg_entry, next); - list_for_each_safe(p2, h2, &e->reg_apis) { + list_for_each_safe(p2, h2, &e->reg_pids) { struct pid_el * a = list_entry(p2, struct pid_el, next); if (kill(a->pid, 0) >= 0) continue; - log_dbg("Dead AP-I removed from: %d %s.", + log_dbg("Dead process removed from: %d %s.", a->pid, e->name); reg_entry_del_pid_el(e, a); } @@ -1766,23 +1766,23 @@ void * irm_sanitize(void * o) && ts_diff_ms(&f->t0, &now) > IRMD_FLOW_TIMEOUT) { log_dbg("Pending port_id %d timed out.", f->port_id); - f->n_api = -1; + f->n_pid = -1; irm_flow_set_state(f, FLOW_DEALLOC_PENDING); - ipcpi = f->n_1_api; + ipcpi = f->n_1_pid; port_id = f->port_id; continue; } - if (kill(f->n_api, 0) < 0) { + if (kill(f->n_pid, 0) < 0) { struct shm_flow_set * set; - log_dbg("AP-I %d gone, deallocating flow %d.", - f->n_api, f->port_id); - set = shm_flow_set_open(f->n_api); + log_dbg("Process %d gone, deallocating flow %d.", + f->n_pid, f->port_id); + set = shm_flow_set_open(f->n_pid); if (set != NULL) shm_flow_set_destroy(set); - f->n_api = -1; + f->n_pid = -1; irm_flow_set_state(f, FLOW_DEALLOC_PENDING); - ipcpi = f->n_1_api; + ipcpi = f->n_1_pid; port_id = f->port_id; pthread_rwlock_unlock(&irmd.flows_lock); ipcp_flow_dealloc(ipcpi, port_id); @@ -1790,14 +1790,14 @@ void * irm_sanitize(void * o) continue; } - if (kill(f->n_1_api, 0) < 0) { + if (kill(f->n_1_pid, 0) < 0) { struct shm_flow_set * set; log_err("IPCP %d gone, flow %d removed.", - f->n_1_api, f->port_id); - set = shm_flow_set_open(f->n_api); + f->n_1_pid, f->port_id); + set = shm_flow_set_open(f->n_pid); if (set != NULL) shm_flow_set_destroy(set); - f->n_1_api = -1; + f->n_1_pid = -1; irm_flow_set_state(f, FLOW_DEALLOC_PENDING); } } @@ -1887,7 +1887,7 @@ static void * mainloop(void * o) while (true) { irm_msg_t ret_msg = IRM_MSG__INIT; struct irm_flow * e = NULL; - pid_t * apis = NULL; + pid_t * pids = NULL; struct timespec * timeo = NULL; struct timespec ts = {0, 0}; struct cmd * cmd; @@ -1938,61 +1938,64 @@ static void * mainloop(void * o) break; case IRM_MSG_CODE__IPCP_CREATE_R: ret_msg.has_result = true; - ret_msg.result = create_ipcp_r(msg->api, msg->result); + ret_msg.result = create_ipcp_r(msg->pid, msg->result); break; case IRM_MSG_CODE__IRM_DESTROY_IPCP: ret_msg.has_result = true; - ret_msg.result = destroy_ipcp(msg->api); + ret_msg.result = destroy_ipcp(msg->pid); break; case IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP: ret_msg.has_result = true; - ret_msg.result = bootstrap_ipcp(msg->api, msg->conf); + ret_msg.result = bootstrap_ipcp(msg->pid, msg->conf); break; case IRM_MSG_CODE__IRM_ENROLL_IPCP: ret_msg.has_result = true; - ret_msg.result = enroll_ipcp(msg->api, + ret_msg.result = enroll_ipcp(msg->pid, msg->dif_name[0]); break; case IRM_MSG_CODE__IRM_CONNECT_IPCP: ret_msg.has_result = true; - ret_msg.result = connect_ipcp(msg->api, + ret_msg.result = connect_ipcp(msg->pid, msg->dst_name, msg->comp_name); break; case IRM_MSG_CODE__IRM_DISCONNECT_IPCP: ret_msg.has_result = true; - ret_msg.result = disconnect_ipcp(msg->api, + ret_msg.result = disconnect_ipcp(msg->pid, msg->dst_name, msg->comp_name); break; - case IRM_MSG_CODE__IRM_BIND_AP: + case IRM_MSG_CODE__IRM_BIND_PROGRAM: ret_msg.has_result = true; - ret_msg.result = bind_ap(msg->ap_name, - msg->dst_name, - msg->opts, - msg->n_args, - msg->args); + ret_msg.result = bind_program(msg->prog_name, + msg->dst_name, + msg->opts, + msg->n_args, + msg->args); break; - case IRM_MSG_CODE__IRM_UNBIND_AP: + case IRM_MSG_CODE__IRM_UNBIND_PROGRAM: ret_msg.has_result = true; - ret_msg.result = unbind_ap(msg->ap_name, msg->dst_name); + ret_msg.result = unbind_program(msg->prog_name, + msg->dst_name); break; - case IRM_MSG_CODE__IRM_API_ANNOUNCE: + case IRM_MSG_CODE__IRM_PROC_ANNOUNCE: ret_msg.has_result = true; - ret_msg.result = api_announce(msg->api, msg->ap_name); + ret_msg.result = proc_announce(msg->pid, + msg->prog_name); break; - case IRM_MSG_CODE__IRM_BIND_API: + case IRM_MSG_CODE__IRM_BIND_PROCESS: ret_msg.has_result = true; - ret_msg.result = bind_api(msg->api, msg->dst_name); + ret_msg.result = bind_process(msg->pid, msg->dst_name); break; - case IRM_MSG_CODE__IRM_UNBIND_API: + case IRM_MSG_CODE__IRM_UNBIND_PROCESS: ret_msg.has_result = true; - ret_msg.result = unbind_api(msg->api, msg->dst_name); + ret_msg.result = unbind_process(msg->pid, + msg->dst_name); break; case IRM_MSG_CODE__IRM_LIST_IPCPS: ret_msg.has_result = true; - ret_msg.n_apis = list_ipcps(msg->dst_name, &apis); - ret_msg.apis = apis; + ret_msg.n_pids = list_ipcps(msg->dst_name, &pids); + ret_msg.pids = pids; break; case IRM_MSG_CODE__IRM_REG: ret_msg.has_result = true; @@ -2008,33 +2011,33 @@ static void * mainloop(void * o) break; case IRM_MSG_CODE__IRM_FLOW_ACCEPT: ret_msg.has_result = true; - ret_msg.result = flow_accept(msg->api, timeo, &e); + ret_msg.result = flow_accept(msg->pid, timeo, &e); if (ret_msg.result == 0) { ret_msg.has_port_id = true; ret_msg.port_id = e->port_id; - ret_msg.has_api = true; - ret_msg.api = e->n_1_api; + ret_msg.has_pid = true; + ret_msg.pid = e->n_1_pid; ret_msg.has_qoscube = true; ret_msg.qoscube = e->qc; } break; case IRM_MSG_CODE__IRM_FLOW_ALLOC: ret_msg.has_result = true; - ret_msg.result = flow_alloc(msg->api, msg->dst_name, + ret_msg.result = flow_alloc(msg->pid, msg->dst_name, msg->qoscube, timeo, &e); if (ret_msg.result == 0) { ret_msg.has_port_id = true; ret_msg.port_id = e->port_id; - ret_msg.has_api = true; - ret_msg.api = e->n_1_api; + ret_msg.has_pid = true; + ret_msg.pid = e->n_1_pid; } break; case IRM_MSG_CODE__IRM_FLOW_DEALLOC: ret_msg.has_result = true; - ret_msg.result = flow_dealloc(msg->api, msg->port_id); + ret_msg.result = flow_dealloc(msg->pid, msg->port_id); break; case IRM_MSG_CODE__IPCP_FLOW_REQ_ARR: - e = flow_req_arr(msg->api, + e = flow_req_arr(msg->pid, msg->hash.data, msg->qoscube); ret_msg.has_result = true; @@ -2044,8 +2047,8 @@ static void * mainloop(void * o) } ret_msg.has_port_id = true; ret_msg.port_id = e->port_id; - ret_msg.has_api = true; - ret_msg.api = e->n_api; + ret_msg.has_pid = true; + ret_msg.pid = e->n_pid; break; case IRM_MSG_CODE__IPCP_FLOW_ALLOC_REPLY: ret_msg.has_result = true; @@ -2069,8 +2072,8 @@ static void * mainloop(void * o) buffer.len = irm_msg__get_packed_size(&ret_msg); if (buffer.len == 0) { log_err("Failed to calculate length of reply message."); - if (apis != NULL) - free(apis); + if (pids != NULL) + free(pids); close(sfd); tpm_inc(irmd.tpm); continue; @@ -2078,8 +2081,8 @@ static void * mainloop(void * o) buffer.data = malloc(buffer.len); if (buffer.data == NULL) { - if (apis != NULL) - free(apis); + if (pids != NULL) + free(pids); close(sfd); tpm_inc(irmd.tpm); continue; @@ -2087,8 +2090,8 @@ static void * mainloop(void * o) irm_msg__pack(&ret_msg, buffer.data); - if (apis != NULL) - free(apis); + if (pids != NULL) + free(pids); pthread_cleanup_push(close_ptr, &sfd); @@ -2152,9 +2155,9 @@ static int irm_init(void) pthread_condattr_destroy(&cattr); list_head_init(&irmd.ipcps); - list_head_init(&irmd.api_table); - list_head_init(&irmd.apn_table); - list_head_init(&irmd.spawned_apis); + list_head_init(&irmd.proc_table); + list_head_init(&irmd.prog_table); + list_head_init(&irmd.spawned_pids); list_head_init(&irmd.registry); list_head_init(&irmd.irm_flows); list_head_init(&irmd.cmds); diff --git a/src/irmd/api_table.c b/src/irmd/proc_table.c index a244f3a2..76fd5864 100644 --- a/src/irmd/api_table.c +++ b/src/irmd/proc_table.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2017 * - * The IPC Resource Manager - Application Instance Table + * The IPC Resource Manager - Process Table * * Dimitri Staessens <dimitri.staessens@ugent.be> * Sander Vrijders <sander.vrijders@ugent.be> @@ -28,7 +28,7 @@ #include <ouroboros/errno.h> #include <ouroboros/time_utils.h> -#include "api_table.h" +#include "proc_table.h" #include "registry.h" #include <stdlib.h> @@ -36,13 +36,13 @@ #include <limits.h> #include <assert.h> -struct api_entry * api_entry_create(pid_t api, - char * apn) +struct proc_entry * proc_entry_create(pid_t pid, + char * prog) { - struct api_entry * e; - pthread_condattr_t cattr; + struct proc_entry * e; + pthread_condattr_t cattr; - assert(apn); + assert(prog); e = malloc(sizeof(*e)); if (e == NULL) @@ -51,13 +51,13 @@ struct api_entry * api_entry_create(pid_t api, list_head_init(&e->next); list_head_init(&e->names); - e->api = api; - e->apn = apn; + e->pid = pid; + e->prog = prog; e->daf_name = NULL; e->re = NULL; - e->state = API_INIT; + e->state = PROC_INIT; if (pthread_condattr_init(&cattr)) { free(e); @@ -83,16 +83,16 @@ struct api_entry * api_entry_create(pid_t api, return e; } -void cancel_api_entry(void * o) +static void cancel_proc_entry(void * o) { - struct api_entry * e = (struct api_entry *) o; + struct proc_entry * e = (struct proc_entry *) o; - e->state = API_NULL; + e->state = PROC_NULL; pthread_mutex_unlock(&e->lock); } -void api_entry_destroy(struct api_entry * e) +void proc_entry_destroy(struct proc_entry * e) { struct list_head * p; struct list_head * h; @@ -101,19 +101,19 @@ void api_entry_destroy(struct api_entry * e) pthread_mutex_lock(&e->lock); - if (e->state == API_DESTROY) { + if (e->state == PROC_DESTROY) { pthread_mutex_unlock(&e->lock); return; } - if (e->state == API_SLEEP) - e->state = API_DESTROY; + if (e->state == PROC_SLEEP) + e->state = PROC_DESTROY; pthread_cond_signal(&e->cond); - pthread_cleanup_push(cancel_api_entry, e); + pthread_cleanup_push(cancel_proc_entry, e); - while (e->state != API_INIT) + while (e->state != PROC_INIT) pthread_cond_wait(&e->cond, &e->lock); pthread_cleanup_pop(false); @@ -123,8 +123,8 @@ void api_entry_destroy(struct api_entry * e) pthread_cond_destroy(&e->cond); pthread_mutex_destroy(&e->lock); - if (e->apn != NULL) - free(e->apn); + if (e->prog != NULL) + free(e->prog); list_for_each_safe(p, h, &e->names) { struct str_el * n = list_entry(p, struct str_el, next); @@ -137,8 +137,8 @@ void api_entry_destroy(struct api_entry * e) free(e); } -int api_entry_add_name(struct api_entry * e, - char * name) +int proc_entry_add_name(struct proc_entry * e, + char * name) { struct str_el * s; @@ -155,8 +155,8 @@ int api_entry_add_name(struct api_entry * e, return 0; } -void api_entry_del_name(struct api_entry * e, - const char * name) +void proc_entry_del_name(struct proc_entry * e, + const char * name) { struct list_head * p = NULL; struct list_head * h = NULL; @@ -175,8 +175,8 @@ void api_entry_del_name(struct api_entry * e, } } -int api_entry_sleep(struct api_entry * e, - struct timespec * timeo) +int proc_entry_sleep(struct proc_entry * e, + struct timespec * timeo) { struct timespec dl; @@ -191,12 +191,12 @@ int api_entry_sleep(struct api_entry * e, pthread_mutex_lock(&e->lock); - if (e->state != API_WAKE && e->state != API_DESTROY) - e->state = API_SLEEP; + if (e->state != PROC_WAKE && e->state != PROC_DESTROY) + e->state = PROC_SLEEP; - pthread_cleanup_push(cancel_api_entry, e); + pthread_cleanup_push(cancel_proc_entry, e); - while (e->state == API_SLEEP && ret != -ETIMEDOUT) + while (e->state == PROC_SLEEP && ret != -ETIMEDOUT) if (timeo) ret = -pthread_cond_timedwait(&e->cond, &e->lock, &dl); else @@ -204,13 +204,13 @@ int api_entry_sleep(struct api_entry * e, pthread_cleanup_pop(false); - if (e->state == API_DESTROY) { + if (e->state == PROC_DESTROY) { if (e->re != NULL) - reg_entry_del_api(e->re, e->api); + reg_entry_del_pid(e->re, e->pid); ret = -1; } - e->state = API_INIT; + e->state = PROC_INIT; pthread_cond_broadcast(&e->cond); pthread_mutex_unlock(&e->lock); @@ -218,76 +218,76 @@ int api_entry_sleep(struct api_entry * e, return ret; } -void api_entry_wake(struct api_entry * e, - struct reg_entry * re) +void proc_entry_wake(struct proc_entry * e, + struct reg_entry * re) { assert(e); assert(re); pthread_mutex_lock(&e->lock); - if (e->state != API_SLEEP) { + if (e->state != PROC_SLEEP) { pthread_mutex_unlock(&e->lock); return; } - e->state = API_WAKE; + e->state = PROC_WAKE; e->re = re; pthread_cond_broadcast(&e->cond); - pthread_cleanup_push(cancel_api_entry, e); + pthread_cleanup_push(cancel_proc_entry, e); - while (e->state == API_WAKE) + while (e->state == PROC_WAKE) pthread_cond_wait(&e->cond, &e->lock); pthread_cleanup_pop(false); - if (e->state == API_DESTROY) - e->state = API_INIT; + if (e->state == PROC_DESTROY) + e->state = PROC_INIT; pthread_mutex_unlock(&e->lock); } -int api_table_add(struct list_head * api_table, - struct api_entry * e) +int proc_table_add(struct list_head * proc_table, + struct proc_entry * e) { - assert(api_table); + assert(proc_table); assert(e); - list_add(&e->next, api_table); + list_add(&e->next, proc_table); return 0; } -void api_table_del(struct list_head * api_table, - pid_t api) +void proc_table_del(struct list_head * proc_table, + pid_t pid) { struct list_head * p; struct list_head * h; - assert(api_table); + assert(proc_table); - list_for_each_safe(p, h, api_table) { - struct api_entry * e = list_entry(p, struct api_entry, next); - if (api == e->api) { + list_for_each_safe(p, h, proc_table) { + struct proc_entry * e = list_entry(p, struct proc_entry, next); + if (pid == e->pid) { list_del(&e->next); - api_entry_destroy(e); + proc_entry_destroy(e); } } } -struct api_entry * api_table_get(struct list_head * api_table, - pid_t api) +struct proc_entry * proc_table_get(struct list_head * proc_table, + pid_t pid) { struct list_head * h; - assert(api_table); + assert(proc_table); - list_for_each(h, api_table) { - struct api_entry * e = list_entry(h, struct api_entry, next); - if (api == e->api) + list_for_each(h, proc_table) { + struct proc_entry * e = list_entry(h, struct proc_entry, next); + if (pid == e->pid) return e; } diff --git a/src/irmd/proc_table.h b/src/irmd/proc_table.h new file mode 100644 index 00000000..f95649ba --- /dev/null +++ b/src/irmd/proc_table.h @@ -0,0 +1,83 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * The IPC Resource Manager - Process Table + * + * Dimitri Staessens <dimitri.staessens@ugent.be> + * Sander Vrijders <sander.vrijders@ugent.be> + * + * 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., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_IRMD_PROC_TABLE_H +#define OUROBOROS_IRMD_PROC_TABLE_H + +#include "time.h" +#include "utils.h" + +#include <unistd.h> +#include <pthread.h> + +enum proc_state { + PROC_NULL = 0, + PROC_INIT, + PROC_SLEEP, + PROC_WAKE, + PROC_DESTROY +}; + +struct proc_entry { + struct list_head next; + pid_t pid; + char * prog; /* program instantiated */ + char * daf_name; /* DAF this process belongs to */ + struct list_head names; /* names for which process accepts flows */ + + struct reg_entry * re; /* reg_entry for which a flow arrived */ + + /* The process will block on this */ + enum proc_state state; + pthread_cond_t cond; + pthread_mutex_t lock; +}; + +struct proc_entry * proc_entry_create(pid_t proc, + char * prog); + +void proc_entry_destroy(struct proc_entry * e); + +int proc_entry_sleep(struct proc_entry * e, + struct timespec * timeo); + +void proc_entry_wake(struct proc_entry * e, + struct reg_entry * re); + +void proc_entry_cancel(struct proc_entry * e); + +int proc_entry_add_name(struct proc_entry * e, + char * name); + +void proc_entry_del_name(struct proc_entry * e, + const char * name); + +int proc_table_add(struct list_head * proc_table, + struct proc_entry * e); + +void proc_table_del(struct list_head * proc_table, + pid_t pid); + +struct proc_entry * proc_table_get(struct list_head * proc_table, + pid_t pid); + +#endif /* OUROBOROS_IRMD_PROC_TABLE_H */ diff --git a/src/irmd/apn_table.c b/src/irmd/prog_table.c index da4f4da1..1aeb0982 100644 --- a/src/irmd/apn_table.c +++ b/src/irmd/prog_table.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2017 * - * The IPC Resource Manager - Application Process Table + * The IPC Resource Manager - Program Table * * Dimitri Staessens <dimitri.staessens@ugent.be> * Sander Vrijders <sander.vrijders@ugent.be> @@ -23,20 +23,22 @@ #include <ouroboros/errno.h> #include <ouroboros/irm.h> -#include "apn_table.h" +#include "prog_table.h" #include "utils.h" +#include <assert.h> #include <stdlib.h> #include <string.h> -struct apn_entry * apn_entry_create(char * apn, - char * ap, - uint32_t flags, - char ** argv) +struct prog_entry * prog_entry_create(char * progn, + char * prog, + uint32_t flags, + char ** argv) { - struct apn_entry * e; - if (apn == NULL) - return NULL; + struct prog_entry * e; + + assert(progn); + assert(prog); e = malloc(sizeof(*e)); if (e == NULL) @@ -45,11 +47,11 @@ struct apn_entry * apn_entry_create(char * apn, list_head_init(&e->next); list_head_init(&e->names); - e->apn = apn; - e->ap = ap; + e->progn = progn; + e->prog = prog; e->flags = flags; - if (flags & BIND_AP_AUTO) { + if (flags & BIND_AUTO) { e->argv = argv; } else { e->argv = NULL; @@ -59,7 +61,7 @@ struct apn_entry * apn_entry_create(char * apn, return e; } -void apn_entry_destroy(struct apn_entry * e) +void prog_entry_destroy(struct prog_entry * e) { struct list_head * p = NULL; struct list_head * h = NULL; @@ -67,11 +69,11 @@ void apn_entry_destroy(struct apn_entry * e) if (e == NULL) return; - if (e->apn != NULL) - free(e->apn); + if (e->progn != NULL) + free(e->progn); - if (e->ap != NULL) - free(e->ap); + if (e->prog != NULL) + free(e->prog); if (e->argv != NULL) argvfree(e->argv); @@ -87,7 +89,8 @@ void apn_entry_destroy(struct apn_entry * e) free(e); } -int apn_entry_add_name(struct apn_entry * e, char * name) +int prog_entry_add_name(struct prog_entry * e, + char * name) { struct str_el * s; @@ -104,7 +107,8 @@ int apn_entry_add_name(struct apn_entry * e, char * name) return 0; } -void apn_entry_del_name(struct apn_entry * e, char * name) +void prog_entry_del_name(struct prog_entry * e, + char * name) { struct list_head * p = NULL; struct list_head * h = NULL; @@ -120,60 +124,63 @@ void apn_entry_del_name(struct apn_entry * e, char * name) } } -int apn_table_add(struct list_head * apn_table, struct apn_entry * e) +int prog_table_add(struct list_head * prog_table, + struct prog_entry * e) { - if (apn_table == NULL || e == NULL) - return -EINVAL; + assert(prog_table); + assert(e); - list_add(&e->next, apn_table); + list_add(&e->next, prog_table); return 0; } -void apn_table_del(struct list_head * apn_table, char * ap) +void prog_table_del(struct list_head * prog_table, + char * prog) { struct list_head * p; struct list_head * h; - if (apn_table == NULL || ap == NULL) - return; + assert(prog_table); + assert(prog); - list_for_each_safe(p, h, apn_table) { - struct apn_entry * e = list_entry(p, struct apn_entry, next); - if (!wildcard_match(ap, e->ap)) { + list_for_each_safe(p, h, prog_table) { + struct prog_entry * e = list_entry(p, struct prog_entry, next); + if (!wildcard_match(prog, e->prog)) { list_del(&e->next); - apn_entry_destroy(e); + prog_entry_destroy(e); } } } -struct apn_entry * apn_table_get(struct list_head * apn_table, char * ap) +struct prog_entry * prog_table_get(struct list_head * prog_table, + char * prog) { struct list_head * p; - if (apn_table == NULL || ap == NULL) - return NULL; + assert(prog_table); + assert(prog); - list_for_each(p, apn_table) { - struct apn_entry * e = list_entry(p, struct apn_entry, next); - if (!strcmp(e->ap, ap)) + list_for_each(p, prog_table) { + struct prog_entry * e = list_entry(p, struct prog_entry, next); + if (!strcmp(e->prog, prog)) return e; } return NULL; } -struct apn_entry * apn_table_get_by_apn(struct list_head * apn_table, - char * apn) +struct prog_entry * prog_table_get_by_progn(struct list_head * prog_table, + char * progn) { struct list_head * p; - if (apn_table == NULL || apn == NULL) - return NULL; + assert(prog_table); + assert(progn); - list_for_each(p, apn_table) { - struct apn_entry * e = list_entry(p, struct apn_entry, next); - if (!strcmp(e->apn, apn)) + list_for_each(p, prog_table) { + struct prog_entry * e = list_entry(p, struct prog_entry, next); + if (!strcmp(e->progn, progn)) return e; } diff --git a/src/irmd/prog_table.h b/src/irmd/prog_table.h new file mode 100644 index 00000000..f4692ce6 --- /dev/null +++ b/src/irmd/prog_table.h @@ -0,0 +1,65 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * The IPC Resource Manager - Program Table + * + * Dimitri Staessens <dimitri.staessens@ugent.be> + * Sander Vrijders <sander.vrijders@ugent.be> + * + * 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., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_IRMD_PROG_TABLE_H +#define OUROBOROS_IRMD_PROG_TABLE_H + +#include <ouroboros/list.h> + +#include <unistd.h> +#include <stdint.h> + +struct prog_entry { + struct list_head next; + char * progn; /* name for irmd */ + char * prog; /* name of binary */ + uint32_t flags; + char ** argv; + struct list_head names; /* names that all instances will listen for */ +}; + +struct prog_entry * prog_entry_create(char * progn, + char * prog, + uint32_t flags, + char ** argv); + +void prog_entry_destroy(struct prog_entry * e); + +int prog_entry_add_name(struct prog_entry * e, + char * name); + +void prog_entry_del_name(struct prog_entry * e, + char * name); + +int prog_table_add(struct list_head * prog_table, + struct prog_entry * e); + +void prog_table_del(struct list_head * prog_table, + char * prog); + +struct prog_entry * prog_table_get(struct list_head * prog_table, + char * prog); + +struct prog_entry * prog_table_get_by_progn(struct list_head * prog_table, + char * progn); + +#endif /* OUROBOROS_IRMD_PROG_TABLE_H */ diff --git a/src/irmd/registry.c b/src/irmd/registry.c index 21399118..61dcf655 100644 --- a/src/irmd/registry.c +++ b/src/irmd/registry.c @@ -70,8 +70,8 @@ static int reg_entry_init(struct reg_entry * e, list_head_init(&e->next); list_head_init(&e->difs); - list_head_init(&e->reg_apns); - list_head_init(&e->reg_apis); + list_head_init(&e->reg_progs); + list_head_init(&e->reg_pids); e->name = name; @@ -108,13 +108,13 @@ static void cancel_reg_entry_destroy(void * o) if (e->name != NULL) free(e->name); - list_for_each_safe(p, h, &e->reg_apis) { + list_for_each_safe(p, h, &e->reg_pids) { struct pid_el * pe = list_entry(p, struct pid_el, next); list_del(&pe->next); free(pe); } - list_for_each_safe(p, h, &e->reg_apns) { + list_for_each_safe(p, h, &e->reg_progs) { struct str_el * a = list_entry(p, struct str_el, next); list_del(&a->next); free(a->str); @@ -214,33 +214,33 @@ static void reg_entry_del_local_from_dif(struct reg_entry * e, } } -static bool reg_entry_has_apn(struct reg_entry * e, - const char * apn) +static bool reg_entry_has_prog(struct reg_entry * e, + const char * prog) { struct list_head * p; - list_for_each(p, &e->reg_apns) { + list_for_each(p, &e->reg_progs) { struct str_el * e = list_entry(p, struct str_el, next); - if (!strcmp(e->str, apn)) + if (!strcmp(e->str, prog)) return true; } return false; } -int reg_entry_add_apn(struct reg_entry * e, - struct apn_entry * a) +int reg_entry_add_prog(struct reg_entry * e, + struct prog_entry * a) { struct str_el * n; - if (reg_entry_has_apn(e, a->apn)) { - log_warn("AP %s already accepting flows for %s.", - a->apn, e->name); + if (reg_entry_has_prog(e, a->prog)) { + log_warn("Program %s already accepting flows for %s.", + a->prog, e->name); return 0; } - if (!(a->flags & BIND_AP_AUTO)) { - log_dbg("AP %s cannot be auto-instantiated.", a->apn); + if (!(a->flags & BIND_AUTO)) { + log_dbg("Program %s cannot be auto-instantiated.", a->prog); return 0; } @@ -248,13 +248,13 @@ int reg_entry_add_apn(struct reg_entry * e, if (n == NULL) return -ENOMEM; - n->str = strdup(a->apn); + n->str = strdup(a->prog); if (n->str == NULL) { free(n); return -ENOMEM; } - list_add(&n->next, &e->reg_apns); + list_add(&n->next, &e->reg_progs); pthread_mutex_lock(&e->state_lock); @@ -266,15 +266,15 @@ int reg_entry_add_apn(struct reg_entry * e, return 0; } -void reg_entry_del_apn(struct reg_entry * e, - const char * apn) +void reg_entry_del_prog(struct reg_entry * e, + const char * prog) { struct list_head * p = NULL; struct list_head * h = NULL; - list_for_each_safe(p, h, &e->reg_apns) { + list_for_each_safe(p, h, &e->reg_progs) { struct str_el * e = list_entry(p, struct str_el, next); - if (!wildcard_match(apn, e->str)) { + if (!wildcard_match(prog, e->str)) { list_del(&e->next); free(e->str); free(e); @@ -283,7 +283,7 @@ void reg_entry_del_apn(struct reg_entry * e, pthread_mutex_lock(&e->state_lock); - if (e->state == REG_NAME_AUTO_ACCEPT && list_is_empty(&e->reg_apns)) { + if (e->state == REG_NAME_AUTO_ACCEPT && list_is_empty(&e->reg_progs)) { e->state = REG_NAME_IDLE; pthread_cond_broadcast(&e->state_cond); } @@ -291,37 +291,37 @@ void reg_entry_del_apn(struct reg_entry * e, pthread_mutex_unlock(&e->state_lock); } -char * reg_entry_get_apn(struct reg_entry * e) +char * reg_entry_get_prog(struct reg_entry * e) { - if (!list_is_empty(&e->reg_apis) || list_is_empty(&e->reg_apns)) + if (!list_is_empty(&e->reg_pids) || list_is_empty(&e->reg_progs)) return NULL; - return list_first_entry(&e->reg_apns, struct str_el, next)->str; + return list_first_entry(&e->reg_progs, struct str_el, next)->str; } -static bool reg_entry_has_api(struct reg_entry * e, - pid_t api) +static bool reg_entry_has_pid(struct reg_entry * e, + pid_t pid) { struct list_head * p; - list_for_each(p, &e->reg_apns) { + list_for_each(p, &e->reg_progs) { struct pid_el * e = list_entry(p, struct pid_el, next); - if (e->pid == api) + if (e->pid == pid) return true; } return false; } -int reg_entry_add_api(struct reg_entry * e, - pid_t api) +int reg_entry_add_pid(struct reg_entry * e, + pid_t pid) { struct pid_el * i; assert(e); - if (reg_entry_has_api(e, api)) { - log_dbg("Instance already registered with this name."); + if (reg_entry_has_pid(e, pid)) { + log_dbg("Process already registered with this name."); return -EPERM; } @@ -339,9 +339,9 @@ int reg_entry_add_api(struct reg_entry * e, return -ENOMEM; } - i->pid = api; + i->pid = pid; - list_add(&i->next, &e->reg_apis); + list_add(&i->next, &e->reg_pids); if (e->state == REG_NAME_IDLE || e->state == REG_NAME_AUTO_ACCEPT || @@ -365,8 +365,8 @@ static void reg_entry_check_state(struct reg_entry * e) return; } - if (list_is_empty(&e->reg_apis)) { - if (!list_is_empty(&e->reg_apns)) + if (list_is_empty(&e->reg_pids)) { + if (!list_is_empty(&e->reg_progs)) e->state = REG_NAME_AUTO_ACCEPT; else e->state = REG_NAME_IDLE; @@ -389,8 +389,8 @@ void reg_entry_del_pid_el(struct reg_entry * e, reg_entry_check_state(e); } -void reg_entry_del_api(struct reg_entry * e, - pid_t api) +void reg_entry_del_pid(struct reg_entry * e, + pid_t pid) { struct list_head * p; struct list_head * h; @@ -400,9 +400,9 @@ void reg_entry_del_api(struct reg_entry * e, if (e == NULL) return; - list_for_each_safe(p, h, &e->reg_apis) { + list_for_each_safe(p, h, &e->reg_pids) { struct pid_el * a = list_entry(p, struct pid_el, next); - if (a->pid == api) { + if (a->pid == pid) { list_del(&a->next); free(a); } @@ -411,15 +411,15 @@ void reg_entry_del_api(struct reg_entry * e, reg_entry_check_state(e); } -pid_t reg_entry_get_api(struct reg_entry * e) +pid_t reg_entry_get_pid(struct reg_entry * e) { if (e == NULL) return -1; - if (list_is_empty(&e->reg_apis)) + if (list_is_empty(&e->reg_pids)) return -1; - return list_first_entry(&e->reg_apis, struct pid_el, next)->pid; + return list_first_entry(&e->reg_pids, struct pid_el, next)->pid; } enum reg_name_state reg_entry_get_state(struct reg_entry * e) @@ -618,19 +618,19 @@ void registry_del_name(struct list_head * registry, return; } -void registry_del_api(struct list_head * registry, - pid_t api) +void registry_del_process(struct list_head * registry, + pid_t pid) { struct list_head * p; assert(registry); - assert(api > 0); + assert(pid > 0); list_for_each(p, registry) { struct reg_entry * e = list_entry(p, struct reg_entry, next); pthread_mutex_lock(&e->state_lock); assert(e); - reg_entry_del_api(e, api); + reg_entry_del_pid(e, pid); pthread_mutex_unlock(&e->state_lock); } diff --git a/src/irmd/registry.h b/src/irmd/registry.h index 486843a2..f1f52b9e 100644 --- a/src/irmd/registry.h +++ b/src/irmd/registry.h @@ -28,8 +28,8 @@ #include <ouroboros/list.h> #include <ouroboros/qoscube.h> -#include "api_table.h" -#include "apn_table.h" +#include "proc_table.h" +#include "prog_table.h" #include <stdint.h> #include <stdbool.h> @@ -57,35 +57,35 @@ struct reg_entry { /* DIFs in which this name is registered */ struct list_head difs; - /* APs that can be instantiated by the irmd */ - struct list_head reg_apns; - /* Instances that are listening for this name */ - struct list_head reg_apis; + /* Programs that can be instantiated by the irmd */ + struct list_head reg_progs; + /* Processes that are listening for this name */ + struct list_head reg_pids; enum reg_name_state state; pthread_cond_t state_cond; pthread_mutex_t state_lock; }; -int reg_entry_add_apn(struct reg_entry * e, - struct apn_entry * a); +int reg_entry_add_prog(struct reg_entry * e, + struct prog_entry * a); -void reg_entry_del_apn(struct reg_entry * e, - const char * apn); +void reg_entry_del_prog(struct reg_entry * e, + const char * prog); -char * reg_entry_get_apn(struct reg_entry * e); +char * reg_entry_get_prog(struct reg_entry * e); -int reg_entry_add_api(struct reg_entry * e, - pid_t api); +int reg_entry_add_pid(struct reg_entry * e, + pid_t pid); -void reg_entry_del_api(struct reg_entry * e, - pid_t api); +void reg_entry_del_pid(struct reg_entry * e, + pid_t pid); void reg_entry_del_pid_el(struct reg_entry * e, struct pid_el * a); -pid_t reg_entry_get_api(struct reg_entry * e); +pid_t reg_entry_get_pid(struct reg_entry * e); enum reg_name_state reg_entry_get_state(struct reg_entry * e); @@ -106,10 +106,10 @@ struct reg_entry * registry_add_name(struct list_head * registry, void registry_del_name(struct list_head * registry, const char * name); -void registry_del_api(struct list_head * registry, - pid_t api); +void registry_del_process(struct list_head * registry, + pid_t pid); -void registry_sanitize_apis(struct list_head * registry); +void registry_sanitize_pids(struct list_head * registry); struct reg_entry * registry_get_entry(struct list_head * registry, const char * name); 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; } diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt index 03c1490a..08bf5487 100644 --- a/src/tools/irm/CMakeLists.txt +++ b/src/tools/irm/CMakeLists.txt @@ -7,8 +7,8 @@ include_directories(${CMAKE_BINARY_DIR}/include) set(SOURCE_FILES # Add source files here irm.c - irm_bind_ap.c - irm_bind_api.c + irm_bind_program.c + irm_bind_process.c irm_bind_ipcp.c irm_ipcp_create.c irm_ipcp_destroy.c @@ -16,8 +16,8 @@ set(SOURCE_FILES irm_ipcp_enroll.c irm_ipcp_connect.c irm_ipcp_disconnect.c - irm_unbind_ap.c - irm_unbind_api.c + irm_unbind_program.c + irm_unbind_process.c irm_unbind_ipcp.c irm_unbind.c irm_bind.c diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index 6ca902b0..ccadc0f8 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -53,7 +53,8 @@ static void usage(void) " register unregister}\n"); } -static int do_help(int argc, char **argv) +static int do_help(int argc, + char **argv) { (void) argc; (void) argv; @@ -76,8 +77,8 @@ static const struct cmd { }; static int do_cmd(const char * argv0, - int argc, - char ** argv) + int argc, + char ** argv) { const struct cmd * c; @@ -91,7 +92,8 @@ static int do_cmd(const char * argv0, return -1; } -int main(int argc, char ** argv) +int main(int argc, + char ** argv) { int ret = 0; diff --git a/src/tools/irm/irm_bind.c b/src/tools/irm/irm_bind.c index 023b5c3a..6b73f83f 100644 --- a/src/tools/irm/irm_bind.c +++ b/src/tools/irm/irm_bind.c @@ -47,10 +47,11 @@ static void usage(void) { printf("Usage: irm bind [OPERATION]\n" "\n" - "where OPERATION = {ap api ipcp help}\n"); + "where OPERATION = {program process ipcp help}\n"); } -static int do_help(int argc, char **argv) +static int do_help(int argc, + char **argv) { (void) argc; (void) argv; @@ -63,16 +64,16 @@ static const struct cmd { const char * cmd; int (* func)(int argc, char ** argv); } cmds[] = { - { "ap", do_bind_ap }, - { "api", do_bind_api }, - { "ipcp", do_bind_ipcp }, - { "help", do_help }, - { NULL, NULL } + { "program", do_bind_program }, + { "process", do_bind_process }, + { "ipcp", do_bind_ipcp }, + { "help", do_help }, + { NULL, NULL } }; static int do_cmd(const char * argv0, - int argc, - char ** argv) + int argc, + char ** argv) { const struct cmd * c; @@ -86,7 +87,8 @@ static int do_cmd(const char * argv0, return -1; } -int bind_cmd(int argc, char ** argv) +int bind_cmd(int argc, + char ** argv) { if (argc < 1) { usage(); diff --git a/src/tools/irm/irm_bind_ipcp.c b/src/tools/irm/irm_bind_ipcp.c index 375be03c..6299ca2b 100644 --- a/src/tools/irm/irm_bind_ipcp.c +++ b/src/tools/irm/irm_bind_ipcp.c @@ -50,12 +50,13 @@ static void usage(void) printf("Usage: irm bind ipcp <name> name <name>\n"); } -int do_bind_ipcp(int argc, char ** argv) +int do_bind_ipcp(int argc, + char ** argv) { char * ipcp = NULL; char * name = NULL; - pid_t * apis = NULL; + pid_t * pids = NULL; ssize_t len = 0; int i; @@ -84,12 +85,12 @@ int do_bind_ipcp(int argc, char ** argv) return -1; } - len = irm_list_ipcps(ipcp, &apis); + len = irm_list_ipcps(ipcp, &pids); for (i = 0; i < len; ++i) - irm_bind_api(apis[i], name); + irm_bind_process(pids[i], name); - free(apis); + free(pids); return 0; } diff --git a/src/tools/irm/irm_bind_api.c b/src/tools/irm/irm_bind_process.c index d441852d..b1d36163 100644 --- a/src/tools/irm/irm_bind_api.c +++ b/src/tools/irm/irm_bind_process.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2017 * - * Bind AP-I to a name + * Bind a process to a name * * Dimitri Staessens <dimitri.staessens@ugent.be> * Sander Vrijders <sander.vrijders@ugent.be> @@ -51,12 +51,13 @@ static void usage(void) { - printf("Usage: irm bind api <pid> name <name>\n"); + printf("Usage: irm bind process <pid> name <name>\n"); } -int do_bind_api(int argc, char ** argv) +int do_bind_process(int argc, + char ** argv) { - pid_t api = -1; + pid_t pid = -1; char * name = NULL; char * t; @@ -65,9 +66,9 @@ int do_bind_api(int argc, char ** argv) name = *(argv + 1); ++argv; --argc; - } else if (matches(*argv, "api") == 0) { - api = strtol(*(argv + 1), &t, 10); - if (*(argv + 1) == t || *t != '\0' || kill(api, 0)) { + } else if (matches(*argv, "process") == 0) { + pid = strtol(*(argv + 1), &t, 10); + if (*(argv + 1) == t || *t != '\0' || kill(pid, 0)) { printf("\"%s\" is not a valid process id.\n", *(argv + 1)); return -1; @@ -76,7 +77,7 @@ int do_bind_api(int argc, char ** argv) --argc; } else { printf("\"%s\" is unknown, try \"irm " - "bind api\".\n", *argv); + "bind process\".\n", *argv); return -1; } @@ -84,10 +85,10 @@ int do_bind_api(int argc, char ** argv) --argc; } - if (argc == 1 || api < 0 || name == NULL) { + if (argc == 1 || pid < 0 || name == NULL) { usage(); return -1; } - return irm_bind_api(api, name); + return irm_bind_process(pid, name); } diff --git a/src/tools/irm/irm_bind_ap.c b/src/tools/irm/irm_bind_program.c index ae213ab0..3fc8dbd4 100644 --- a/src/tools/irm/irm_bind_ap.c +++ b/src/tools/irm/irm_bind_program.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2017 * - * Bind AP to a name + * Bind programs to a name * * Dimitri Staessens <dimitri.staessens@ugent.be> * Sander Vrijders <sander.vrijders@ugent.be> @@ -51,46 +51,43 @@ static void usage(void) { - printf("Usage: irm bind ap <ap>\n" + printf("Usage: irm bind program <program>\n" " name <name>\n" - " [auto] (instantiate apn if not running)\n" - " [loc] (location-dependent application)\n" - " [unique] (there can only be one instantiation)\n" + " [auto] (instantiate program if not running)\n" " [-- <application arguments>]\n"); } -int do_bind_ap(int argc, char ** argv) +int do_bind_program(int argc, + char ** argv) { - char * name = NULL; - char * ap_name = NULL; + char * name = NULL; + char * prog = NULL; uint16_t flags = 0; - int ret = 0; - char * temp = NULL; + int ret = 0; + char * temp = NULL; while (argc > 0) { if (matches(*argv, "name") == 0) { name = *(argv + 1); ++argv; --argc; - } else if (matches(*argv, "ap") == 0) { + } else if (matches(*argv, "program") == 0) { ++argv; temp = realpath(*argv, NULL); if (temp != NULL) *argv = temp; - ap_name = *argv; + prog = *argv; --argc; } else if (strcmp(*argv, "auto") == 0) { - flags |= BIND_AP_AUTO; - } else if (strcmp(*argv, "unique") == 0) { - flags |= BIND_AP_UNIQUE; + flags |= BIND_AUTO; } else if (strcmp(*argv, "--") == 0) { ++argv; --argc; break; } else { printf("\"%s\" is unknown, try \"irm " - "bind\".\n", *argv); + "bind program\".\n", *argv); return -1; } @@ -98,20 +95,19 @@ int do_bind_ap(int argc, char ** argv) --argc; } - if (name == NULL || ap_name == NULL) { + if (name == NULL || prog == NULL) { usage(); return -1; } - ret = irm_bind_ap(ap_name, name, flags, argc, argv); + ret = irm_bind_program(prog, name, flags, argc, argv); if (ret == -ENOENT) { - printf("%s does not exist.\n", ap_name); + printf("%s does not exist.\n", prog); return ret; } if (ret == -EPERM) { - printf("Cannot execute %s, please check permissions.\n", - ap_name); + printf("Cannot execute %s, please check permissions.\n", prog); return ret; } diff --git a/src/tools/irm/irm_ipcp_bootstrap.c b/src/tools/irm/irm_ipcp_bootstrap.c index 3da78a2b..acd3779e 100644 --- a/src/tools/irm/irm_ipcp_bootstrap.c +++ b/src/tools/irm/irm_ipcp_bootstrap.c @@ -107,10 +107,11 @@ static void usage(void) LINK_STATE_ROUTING, SIMPLE_PFF, SHA3_256); } -int do_bootstrap_ipcp(int argc, char ** argv) +int do_bootstrap_ipcp(int argc, + char ** argv) { char * name = NULL; - pid_t api; + pid_t pid; struct ipcp_config conf; uint8_t addr_size = DEFAULT_ADDR_SIZE; uint8_t fd_size = DEFAULT_FD_SIZE; @@ -124,7 +125,7 @@ int do_bootstrap_ipcp(int argc, char ** argv) char * ipcp_type = NULL; char * dif_name = NULL; char * if_name = NULL; - pid_t * apis = NULL; + pid_t * pids = NULL; ssize_t len = 0; int i = 0; bool autobind = false; @@ -239,39 +240,39 @@ int do_bootstrap_ipcp(int argc, char ** argv) autobind = false; } - len = irm_list_ipcps(name, &apis); + len = irm_list_ipcps(name, &pids); if (len <= 0) { - api = irm_create_ipcp(name, conf.type); - if (api == 0) + pid = irm_create_ipcp(name, conf.type); + if (pid== 0) return -1; - len = irm_list_ipcps(name, &apis); + len = irm_list_ipcps(name, &pids); } for (i = 0; i < len; i++) { - if (autobind && irm_bind_api(apis[i], name)) { - printf("Failed to bind %d to %s.\n", apis[i], name); - free(apis); + if (autobind && irm_bind_process(pids[i], name)) { + printf("Failed to bind %d to %s.\n", pids[i], name); + free(pids); return -1; } - if (autobind && irm_bind_api(apis[i], dif_name)) { - printf("Failed to bind %d to %s.\n", apis[i], dif_name); - irm_unbind_api(apis[i], name); - free(apis); + if (autobind && irm_bind_process(pids[i], dif_name)) { + printf("Failed to bind %d to %s.\n", pids[i], dif_name); + irm_unbind_process(pids[i], name); + free(pids); return -1; } - if (irm_bootstrap_ipcp(apis[i], &conf)) { + if (irm_bootstrap_ipcp(pids[i], &conf)) { if (autobind) { - irm_unbind_api(apis[i], name); - irm_unbind_api(apis[i], dif_name); + irm_unbind_process(pids[i], name); + irm_unbind_process(pids[i], dif_name); } - free(apis); + free(pids); return -1; } } - free(apis); + free(pids); return 0; diff --git a/src/tools/irm/irm_ipcp_connect.c b/src/tools/irm/irm_ipcp_connect.c index 0f52d71b..a874afc2 100644 --- a/src/tools/irm/irm_ipcp_connect.c +++ b/src/tools/irm/irm_ipcp_connect.c @@ -63,7 +63,7 @@ int do_connect_ipcp(int argc, char * name = NULL; char * dst_name = NULL; char * comp_name = NULL; - pid_t * apis = NULL; + pid_t * pids = NULL; ssize_t len = 0; while (argc > 0) { @@ -88,7 +88,7 @@ int do_connect_ipcp(int argc, return -1; } - len = irm_list_ipcps(name, &apis); + len = irm_list_ipcps(name, &pids); if (len != 1) return -1; @@ -98,13 +98,13 @@ int do_connect_ipcp(int argc, if (!strcmp(comp_name , MGMT)) comp_name = MGMT_AE; - if (irm_connect_ipcp(apis[0], dst_name, comp_name)) { - free(apis); + if (irm_connect_ipcp(pids[0], dst_name, comp_name)) { + free(pids); return -1; } - if (apis != NULL) - free(apis); + if (pids != NULL) + free(pids); return 0; } diff --git a/src/tools/irm/irm_ipcp_create.c b/src/tools/irm/irm_ipcp_create.c index 99da0a51..bad62aed 100644 --- a/src/tools/irm/irm_ipcp_create.c +++ b/src/tools/irm/irm_ipcp_create.c @@ -63,7 +63,7 @@ int do_create_ipcp(int argc, char ** argv) char * ipcp_type = NULL; char * ipcp_name = NULL; enum ipcp_type type = 0; - pid_t api; + pid_t pid; while (argc > 0) { if (matches(*argv, "type") == 0) { @@ -98,8 +98,8 @@ int do_create_ipcp(int argc, char ** argv) return -1; } - api = irm_create_ipcp(ipcp_name, type); - if (api == 0) + pid = irm_create_ipcp(ipcp_name, type); + if (pid == 0) return -1; return 0; diff --git a/src/tools/irm/irm_ipcp_destroy.c b/src/tools/irm/irm_ipcp_destroy.c index 2a44c59b..f9d7fcc3 100644 --- a/src/tools/irm/irm_ipcp_destroy.c +++ b/src/tools/irm/irm_ipcp_destroy.c @@ -53,7 +53,7 @@ static void usage(void) int do_destroy_ipcp(int argc, char ** argv) { char * name = NULL; - pid_t * apis; + pid_t * pids; ssize_t len = 0; int i = 0; @@ -75,15 +75,15 @@ int do_destroy_ipcp(int argc, char ** argv) return -1; } - len = irm_list_ipcps(name, &apis); + len = irm_list_ipcps(name, &pids); if (len <= 0) return -1; for (i = 0; i < len; i++) - if (irm_destroy_ipcp(apis[i])) + if (irm_destroy_ipcp(pids[i])) return -1; - free(apis); + free(pids); return 0; } diff --git a/src/tools/irm/irm_ipcp_disconnect.c b/src/tools/irm/irm_ipcp_disconnect.c index 0fc4d01c..2b8c69dd 100644 --- a/src/tools/irm/irm_ipcp_disconnect.c +++ b/src/tools/irm/irm_ipcp_disconnect.c @@ -63,7 +63,7 @@ int do_disconnect_ipcp(int argc, char * name = NULL; char * dst_name = NULL; char * comp_name = NULL; - pid_t * apis = NULL; + pid_t * pids = NULL; ssize_t len = 0; while (argc > 0) { @@ -88,7 +88,7 @@ int do_disconnect_ipcp(int argc, return -1; } - len = irm_list_ipcps(name, &apis); + len = irm_list_ipcps(name, &pids); if (len != 1) return -1; @@ -98,13 +98,13 @@ int do_disconnect_ipcp(int argc, if (!strcmp(comp_name , MGMT)) comp_name = MGMT_AE; - if (irm_disconnect_ipcp(apis[0], dst_name, comp_name)) { - free(apis); + if (irm_disconnect_ipcp(pids[0], dst_name, comp_name)) { + free(pids); return -1; } - if (apis != NULL) - free(apis); + if (pids != NULL) + free(pids); return 0; } diff --git a/src/tools/irm/irm_ipcp_enroll.c b/src/tools/irm/irm_ipcp_enroll.c index 1ebe9a6d..4beb6754 100644 --- a/src/tools/irm/irm_ipcp_enroll.c +++ b/src/tools/irm/irm_ipcp_enroll.c @@ -56,8 +56,8 @@ int do_enroll_ipcp(int argc, char ** argv) { char * name = NULL; char * dif_name = NULL; - pid_t * apis = NULL; - pid_t api; + pid_t * pids = NULL; + pid_t pid; ssize_t len = 0; int i = 0; bool autobind = false; @@ -87,36 +87,36 @@ int do_enroll_ipcp(int argc, char ** argv) return -1; } - len = irm_list_ipcps(name, &apis); + len = irm_list_ipcps(name, &pids); if (len <= 0) { - api = irm_create_ipcp(name, IPCP_NORMAL); - if (api == 0) + pid = irm_create_ipcp(name, IPCP_NORMAL); + if (pid == 0) return -1; - len = irm_list_ipcps(name, &apis); + len = irm_list_ipcps(name, &pids); } for (i = 0; i < len; i++) { - if (autobind && irm_bind_api(apis[i], name)) { - free(apis); + if (autobind && irm_bind_process(pids[i], name)) { + free(pids); return -1; } - if (irm_enroll_ipcp(apis[i], dif_name)) { + if (irm_enroll_ipcp(pids[i], dif_name)) { if (autobind) - irm_unbind_api(apis[i], name); - free(apis); + irm_unbind_process(pids[i], name); + free(pids); return -1; } - if (autobind && irm_bind_api(apis[i], dif_name)) { - printf("Failed to bind %d to %s.\n", apis[i], dif_name); - free(apis); + if (autobind && irm_bind_process(pids[i], dif_name)) { + printf("Failed to bind %d to %s.\n", pids[i], dif_name); + free(pids); return -1; } } - if (apis != NULL) - free(apis); + if (pids != NULL) + free(pids); return 0; } diff --git a/src/tools/irm/irm_ops.h b/src/tools/irm/irm_ops.h index 7a8127a1..d3cb8d21 100644 --- a/src/tools/irm/irm_ops.h +++ b/src/tools/irm/irm_ops.h @@ -60,11 +60,11 @@ int do_disconnect_ipcp(int argc, int bind_cmd(int argc, char ** argv); -int do_bind_ap(int argc, - char ** argv); +int do_bind_program(int argc, + char ** argv); -int do_bind_api(int argc, - char ** argv); +int do_bind_process(int argc, + char ** argv); int do_bind_ipcp(int argc, char ** argv); @@ -72,11 +72,11 @@ int do_bind_ipcp(int argc, int unbind_cmd(int argc, char ** argv); -int do_unbind_ap(int argc, - char ** argv); +int do_unbind_program(int argc, + char ** argv); -int do_unbind_api(int argc, - char ** argv); +int do_unbind_process(int argc, + char ** argv); int do_unbind_ipcp(int argc, char ** argv); diff --git a/src/tools/irm/irm_unbind.c b/src/tools/irm/irm_unbind.c index a4d780b8..fb66e456 100644 --- a/src/tools/irm/irm_unbind.c +++ b/src/tools/irm/irm_unbind.c @@ -47,10 +47,11 @@ static void usage(void) { printf("Usage: irm unbind [OPERATION]\n" "\n" - "where OPERATION = {ap api ipcp help}\n"); + "where OPERATION = {program process ipcp help}\n"); } -static int do_help(int argc, char **argv) +static int do_help(int argc, + char ** argv) { (void) argc; (void) argv; @@ -63,14 +64,16 @@ static const struct cmd { const char * cmd; int (* func)(int argc, char ** argv); } cmds[] = { - { "ap", do_unbind_ap }, - { "api", do_unbind_api }, - { "ipcp", do_unbind_ipcp }, - { "help", do_help }, - { NULL, NULL } + { "program", do_unbind_program }, + { "process", do_unbind_process }, + { "ipcp", do_unbind_ipcp }, + { "help", do_help }, + { NULL, NULL } }; -static int do_cmd(const char * argv0, int argc, char ** argv) +static int do_cmd(const char * argv0, + int argc, + char ** argv) { const struct cmd * c; @@ -83,7 +86,8 @@ static int do_cmd(const char * argv0, int argc, char ** argv) return -1; } -int unbind_cmd(int argc, char ** argv) +int unbind_cmd(int argc, + char ** argv) { if (argc < 1) { usage(); diff --git a/src/tools/irm/irm_unbind_ipcp.c b/src/tools/irm/irm_unbind_ipcp.c index 9f5b98b9..1a442cd4 100644 --- a/src/tools/irm/irm_unbind_ipcp.c +++ b/src/tools/irm/irm_unbind_ipcp.c @@ -57,7 +57,7 @@ int do_unbind_ipcp(int argc, char ** argv) char * ipcp = NULL; char * name = NULL; - pid_t * apis = NULL; + pid_t * pids = NULL; ssize_t len = 0; int i; @@ -86,12 +86,12 @@ int do_unbind_ipcp(int argc, char ** argv) return -1; } - len = irm_list_ipcps(ipcp, &apis); + len = irm_list_ipcps(ipcp, &pids); for (i = 0; i < len; ++i) - irm_unbind_api(apis[i], name); + irm_unbind_process(pids[i], name); - free(apis); + free(pids); return 0; } diff --git a/src/tools/irm/irm_unbind_api.c b/src/tools/irm/irm_unbind_process.c index 0213737a..840be750 100644 --- a/src/tools/irm/irm_unbind_api.c +++ b/src/tools/irm/irm_unbind_process.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2017 * - * Unbind AP-I names + * Unbind process names * * Dimitri Staessens <dimitri.staessens@ugent.be> * Sander Vrijders <sander.vrijders@ugent.be> @@ -47,14 +47,15 @@ static void usage(void) { - printf("Usage: irm unbind api <pid>\n" - " [name <name> (default: remove all AP-I info)]" + printf("Usage: irm unbind process <pid>\n" + " [name <name> (default: unbind all names)]" "\n"); } -int do_unbind_api(int argc, char ** argv) +int do_unbind_process(int argc, + char ** argv) { - pid_t api = -1; + pid_t pid = -1; char * name = NULL; while (argc > 1) { @@ -62,13 +63,13 @@ int do_unbind_api(int argc, char ** argv) name = *(argv + 1); ++argv; --argc; - } else if (matches(*argv, "api") == 0) { - api = strtol(*(argv + 1), NULL, 10); + } else if (matches(*argv, "process") == 0) { + pid = strtol(*(argv + 1), NULL, 10); ++argv; --argc; } else { printf("\"%s\" is unknown, try \"irm " - "unbind api\".\n", *argv); + "unbind process\".\n", *argv); return -1; } @@ -76,10 +77,10 @@ int do_unbind_api(int argc, char ** argv) --argc; } - if (api < 0) { + if (pid < 0) { usage(); return -1; } - return irm_unbind_api(api, name); + return irm_unbind_process(pid, name); } diff --git a/src/tools/irm/irm_unbind_ap.c b/src/tools/irm/irm_unbind_program.c index 46a147db..22c8bd57 100644 --- a/src/tools/irm/irm_unbind_ap.c +++ b/src/tools/irm/irm_unbind_program.c @@ -1,7 +1,7 @@ /* * Ouroboros - Copyright (C) 2016 - 2017 * - * Unbind AP names + * Unbind programs * * Dimitri Staessens <dimitri.staessens@ugent.be> * Sander Vrijders <sander.vrijders@ugent.be> @@ -46,28 +46,29 @@ static void usage(void) { - printf("Usage: irm unbind ap <ap>\n" - " [name <name> (default: remove all AP info)]" + printf("Usage: irm unbind program <program>\n" + " [name <name> (default: unbind all names)]" "\n"); } -int do_unbind_ap(int argc, char ** argv) +int do_unbind_program(int argc, + char ** argv) { char * name = NULL; - char * ap_name = NULL; + char * prog = NULL; while (argc > 0) { if (matches(*argv, "name") == 0) { name = *(argv + 1); ++argv; --argc; - } else if (matches(*argv, "ap") == 0) { - ap_name = *(argv + 1); + } else if (matches(*argv, "program") == 0) { + prog = *(argv + 1); ++argv; --argc; } else { printf("\"%s\" is unknown, try \"irm " - "unbind ap\".\n", *argv); + "unbind program\".\n", *argv); return -1; } @@ -75,10 +76,10 @@ int do_unbind_ap(int argc, char ** argv) --argc; } - if (ap_name == NULL) { + if (prog == NULL) { usage(); return -1; } - return irm_unbind_ap(ap_name, name); + return irm_unbind_program(prog, name); } diff --git a/src/tools/irm/irm_utils.c b/src/tools/irm/irm_utils.c index 524f4dff..4f3c7e21 100644 --- a/src/tools/irm/irm_utils.c +++ b/src/tools/irm/irm_utils.c @@ -42,7 +42,8 @@ #include "irm_utils.h" -int matches(const char * cmd, const char * pattern) +int matches(const char * cmd, + const char * pattern) { size_t len = strlen(cmd); diff --git a/src/tools/irm/irm_utils.h b/src/tools/irm/irm_utils.h index 1d222554..458ec34e 100644 --- a/src/tools/irm/irm_utils.h +++ b/src/tools/irm/irm_utils.h @@ -36,5 +36,10 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef OUROBOROS_TOOLS_IRM_UTILS_H +#define OUROBOROS_TOOLS_IRM_UTILS_H + int matches(const char * cmd, const char * pattern); + +#endif /* OUROBOROS_TOOLS_IRM_UTILS_H */ |