w3mail

program to send a web page by email
git clone https://logand.com/git/w3mail.git/
Log | Files | Refs | README | LICENSE

commit 45cde57ee73cafe5fa02a84b0553b9011a82d617
parent 6774dc90e7defb6f2007d7919c5ebdf582c854ea
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sat, 20 Nov 2010 16:11:53 +0100

wget error messages added

Diffstat:
Mw3mail.c | 41++++++++++++++++-------------------------
1 file changed, 16 insertions(+), 25 deletions(-)

diff --git a/w3mail.c b/w3mail.c @@ -77,29 +77,18 @@ static void fpr(FILE *out, ...) { va_end(v); } -// TODO display readable error message instead of just exit status -// // http://www.gnu.org/software/wget/manual/html_node/Exit-Status.html -// -// 0 No problems occurred. -// 1 Generic error code. -// 2 Parse error, e.g. when parsing command-line options, .wgetrc or .netrc -// 3 File I/O error. -// 4 Network failure. -// 5 SSL verification failure. -// 6 Username/password authentication failure. -// 7 Protocol errors. -// 8 Server issued an error response. -// -// With the exceptions of 0 and 1, the lower-numbered exit codes take -// precedence over higher-numbered ones, when multiple types of errors -// are encountered. -// -// In versions of Wget prior to 1.12, Wget's exit status tended to be -// unhelpful and inconsistent. Recursive downloads would virtually always -// return 0 (success), regardless of any issues encountered, and -// non-recursive fetches only returned the status corresponding to the -// most recently-attempted download. +static char *wgetmsg[] = { + "No problems occurred", + "Generic error code", + "Parse error, e.g. when parsing command-line options, .wgetrc or .netrc", + "File I/O error", + "Network failure", + "SSL verification failure", + "Username/password authentication failure", + "Protocol errors", + "Server issued an error response" +}; static void wget(char *url, char *fname) { int pid = fork(); @@ -110,9 +99,11 @@ static void wget(char *url, char *fname) { do { pid_t w = waitpid(pid, &status, WUNTRACED | WCONTINUED); if(w == -1) die(1, "wget(): waitpid failed on wget '%s'", url); - if(WIFEXITED(status) && WEXITSTATUS(status)) - fprintf(stderr, "wget '%s' failed with status %d\n", url, - WEXITSTATUS(status)); + if(WIFEXITED(status) && WEXITSTATUS(status)) { + int n = WEXITSTATUS(status); + fprintf(stderr, "wget '%s' failed with status %d: %s\n", url, + n, (0 <= n && n <= 8) ? wgetmsg[n] : "unexpected status"); + } else if(WIFSIGNALED(status)) fprintf(stderr, "wget '%s' killed by signal %d\n", url, WTERMSIG(status));