From 9b8a3e11c558877c09416991ff1ec840fea6d0ab Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 2 Dec 2017 14:01:03 +0100 Subject: lib, tools: Rename application process and instance This refactors ouroboros to use "program" instead of "application process" and "process" instead of "application process instance" to align with current naming in current Operating Systems courses instead of the ISO nomenclature adopted by RINA. This change permeates through the entire implementation. Also contains some minor other refactors. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/tools/irm/CMakeLists.txt | 8 +-- src/tools/irm/irm.c | 10 +-- src/tools/irm/irm_bind.c | 22 ++++--- src/tools/irm/irm_bind_ap.c | 122 ------------------------------------ src/tools/irm/irm_bind_api.c | 93 --------------------------- src/tools/irm/irm_bind_ipcp.c | 11 ++-- src/tools/irm/irm_bind_process.c | 94 +++++++++++++++++++++++++++ src/tools/irm/irm_bind_program.c | 118 ++++++++++++++++++++++++++++++++++ src/tools/irm/irm_ipcp_bootstrap.c | 39 ++++++------ src/tools/irm/irm_ipcp_connect.c | 12 ++-- src/tools/irm/irm_ipcp_create.c | 6 +- src/tools/irm/irm_ipcp_destroy.c | 8 +-- src/tools/irm/irm_ipcp_disconnect.c | 12 ++-- src/tools/irm/irm_ipcp_enroll.c | 32 +++++----- src/tools/irm/irm_ops.h | 16 ++--- src/tools/irm/irm_unbind.c | 22 ++++--- src/tools/irm/irm_unbind_ap.c | 84 ------------------------- src/tools/irm/irm_unbind_api.c | 85 ------------------------- src/tools/irm/irm_unbind_ipcp.c | 8 +-- src/tools/irm/irm_unbind_process.c | 86 +++++++++++++++++++++++++ src/tools/irm/irm_unbind_program.c | 85 +++++++++++++++++++++++++ src/tools/irm/irm_utils.c | 3 +- src/tools/irm/irm_utils.h | 5 ++ 23 files changed, 498 insertions(+), 483 deletions(-) delete mode 100644 src/tools/irm/irm_bind_ap.c delete mode 100644 src/tools/irm/irm_bind_api.c create mode 100644 src/tools/irm/irm_bind_process.c create mode 100644 src/tools/irm/irm_bind_program.c delete mode 100644 src/tools/irm/irm_unbind_ap.c delete mode 100644 src/tools/irm/irm_unbind_api.c create mode 100644 src/tools/irm/irm_unbind_process.c create mode 100644 src/tools/irm/irm_unbind_program.c (limited to 'src/tools') 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_ap.c b/src/tools/irm/irm_bind_ap.c deleted file mode 100644 index ae213ab0..00000000 --- a/src/tools/irm/irm_bind_ap.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Bind AP to a name - * - * Dimitri Staessens - * Sander Vrijders - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define _POSIX_C_SOURCE 200809L -#define _XOPEN_SOURCE 500 - -#include -#include -#include - -#include -#include - -#include "irm_ops.h" -#include "irm_utils.h" - -static void usage(void) -{ - printf("Usage: irm bind ap \n" - " name \n" - " [auto] (instantiate apn if not running)\n" - " [loc] (location-dependent application)\n" - " [unique] (there can only be one instantiation)\n" - " [-- ]\n"); -} - - -int do_bind_ap(int argc, char ** argv) -{ - char * name = NULL; - char * ap_name = NULL; - uint16_t flags = 0; - 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) { - ++argv; - temp = realpath(*argv, NULL); - if (temp != NULL) - *argv = temp; - ap_name = *argv; - --argc; - } else if (strcmp(*argv, "auto") == 0) { - flags |= BIND_AP_AUTO; - } else if (strcmp(*argv, "unique") == 0) { - flags |= BIND_AP_UNIQUE; - } else if (strcmp(*argv, "--") == 0) { - ++argv; - --argc; - break; - } else { - printf("\"%s\" is unknown, try \"irm " - "bind\".\n", *argv); - return -1; - } - - ++argv; - --argc; - } - - if (name == NULL || ap_name == NULL) { - usage(); - return -1; - } - - ret = irm_bind_ap(ap_name, name, flags, argc, argv); - if (ret == -ENOENT) { - printf("%s does not exist.\n", ap_name); - return ret; - } - - if (ret == -EPERM) { - printf("Cannot execute %s, please check permissions.\n", - ap_name); - return ret; - } - - if (temp != NULL) - free(temp); - - return ret; -} diff --git a/src/tools/irm/irm_bind_api.c b/src/tools/irm/irm_bind_api.c deleted file mode 100644 index d441852d..00000000 --- a/src/tools/irm/irm_bind_api.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Bind AP-I to a name - * - * Dimitri Staessens - * Sander Vrijders - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define _POSIX_C_SOURCE 200112L - -#include -#include -#include -#include - -#include -#include - -#include "irm_ops.h" -#include "irm_utils.h" - -static void usage(void) -{ - printf("Usage: irm bind api name \n"); -} - -int do_bind_api(int argc, char ** argv) -{ - pid_t api = -1; - char * name = NULL; - char * t; - - while (argc > 1) { - if (matches(*argv, "name") == 0) { - 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)) { - printf("\"%s\" is not a valid process id.\n", - *(argv + 1)); - return -1; - } - ++argv; - --argc; - } else { - printf("\"%s\" is unknown, try \"irm " - "bind api\".\n", *argv); - return -1; - } - - ++argv; - --argc; - } - - if (argc == 1 || api < 0 || name == NULL) { - usage(); - return -1; - } - - return irm_bind_api(api, name); -} 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 \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_process.c b/src/tools/irm/irm_bind_process.c new file mode 100644 index 00000000..b1d36163 --- /dev/null +++ b/src/tools/irm/irm_bind_process.c @@ -0,0 +1,94 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Bind a process to a name + * + * Dimitri Staessens + * Sander Vrijders + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define _POSIX_C_SOURCE 200112L + +#include +#include +#include +#include + +#include +#include + +#include "irm_ops.h" +#include "irm_utils.h" + +static void usage(void) +{ + printf("Usage: irm bind process name \n"); +} + +int do_bind_process(int argc, + char ** argv) +{ + pid_t pid = -1; + char * name = NULL; + char * t; + + while (argc > 1) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + ++argv; + --argc; + } 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; + } + ++argv; + --argc; + } else { + printf("\"%s\" is unknown, try \"irm " + "bind process\".\n", *argv); + return -1; + } + + ++argv; + --argc; + } + + if (argc == 1 || pid < 0 || name == NULL) { + usage(); + return -1; + } + + return irm_bind_process(pid, name); +} diff --git a/src/tools/irm/irm_bind_program.c b/src/tools/irm/irm_bind_program.c new file mode 100644 index 00000000..3fc8dbd4 --- /dev/null +++ b/src/tools/irm/irm_bind_program.c @@ -0,0 +1,118 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Bind programs to a name + * + * Dimitri Staessens + * Sander Vrijders + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define _POSIX_C_SOURCE 200809L +#define _XOPEN_SOURCE 500 + +#include +#include +#include + +#include +#include + +#include "irm_ops.h" +#include "irm_utils.h" + +static void usage(void) +{ + printf("Usage: irm bind program \n" + " name \n" + " [auto] (instantiate program if not running)\n" + " [-- ]\n"); +} + + +int do_bind_program(int argc, + char ** argv) +{ + char * name = NULL; + char * prog = NULL; + uint16_t flags = 0; + int ret = 0; + char * temp = NULL; + + while (argc > 0) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + ++argv; + --argc; + } else if (matches(*argv, "program") == 0) { + ++argv; + temp = realpath(*argv, NULL); + if (temp != NULL) + *argv = temp; + prog = *argv; + --argc; + } else if (strcmp(*argv, "auto") == 0) { + flags |= BIND_AUTO; + } else if (strcmp(*argv, "--") == 0) { + ++argv; + --argc; + break; + } else { + printf("\"%s\" is unknown, try \"irm " + "bind program\".\n", *argv); + return -1; + } + + ++argv; + --argc; + } + + if (name == NULL || prog == NULL) { + usage(); + return -1; + } + + ret = irm_bind_program(prog, name, flags, argc, argv); + if (ret == -ENOENT) { + printf("%s does not exist.\n", prog); + return ret; + } + + if (ret == -EPERM) { + printf("Cannot execute %s, please check permissions.\n", prog); + return ret; + } + + if (temp != NULL) + free(temp); + + 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_ap.c b/src/tools/irm/irm_unbind_ap.c deleted file mode 100644 index 46a147db..00000000 --- a/src/tools/irm/irm_unbind_ap.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Unbind AP names - * - * Dimitri Staessens - * Sander Vrijders - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include - -#include "irm_ops.h" -#include "irm_utils.h" - -static void usage(void) -{ - printf("Usage: irm unbind ap \n" - " [name (default: remove all AP info)]" - "\n"); -} - -int do_unbind_ap(int argc, char ** argv) -{ - char * name = NULL; - char * ap_name = NULL; - - while (argc > 0) { - if (matches(*argv, "name") == 0) { - name = *(argv + 1); - ++argv; - --argc; - } else if (matches(*argv, "ap") == 0) { - ap_name = *(argv + 1); - ++argv; - --argc; - } else { - printf("\"%s\" is unknown, try \"irm " - "unbind ap\".\n", *argv); - return -1; - } - - ++argv; - --argc; - } - - if (ap_name == NULL) { - usage(); - return -1; - } - - return irm_unbind_ap(ap_name, name); -} diff --git a/src/tools/irm/irm_unbind_api.c b/src/tools/irm/irm_unbind_api.c deleted file mode 100644 index 0213737a..00000000 --- a/src/tools/irm/irm_unbind_api.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Unbind AP-I names - * - * Dimitri Staessens - * Sander Vrijders - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include - -#include "irm_ops.h" -#include "irm_utils.h" - -static void usage(void) -{ - printf("Usage: irm unbind api \n" - " [name (default: remove all AP-I info)]" - "\n"); -} - -int do_unbind_api(int argc, char ** argv) -{ - pid_t api = -1; - char * name = NULL; - - while (argc > 1) { - if (matches(*argv, "name") == 0) { - name = *(argv + 1); - ++argv; - --argc; - } else if (matches(*argv, "api") == 0) { - api = strtol(*(argv + 1), NULL, 10); - ++argv; - --argc; - } else { - printf("\"%s\" is unknown, try \"irm " - "unbind api\".\n", *argv); - return -1; - } - - ++argv; - --argc; - } - - if (api < 0) { - usage(); - return -1; - } - - return irm_unbind_api(api, name); -} 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_process.c b/src/tools/irm/irm_unbind_process.c new file mode 100644 index 00000000..840be750 --- /dev/null +++ b/src/tools/irm/irm_unbind_process.c @@ -0,0 +1,86 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Unbind process names + * + * Dimitri Staessens + * Sander Vrijders + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +#include "irm_ops.h" +#include "irm_utils.h" + +static void usage(void) +{ + printf("Usage: irm unbind process \n" + " [name (default: unbind all names)]" + "\n"); +} + +int do_unbind_process(int argc, + char ** argv) +{ + pid_t pid = -1; + char * name = NULL; + + while (argc > 1) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + ++argv; + --argc; + } else if (matches(*argv, "process") == 0) { + pid = strtol(*(argv + 1), NULL, 10); + ++argv; + --argc; + } else { + printf("\"%s\" is unknown, try \"irm " + "unbind process\".\n", *argv); + return -1; + } + + ++argv; + --argc; + } + + if (pid < 0) { + usage(); + return -1; + } + + return irm_unbind_process(pid, name); +} diff --git a/src/tools/irm/irm_unbind_program.c b/src/tools/irm/irm_unbind_program.c new file mode 100644 index 00000000..22c8bd57 --- /dev/null +++ b/src/tools/irm/irm_unbind_program.c @@ -0,0 +1,85 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2017 + * + * Unbind programs + * + * Dimitri Staessens + * Sander Vrijders + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include + +#include "irm_ops.h" +#include "irm_utils.h" + +static void usage(void) +{ + printf("Usage: irm unbind program \n" + " [name (default: unbind all names)]" + "\n"); +} + +int do_unbind_program(int argc, + char ** argv) +{ + char * name = NULL; + char * prog = NULL; + + while (argc > 0) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + ++argv; + --argc; + } else if (matches(*argv, "program") == 0) { + prog = *(argv + 1); + ++argv; + --argc; + } else { + printf("\"%s\" is unknown, try \"irm " + "unbind program\".\n", *argv); + return -1; + } + + ++argv; + --argc; + } + + if (prog == NULL) { + usage(); + return -1; + } + + 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 */ -- cgit v1.2.3