# include <unistd.h>
#endif /* HAVE_UNISTD_H */
#include <string.h>
-#ifdef HAVE_SIGNAL_H
-# include <signal.h>
-#endif
-#ifdef HAVE_NLS
-#ifdef HAVE_LOCALE_H
+#include <signal.h>
+#if defined(HAVE_NLS) && defined(HAVE_LOCALE_H)
# include <locale.h>
-#endif /* HAVE_LOCALE_H */
-#endif /* HAVE_NLS */
+#endif
#include <assert.h>
#include <errno.h>
extern struct cookie_jar *wget_cookie_jar;
-static RETSIGTYPE redirect_output_signal (int);
+static void redirect_output_signal (int);
const char *exec_name;
\f
ws_startup ();
#endif
+#ifdef SIGHUP
/* Setup the signal handler to redirect output when hangup is
received. */
-#ifdef HAVE_SIGNAL
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
signal(SIGHUP, redirect_output_signal);
+#endif
/* ...and do the same for SIGUSR1. */
+#ifdef SIGUSR1
signal (SIGUSR1, redirect_output_signal);
+#endif
+#ifdef SIGPIPE
/* Writing to a closed socket normally signals SIGPIPE, and the
process exits. What we want is to ignore SIGPIPE and just check
for the return value of write(). */
signal (SIGPIPE, SIG_IGN);
+#endif
#ifdef SIGWINCH
signal (SIGWINCH, progress_handle_sigwinch);
#endif
-#endif /* HAVE_SIGNAL */
status = RETROK; /* initialize it, just-in-case */
/* Retrieve the URLs from argument list. */
return 1;
}
\f
-#ifdef HAVE_SIGNAL
+#if defined(SIGHUP) || defined(SIGUSR1)
/* Hangup signal handler. When wget receives SIGHUP or SIGUSR1, it
will proceed operation as usual, trying to write into a log file.
- If that is impossible, the output will be turned off.
-
- #### It is unsafe to do call libc functions from a signal handler.
- What we should do is, set a global variable, and have the code in
- log.c pick it up. */
+ If that is impossible, the output will be turned off. */
-static RETSIGTYPE
+static void
redirect_output_signal (int sig)
{
const char *signal_name = (sig == SIGHUP ? "SIGHUP" :
progress_schedule_redirect ();
signal (sig, redirect_output_signal);
}
-#endif /* HAVE_SIGNAL */
+#endif