tweaks: reduce the scope of a variable, and let the compiler zero it

Also, rename the variable, to have a unique name.
master
Benno Schulenberg 2019-05-28 14:09:54 +02:00
parent b75563b88e
commit d9deaf9f2f
1 changed files with 21 additions and 23 deletions

View File

@ -60,9 +60,6 @@ static struct termios oldterm;
# define tcgetattr(...) # define tcgetattr(...)
#endif #endif
static struct sigaction act;
/* Used to set up all our fun signal handlers. */
static struct sigaction oldaction, newaction; static struct sigaction oldaction, newaction;
/* Containers for the original and the temporary handler for SIGINT. */ /* Containers for the original and the temporary handler for SIGINT. */
@ -1133,44 +1130,45 @@ bool scoop_stdin(void)
/* Register half a dozen signal handlers. */ /* Register half a dozen signal handlers. */
void signal_init(void) void signal_init(void)
{ {
struct sigaction deed = {{0}};
/* Trap SIGINT and SIGQUIT because we want them to do useful things. */ /* Trap SIGINT and SIGQUIT because we want them to do useful things. */
memset(&act, 0, sizeof(struct sigaction)); deed.sa_handler = SIG_IGN;
act.sa_handler = SIG_IGN; sigaction(SIGINT, &deed, NULL);
sigaction(SIGINT, &act, NULL);
#ifdef SIGQUIT #ifdef SIGQUIT
sigaction(SIGQUIT, &act, NULL); sigaction(SIGQUIT, &deed, NULL);
#endif #endif
/* Trap SIGHUP and SIGTERM because we want to write the file out. */ /* Trap SIGHUP and SIGTERM because we want to write the file out. */
act.sa_handler = handle_hupterm; deed.sa_handler = handle_hupterm;
#ifdef SIGHUP #ifdef SIGHUP
sigaction(SIGHUP, &act, NULL); sigaction(SIGHUP, &deed, NULL);
#endif #endif
sigaction(SIGTERM, &act, NULL); sigaction(SIGTERM, &deed, NULL);
#ifndef NANO_TINY #ifndef NANO_TINY
/* Trap SIGWINCH because we want to handle window resizes. */ /* Trap SIGWINCH because we want to handle window resizes. */
act.sa_handler = handle_sigwinch; deed.sa_handler = handle_sigwinch;
sigaction(SIGWINCH, &act, NULL); sigaction(SIGWINCH, &deed, NULL);
#endif #endif
if (ISSET(SUSPEND)) { if (ISSET(SUSPEND)) {
/* Block all other signals in the suspend and continue handlers. /* Block all other signals in the suspend and continue handlers.
* If we don't do this, other stuff interrupts them! */ * If we don't do this, other stuff interrupts them! */
sigfillset(&act.sa_mask); sigfillset(&deed.sa_mask);
#ifdef SIGTSTP #ifdef SIGTSTP
/* Trap a normal suspend (^Z) so we can handle it ourselves. */ /* Trap a normal suspend (^Z) so we can handle it ourselves. */
act.sa_handler = do_suspend; deed.sa_handler = do_suspend;
sigaction(SIGTSTP, &act, NULL); sigaction(SIGTSTP, &deed, NULL);
#endif #endif
#ifdef SIGCONT #ifdef SIGCONT
act.sa_handler = do_continue; deed.sa_handler = do_continue;
sigaction(SIGCONT, &act, NULL); sigaction(SIGCONT, &deed, NULL);
#endif #endif
} else { } else {
#ifdef SIGTSTP #ifdef SIGTSTP
act.sa_handler = SIG_IGN; deed.sa_handler = SIG_IGN;
sigaction(SIGTSTP, &act, NULL); sigaction(SIGTSTP, &deed, NULL);
#endif #endif
} }
@ -1179,10 +1177,10 @@ void signal_init(void)
/* Trap SIGSEGV and SIGABRT to save any changed buffers and reset /* Trap SIGSEGV and SIGABRT to save any changed buffers and reset
* the terminal to a usable state. Reset these handlers to their * the terminal to a usable state. Reset these handlers to their
* defaults as soon as their signal fires. */ * defaults as soon as their signal fires. */
act.sa_handler = handle_crash; deed.sa_handler = handle_crash;
act.sa_flags |= SA_RESETHAND; deed.sa_flags |= SA_RESETHAND;
sigaction(SIGSEGV, &act, NULL); sigaction(SIGSEGV, &deed, NULL);
sigaction(SIGABRT, &act, NULL); sigaction(SIGABRT, &deed, NULL);
} }
#endif #endif
} }