top: do not touch stdin if -b
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
06a98e32ae
commit
73a1990897
26
procps/top.c
26
procps/top.c
@ -717,7 +717,8 @@ static void clearmems(void)
|
|||||||
|
|
||||||
static void reset_term(void)
|
static void reset_term(void)
|
||||||
{
|
{
|
||||||
tcsetattr_stdin_TCSANOW(&initial_settings);
|
if (!OPT_BATCH_MODE)
|
||||||
|
tcsetattr_stdin_TCSANOW(&initial_settings);
|
||||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||||
clearmems();
|
clearmems();
|
||||||
# if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
# if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
|
||||||
@ -729,7 +730,7 @@ static void reset_term(void)
|
|||||||
static void sig_catcher(int sig UNUSED_PARAM)
|
static void sig_catcher(int sig UNUSED_PARAM)
|
||||||
{
|
{
|
||||||
reset_term();
|
reset_term();
|
||||||
_exit(EXIT_FAILURE);
|
kill_myself_with_sig(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* FEATURE_USE_TERMIOS */
|
#endif /* FEATURE_USE_TERMIOS */
|
||||||
@ -919,6 +920,12 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval)
|
|||||||
{
|
{
|
||||||
struct pollfd pfd[1];
|
struct pollfd pfd[1];
|
||||||
|
|
||||||
|
if (option_mask32 & OPT_EOF) {
|
||||||
|
/* EOF on stdin ("top </dev/null") */
|
||||||
|
sleep(interval);
|
||||||
|
return scan_mask;
|
||||||
|
}
|
||||||
|
|
||||||
pfd[0].fd = 0;
|
pfd[0].fd = 0;
|
||||||
pfd[0].events = POLLIN;
|
pfd[0].events = POLLIN;
|
||||||
|
|
||||||
@ -1154,10 +1161,13 @@ int top_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
sort_function[0] = mem_sort;
|
sort_function[0] = mem_sort;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (OPT_BATCH_MODE) {
|
||||||
|
option_mask32 |= OPT_EOF;
|
||||||
|
}
|
||||||
#if ENABLE_FEATURE_USE_TERMIOS
|
#if ENABLE_FEATURE_USE_TERMIOS
|
||||||
tcgetattr(0, (void *) &initial_settings);
|
else {
|
||||||
memcpy(&new_settings, &initial_settings, sizeof(new_settings));
|
tcgetattr(0, (void *) &initial_settings);
|
||||||
if (!OPT_BATCH_MODE) {
|
memcpy(&new_settings, &initial_settings, sizeof(new_settings));
|
||||||
/* unbuffered input, turn off echo */
|
/* unbuffered input, turn off echo */
|
||||||
new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
|
new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
|
||||||
tcsetattr_stdin_TCSANOW(&new_settings);
|
tcsetattr_stdin_TCSANOW(&new_settings);
|
||||||
@ -1269,11 +1279,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
#if !ENABLE_FEATURE_USE_TERMIOS
|
#if !ENABLE_FEATURE_USE_TERMIOS
|
||||||
sleep(interval);
|
sleep(interval);
|
||||||
#else
|
#else
|
||||||
if (option_mask32 & OPT_EOF)
|
scan_mask = handle_input(scan_mask, interval);
|
||||||
/* EOF on stdin ("top </dev/null") */
|
|
||||||
sleep(interval);
|
|
||||||
else
|
|
||||||
scan_mask = handle_input(scan_mask, interval);
|
|
||||||
#endif /* FEATURE_USE_TERMIOS */
|
#endif /* FEATURE_USE_TERMIOS */
|
||||||
} /* end of "while (not Q)" */
|
} /* end of "while (not Q)" */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user