Signal handling fixes: fixed nbase configure to actually set HAVE_SIGNAL

properly so our signal handing code actually activates.  But our signal
handling code was a bit questionable in many respects, so I removed most
of it under the theory that it hasn't been working for years and nobody
seemed to notice/care, so we presumably don't really need it.  And if we
do decide to add it again, we basically will need to do it over because
we now want to do it safely from a reentrancy perspective.  In particular,
I removed sigdie() and reaper().  We still have a few signal() calls.  In
particular, we ignore SIGPIPE and we set SIGINT, SIGTERM, SIGHUP, and
SIGSEGV to the defaults (SIG_DFL) explicitly.  Thanks to Ithilgore, Luis,
and Solar Designer in particular for fidning or commenting on the issue.
This commit is contained in:
fyodor 2009-08-13 21:54:55 +00:00
parent 5767865bba
commit 0df6272cf9
3 changed files with 1 additions and 79 deletions

10
main.cc
View file

@ -170,16 +170,6 @@ int main(int argc, char *argv[]) {
mtrace();
#endif
/* Trap these sigs for cleanup */
#if HAVE_SIGNAL
signal(SIGINT, sigdie);
signal(SIGTERM, sigdie);
#ifndef WIN32
signal(SIGHUP, sigdie);
signal(SIGCHLD, reaper);
#endif
#endif
if ((cptr = getenv("NMAP_ARGS"))) {
if (Snprintf(command, sizeof(command), "nmap %s", cptr) >= (int) sizeof(command)) {
error("Warning: NMAP_ARGS variable is too long, truncated");

69
nmap.cc
View file

@ -1326,11 +1326,6 @@ int nmap_main(int argc, char *argv[]) {
tty_init(); // Put the keyboard in raw mode
#if HAVE_SIGNAL
if (!o.debugging)
signal(SIGSEGV, sigdie);
#endif
// After the arguments are fully processed we now make any of the timing
// tweaks the user might've specified:
if (pre_max_parallelism != -1) o.max_parallelism = pre_max_parallelism;
@ -1614,7 +1609,7 @@ int nmap_main(int argc, char *argv[]) {
#if defined(HAVE_SIGNAL) && defined(SIGPIPE)
signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE so our program doesn't crash because
of it, but we really shouldn't get an unsuspected
of it, but we really shouldn't get an unexpected
SIGPIPE */
#endif
@ -2738,68 +2733,6 @@ int ftp_anon_connect(struct ftpinfo *ftp) {
return sd;
}
#ifndef WIN32
void reaper(int signo) {
int status;
pid_t pid;
if ((pid = wait(&status)) == -1) {
gh_perror("waiting to reap child");
} else {
fprintf(stderr, "\n[%d finished status=%d (%s)]\nnmap> ", (int) pid, status, (status == 0)? "success" : "failure");
}
}
#endif
void sigdie(int signo) {
int abt = 0;
fflush(stdout);
switch(signo) {
case SIGINT:
error("caught SIGINT signal, cleaning up");
break;
#ifdef SIGTERM
case SIGTERM:
error("caught SIGTERM signal, cleaning up");
break;
#endif
#ifdef SIGHUP
case SIGHUP:
error("caught SIGHUP signal, cleaning up");
break;
#endif
#ifdef SIGSEGV
case SIGSEGV:
error("caught SIGSEGV signal, cleaning up");
abt = 1;
break;
#endif
#ifdef SIGBUS
case SIGBUS:
error("caught SIGBUS signal, cleaning up");
abt = 1;
break;
#endif
default:
error("caught signal %d, cleaning up", signo);
abt = 1;
break;
}
fflush(stderr);
log_close(LOG_MACHINE|LOG_NORMAL|LOG_SKID);
if (abt) abort();
exit(1);
}
/* Returns one if the file pathname given exists, is not a directory and
* is readable by the executing process. Returns two if it is readable
* and is a directory. Otherwise returns 0.

1
nmap.h
View file

@ -439,7 +439,6 @@ void nmap_free_mem();
/* general helper functions */
const char *statenum2str(int state);
const char *scantype2str(stype scantype);
void sigdie(int signo);
void reaper(int signo);
char *seqreport(struct seq_info *seq);
const char *ipidclass2ascii(int seqclass);