diff options
author | Chris Johns <chrisj@rtems.org> | 2008-04-08 04:53:26 +0000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2008-04-08 04:53:26 +0000 |
commit | 8c422e23462130dee38d18ad175064d402b0566d (patch) | |
tree | e158c101a793909f469f17645fe96e6efc13d751 | |
parent | startup/bspstart.c: Clean up non-FPGA use of EPORT interrupts. (diff) | |
download | rtems-8c422e23462130dee38d18ad175064d402b0566d.tar.bz2 |
2008-04-08 Chris Johns <chrisj@rtems.org>
* libmisc/shell/shell.c: Copy the cmd line to a buffer to split
into argv parts. Was using the command line history buffer so the
history was being corrupted.
-rw-r--r-- | cpukit/ChangeLog | 6 | ||||
-rw-r--r-- | cpukit/libmisc/shell/shell.c | 20 |
2 files changed, 22 insertions, 4 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index e220fa3e99..dbf981b778 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,9 @@ +2008-04-08 Chris Johns <chrisj@rtems.org> + + * libmisc/shell/shell.c: Copy the cmd line to a buffer to split + into argv parts. Was using the command line history buffer so the + history was being corrupted. + 2008-04-03 Chris Johns <chrisj@rtems.org> * libfs/src/nfsclient/src/librtemsNfs.h, diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c index de2147e7fc..76ca6c0d7b 100644 --- a/cpukit/libmisc/shell/shell.c +++ b/cpukit/libmisc/shell/shell.c @@ -276,7 +276,7 @@ int rtems_shell_line_editor( break; case EOF: if (output) - fputc(out, '\n'); + fputc('\n', out); return -2; case '\f': @@ -668,6 +668,7 @@ rtems_boolean rtems_shell_main_loop( int cmd; int cmd_count = 1; /* assume a script and so only 1 command line */ char *cmds[RTEMS_SHELL_CMD_COUNT]; + char *cmd_argv; int argc; char *argv[RTEMS_SHELL_MAXIMUM_ARGUMENTS]; rtems_boolean result = TRUE; @@ -769,11 +770,17 @@ rtems_boolean rtems_shell_main_loop( /* * Allocate the command line buffers. */ + cmd_argv = malloc (RTEMS_SHELL_CMD_SIZE); + if (!cmd_argv) { + fprintf(stderr, "no memory for command line buffers\n" ); + } + cmds[0] = calloc (cmd_count, RTEMS_SHELL_CMD_SIZE); if (!cmds[0]) { fprintf(stderr, "no memory for command line buffers\n" ); } - else { + + if (cmd_argv && cmds[0]) { memset (cmds[0], 0, cmd_count * RTEMS_SHELL_CMD_SIZE); @@ -856,7 +863,8 @@ rtems_boolean rtems_shell_main_loop( * Run in a new shell task background. (unix &) * Resuming. A little bash. */ - if (!rtems_shell_make_args(cmds[cmd], &argc, argv, + memcpy (cmd_argv, cmds[cmd], RTEMS_SHELL_CMD_SIZE); + if (!rtems_shell_make_args(cmd_argv, &argc, argv, RTEMS_SHELL_MAXIMUM_ARGUMENTS)) { shell_cmd = rtems_shell_lookup_cmd(argv[0]); if ( argv[0] == NULL ) { @@ -878,9 +886,13 @@ rtems_boolean rtems_shell_main_loop( } } while (result && shell_env->forever); - free (cmds[0]); } + if (cmds[0]) + free (cmds[0]); + if (cmd_argv) + free (cmd_argv); + if ( stdinToClose ) fclose( stdinToClose ); if ( stdoutToClose ) |