diff --git a/system/nxinit/builtin.c b/system/nxinit/builtin.c index 5ed7f3a29..a2bc722bf 100644 --- a/system/nxinit/builtin.c +++ b/system/nxinit/builtin.c @@ -25,16 +25,23 @@ ****************************************************************************/ #include +#include #include #include #include #include +#include #include +#include #include #include #include +#ifdef CONFIG_RPTUN +#include +#endif + #include "builtin.h" #include "init.h" #include "property.h" @@ -91,6 +98,12 @@ static int cmd_start_cpu(FAR struct action_manager_s *am, static int cmd_netinit(FAR struct action_manager_s *am, int argc, FAR char **argv); #endif +#ifdef CONFIG_RPTUN +static int cmd_rptun(FAR struct action_manager_s *am, + int argc, FAR char **argv); +#endif +static int cmd_unlink(FAR struct action_manager_s *am, + int argc, FAR char **argv); /**************************************************************************** * Private Data @@ -120,6 +133,10 @@ static const struct cmd_map_s g_builtin[] = {"start", 2, 2, cmd_start}, {"stop", 2, 2, cmd_stop}, {"trigger", 2, 2, cmd_trigger}, +#ifdef CONFIG_RPTUN + {"rptun", 3, 3, cmd_rptun}, +#endif + {"unlink", 2, 2, cmd_unlink}, }; /**************************************************************************** @@ -269,6 +286,63 @@ static int cmd_exec(FAR struct action_manager_s *am, return -EINVAL; } +#ifdef CONFIG_RPTUN +static int cmd_rptun(FAR struct action_manager_s *am, + int argc, FAR char **argv) +{ + int fd; + int ret; + + UNUSED(am); + + fd = open(argv[2], O_WRONLY | O_CLOEXEC); + if (fd < 0) + { + init_err("rptun %s: open '%s' failed: %d", + argv[1], argv[2], errno); + return -errno; + } + + if (!strcmp(argv[1], "start")) + { + ret = ioctl(fd, RPTUNIOC_START, 0); + } + else if (!strcmp(argv[1], "stop")) + { + ret = ioctl(fd, RPTUNIOC_STOP, 0); + } + else + { + init_err("rptun: unknown command '%s'", argv[1]); + ret = -EINVAL; + } + + if (ret < 0) + { + init_err("rptun %s: failed: %d", argv[1], errno); + } + + close(fd); + return ret; +} +#endif + +static int cmd_unlink(FAR struct action_manager_s *am, + int argc, FAR char **argv) +{ + int ret; + + UNUSED(am); + + ret = unlink(argv[1]); + if (ret < 0) + { + init_err("unlink '%s' failed: %d", argv[1], errno); + } + + return ret; +} + /**************************************************************************** * Public Functions ****************************************************************************/