From 39b2248bdede16a64f2d748b757161913ddef682 Mon Sep 17 00:00:00 2001 From: hniksic Date: Wed, 5 Dec 2001 23:14:35 -0800 Subject: [PATCH] [svn] Fall back to dot progress when forced to background. Published in . --- src/ChangeLog | 15 +++++++++++++++ src/main.c | 7 ++++++- src/progress.c | 25 +++++++++++++++++++++++-- src/progress.h | 1 + 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f8966093..4b45765c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2001-12-06 Hrvoje Niksic + + * 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 * log.c (logvprintf): Restructure to allow being called multiple diff --git a/src/main.c b/src/main.c index 1933cfc5..49e979fb 100644 --- a/src/main.c +++ b/src/main.c @@ -880,7 +880,11 @@ Can't timestamp and not clobber old files at the same time.\n")); #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) @@ -894,5 +898,6 @@ redirect_output_signal (int sig) (sig == SIGUSR1 ? "SIGUSR1" : "WTF?!"))); redirect_output (tmp); + progress_schedule_redirect (); } #endif /* HAVE_SIGNAL */ diff --git a/src/progress.c b/src/progress.c index d57fbc4e..4bf8541b 100644 --- a/src/progress.c +++ b/src/progress.c @@ -61,6 +61,7 @@ static struct progress_implementation implementations[] = { { "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. */ @@ -111,6 +112,7 @@ set_progress_implementation (const char *name) 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 @@ -125,6 +127,14 @@ set_progress_implementation (const char *name) 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 @@ -134,6 +144,14 @@ set_progress_implementation (const char *name) 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); } @@ -653,6 +671,10 @@ bar_set_params (const char *params) { int sw; + if (params + && 0 == strcmp (params, "force")) + current_impl_locked = 1; + if ((opt.lfilename #ifdef HAVE_ISATTY || !isatty (fileno (stderr)) @@ -660,8 +682,7 @@ bar_set_params (const char *params) 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 diff --git a/src/progress.h b/src/progress.h index 5566cb9a..64de3996 100644 --- a/src/progress.h +++ b/src/progress.h @@ -22,6 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 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)); -- 2.39.2