v1-->v2: - FILE *tty_fp --> FILE *out - Using out = stdout to replace the fdopen() operate;
Signed-off-by: Li Wang <liw...@redhat.com> Signed-off-by: Cyril Hrubis <chru...@suse.cz> --- tools/pounder21/Install | 2 +- tools/pounder21/fancy_timed_loop.c | 29 ++++++++++++----------------- tools/pounder21/infinite_loop.c | 25 ++++++++++--------------- tools/pounder21/pounder | 14 +++++++------- tools/pounder21/test_scripts/memtest | 2 +- tools/pounder21/timed_loop.c | 27 +++++++++++---------------- 6 files changed, 42 insertions(+), 57 deletions(-) diff --git a/tools/pounder21/Install b/tools/pounder21/Install index bf13528..6fb3a8f 100755 --- a/tools/pounder21/Install +++ b/tools/pounder21/Install @@ -65,7 +65,7 @@ done # Set up optdir mkdir -p "$POUNDER_OPTDIR" if [ ! -d "$POUNDER_OPTDIR" ]; then - echo "Could not create $POUNDER_OPTDIR; aborting." > /dev/tty + echo "Could not create $POUNDER_OPTDIR; aborting." exit 1 fi diff --git a/tools/pounder21/fancy_timed_loop.c b/tools/pounder21/fancy_timed_loop.c index cf8580e..e2ca1dc 100644 --- a/tools/pounder21/fancy_timed_loop.c +++ b/tools/pounder21/fancy_timed_loop.c @@ -32,13 +32,13 @@ static int res = 0; static char *progname; static pid_t test_pgrp; -static FILE *tty_fp; +static FILE *out; static int the_signal = SIGTERM; static void int_func(int signum) { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "%s: Killed by interrupt. Last exit code = %d.\n", progname, res); kill(-test_pgrp, the_signal); @@ -47,7 +47,7 @@ static void int_func(int signum) static void alarm_func(int signum) { - pounder_fprintf(tty_fp, "%s: Killed by timer. Last exit code = %d.\n", + pounder_fprintf(out, "%s: Killed by timer. Last exit code = %d.\n", progname, res); kill(-test_pgrp, the_signal); exit(res); @@ -90,14 +90,9 @@ int main(int argc, char *argv[]) } } - tty_fp = fdopen(3, "w+"); - if (tty_fp == NULL) { - tty_fp = fopen("/dev/tty", "w+"); - if (tty_fp == NULL) { - perror("stdout"); - exit(2); - } - } + out = fdopen(3, "w+"); + if (out == NULL) + out = stdout; if (use_max_failures) { progname = rindex(argv[7], '/'); @@ -142,11 +137,11 @@ int main(int argc, char *argv[]) gid = atoi(argv[3]); } - pounder_fprintf(tty_fp, "%s: uid = %d, gid = %d, sig = %d\n", + pounder_fprintf(out, "%s: uid = %d, gid = %d, sig = %d\n", progname, uid, gid, the_signal); while (1) { - pounder_fprintf(tty_fp, "%s: %s loop #%d.\n", progname, + pounder_fprintf(out, "%s: %s loop #%d.\n", progname, start_msg, revs++); pid = fork(); if (pid == 0) { @@ -196,22 +191,22 @@ int main(int argc, char *argv[]) } // interrogate it if (WIFSIGNALED(stat)) { - pounder_fprintf(tty_fp, "%s: %s on signal %d.\n", + pounder_fprintf(out, "%s: %s on signal %d.\n", progname, fail_msg, WTERMSIG(stat)); res = 255; } else { res = WEXITSTATUS(stat); if (res == 0) { - pounder_fprintf(tty_fp, "%s: %s.\n", progname, + pounder_fprintf(out, "%s: %s.\n", progname, pass_msg); } else if (res < 0 || res == 255) { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "%s: %s with code %d.\n", progname, abort_msg, res); exit(-1); // FIXME: add test to blacklist } else { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "%s: %s with code %d.\n", progname, fail_msg, res); if (max_failures > 0) { diff --git a/tools/pounder21/infinite_loop.c b/tools/pounder21/infinite_loop.c index d78b442..3a9d68c 100644 --- a/tools/pounder21/infinite_loop.c +++ b/tools/pounder21/infinite_loop.c @@ -32,11 +32,11 @@ static int res = 0; static char *progname; static pid_t test_pgrp; -static FILE *tty_fp; +static FILE *out; static void int_func(int signum) { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "%s: Killed by interrupt. Last exit code = %d.\n", progname, res); kill(-test_pgrp, SIGTERM); @@ -75,14 +75,9 @@ int main(int argc, char *argv[]) } } - tty_fp = fdopen(3, "w+"); - if (tty_fp == NULL) { - tty_fp = fopen("/dev/tty", "w+"); - if (tty_fp == NULL) { - perror("stdout"); - exit(2); - } - } + out = fdopen(3, "w+"); + if (out == NULL) + out = stdout; if (use_max_failures) { progname = rindex(argv[3], '/'); @@ -110,7 +105,7 @@ int main(int argc, char *argv[]) * loop test and descendants easily */ while (1) { - pounder_fprintf(tty_fp, "%s: %s loop #%d.\n", progname, + pounder_fprintf(out, "%s: %s loop #%d.\n", progname, start_msg, revs++); pid = fork(); if (pid == 0) { @@ -149,22 +144,22 @@ int main(int argc, char *argv[]) } // interrogate it if (WIFSIGNALED(stat)) { - pounder_fprintf(tty_fp, "%s: %s on signal %d.\n", + pounder_fprintf(out, "%s: %s on signal %d.\n", progname, fail_msg, WTERMSIG(stat)); res = 255; } else { res = WEXITSTATUS(stat); if (res == 0) { - pounder_fprintf(tty_fp, "%s: %s.\n", progname, + pounder_fprintf(out, "%s: %s.\n", progname, pass_msg); } else if (res < 0 || res == 255) { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "%s: %s with code %d.\n", progname, abort_msg, res); exit(-1); // FIXME: add test to blacklist } else { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "%s: %s with code %d.\n", progname, fail_msg, res); if (max_failures > 0) { diff --git a/tools/pounder21/pounder b/tools/pounder21/pounder index c3defcf..caf60d3 100755 --- a/tools/pounder21/pounder +++ b/tools/pounder21/pounder @@ -201,8 +201,8 @@ shift `expr $OPTIND - 1` # Are we already running? if [ -f "$POUNDER_PIDFILE" ]; then - echo "File $POUNDER_PIDFILE exists; pounder may already be running." > /dev/tty - echo "Either run 'pounder -k' to stop all tests, or remove it." > /dev/tty + echo "File $POUNDER_PIDFILE exists; pounder may already be running." + echo "Either run 'pounder -k' to stop all tests, or remove it." exit 1 fi @@ -225,21 +225,21 @@ fi # Set up log directory mkdir -p "$POUNDER_LOGDIR" 2> /dev/null if [ ! -d "$POUNDER_LOGDIR" ]; then - echo "Could not create $POUNDER_LOGDIR; aborting." > /dev/tty + echo "Could not create $POUNDER_LOGDIR; aborting." exit 1 fi # Set up dir for optional components mkdir -p "$POUNDER_OPTDIR" if [ ! -d "$POUNDER_OPTDIR" ]; then - echo "Could not create $POUNDER_OPTDIR; aborting." > /dev/tty + echo "Could not create $POUNDER_OPTDIR; aborting." exit 1 fi # Set up tmpdir mkdir -p "$POUNDER_TMPDIR" if [ ! -d "$POUNDER_TMPDIR" ]; then - echo "Could not create $POUNDER_TMPDIR; aborting." > /dev/tty + echo "Could not create $POUNDER_TMPDIR; aborting." exit 1 fi @@ -259,8 +259,8 @@ fi export > "$POUNDER_LOGDIR/environment" echo "Starting $POUNDER_VERSION" -echo "STARTING TESTS." > /dev/tty -echo "To kill all tests, run 'pounder -k' or press ^C."> /dev/tty +echo "STARTING TESTS." +echo "To kill all tests, run 'pounder -k' or press ^C." # Handle the duration thing... function kill_after { diff --git a/tools/pounder21/test_scripts/memtest b/tools/pounder21/test_scripts/memtest index c040147..e212bde 100755 --- a/tools/pounder21/test_scripts/memtest +++ b/tools/pounder21/test_scripts/memtest @@ -22,7 +22,7 @@ # Can we find the script? if [ ! -f "$POUNDER_OPTDIR/memtest.sh" ]; then - echo "Can't find memtest.sh; did you run Install?" > /dev/tty + echo "Can't find memtest.sh; did you run Install?" exit -1 fi diff --git a/tools/pounder21/timed_loop.c b/tools/pounder21/timed_loop.c index 966c08a..a7413c3 100644 --- a/tools/pounder21/timed_loop.c +++ b/tools/pounder21/timed_loop.c @@ -32,11 +32,11 @@ static int res = 0; static char *progname; static pid_t test_pgrp; -static FILE *tty_fp; +static FILE *out; static void int_func(int signum) { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "%s: Killed by interrupt. Last exit code = %d.\n", progname, res); kill(-test_pgrp, SIGTERM); @@ -45,7 +45,7 @@ static void int_func(int signum) static void alarm_func(int signum) { - pounder_fprintf(tty_fp, "%s: Killed by timer. Last exit code = %d.\n", + pounder_fprintf(out, "%s: Killed by timer. Last exit code = %d.\n", progname, res); kill(-test_pgrp, SIGTERM); exit(res); @@ -92,14 +92,9 @@ int main(int argc, char *argv[]) } } - tty_fp = fdopen(3, "w+"); - if (tty_fp == NULL) { - tty_fp = fopen("/dev/tty", "w+"); - if (tty_fp == NULL) { - perror("stdout"); - exit(2); - } - } + out = fdopen(3, "w+"); + if (out == NULL) + out = stdout; if (use_max_failures) { progname = rindex(argv[4], '/'); @@ -136,7 +131,7 @@ int main(int argc, char *argv[]) alarm(secs); while (1) { - pounder_fprintf(tty_fp, "%s: %s loop #%d.\n", progname, + pounder_fprintf(out, "%s: %s loop #%d.\n", progname, start_msg, revs++); pid = fork(); if (pid == 0) { @@ -175,22 +170,22 @@ int main(int argc, char *argv[]) } // interrogate it if (WIFSIGNALED(stat)) { - pounder_fprintf(tty_fp, "%s: %s on signal %d.\n", + pounder_fprintf(out, "%s: %s on signal %d.\n", progname, fail_msg, WTERMSIG(stat)); res = 255; } else { res = WEXITSTATUS(stat); if (res == 0) { - pounder_fprintf(tty_fp, "%s: %s.\n", progname, + pounder_fprintf(out, "%s: %s.\n", progname, pass_msg); } else if (res < 0 || res == 255) { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "CHECK %s: %s with code %d.\n", progname, abort_msg, res); exit(-1); // FIXME: add test to blacklist } else { - pounder_fprintf(tty_fp, + pounder_fprintf(out, "%s: %s with code %d.\n", progname, fail_msg, res); if (max_failures > 0) { -- 1.8.3.1 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list