summaryrefslogtreecommitdiff
path: root/src/tools/irm/irm_ipcp_destroy.c
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2018-03-22 11:02:15 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2018-03-22 12:36:58 +0100
commit751fb58bcf5fdb31c0627a5153684e96126cffb6 (patch)
tree5c4e8d8b2b2b323738703644c422a7e6c7095d5e /src/tools/irm/irm_ipcp_destroy.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 <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/tools/irm/irm_ipcp_destroy.c')
-rw-r--r--src/tools/irm/irm_ipcp_destroy.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/tools/irm/irm_ipcp_destroy.c b/src/tools/irm/irm_ipcp_destroy.c
index 4c37f52b..cb86b167 100644
--- a/src/tools/irm/irm_ipcp_destroy.c
+++ b/src/tools/irm/irm_ipcp_destroy.c
@@ -44,22 +44,25 @@
#include "irm_ops.h"
#include "irm_utils.h"
+#include <string.h>
+
static void usage(void)
{
printf("Usage: irm ipcp destroy\n"
" name <ipcp name>\n");
}
-int do_destroy_ipcp(int argc, char ** argv)
+int do_destroy_ipcp(int argc,
+ char ** argv)
{
- char * name = NULL;
- pid_t * pids;
- ssize_t len = 0;
- int i = 0;
+ char * ipcp = NULL;
+ struct ipcp_info * ipcps;
+ ssize_t len;
+ int i;
while (argc > 0) {
if (matches(*argv, "name") == 0) {
- name = *(argv + 1);
+ ipcp = *(argv + 1);
} else {
printf("\"%s\" is unknown, try \"irm "
"ipcp destroy\".\n", *argv);
@@ -70,20 +73,26 @@ int do_destroy_ipcp(int argc, char ** argv)
argv += 2;
}
- if (name == NULL) {
+ if (ipcp == NULL) {
usage();
return -1;
}
- len = irm_list_ipcps(name, &pids);
+ len = irm_list_ipcps(&ipcps);
if (len <= 0)
- return -1;
+ goto fail;
for (i = 0; i < len; i++)
- if (irm_destroy_ipcp(pids[i]))
- return -1;
+ if (strcmp(ipcps[i].name, ipcp) == 0) {
+ if (irm_destroy_ipcp(ipcps[i].pid))
+ goto fail_destroy;
+ break;
+ }
- free(pids);
return 0;
+ fail_destroy:
+ free(ipcps);
+ fail:
+ return -1;
}