summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/shell.c
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2008-04-08 04:53:26 +0000
committerChris Johns <chrisj@rtems.org>2008-04-08 04:53:26 +0000
commit8c422e23462130dee38d18ad175064d402b0566d (patch)
treee158c101a793909f469f17645fe96e6efc13d751 /cpukit/libmisc/shell/shell.c
parentstartup/bspstart.c: Clean up non-FPGA use of EPORT interrupts. (diff)
downloadrtems-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.
Diffstat (limited to 'cpukit/libmisc/shell/shell.c')
-rw-r--r--cpukit/libmisc/shell/shell.c20
1 files changed, 16 insertions, 4 deletions
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 )