summaryrefslogtreecommitdiff
path: root/src/lib/irm.c
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2018-03-22 11:02:15 +0100
committerSander Vrijders <[email protected]>2018-03-22 12:36:58 +0100
commit751fb58bcf5fdb31c0627a5153684e96126cffb6 (patch)
tree5c4e8d8b2b2b323738703644c422a7e6c7095d5e /src/lib/irm.c
parentfd5508b8daec47e9f646c086d4cc310583154b97 (diff)
downloadouroboros-751fb58bcf5fdb31c0627a5153684e96126cffb6.tar.gz
ouroboros-751fb58bcf5fdb31c0627a5153684e96126cffb6.zip
lib: Simplify reg/unreg API
The reg/unreg API is simplified to registering and unregistering a single name with a single IPCP. The functionality associated with registering names was moved from the IRMd to the irm tool. The function to list IPCPs was simplified to return all IPCPs in the system with their basic properties needed for management. The above changes led to some needed changes in the irm tool and the management functions that were depending on the previous behaviour of list_ipcps. Command line functionality to list IPCPs in the system is also added to the irm tool. Some older code was refactored. Signed-off-by: Dimitri Staessens <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/lib/irm.c')
-rw-r--r--src/lib/irm.c135
1 files changed, 65 insertions, 70 deletions
diff --git a/src/lib/irm.c b/src/lib/irm.c
index c12ab893..6a9f837e 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -34,7 +34,7 @@
#include <sys/stat.h>
pid_t irm_create_ipcp(const char * name,
- enum ipcp_type ipcp_type)
+ enum ipcp_type type)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
@@ -44,9 +44,9 @@ pid_t irm_create_ipcp(const char * name,
return -EINVAL;
msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP;
- msg.dst_name = (char *) name;
+ msg.name = (char *) name;
msg.has_ipcp_type = true;
- msg.ipcp_type = ipcp_type;
+ msg.ipcp_type = type;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -54,7 +54,7 @@ pid_t irm_create_ipcp(const char * name,
if (!recv_msg->has_result) {
irm_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return -EIRMD;
}
ret = recv_msg->result;
@@ -174,8 +174,8 @@ int irm_connect_ipcp(pid_t pid,
int ret;
msg.code = IRM_MSG_CODE__IRM_CONNECT_IPCP;
- msg.dst_name = (char *) dst;
- msg.comp_name = (char *) component;
+ msg.dst = (char *) dst;
+ msg.comp = (char *) component;
msg.has_pid = true;
msg.pid = pid;
@@ -202,11 +202,11 @@ int irm_disconnect_ipcp(pid_t pid,
irm_msg_t * recv_msg = NULL;
int ret;
- msg.code = IRM_MSG_CODE__IRM_DISCONNECT_IPCP;
- msg.dst_name = (char *) dst;
- msg.comp_name = (char *) component;
- msg.has_pid = true;
- msg.pid = pid;
+ msg.code = IRM_MSG_CODE__IRM_DISCONNECT_IPCP;
+ msg.dst = (char *) dst;
+ msg.comp = (char *) component;
+ msg.has_pid = true;
+ msg.pid = pid;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -223,38 +223,47 @@ int irm_disconnect_ipcp(pid_t pid,
return ret;
}
-ssize_t irm_list_ipcps(const char * name,
- pid_t ** pids)
+ssize_t irm_list_ipcps(struct ipcp_info ** ipcps)
{
irm_msg_t msg = IRM_MSG__INIT;
- irm_msg_t * recv_msg = NULL;
- size_t nr = 0;
+ irm_msg_t * recv_msg;
+ size_t nr;
size_t i;
- if (pids == NULL)
+ if (ipcps == NULL)
return -EINVAL;
+ *ipcps = NULL;
+
msg.code = IRM_MSG_CODE__IRM_LIST_IPCPS;
- msg.dst_name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
return -EIRMD;
- if (recv_msg->pids == NULL) {
+ if (recv_msg->ipcps == NULL) {
irm_msg__free_unpacked(recv_msg, NULL);
- return -1;
+ return 0;
+ }
+
+ nr = recv_msg->n_ipcps;
+ if (nr == 0) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return 0;
}
- nr = recv_msg->n_pids;
- *pids = malloc(nr * sizeof(pid_t));
- if (*pids == NULL) {
+ *ipcps = malloc(nr * sizeof(**ipcps));
+ if (*ipcps == NULL) {
irm_msg__free_unpacked(recv_msg, NULL);
return -ENOMEM;
}
- for (i = 0; i < nr; i++)
- (*pids)[i] = recv_msg->pids[i];
+ for (i = 0; i < nr; i++) {
+ (*ipcps)[i].pid = recv_msg->ipcps[i]->pid;
+ (*ipcps)[i].type = recv_msg->ipcps[i]->type;
+ strcpy((*ipcps)[i].name, recv_msg->ipcps[i]->name);
+ strcpy((*ipcps)[i].layer, recv_msg->ipcps[i]->layer);
+ }
irm_msg__free_unpacked(recv_msg, NULL);
@@ -262,30 +271,23 @@ ssize_t irm_list_ipcps(const char * name,
}
int irm_enroll_ipcp(pid_t pid,
- const char * layer_name)
+ const char * dst)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (pid == -1 || layer_name == NULL)
+ if (pid == -1 || dst == NULL)
return -EINVAL;
msg.code = IRM_MSG_CODE__IRM_ENROLL_IPCP;
msg.has_pid = true;
msg.pid = pid;
- msg.n_layer_name = 1;
- msg.layer_name = malloc(sizeof(*(msg.layer_name)));
- if (msg.layer_name == NULL)
- return -ENOMEM;
-
- msg.layer_name[0] = (char *) layer_name;
+ msg.dst = (char *) dst;
recv_msg = send_recv_irm_msg(&msg);
- if (recv_msg == NULL) {
- free(msg.layer_name);
+ if (recv_msg == NULL)
return -EIRMD;
- }
if (!recv_msg->has_result) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -295,7 +297,6 @@ int irm_enroll_ipcp(pid_t pid,
ret = recv_msg->result;
irm_msg__free_unpacked(recv_msg, NULL);
- free(msg.layer_name);
return ret;
}
@@ -403,9 +404,9 @@ int irm_bind_program(const char * prog,
return ret;
}
- msg.code = IRM_MSG_CODE__IRM_BIND_PROGRAM;
- msg.dst_name = (char *) name;
- msg.prog_name = full_name;
+ msg.code = IRM_MSG_CODE__IRM_BIND_PROGRAM;
+ msg.name = (char *) name;
+ msg.prog = full_name;
if (argv != NULL) {
msg.n_args = argc;
@@ -443,10 +444,10 @@ int irm_bind_process(pid_t pid,
if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_BIND_PROCESS;
- msg.has_pid = true;
- msg.pid = pid;
- msg.dst_name = (char *) name;
+ msg.code = IRM_MSG_CODE__IRM_BIND_PROCESS;
+ msg.has_pid = true;
+ msg.pid = pid;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -473,9 +474,9 @@ int irm_unbind_program(const char * prog,
if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_UNBIND_PROGRAM;
- msg.prog_name = (char *) prog;
- msg.dst_name = (char *) name;
+ msg.code = IRM_MSG_CODE__IRM_UNBIND_PROGRAM;
+ msg.prog = (char *) prog;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -502,10 +503,10 @@ int irm_unbind_process(pid_t pid,
if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_UNBIND_PROCESS;
- msg.has_pid = true;
- msg.pid = pid;
- msg.dst_name = (char *) name;
+ msg.code = IRM_MSG_CODE__IRM_UNBIND_PROCESS;
+ msg.has_pid = true;
+ msg.pid = pid;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -522,23 +523,20 @@ int irm_unbind_process(pid_t pid,
return ret;
}
-int irm_reg(const char * name,
- char ** layers,
- size_t len)
+int irm_reg(pid_t pid,
+ const char * name)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (name == NULL || layers == NULL || len == 0)
+ if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_REG;
-
- msg.dst_name = (char *) name;
-
- msg.layer_name = layers;
- msg.n_layer_name = len;
+ msg.code = IRM_MSG_CODE__IRM_REG;
+ msg.has_pid = true;
+ msg.pid = pid;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
@@ -556,23 +554,20 @@ int irm_reg(const char * name,
}
-int irm_unreg(const char * name,
- char ** layers,
- size_t len)
+int irm_unreg(pid_t pid,
+ const char * name)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (name == NULL || layers == NULL || len == 0)
+ if (name == NULL)
return -EINVAL;
- msg.code = IRM_MSG_CODE__IRM_UNREG;
-
- msg.dst_name = (char *) name;
-
- msg.layer_name = (char **) layers;
- msg.n_layer_name = len;
+ msg.code = IRM_MSG_CODE__IRM_UNREG;
+ msg.has_pid = true;
+ msg.pid = pid;
+ msg.name = (char *) name;
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)