summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_fscmds.c
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 /apps/nshlib/nsh_fscmds.c
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
Diffstat (limited to 'apps/nshlib/nsh_fscmds.c')
-rw-r--r--apps/nshlib/nsh_fscmds.c202
1 files changed, 111 insertions, 91 deletions
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
****************************************************************************/