This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 64f65dbf3d3adda5aa08feb3af6da5634a39248f Author: wangyongrong <[email protected]> AuthorDate: Fri Aug 28 21:13:04 2026 +0800 system/nxinit: add rptun and unlink builtin commands BL uses init framework (not NSH), so the NSH rptun command is not available. Add rptun as an init builtin command that supports start and stop subcommands. Also add a generic unlink builtin command for removing device nodes. Usage in init.bl.rc: rptun stop /dev/rptun/corecs unlink /dev/rptun/corecs rptun start /dev/rptun/corecs - rptun start/stop: open device, ioctl(RPTUNIOC_START/STOP), close - unlink: generic command to unlink any file/device node Signed-off-by: wangyongrong <[email protected]> --- system/nxinit/builtin.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) 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 <errno.h> +#include <fcntl.h> #include <inttypes.h> #include <stdlib.h> #include <string.h> #include <spawn.h> +#include <unistd.h> #include <sys/boardctl.h> +#include <sys/ioctl.h> #include <sys/param.h> #include <sys/wait.h> #include <netutils/netinit.h> +#ifdef CONFIG_RPTUN +#include <nuttx/rptun/rptun.h> +#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 ****************************************************************************/
