Skip to content

Commit

Permalink
nshlib:dmesg add '-c|-C' opt
Browse files Browse the repository at this point in the history
Signed-off-by: yuanyongjian <[email protected]>
  • Loading branch information
yuanyongjian authored and xiaoxiang781216 committed Dec 15, 2023
1 parent b7c5bdb commit dcfb4d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion nshlib/nsh_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static const struct cmdmap_s g_cmdmap[] =
#endif

#if defined(CONFIG_SYSLOG_DEVPATH) && !defined(CONFIG_NSH_DISABLE_DMESG)
CMD_MAP("dmesg", cmd_dmesg, 1, 1, NULL),
CMD_MAP("dmesg", cmd_dmesg, 1, 2, "[-c,--clear |-C,--read-clear]"),
#endif

#ifndef CONFIG_NSH_DISABLE_ECHO
Expand Down
41 changes: 37 additions & 4 deletions nshlib/nsh_fscmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <nuttx/config.h>

#include <sys/types.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdint.h>
Expand All @@ -49,14 +50,12 @@
# include <sys/boardctl.h>
# include <nuttx/drivers/ramdisk.h>
# ifdef CONFIG_DEV_LOOP
# include <sys/ioctl.h>
# include <nuttx/fs/loop.h>
# endif
# ifdef CONFIG_FS_SMARTFS
# include "fsutils/mksmartfs.h"
# endif
# ifdef CONFIG_SMART_DEV_LOOP
# include <sys/ioctl.h>
# include <nuttx/fs/smart.h>
# endif
# ifdef CONFIG_MTD_LOOP
Expand Down Expand Up @@ -572,9 +571,43 @@ int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
#if defined(CONFIG_SYSLOG_DEVPATH) && !defined(CONFIG_NSH_DISABLE_DMESG)
int cmd_dmesg(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
UNUSED(argc);
int ret = ERROR;
int fd;
int option;

if (argc > 1 && (option = getopt(argc, argv, "cC:")) != ERROR)
{
switch (option)
{
case 'c':
ret = nsh_catfile(vtbl, argv[0], CONFIG_SYSLOG_DEVPATH);

/* Go through */

case 'C':
fd = open(CONFIG_SYSLOG_DEVPATH, O_RDONLY);
if (fd < 0)
{
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
return fd;
}

return nsh_catfile(vtbl, argv[0], CONFIG_SYSLOG_DEVPATH);
ret = ioctl(fd, BIOC_FLUSH, 0);
if (ret < 0)
{
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "ioctl", NSH_ERRNO);
}

close(fd);
break;
}
}
else
{
ret = nsh_catfile(vtbl, argv[0], CONFIG_SYSLOG_DEVPATH);
}

return ret;
}
#endif

Expand Down

0 comments on commit dcfb4d0

Please sign in to comment.