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