Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nshlib:dmesg add '-c|-C' opt #2231

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading