]> sjero.net Git - wget/commitdiff
[svn] Fall back to dot progress when forced to background.
authorhniksic <devnull@localhost>
Thu, 6 Dec 2001 07:14:35 +0000 (23:14 -0800)
committerhniksic <devnull@localhost>
Thu, 6 Dec 2001 07:14:35 +0000 (23:14 -0800)
Published in <sxs1yi8n7lx.fsf@florida.arsdigita.de>.

src/ChangeLog
src/main.c
src/progress.c
src/progress.h

index f8966093bd8acb7f93c01dcbce053f0cd81b199c..4b45765c5a7d4761d03a21f258156e3633f4d0f0 100644 (file)
@@ -1,3 +1,18 @@
+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
index 1933cfc5cc9467d558b48acf78277e8603976976..49e979fb910ffae0bbe8940e67cd8c7c889cc2a1 100644 (file)
@@ -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 */
index d57fbc4e4af0ce5eadd2efd2c20b3bfa48015852..4bf8541b3bdb7157a2fede69e7395687b51f1890 100644 (file)
@@ -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
index 5566cb9aa9fa7675487339a31792c5587dd0830d..64de3996576a1312e648ded8531dfb841d669034 100644 (file)
@@ -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));