mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-10-01 19:36:36 +00:00
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 <wangyongrong@xiaomi.com>
This commit is contained in:
parent
04ee0d45ef
commit
64f65dbf3d
1 changed files with 74 additions and 0 deletions
|
|
@ -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
|
||||
****************************************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue