Add dmesg command that can be used to dump the syslog
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4382 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
96abf2590b
commit
3ef447cf6e
@ -184,4 +184,6 @@
|
||||
checkin).
|
||||
* apps/examples/ftpd: Add a test for the FTPD server (untest on initial
|
||||
check-in).
|
||||
* apps/nshlib/nsh_fscmds.c: Add support for a 'dmesg' command that will
|
||||
dump the system log if CONFIG_SYSLOG is selected.
|
||||
|
||||
|
28
nshlib/nsh.h
28
nshlib/nsh.h
@ -218,6 +218,25 @@
|
||||
# define nsh_freefullpath(p)
|
||||
#endif
|
||||
|
||||
/* The size of the I/O buffer may be specified in the
|
||||
* configs/<board-name>defconfig file -- provided that it is at least as
|
||||
* large as PATH_MAX.
|
||||
*/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
# ifdef CONFIG_NSH_FILEIOSIZE
|
||||
# if CONFIG_NSH_FILEIOSIZE > (PATH_MAX + 1)
|
||||
# define IOBUFFERSIZE CONFIG_NSH_FILEIOSIZE
|
||||
# else
|
||||
# define IOBUFFERSIZE (PATH_MAX + 1)
|
||||
# endif
|
||||
# else
|
||||
# define IOBUFFERSIZE 1024
|
||||
# endif
|
||||
# else
|
||||
# define IOBUFFERSIZE (PATH_MAX + 1)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@ -396,10 +415,13 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg,
|
||||
# ifndef CONFIG_NSH_DISABLE_LS
|
||||
int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
# if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
|
||||
# ifndef CONFIG_NSH_DISABLE_SH
|
||||
# if defined(CONFIG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG)
|
||||
int cmd_dmesg(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
# if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
|
||||
# ifndef CONFIG_NSH_DISABLE_SH
|
||||
int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
# endif
|
||||
# endif /* CONFIG_NFILE_STREAMS && !CONFIG_NSH_DISABLESCRIPT */
|
||||
# ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
# ifndef CONFIG_NSH_DISABLE_LOSETUP
|
||||
|
@ -353,4 +353,3 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -78,25 +78,6 @@
|
||||
#define LSFLAGS_LONG 2
|
||||
#define LSFLAGS_RECURSIVE 4
|
||||
|
||||
/* The size of the I/O buffer may be specified in the
|
||||
* configs/<board-name>defconfig file -- provided that it is at least as
|
||||
* large as PATH_MAX.
|
||||
*/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
# ifdef CONFIG_NSH_FILEIOSIZE
|
||||
# if CONFIG_NSH_FILEIOSIZE > (PATH_MAX + 1)
|
||||
# define IOBUFFERSIZE CONFIG_NSH_FILEIOSIZE
|
||||
# else
|
||||
# define IOBUFFERSIZE (PATH_MAX + 1)
|
||||
# endif
|
||||
# else
|
||||
# define IOBUFFERSIZE 1024
|
||||
# endif
|
||||
# else
|
||||
# define IOBUFFERSIZE (PATH_MAX + 1)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@ -387,6 +368,107 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath,
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cat_common
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
#ifndef CONFIG_NSH_DISABLE_CAT
|
||||
static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
FAR const char *filename)
|
||||
{
|
||||
char buffer[IOBUFFERSIZE];
|
||||
int fd;
|
||||
int ret = OK;
|
||||
|
||||
/* Open the file for reading */
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* And just dump it byte for byte into stdout */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int nbytesread = read(fd, buffer, IOBUFFERSIZE);
|
||||
|
||||
/* Check for read errors */
|
||||
|
||||
if (nbytesread < 0)
|
||||
{
|
||||
int errval = errno;
|
||||
|
||||
/* EINTR is not an error (but will stop stop the cat) */
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
if (errval == EINTR)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtsignalrecvd, cmd);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, cmd, "read", NSH_ERRNO_OF(errval));
|
||||
}
|
||||
|
||||
ret = ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check for data successfully read */
|
||||
|
||||
else if (nbytesread > 0)
|
||||
{
|
||||
int nbyteswritten = 0;
|
||||
|
||||
while (nbyteswritten < nbytesread)
|
||||
{
|
||||
ssize_t n = nsh_write(vtbl, buffer, nbytesread);
|
||||
if (n < 0)
|
||||
{
|
||||
int errval = errno;
|
||||
|
||||
/* EINTR is not an error (but will stop stop the cat) */
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
if (errval == EINTR)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtsignalrecvd, cmd);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, cmd, "write", NSH_ERRNO);
|
||||
}
|
||||
|
||||
ret = ERROR;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbyteswritten += n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise, it is the end of file */
|
||||
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void)close(fd);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -399,9 +481,7 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath,
|
||||
#ifndef CONFIG_NSH_DISABLE_CAT
|
||||
int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
char buffer[IOBUFFERSIZE];
|
||||
char *fullpath;
|
||||
int fd;
|
||||
int i;
|
||||
int ret = OK;
|
||||
|
||||
@ -412,98 +492,38 @@ int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
/* Get the fullpath to the file */
|
||||
|
||||
fullpath = nsh_getfullpath(vtbl, argv[i]);
|
||||
if (fullpath)
|
||||
if (!fullpath)
|
||||
{
|
||||
/* Open the file for reading */
|
||||
ret = ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Dump the file to the console */
|
||||
|
||||
fd = open(fullpath, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* And just dump it byte for byte into stdout */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int nbytesread = read(fd, buffer, IOBUFFERSIZE);
|
||||
|
||||
/* Check for read errors */
|
||||
|
||||
if (nbytesread < 0)
|
||||
{
|
||||
/* EINTR is not an error (but will stop stop the cat) */
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
if (errno == EINTR)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtsignalrecvd, argv[0]);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
|
||||
}
|
||||
|
||||
ret = ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check for data successfully read */
|
||||
|
||||
else if (nbytesread > 0)
|
||||
{
|
||||
int nbyteswritten = 0;
|
||||
|
||||
while (nbyteswritten < nbytesread)
|
||||
{
|
||||
ssize_t n = nsh_write(vtbl, buffer, nbytesread);
|
||||
if (n < 0)
|
||||
{
|
||||
/* EINTR is not an error (but will stop stop the cat) */
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
if (errno == EINTR)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtsignalrecvd, argv[0]);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
|
||||
}
|
||||
ret = ERROR;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbyteswritten += n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise, it is the end of file */
|
||||
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void)close(fd);
|
||||
}
|
||||
ret = cat_common(vtbl, argv[0], fullpath);
|
||||
|
||||
/* Free the allocated full path */
|
||||
|
||||
nsh_freefullpath(fullpath);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_dmesg
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG)
|
||||
int cmd_dmesg(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
return cat_common(vtbl, argv[0], "/dev/syslog");
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_cp
|
||||
****************************************************************************/
|
||||
|
@ -167,6 +167,9 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
# ifndef CONFIG_NSH_DISABLE_DD
|
||||
{ "dd", cmd_dd, 3, 6, "if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]" },
|
||||
# endif
|
||||
# if defined(CONFIG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG)
|
||||
{ "dmesg", cmd_dmesg, 1, 1, NULL },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NSH_DISABLE_ECHO
|
||||
|
Loading…
Reference in New Issue
Block a user