+2001-12-06 Hrvoje Niksic <hniksic@arsdigita.com>
+
+ * progress.c (progress_create): Make sure that, when the output is
+ redirected, the progress implementation gets changed to the
+ fallback one.
+ (bar_set_params): Set current_impl_locked to 1 when "force" is
+ specified.
+ (progress_create): Don't change the progress implementation if
+ current_impl_locked is non-zero.
+
+ * main.c (redirect_output_signal): Call
+ progress_schedule_redirect.
+
+ * progress.c (progress_schedule_redirect): New function.
+
2001-12-06 Hrvoje Niksic <hniksic@arsdigita.com>
* log.c (logvprintf): Restructure to allow being called multiple
#ifdef HAVE_SIGNAL
/* 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. */
+ 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. */
static RETSIGTYPE
redirect_output_signal (int sig)
(sig == SIGUSR1 ? "SIGUSR1" :
"WTF?!")));
redirect_output (tmp);
+ progress_schedule_redirect ();
}
#endif /* HAVE_SIGNAL */
{ "bar", bar_create, bar_update, bar_finish, bar_set_params }
};
static struct progress_implementation *current_impl;
+int current_impl_locked;
/* Progress implementation used by default. Can be overriden in
wgetrc or by the fallback one. */
if (!strncmp (pi->name, name, namelen))
{
current_impl = pi;
+ current_impl_locked = 0;
if (colon)
/* We call pi->set_params even if colon is NULL because we
abort ();
}
+static int output_redirected;
+
+void
+progress_schedule_redirect (void)
+{
+ output_redirected = 1;
+}
+
/* Create a progress gauge. INITIAL is the number of bytes the
download starts from (zero if the download starts from scratch).
TOTAL is the expected total number of bytes in this download. If
void *
progress_create (long initial, long total)
{
+ /* Check if the log status has changed under our feet. */
+ if (output_redirected)
+ {
+ if (!current_impl_locked)
+ set_progress_implementation (FALLBACK_PROGRESS_IMPLEMENTATION);
+ output_redirected = 0;
+ }
+
return current_impl->create (initial, total);
}
{
int sw;
+ if (params
+ && 0 == strcmp (params, "force"))
+ current_impl_locked = 1;
+
if ((opt.lfilename
#ifdef HAVE_ISATTY
|| !isatty (fileno (stderr))
1
#endif
)
- && !(params != NULL
- && 0 == strcmp (params, "force")))
+ && !current_impl_locked)
{
/* We're not printing to a TTY, so revert to the fallback
display. #### We're recursively calling
int valid_progress_implementation_p PARAMS ((const char *));
void set_progress_implementation PARAMS ((const char *));
+void progress_schedule_redirect PARAMS ((void));
void *progress_create PARAMS ((long, long));
void progress_update PARAMS ((void *, long, long));