| 1 |
/* Exit status handling. |
| 2 |
Copyright (C) 2009-2012, 2015, 2018-2024 Free Software Foundation, |
| 3 |
Inc. |
| 4 |
|
| 5 |
This file is part of GNU Wget. |
| 6 |
|
| 7 |
GNU Wget is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
GNU Wget is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with Wget. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "wget.h" |
| 22 |
#include "exits.h" |
| 23 |
|
| 24 |
static int final_exit_status = WGET_EXIT_SUCCESS; |
| 25 |
|
| 26 |
/* XXX: I don't like that newly-added uerr_t codes will doubtless fall |
| 27 |
through the craccks, or the fact that we seem to have way more |
| 28 |
codes than we know what to do with. Need to go through and sort |
| 29 |
through the truly essential codes, and merge the rest with |
| 30 |
those. Quite a few are never even used! |
| 31 |
|
| 32 |
Quite a few of the codes below would have no business being |
| 33 |
returned to retrieve_url's caller, but since it's very difficult to |
| 34 |
determine which do and which don't, I grab virtually all of them to |
| 35 |
be safe. */ |
| 36 |
static int |
| 37 |
get_status_for_err (uerr_t err) |
| 38 |
{ |
| 39 |
switch (err) |
| 40 |
{ |
| 41 |
case RETROK: |
| 42 |
return WGET_EXIT_SUCCESS; |
| 43 |
case FOPENERR: case FOPEN_EXCL_ERR: case FWRITEERR: case WRITEFAILED: |
| 44 |
case UNLINKERR: case CLOSEFAILED: case FILEBADFILE: |
| 45 |
return WGET_EXIT_IO_FAIL; |
| 46 |
case NOCONERROR: case HOSTERR: case CONSOCKERR: case CONERROR: |
| 47 |
case CONSSLERR: case CONIMPOSSIBLE: case FTPRERR: case FTPINVPASV: |
| 48 |
case READERR: case TRYLIMEXC: |
| 49 |
return WGET_EXIT_NETWORK_FAIL; |
| 50 |
case VERIFCERTERR: |
| 51 |
return WGET_EXIT_SSL_AUTH_FAIL; |
| 52 |
case FTPLOGINC: case FTPLOGREFUSED: case AUTHFAILED: |
| 53 |
return WGET_EXIT_SERVER_AUTH_FAIL; |
| 54 |
case HEOF: case HERR: case ATTRMISSING: |
| 55 |
return WGET_EXIT_PROTOCOL_ERROR; |
| 56 |
case WRONGCODE: case FTPPORTERR: case FTPSYSERR: |
| 57 |
case FTPNSFOD: case FTPUNKNOWNTYPE: case FTPSRVERR: |
| 58 |
case FTPRETRINT: case FTPRESTFAIL: case FTPNOPASV: |
| 59 |
case CONTNOTSUPPORTED: case RANGEERR: case RETRBADPATTERN: |
| 60 |
case PROXERR: case GATEWAYTIMEOUT: |
| 61 |
return WGET_EXIT_SERVER_ERROR; |
| 62 |
case URLERROR: case QUOTEXC: case SSLINITFAILED: case UNKNOWNATTR: |
| 63 |
default: |
| 64 |
return WGET_EXIT_UNKNOWN; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/* inform_exit_status |
| 69 |
* |
| 70 |
* Ensure that Wget's exit status will reflect the problem indicated |
| 71 |
* by ERR, unless the exit status has already been set to reflect a more |
| 72 |
* important problem. */ |
| 73 |
void |
| 74 |
inform_exit_status (uerr_t err) |
| 75 |
{ |
| 76 |
int new_status = get_status_for_err (err); |
| 77 |
|
| 78 |
if (new_status != WGET_EXIT_SUCCESS |
| 79 |
&& (final_exit_status == WGET_EXIT_SUCCESS |
| 80 |
|| new_status < final_exit_status)) |
| 81 |
{ |
| 82 |
final_exit_status = new_status; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
int |
| 87 |
get_exit_status (void) |
| 88 |
{ |
| 89 |
return |
| 90 |
(final_exit_status == WGET_EXIT_UNKNOWN) |
| 91 |
? 1 |
| 92 |
: final_exit_status; |
| 93 |
} |