mirror of
https://github.com/ipxe/ipxe
synced 2025-12-26 09:32:33 +03:00
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc. This does not cover all possible circumstances. For example, if a connection to a web server is successfully established and the web server acknowledges the HTTP request but never sends any data in response, then no timeout will be triggered. There is no timeout defined within the HTTP specifications, and the underlying TCP connection will not generate a timeout since it has no way to know that the HTTP layer is expecting to receive data from the server. Add a "--timeout" parameter to "imgfetch", "chain", etc. If no progress is made (i.e. no data is downloaded) within the timeout period, then the download will be aborted. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -40,6 +40,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
struct imgsingle_options {
|
||||
/** Image name */
|
||||
char *name;
|
||||
/** Download timeout */
|
||||
unsigned long timeout;
|
||||
/** Replace image */
|
||||
int replace;
|
||||
/** Free image after execution */
|
||||
@@ -49,13 +51,17 @@ struct imgsingle_options {
|
||||
/** "img{single}" option list */
|
||||
static union {
|
||||
/* "imgexec" takes all three options */
|
||||
struct option_descriptor imgexec[3];
|
||||
/* Other "img{single}" commands take only --name and --autofree */
|
||||
struct option_descriptor imgsingle[2];
|
||||
struct option_descriptor imgexec[4];
|
||||
/* Other "img{single}" commands take only --name, --timeout,
|
||||
* and --autofree
|
||||
*/
|
||||
struct option_descriptor imgsingle[3];
|
||||
} opts = {
|
||||
.imgexec = {
|
||||
OPTION_DESC ( "name", 'n', required_argument,
|
||||
struct imgsingle_options, name, parse_string ),
|
||||
OPTION_DESC ( "timeout", 't', required_argument,
|
||||
struct imgsingle_options, timeout, parse_timeout),
|
||||
OPTION_DESC ( "autofree", 'a', no_argument,
|
||||
struct imgsingle_options, autofree, parse_flag ),
|
||||
OPTION_DESC ( "replace", 'r', no_argument,
|
||||
@@ -68,7 +74,8 @@ struct imgsingle_descriptor {
|
||||
/** Command descriptor */
|
||||
struct command_descriptor *cmd;
|
||||
/** Function to use to acquire the image */
|
||||
int ( * acquire ) ( const char *name, struct image **image );
|
||||
int ( * acquire ) ( const char *name, unsigned long timeout,
|
||||
struct image **image );
|
||||
/** Pre-action to take upon image, or NULL */
|
||||
void ( * preaction ) ( struct image *image );
|
||||
/** Action to take upon image, or NULL */
|
||||
@@ -114,7 +121,8 @@ static int imgsingle_exec ( int argc, char **argv,
|
||||
|
||||
/* Acquire the image */
|
||||
if ( name_uri ) {
|
||||
if ( ( rc = desc->acquire ( name_uri, &image ) ) != 0 )
|
||||
if ( ( rc = desc->acquire ( name_uri, opts.timeout,
|
||||
&image ) ) != 0 )
|
||||
goto err_acquire;
|
||||
} else {
|
||||
image = image_find_selected();
|
||||
|
||||
Reference in New Issue
Block a user