summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-11 15:27:44 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-11 15:27:44 +0000
commit4cb67b0b1b9ce6ba8c524a3a5b4fbb8f8aa184bb (patch)
tree521e0720bfb45fd55e5fb5970cae76d38f60bc4d
parent75e67f05d4b97efc32d95b478ec1c1f959992a4b (diff)
downloadnuttx-4cb67b0b1b9ce6ba8c524a3a5b4fbb8f8aa184bb.tar.gz
nuttx-4cb67b0b1b9ce6ba8c524a3a5b4fbb8f8aa184bb.tar.bz2
nuttx-4cb67b0b1b9ce6ba8c524a3a5b4fbb8f8aa184bb.zip
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
-rwxr-xr-xapps/ChangeLog.txt2
-rw-r--r--apps/nshlib/nsh.h28
-rw-r--r--apps/nshlib/nsh_dbgcmds.c1
-rw-r--r--apps/nshlib/nsh_fscmds.c202
-rw-r--r--apps/nshlib/nsh_parse.c3
-rw-r--r--nuttx/drivers/ramlog.c10
-rw-r--r--nuttx/include/nuttx/ramlog.h6
-rw-r--r--nuttx/include/nuttx/streams.h2
-rw-r--r--nuttx/lib/stdio/Make.defs2
-rw-r--r--nuttx/lib/stdio/lib_lowprintf.c7
-rw-r--r--nuttx/lib/stdio/lib_rawprintf.c9
-rw-r--r--nuttx/lib/stdio/lib_syslogstream.c4
12 files changed, 169 insertions, 107 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 78011ef84..5d855c379 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -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.
diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h
index 90d02bb7f..46226adcd 100644
--- a/apps/nshlib/nsh.h
+++ b/apps/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
diff --git a/apps/nshlib/nsh_dbgcmds.c b/apps/nshlib/nsh_dbgcmds.c
index 31199db3e..384b377f3 100644
--- a/apps/nshlib/nsh_dbgcmds.c
+++ b/apps/nshlib/nsh_dbgcmds.c
@@ -353,4 +353,3 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return OK;
}
#endif
-
diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c
index e478ddefb..764caca6d 100644
--- a/apps/nshlib/nsh_fscmds.c
+++ b/apps/nshlib/nsh_fscmds.c
@@ -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
****************************************************************************/
@@ -388,123 +369,162 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath,
#endif
/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: cmd_cat
+ * Name: cat_common
****************************************************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0
#ifndef CONFIG_NSH_DISABLE_CAT
-int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+static int cat_common(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
+ FAR const char *filename)
{
char buffer[IOBUFFERSIZE];
- char *fullpath;
int fd;
- int i;
int ret = OK;
- /* Loop for each file name on the command line */
+ /* Open the file for reading */
- for (i = 1; i < argc && ret == OK; i++)
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
{
- /* Get the fullpath to the file */
+ nsh_output(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
+ return ERROR;
+ }
- fullpath = nsh_getfullpath(vtbl, argv[i]);
- if (fullpath)
+ /* And just dump it byte for byte into stdout */
+
+ for (;;)
+ {
+ int nbytesread = read(fd, buffer, IOBUFFERSIZE);
+
+ /* Check for read errors */
+
+ if (nbytesread < 0)
{
- /* Open the file for reading */
+ int errval = errno;
+
+ /* EINTR is not an error (but will stop stop the cat) */
- fd = open(fullpath, O_RDONLY);
- if (fd < 0)
+#ifndef CONFIG_DISABLE_SIGNALS
+ if (errval == EINTR)
{
- nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
+ nsh_output(vtbl, g_fmtsignalrecvd, cmd);
}
else
+#endif
{
- /* And just dump it byte for byte into stdout */
+ nsh_output(vtbl, g_fmtcmdfailed, cmd, "read", NSH_ERRNO_OF(errval));
+ }
+
+ ret = ERROR;
+ break;
+ }
- for (;;)
+ /* 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 nbytesread = read(fd, buffer, IOBUFFERSIZE);
+ int errval = errno;
- /* Check for read errors */
+ /* EINTR is not an error (but will stop stop the cat) */
- if (nbytesread < 0)
+ #ifndef CONFIG_DISABLE_SIGNALS
+ if (errval == EINTR)
{
- /* 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
+ nsh_output(vtbl, g_fmtsignalrecvd, cmd);
+ }
+ else
#endif
- {
- nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
- }
-
- ret = ERROR;
- break;
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, cmd, "write", NSH_ERRNO);
}
- /* Check for data successfully read */
+ ret = ERROR;
+ break;
+ }
+ else
+ {
+ nbyteswritten += n;
+ }
+ }
+ }
- else if (nbytesread > 0)
- {
- int nbyteswritten = 0;
+ /* Otherwise, it is the end of file */
- 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) */
+ else
+ {
+ break;
+ }
+ }
- #ifndef CONFIG_DISABLE_SIGNALS
- if (errno == EINTR)
- {
- nsh_output(vtbl, g_fmtsignalrecvd, argv[0]);
- }
- else
+ (void)close(fd);
+ return ret;
+}
+#endif
#endif
- {
- nsh_output(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
- }
- ret = ERROR;
- break;
- }
- else
- {
- nbyteswritten += n;
- }
- }
- }
- /* Otherwise, it is the end of file */
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
- else
- {
- break;
- }
- }
+/****************************************************************************
+ * Name: cmd_cat
+ ****************************************************************************/
- (void)close(fd);
- }
+#if CONFIG_NFILE_DESCRIPTORS > 0
+#ifndef CONFIG_NSH_DISABLE_CAT
+int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ char *fullpath;
+ int i;
+ int ret = OK;
+
+ /* Loop for each file name on the command line */
+
+ for (i = 1; i < argc && ret == OK; i++)
+ {
+ /* Get the fullpath to the file */
+
+ fullpath = nsh_getfullpath(vtbl, argv[i]);
+ if (!fullpath)
+ {
+ ret = ERROR;
+ }
+ else
+ {
+ /* Dump the file to the console */
+
+ 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
****************************************************************************/
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index ff1a50962..67d529013 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -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
diff --git a/nuttx/drivers/ramlog.c b/nuttx/drivers/ramlog.c
index 0245e6051..fd94f5bf4 100644
--- a/nuttx/drivers/ramlog.c
+++ b/nuttx/drivers/ramlog.c
@@ -617,8 +617,8 @@ int ramlog_consoleinit(void)
sem_init(&priv->rl_exclsem, 0, 1);
sem_init(&priv->rl_waitsem, 0, 0);
- priv->rl_bufsize = g_sysbuffer;
- priv->rl_buffer = CONFIG_RAMLOG_CONSOLE_BUFSIZE;
+ priv->rl_bufsize = CONFIG_RAMLOG_CONSOLE_BUFSIZE;
+ priv->rl_buffer = g_sysbuffer;
/* Register the console character driver */
@@ -657,8 +657,8 @@ int ramlog_sysloginit(void)
sem_init(&priv->rl_exclsem, 0, 1);
sem_init(&priv->rl_waitsem, 0, 0);
- priv->rl_bufsize = g_sysbuffer;
- priv->rl_buffer = CONFIG_RAMLOG_CONSOLE_BUFSIZE;
+ priv->rl_bufsize = CONFIG_RAMLOG_CONSOLE_BUFSIZE;
+ priv->rl_buffer = g_sysbuffer;
return register_driver("/dev/syslog", &g_ramlogfops, 0666, priv);
}
@@ -681,7 +681,7 @@ int ramlog_sysloginit(void)
int ramlog_putc(int ch)
{
FAR struct ramlog_dev_s *priv = &g_sysdev;
- (void)ramlog_addchar(priv, ch)
+ (void)ramlog_addchar(priv, ch);
return ch;
}
#endif
diff --git a/nuttx/include/nuttx/ramlog.h b/nuttx/include/nuttx/ramlog.h
index d1b9dea97..a800c077f 100644
--- a/nuttx/include/nuttx/ramlog.h
+++ b/nuttx/include/nuttx/ramlog.h
@@ -98,6 +98,10 @@
# undef CONFIG_RAMLOG_SYSLOG
#endif
+#ifndef CONFIG_RAMLOG_CONSOLE_BUFSIZE
+# define CONFIG_RAMLOG_CONSOLE_BUFSIZE 1024
+#endif
+
/****************************************************************************
* Public Data
****************************************************************************/
@@ -164,7 +168,7 @@ EXTERN int ramlog_consoleinit(void)
****************************************************************************/
#if !defined(CONFIG_RAMLOG_CONSOLE) && defined(CONFIG_RAMLOG_SYSLOG)
-EXTERN int ramlog_sysloginit(void)
+EXTERN int ramlog_sysloginit(void);
#endif
/****************************************************************************
diff --git a/nuttx/include/nuttx/streams.h b/nuttx/include/nuttx/streams.h
index 8317eacbd..38ceb584c 100644
--- a/nuttx/include/nuttx/streams.h
+++ b/nuttx/include/nuttx/streams.h
@@ -284,7 +284,7 @@ EXTERN void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream);
****************************************************************************/
#ifdef CONFIG_SYSLOG
-EXTERN void lib_sylogstream(FAR struct lib_outstream_s *stream);
+EXTERN void lib_syslogstream(FAR struct lib_outstream_s *stream);
#endif
#undef EXTERN
diff --git a/nuttx/lib/stdio/Make.defs b/nuttx/lib/stdio/Make.defs
index 690c83641..ddccaca71 100644
--- a/nuttx/lib/stdio/Make.defs
+++ b/nuttx/lib/stdio/Make.defs
@@ -52,7 +52,7 @@ STDIO_SRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \
endif
endif
-ifdef ($(CONFIG_SYSLOG)
+ifeq ($(CONFIG_SYSLOG),y)
STDIO_SRCS += lib_syslogstream.c
endif
diff --git a/nuttx/lib/stdio/lib_lowprintf.c b/nuttx/lib/stdio/lib_lowprintf.c
index 0314a27f0..e27a5021b 100644
--- a/nuttx/lib/stdio/lib_lowprintf.c
+++ b/nuttx/lib/stdio/lib_lowprintf.c
@@ -42,6 +42,10 @@
#include <debug.h>
#include "lib_internal.h"
+/* This interface can only be used from within the kernel */
+
+#if !defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__)
+
/****************************************************************************
* Definitions
****************************************************************************/
@@ -113,4 +117,5 @@ int lib_lowprintf(const char *fmt, ...)
return ret;
}
-#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG*/
+#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_SYSLOG */
+#endif /* __KERNEL__ */
diff --git a/nuttx/lib/stdio/lib_rawprintf.c b/nuttx/lib/stdio/lib_rawprintf.c
index d738b212a..a28e6b695 100644
--- a/nuttx/lib/stdio/lib_rawprintf.c
+++ b/nuttx/lib/stdio/lib_rawprintf.c
@@ -42,9 +42,16 @@
#include "lib_internal.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
+/* Some output destinations are only available from within the kernel */
+
+#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__)
+# undef CONFIG_SYSLOG
+# undef CONFIG_ARCH_LOWPUTC
+#endif
+
/****************************************************************************
* Private Type Declarations
****************************************************************************/
diff --git a/nuttx/lib/stdio/lib_syslogstream.c b/nuttx/lib/stdio/lib_syslogstream.c
index 0b5a95144..3da066408 100644
--- a/nuttx/lib/stdio/lib_syslogstream.c
+++ b/nuttx/lib/stdio/lib_syslogstream.c
@@ -75,7 +75,7 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
****************************************************************************/
/****************************************************************************
- * Name: lib_sylogstream
+ * Name: lib_syslogstream
*
* Description:
* Initializes a stream for use with the coinfigured syslog interface.
@@ -89,7 +89,7 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
*
****************************************************************************/
-void lib_sylogstream(FAR struct lib_outstream_s *stream)
+void lib_syslogstream(FAR struct lib_outstream_s *stream)
{
stream->put = syslogstream_putc;
#ifdef CONFIG_STDIO_LINEBUFFER