top: ignore the SIGHUP signal if running in batch mode
It would appear that openSUSE was the first to release procps-ng version 4.0.0 (in the tumbleweed distro). As a result I checked their source rpm and found a couple of patches I'm porting to newlib for the next release. This particulate commit was a refactor of the openSUSE patch 'procps-ng-3.3.8-bnc634840.patch'. Unfortunately their original patch did not have the intended effect. That was because the amended signal handling logic was performed well before the command line parameters were parsed. So the global 'Batch' flag was in its 0 state. . what follows is the original openSUSE commit message ------------------------------------------------------ Do not setup SIGHUP signal handler if we are in the batch mode Top enables a signal handler for the SIGHUP signal (loss of terminal). While this makes sense for top's default interactive mode, it doesn't make any sense for batch mode. If you run top in nohup just to collect data over time and disconnect top finishes which is not what one would expect. ------------------------------------------------------ Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
7597aaf7f9
commit
6aec3ec93a
85
top/top.c
85
top/top.c
@ -3451,7 +3451,6 @@ static inline int osel_matched (const WIN_t *q, FLG_t enu, const char *str) {
|
|||||||
* IMPORTANT stuff upon which all those lessor functions depend! */
|
* IMPORTANT stuff upon which all those lessor functions depend! */
|
||||||
static void before (char *me) {
|
static void before (char *me) {
|
||||||
#define doALL STAT_REAP_NUMA_NODES_TOO
|
#define doALL STAT_REAP_NUMA_NODES_TOO
|
||||||
struct sigaction sa;
|
|
||||||
int i, rc;
|
int i, rc;
|
||||||
int linux_version_code = procps_linux_version();
|
int linux_version_code = procps_linux_version();
|
||||||
|
|
||||||
@ -3515,11 +3514,13 @@ static void before (char *me) {
|
|||||||
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt), __LINE__, strerror(-rc)));
|
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt), __LINE__, strerror(-rc)));
|
||||||
|
|
||||||
#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
|
#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
|
||||||
|
{ struct sigaction sa;
|
||||||
Thread_id_main = pthread_self();
|
Thread_id_main = pthread_self();
|
||||||
/* in case any of our threads have been enabled, they'll inherit this mask
|
/* in case any of our threads have been enabled, they'll inherit this mask
|
||||||
with everything blocked. therefore, signals go to the main thread (us). */
|
with everything blocked. therefore, signals go to the main thread (us). */
|
||||||
sigfillset(&sa.sa_mask);
|
sigfillset(&sa.sa_mask);
|
||||||
pthread_sigmask(SIG_BLOCK, &sa.sa_mask, NULL);
|
pthread_sigmask(SIG_BLOCK, &sa.sa_mask, NULL);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef THREADED_CPU
|
#ifdef THREADED_CPU
|
||||||
@ -3546,38 +3547,6 @@ static void before (char *me) {
|
|||||||
error_exit(fmtmk(N_fmt(X_THREADINGS_fmt), __LINE__, strerror(errno)));
|
error_exit(fmtmk(N_fmt(X_THREADINGS_fmt), __LINE__, strerror(errno)));
|
||||||
pthread_setname_np(Thread_id_tasks, "update tasks");
|
pthread_setname_np(Thread_id_tasks, "update tasks");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SIGRTMAX // not available on hurd, maybe others too
|
|
||||||
#define SIGRTMAX 32
|
|
||||||
#endif
|
|
||||||
// lastly, establish a robust signals environment
|
|
||||||
memset(&sa, 0, sizeof(sa));
|
|
||||||
sigemptyset(&sa.sa_mask);
|
|
||||||
// with user position preserved through SIGWINCH, we must avoid SA_RESTART
|
|
||||||
sa.sa_flags = 0;
|
|
||||||
for (i = SIGRTMAX; i; i--) {
|
|
||||||
switch (i) {
|
|
||||||
case SIGALRM: case SIGHUP: case SIGINT:
|
|
||||||
case SIGPIPE: case SIGQUIT: case SIGTERM:
|
|
||||||
case SIGUSR1: case SIGUSR2:
|
|
||||||
sa.sa_handler = sig_endpgm;
|
|
||||||
break;
|
|
||||||
case SIGTSTP: case SIGTTIN: case SIGTTOU:
|
|
||||||
sa.sa_handler = sig_paused;
|
|
||||||
break;
|
|
||||||
case SIGCONT: case SIGWINCH:
|
|
||||||
sa.sa_handler = sig_resize;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sa.sa_handler = sig_abexit;
|
|
||||||
break;
|
|
||||||
case SIGKILL: case SIGSTOP:
|
|
||||||
// because uncatchable, fall through
|
|
||||||
case SIGCHLD: // we can't catch this
|
|
||||||
continue; // when opening a pipe
|
|
||||||
}
|
|
||||||
sigaction(i, &sa, NULL);
|
|
||||||
}
|
|
||||||
#undef doALL
|
#undef doALL
|
||||||
} // end: before
|
} // end: before
|
||||||
|
|
||||||
@ -4240,6 +4209,51 @@ static void parse_args (int argc, char **argv) {
|
|||||||
} // end: parse_args
|
} // end: parse_args
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Establish a robust signals environment */
|
||||||
|
static void signals_set (void) {
|
||||||
|
#ifndef SIGRTMAX // not available on hurd, maybe others too
|
||||||
|
#define SIGRTMAX 32
|
||||||
|
#endif
|
||||||
|
int i;
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
// with user position preserved through SIGWINCH, we must avoid SA_RESTART
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
for (i = SIGRTMAX; i; i--) {
|
||||||
|
switch (i) {
|
||||||
|
case SIGHUP:
|
||||||
|
if (Batch)
|
||||||
|
sa.sa_handler = SIG_IGN;
|
||||||
|
else
|
||||||
|
sa.sa_handler = sig_endpgm;
|
||||||
|
break;
|
||||||
|
case SIGALRM: case SIGINT: case SIGPIPE:
|
||||||
|
case SIGQUIT: case SIGTERM: case SIGUSR1:
|
||||||
|
case SIGUSR2:
|
||||||
|
sa.sa_handler = sig_endpgm;
|
||||||
|
break;
|
||||||
|
case SIGTSTP: case SIGTTIN: case SIGTTOU:
|
||||||
|
sa.sa_handler = sig_paused;
|
||||||
|
break;
|
||||||
|
case SIGCONT: case SIGWINCH:
|
||||||
|
sa.sa_handler = sig_resize;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sa.sa_handler = sig_abexit;
|
||||||
|
break;
|
||||||
|
case SIGKILL: case SIGSTOP:
|
||||||
|
// because uncatchable, fall through
|
||||||
|
case SIGCHLD: // we can't catch this
|
||||||
|
continue; // when opening a pipe
|
||||||
|
}
|
||||||
|
sigaction(i, &sa, NULL);
|
||||||
|
}
|
||||||
|
} // end: signals_set
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the terminal attributes */
|
* Set up the terminal attributes */
|
||||||
static void whack_terminal (void) {
|
static void whack_terminal (void) {
|
||||||
@ -6731,8 +6745,9 @@ int main (int argc, char *argv[]) {
|
|||||||
// +-------------+
|
// +-------------+
|
||||||
wins_stage_1(); // top (sic) slice
|
wins_stage_1(); // top (sic) slice
|
||||||
configs_reads(); // > spread etc, <
|
configs_reads(); // > spread etc, <
|
||||||
parse_args(argc, argv); // > lean stuff, <
|
parse_args(argc, argv); // > onions etc, <
|
||||||
whack_terminal(); // > onions etc. <
|
signals_set(); // > lean stuff, <
|
||||||
|
whack_terminal(); // > more stuff. <
|
||||||
wins_stage_2(); // as bottom slice
|
wins_stage_2(); // as bottom slice
|
||||||
// +-------------+
|
// +-------------+
|
||||||
|
|
||||||
|
@ -711,6 +711,7 @@ typedef struct WIN_t {
|
|||||||
//atic int configs_path (const char *const fmts, ...);
|
//atic int configs_path (const char *const fmts, ...);
|
||||||
//atic void configs_reads (void);
|
//atic void configs_reads (void);
|
||||||
//atic void parse_args (int argc, char **argv);
|
//atic void parse_args (int argc, char **argv);
|
||||||
|
//atic void signals_set (void);
|
||||||
//atic void whack_terminal (void);
|
//atic void whack_terminal (void);
|
||||||
/*------ Windows/Field Groups support ----------------------------------*/
|
/*------ Windows/Field Groups support ----------------------------------*/
|
||||||
//atic void win_names (WIN_t *q, const char *name);
|
//atic void win_names (WIN_t *q, const char *name);
|
||||||
|
Loading…
Reference in New Issue
Block a user