[Bug-wget] [bug #45790] wget prints it's progress even when background

2016-10-21 Thread Tim Ruehsen
Update of bug #45790 (project wget):

  Status:None => Fixed  
 Open/Closed:Open => Closed 


___

Reply to this item at:

  

___
  Message sent via/by Savannah
  http://savannah.gnu.org/




[Bug-wget] [bug #46584] wget --spider always returns zero exit status

2016-10-21 Thread Tim Ruehsen
Update of bug #46584 (project wget):

  Status:None => Fixed  
 Open/Closed:Open => Closed 


___

Reply to this item at:

  

___
  Message sent via/by Savannah
  http://savannah.gnu.org/




Re: [Bug-wget] [PATCH v5] bug #45790: wget prints it's progress even when background

2016-10-21 Thread Tim Rühsen
Thanks, just pushed.

On Freitag, 21. Oktober 2016 17:12:58 CEST losgrandes wrote:
> Fixed trailing whitespace errors. Sorry for sending dirty patch. Should be
> good now.
> 
> * src/log.c: Use tcgetpgrp(STDIN_FILENO) != getpgrp() to determine when to
> print to STD* or logfile. Deprecate log_request_redirect_output function.
>   Use different file handles for STD* and logfile, to easily switch between
> them when changing fg/bg. * src/log.h: Make redirect_output function
> externally linked.
> * src/main.c: Don't use deprecated log_request_redirect_output function. Use
> redirect_output instead. * src/mswindows.c: Don't use deprecated
> log_request_redirect_output function. Use redirect_output instead. ---
>  src/log.c   | 125
> +--- src/log.h   | 
>  1 +
>  src/main.c  |   2 +-
>  src/mswindows.c |   5 +--
>  4 files changed, 85 insertions(+), 48 deletions(-)
> 
> diff --git a/src/log.c b/src/log.c
> index a1338ca..bcd4d2e 100644
> --- a/src/log.c
> +++ b/src/log.c
> @@ -80,6 +80,18 @@ as that of the covered work.  */
> logging is inhibited, logfp is set back to NULL. */
>  static FILE *logfp;
> 
> +/* Descriptor of the stdout|stderr */
> +static FILE *stdlogfp;
> +
> +/* Descriptor of the wget.log* file (if created) */
> +static FILE *filelogfp;
> +
> +/* Name of log file */
> +static char *logfile;
> +
> +/* Is interactive shell ? */
> +static int shell_is_interactive;
> +
>  /* A second file descriptor pointing to the temporary log file for the
> WARC writer.  If WARC writing is disabled, this is NULL.  */
>  static FILE *warclogfp;
> @@ -611,16 +623,18 @@ log_init (const char *file, bool appendp)
>  {
>if (HYPHENP (file))
>  {
> -  logfp = stdout;
> +  stdlogfp = stdout;
> +  logfp = stdlogfp;
>  }
>else
>  {
> -  logfp = fopen (file, appendp ? "a" : "w");
> -  if (!logfp)
> +  filelogfp = fopen (file, appendp ? "a" : "w");
> +  if (!filelogfp)
>  {
>fprintf (stderr, "%s: %s: %s\n", exec_name, file, strerror
> (errno)); exit (WGET_EXIT_GENERIC_ERROR);
>  }
> +  logfp = filelogfp;
>  }
>  }
>else
> @@ -631,7 +645,8 @@ log_init (const char *file, bool appendp)
>   stderr only if the user actually specifies `-O -'.  He says
>   this inconsistency is harder to document, but is overall
>   easier on the user.  */
> -  logfp = stderr;
> +  stdlogfp = stderr;
> +  logfp = stdlogfp;
> 
>if (1
>  #ifdef HAVE_ISATTY
> @@ -646,6 +661,11 @@ log_init (const char *file, bool appendp)
>save_context_p = true;
>  }
>  }
> +
> +#ifndef WINDOWS
> +  /* Initialize this values so we don't have to ask every time we print
> line */ +  shell_is_interactive = isatty (STDIN_FILENO);
> +#endif
>  }
> 
>  /* Close LOGFP (only if we opened it, not if it's stderr), inhibit
> @@ -880,59 +900,78 @@ log_cleanup (void)
> 
>  /* When SIGHUP or SIGUSR1 are received, the output is redirected
> elsewhere.  Such redirection is only allowed once. */
> -static enum { RR_NONE, RR_REQUESTED, RR_DONE } redirect_request = RR_NONE;
>  static const char *redirect_request_signal_name;
> 
> -/* Redirect output to `wget-log'.  */
> +/* Redirect output to `wget-log' or back to stdout/stderr.  */
> 
> -static void
> -redirect_output (void)
> +void
> +redirect_output (bool to_file, const char *signal_name)
>  {
> -  char *logfile;
> -  logfp = unique_create (DEFAULT_LOGFILE, false, );
> -  if (logfp)
> +  if (to_file && logfp != filelogfp)
>  {
> -  fprintf (stderr, _("\n%s received, redirecting output to %s.\n"),
> -   redirect_request_signal_name, quote (logfile));
> -  xfree (logfile);
> -  /* Dump the context output to the newly opened log.  */
> -  log_dump_context ();
> +  if (signal_name)
> +{
> +  fprintf (stderr, "\n%s received.", signal_name);
> +}
> +  if (!filelogfp)
> +{
> +  filelogfp = unique_create (DEFAULT_LOGFILE, false, );
> +  if (filelogfp)
> +{
> +  fprintf (stderr, _("\nRedirecting output to %s.\n"),
> +  quote (logfile));
> +  /* Store signal name to tell wget it's permanent redirect to
> log file */ +  redirect_request_signal_name = signal_name;
> +  logfp = filelogfp;
> +  /* Dump the context output to the newly opened log.  */
> +  log_dump_context ();
> +}
> +  else
> +{
> +  /* Eek!  Opening the alternate log file has failed.  Nothing
> we +can do but disable printing completely. */
> +  fprintf (stderr, _("%s: %s; disabling logging.\n"),
> +  (logfile) ? logfile : DEFAULT_LOGFILE, strerror
> (errno)); +  inhibit_logging = true;
> +   

[Bug-wget] [PATCH v5] bug #45790: wget prints it's progress even when background

2016-10-21 Thread losgrandes
Fixed trailing whitespace errors. Sorry for sending dirty patch. Should be good 
now.

* src/log.c: Use tcgetpgrp(STDIN_FILENO) != getpgrp() to determine when to 
print to STD* or logfile.
  Deprecate log_request_redirect_output function.
  Use different file handles for STD* and logfile, to easily switch between 
them when changing fg/bg.
* src/log.h: Make redirect_output function externally linked.
* src/main.c: Don't use deprecated log_request_redirect_output function. Use 
redirect_output instead.
* src/mswindows.c: Don't use deprecated log_request_redirect_output function. 
Use redirect_output instead.
---
 src/log.c   | 125 +---
 src/log.h   |   1 +
 src/main.c  |   2 +-
 src/mswindows.c |   5 +--
 4 files changed, 85 insertions(+), 48 deletions(-)

diff --git a/src/log.c b/src/log.c
index a1338ca..bcd4d2e 100644
--- a/src/log.c
+++ b/src/log.c
@@ -80,6 +80,18 @@ as that of the covered work.  */
logging is inhibited, logfp is set back to NULL. */
 static FILE *logfp;
 
+/* Descriptor of the stdout|stderr */
+static FILE *stdlogfp;
+
+/* Descriptor of the wget.log* file (if created) */
+static FILE *filelogfp;
+
+/* Name of log file */
+static char *logfile;
+
+/* Is interactive shell ? */
+static int shell_is_interactive;
+
 /* A second file descriptor pointing to the temporary log file for the
WARC writer.  If WARC writing is disabled, this is NULL.  */
 static FILE *warclogfp;
@@ -611,16 +623,18 @@ log_init (const char *file, bool appendp)
 {
   if (HYPHENP (file))
 {
-  logfp = stdout;
+  stdlogfp = stdout;
+  logfp = stdlogfp;
 }
   else
 {
-  logfp = fopen (file, appendp ? "a" : "w");
-  if (!logfp)
+  filelogfp = fopen (file, appendp ? "a" : "w");
+  if (!filelogfp)
 {
   fprintf (stderr, "%s: %s: %s\n", exec_name, file, strerror 
(errno));
   exit (WGET_EXIT_GENERIC_ERROR);
 }
+  logfp = filelogfp;
 }
 }
   else
@@ -631,7 +645,8 @@ log_init (const char *file, bool appendp)
  stderr only if the user actually specifies `-O -'.  He says
  this inconsistency is harder to document, but is overall
  easier on the user.  */
-  logfp = stderr;
+  stdlogfp = stderr;
+  logfp = stdlogfp;
 
   if (1
 #ifdef HAVE_ISATTY
@@ -646,6 +661,11 @@ log_init (const char *file, bool appendp)
   save_context_p = true;
 }
 }
+
+#ifndef WINDOWS
+  /* Initialize this values so we don't have to ask every time we print line */
+  shell_is_interactive = isatty (STDIN_FILENO);
+#endif
 }
 
 /* Close LOGFP (only if we opened it, not if it's stderr), inhibit
@@ -880,59 +900,78 @@ log_cleanup (void)
 
 /* When SIGHUP or SIGUSR1 are received, the output is redirected
elsewhere.  Such redirection is only allowed once. */
-static enum { RR_NONE, RR_REQUESTED, RR_DONE } redirect_request = RR_NONE;
 static const char *redirect_request_signal_name;
 
-/* Redirect output to `wget-log'.  */
+/* Redirect output to `wget-log' or back to stdout/stderr.  */
 
-static void
-redirect_output (void)
+void
+redirect_output (bool to_file, const char *signal_name)
 {
-  char *logfile;
-  logfp = unique_create (DEFAULT_LOGFILE, false, );
-  if (logfp)
+  if (to_file && logfp != filelogfp)
 {
-  fprintf (stderr, _("\n%s received, redirecting output to %s.\n"),
-   redirect_request_signal_name, quote (logfile));
-  xfree (logfile);
-  /* Dump the context output to the newly opened log.  */
-  log_dump_context ();
+  if (signal_name)
+{
+  fprintf (stderr, "\n%s received.", signal_name);
+}
+  if (!filelogfp)
+{
+  filelogfp = unique_create (DEFAULT_LOGFILE, false, );
+  if (filelogfp)
+{
+  fprintf (stderr, _("\nRedirecting output to %s.\n"),
+  quote (logfile));
+  /* Store signal name to tell wget it's permanent redirect to log 
file */
+  redirect_request_signal_name = signal_name;
+  logfp = filelogfp;
+  /* Dump the context output to the newly opened log.  */
+  log_dump_context ();
+}
+  else
+{
+  /* Eek!  Opening the alternate log file has failed.  Nothing we
+can do but disable printing completely. */
+  fprintf (stderr, _("%s: %s; disabling logging.\n"),
+  (logfile) ? logfile : DEFAULT_LOGFILE, strerror (errno));
+  inhibit_logging = true;
+}
+}
+  else
+{
+  fprintf (stderr, _("\nRedirecting output to %s.\n"),
+  quote (logfile));
+  logfp = filelogfp;
+  log_dump_context ();
+}
 }
-  else
+  else if (!to_file && logfp != stdlogfp)
 {
-  /* Eek!  Opening the alternate log 

Re: [Bug-wget] [PATCH v4] bug #45790: wget prints it's progress even when background

2016-10-21 Thread Tim Rühsen
Could you fix these, please...

Applying: bug #45790: wget prints it's progress even when background
.git/rebase-apply/patch:104: trailing whitespace.
  if (!filelogfp) 
.git/rebase-apply/patch:126: trailing whitespace.
  else 
.git/rebase-apply/patch:158: trailing whitespace.
  /* If it was redirected already to log file by SIGHUP or SIGUSR1, 
.git/rebase-apply/patch:159: trailing whitespace.
   * it was permanent and since that redirect_request_signal_name is set. 
.git/rebase-apply/patch:160: trailing whitespace.
   * If there was no SIGHUP or SIGUSR1 and shell is interactive 
warning: squelched 3 whitespace errors
warning: 8 lines add whitespace errors.

On Mittwoch, 19. Oktober 2016 11:53:21 CEST losgrandes wrote:
> * src/log.c: Use tcgetpgrp(STDIN_FILENO) != getpgrp() to determine when to
> print to STD* or logfile. Deprecate log_request_redirect_output function.
>   Use different file handles for STD* and logfile, to easily switch between
> them when changing fg/bg. * src/log.h: Make redirect_output function
> externally linked.
> * src/main.c: Don't use deprecated log_request_redirect_output function. Use
> redirect_output instead. * src/mswindows.c: Don't use deprecated
> log_request_redirect_output function. Use redirect_output instead. ---
>  src/log.c   | 125
> +--- src/log.h   | 
>  1 +
>  src/main.c  |   2 +-
>  src/mswindows.c |   5 +--
>  4 files changed, 85 insertions(+), 48 deletions(-)
> 
> diff --git a/src/log.c b/src/log.c
> index a1338ca..bcd4d2e 100644
> --- a/src/log.c
> +++ b/src/log.c
> @@ -80,6 +80,18 @@ as that of the covered work.  */
> logging is inhibited, logfp is set back to NULL. */
>  static FILE *logfp;
> 
> +/* Descriptor of the stdout|stderr */
> +static FILE *stdlogfp;
> +
> +/* Descriptor of the wget.log* file (if created) */
> +static FILE *filelogfp;
> +
> +/* Name of log file */
> +static char *logfile;
> +
> +/* Is interactive shell ? */
> +static int shell_is_interactive;
> +
>  /* A second file descriptor pointing to the temporary log file for the
> WARC writer.  If WARC writing is disabled, this is NULL.  */
>  static FILE *warclogfp;
> @@ -611,16 +623,18 @@ log_init (const char *file, bool appendp)
>  {
>if (HYPHENP (file))
>  {
> -  logfp = stdout;
> +  stdlogfp = stdout;
> +  logfp = stdlogfp;
>  }
>else
>  {
> -  logfp = fopen (file, appendp ? "a" : "w");
> -  if (!logfp)
> +  filelogfp = fopen (file, appendp ? "a" : "w");
> +  if (!filelogfp)
>  {
>fprintf (stderr, "%s: %s: %s\n", exec_name, file, strerror
> (errno)); exit (WGET_EXIT_GENERIC_ERROR);
>  }
> +  logfp = filelogfp;
>  }
>  }
>else
> @@ -631,7 +645,8 @@ log_init (const char *file, bool appendp)
>   stderr only if the user actually specifies `-O -'.  He says
>   this inconsistency is harder to document, but is overall
>   easier on the user.  */
> -  logfp = stderr;
> +  stdlogfp = stderr;
> +  logfp = stdlogfp;
> 
>if (1
>  #ifdef HAVE_ISATTY
> @@ -646,6 +661,11 @@ log_init (const char *file, bool appendp)
>save_context_p = true;
>  }
>  }
> +
> +#ifndef WINDOWS
> +  /* Initialize this values so we don't have to ask every time we print
> line */ +  shell_is_interactive = isatty (STDIN_FILENO);
> +#endif
>  }
> 
>  /* Close LOGFP (only if we opened it, not if it's stderr), inhibit
> @@ -880,59 +900,78 @@ log_cleanup (void)
> 
>  /* When SIGHUP or SIGUSR1 are received, the output is redirected
> elsewhere.  Such redirection is only allowed once. */
> -static enum { RR_NONE, RR_REQUESTED, RR_DONE } redirect_request = RR_NONE;
>  static const char *redirect_request_signal_name;
> 
> -/* Redirect output to `wget-log'.  */
> +/* Redirect output to `wget-log' or back to stdout/stderr.  */
> 
> -static void
> -redirect_output (void)
> +void
> +redirect_output (bool to_file, const char *signal_name)
>  {
> -  char *logfile;
> -  logfp = unique_create (DEFAULT_LOGFILE, false, );
> -  if (logfp)
> +  if (to_file && logfp != filelogfp)
>  {
> -  fprintf (stderr, _("\n%s received, redirecting output to %s.\n"),
> -   redirect_request_signal_name, quote (logfile));
> -  xfree (logfile);
> -  /* Dump the context output to the newly opened log.  */
> -  log_dump_context ();
> +  if (signal_name)
> +{
> +  fprintf (stderr, "\n%s received.", signal_name);
> +}
> +  if (!filelogfp)
> +{
> +  filelogfp = unique_create (DEFAULT_LOGFILE, false, );
> +  if (filelogfp)
> +{
> +  fprintf (stderr, _("\nRedirecting output to %s.\n"),
> +  quote (logfile));
> +  /* Store signal name to tell wget it's permanent redirect to
> log file */ +  

Re: [Bug-wget] [PATCH v2] bug #46584: wget --spider always returns zero exit status

2016-10-21 Thread Tim Rühsen
Thanks, pushed.

On Mittwoch, 19. Oktober 2016 11:53:23 CEST losgrandes wrote:
> * src/ftp.c: Return error as exit value if even one file doesn't exist
> 
> ---
>  src/ftp.c | 9 -
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ftp.c b/src/ftp.c
> index cc98ca3..77dc9cd 100644
> --- a/src/ftp.c
> +++ b/src/ftp.c
> @@ -1186,6 +1186,7 @@ Error in server response, closing control
> connection.\n")); if (opt.spider)
>  {
>bool exists = false;
> +  bool all_exist = true;
>struct fileinfo *f;
>uerr_t _res = ftp_get_listing (u, original_url, con, );
>/* Set the DO_RETR command flag again, because it gets unset when
> @@ -1201,6 +1202,8 @@ Error in server response, closing control
> connection.\n")); {
>exists = true;
>break;
> +} else {
> +  all_exist = false;
>  }
>f = f->next;
>  }
> @@ -1221,7 +1224,11 @@ Error in server response, closing control
> connection.\n")); con->csock = -1;
>fd_close (dtsock);
>fd_close (local_sock);
> -  return RETRFINISHED;
> +  if (all_exist) {
> +  return RETRFINISHED;
> +  } else {
> +  return FTPNSFOD;
> +  }
>  }
> 
>if (opt.verbose)



signature.asc
Description: This is a digitally signed message part.


Re: [Bug-wget] [PATCH v2] bug #48811: netrc password wins over interactive --ask-password

2016-10-21 Thread Tim Rühsen
Hi Piotr,

please include netrc.h in utils.c.

In getftp(): 
  struct net_credentials *ftp_cred = malloc (sizeof *ftp_cred);
...
  ftp_cred = pick_credentials()

This looks like a memleak. Also, where do you free ftp_cred ?
Is it really necessary  to allocate ftp_cred on each call to getftp (just a 
question, maybe it is) ?

Basically the same in gethttp()...

Try 'make check-valgrind' to test for some kinds of memleaks.

Regards, Tim

On Mittwoch, 19. Oktober 2016 11:53:22 CEST losgrandes wrote:
> * src/ftp.c: Leverage new struct net_credentials and function
> pick_credentials. pick_credentials is responsible for taking proper order
> when selecting source of credentials. * src/http.c: Leverage new struct
> net_credentials and function pick_credentials. * src/utils.c: New function
> pick_credentials.
> * src/utils.h: New struct net_credentials.
> 
> ---
>  src/ftp.c   | 19 +++
>  src/http.c  | 18 +++---
>  src/utils.c | 19 +++
>  src/utils.h | 11 +++
>  4 files changed, 44 insertions(+), 23 deletions(-)
> 
> diff --git a/src/ftp.c b/src/ftp.c
> index 39f20fa..cc98ca3 100644
> --- a/src/ftp.c
> +++ b/src/ftp.c
> @@ -327,7 +327,8 @@ getftp (struct url *u, struct url *original_url,
>uerr_t err = RETROK;  /* appease the compiler */
>FILE *fp = NULL;
>char *respline, *tms;
> -  const char *user, *passwd, *tmrate;
> +  const char *tmrate;
> +  struct net_credentials *ftp_cred = malloc (sizeof *ftp_cred);
>int cmd = con->cmd;
>wgint expected_bytes = 0;
>bool got_expected_bytes = false;
> @@ -359,13 +360,7 @@ getftp (struct url *u, struct url *original_url,
> 
>*qtyread = restval;
> 
> -  user = u->user;
> -  passwd = u->passwd;
> -  search_netrc (u->host, (const char **), (const char **), 1);
> -  user = user ? user : (opt.ftp_user ? opt.ftp_user : opt.user);
> -  if (!user) user = "anonymous";
> -  passwd = passwd ? passwd : (opt.ftp_passwd ? opt.ftp_passwd :
> opt.passwd); -  if (!passwd) passwd = "-wget@";
> +  ftp_cred = pick_credentials (u, opt.ftp_user, opt.ftp_passwd, opt.user,
> opt.passwd, 1);
> 
>dtsock = -1;
>local_sock = -1;
> @@ -461,18 +456,18 @@ getftp (struct url *u, struct url *original_url,
> 
>/* Second: Login with proper USER/PASS sequence.  */
>logprintf (LOG_VERBOSE, _("Logging in as %s ... "),
> - quotearg_style (escape_quoting_style, user));
> + quotearg_style (escape_quoting_style, ftp_cred->user));
>if (opt.server_response)
>  logputs (LOG_ALWAYS, "\n");
>if (con->proxy)
>  {
>/* If proxy is in use, log in as username@target-site. */
> -  char *logname = concat_strings (user, "@", u->host, (char *) 0);
> -  err = ftp_login (csock, logname, passwd);
> +  char *logname = concat_strings (ftp_cred->user, "@", u->host,
> (char *) 0); +  err = ftp_login (csock, logname, ftp_cred->passwd);
>xfree (logname);
>  }
>else
> -err = ftp_login (csock, user, passwd);
> +err = ftp_login (csock, ftp_cred->user, ftp_cred->passwd);
> 
>/* FTPRERR, FTPSRVERR, WRITEFAILED, FTPLOGREFUSED, FTPLOGINC */
>switch (err)
> diff --git a/src/http.c b/src/http.c
> index 7e2c4ec..41eaa42 100644
> --- a/src/http.c
> +++ b/src/http.c
> @@ -1813,7 +1813,7 @@ time_to_rfc1123 (time_t time, char *buf, size_t
> bufsize) static struct request *
>  initialize_request (const struct url *u, struct http_stat *hs, int *dt,
> struct url *proxy, bool inhibit_keep_alive, bool *basic_auth_finished, -   
> wgint *body_data_size, char **user, char **passwd, uerr_t
> *ret) +wgint *body_data_size, struct net_credentials
> **http_cred, uerr_t *ret) {
>bool head_only = !!(*dt & HEAD_ONLY);
>struct request *req;
> @@ -1876,20 +1876,16 @@ initialize_request (const struct url *u, struct
> http_stat *hs, int *dt, struct u request_set_header (req,
> "Accept-Encoding", "identity", rel_none);
> 
>/* Find the username and password for authentication. */
> -  *user = u->user;
> -  *passwd = u->passwd;
> -  search_netrc (u->host, (const char **)user, (const char **)passwd, 0);
> -  *user = *user ? *user : (opt.http_user ? opt.http_user : opt.user);
> -  *passwd = *passwd ? *passwd : (opt.http_passwd ? opt.http_passwd :
> opt.passwd); +  *http_cred = pick_credentials (u, opt.http_user,
> opt.http_passwd, opt.user, opt.passwd, 0);
> 
>/* We only do "site-wide" authentication with "global" user/password
> * values unless --auth-no-challange has been requested; URL
> user/password * info overrides. */
> -  if (*user && *passwd && (!u->user || opt.auth_without_challenge))
> +  if ((*http_cred)->user && (*http_cred)->passwd && (!u->user ||
> opt.auth_without_challenge)) {
>/* If this is a host for which we've already received a Basic
> * challenge, we'll go ahead and send Basic authentication creds. */
> -