summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-03-07 20:09:36 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-03-07 20:09:36 +0000
commit85659eeeb61570697044d6dc6617a8c6edb84049 (patch)
treef7767fddb777574a1fa22490a7ba2244edf553f4 /cpukit
parent2008-03-07 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-85659eeeb61570697044d6dc6617a8c6edb84049.tar.bz2
2008-03-07 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/shell/main_cp.c, libmisc/shell/main_netstats.c, libmisc/shell/shell_script.c: Add memset() of getopt_data to ensure it is zeroed out each time we use getopt_r(). * libmisc/shell/shell.c: Do not echo commands if input is not a tty. This makes the scripts behave more like UNIX scripts.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/ChangeLog8
-rw-r--r--cpukit/libmisc/shell/main_cp.c6
-rw-r--r--cpukit/libmisc/shell/main_netstats.c1
-rw-r--r--cpukit/libmisc/shell/shell.c30
-rw-r--r--cpukit/libmisc/shell/shell_script.c1
5 files changed, 35 insertions, 11 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 4129af67bc..af230ad26f 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-07 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * libmisc/shell/main_cp.c, libmisc/shell/main_netstats.c,
+ libmisc/shell/shell_script.c: Add memset() of getopt_data to
+ ensure it is zeroed out each time we use getopt_r().
+ * libmisc/shell/shell.c: Do not echo commands if input is not a tty.
+ This makes the scripts behave more like UNIX scripts.
+
2008-03-07 Joel Sherrill <joel.sherrill@OARcorp.com>
* posix/Makefile.am: Make clock_settime() available always just like
diff --git a/cpukit/libmisc/shell/main_cp.c b/cpukit/libmisc/shell/main_cp.c
index 3812c3caac..7b48c47f71 100644
--- a/cpukit/libmisc/shell/main_cp.c
+++ b/cpukit/libmisc/shell/main_cp.c
@@ -65,6 +65,7 @@ __RCSID("$NetBSD: cp.c,v 1.39 2005/10/24 12:59:07 kleink Exp $");
#include <rtems.h>
#include <rtems/shell.h>
#include <rtems/shellconfig.h>
+#include <getopt.h>
#include <sys/param.h>
#include <sys/stat.h>
@@ -116,6 +117,7 @@ main_cp(rtems_shell_cp_globals* cp_globals, int argc, char *argv[])
enum op type;
int Hflag, Lflag, Pflag, ch, fts_options, r;
char *target;
+ struct getopt_data getopt_reent;
to.p_end = to.p_path;
to.target_end = empty;
@@ -123,7 +125,9 @@ main_cp(rtems_shell_cp_globals* cp_globals, int argc, char *argv[])
(void)setlocale(LC_ALL, "");
Hflag = Lflag = Pflag = Rflag = 0;
- while ((ch = getopt(argc, argv, "HLNPRfiprv")) != -1)
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+
+ while ((ch = getopt_r(argc, argv, "HLNPRfiprv", &getopt_reent)) != -1)
switch (ch) {
case 'H':
Hflag = 1;
diff --git a/cpukit/libmisc/shell/main_netstats.c b/cpukit/libmisc/shell/main_netstats.c
index a86b7afa35..2fe5eb7c6d 100644
--- a/cpukit/libmisc/shell/main_netstats.c
+++ b/cpukit/libmisc/shell/main_netstats.c
@@ -55,6 +55,7 @@ int rtems_shell_main_netstats( /* command */
int verbose = 0;
struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
while ( (option = getopt_r( argc, argv, "Aimfpcutv", &getopt_reent)) != -1 ) {
switch ((char)option) {
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 264742a246..e503739f94 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -79,13 +79,23 @@ rtems_shell_env_t *rtems_shell_init_env(
/*
* Get a line of user input with modest features
*/
-int rtems_shell_scanline(char * line,int size,FILE * in,FILE * out) {
- int c,col;
+int rtems_shell_scanline(
+ char *line,
+ int size,
+ FILE *in,
+ FILE *out
+)
+{
+ int c;
+ int col;
+ int doEcho;
+
+ doEcho = (out && isatty(fileno(in)));
col = 0;
if (*line) {
col = strlen(line);
- if (out) fprintf(out,"%s",line);
+ if (doEcho) fprintf(out,"%s",line);
}
tcdrain(fileno(in));
if (out)
@@ -100,38 +110,38 @@ int rtems_shell_scanline(char * line,int size,FILE * in,FILE * out) {
case EOF:
return 0;
case '\f':
- if (out)
+ if (doEcho)
fputc('\f',out);
case 0x03:/*Control-C*/
line[0] = 0;
case '\n':
case '\r':
- if (out)
+ if (doEcho)
fputc('\n',out);
return 1;
case 127:
case '\b':
if (col) {
- if (out) {
+ if (doEcho) {
fputc('\b',out);
fputc(' ',out);
fputc('\b',out);
}
col--;
} else {
- if (out) fputc('\a',out);
+ if (doEcho) fputc('\a',out);
}
break;
default:
if (!iscntrl(c)) {
if (col<size-1) {
line[col++] = c;
- if (out) fputc(c,out);
+ if (doEcho) fputc(c,out);
} else {
- if (out) fputc('\a',out);
+ if (doEcho) fputc('\a',out);
}
} else {
- if (out)
+ if (doEcho)
if (c=='\a') fputc('\a',out);
}
break;
diff --git a/cpukit/libmisc/shell/shell_script.c b/cpukit/libmisc/shell/shell_script.c
index a38d2aa72d..435338951b 100644
--- a/cpukit/libmisc/shell/shell_script.c
+++ b/cpukit/libmisc/shell/shell_script.c
@@ -113,6 +113,7 @@ int rtems_shell_main_joel(
char scriptFile[PATH_MAX];
struct getopt_data getopt_reent;
+ memset(&getopt_reent, 0, sizeof(getopt_data));
while ( (option = getopt_r( argc, argv, "o:p:s:t:v", &getopt_reent)) != -1 ) {
switch ((char)option) {
case 'o':