mirror of
https://github.com/ipxe/ipxe
synced 2025-12-14 16:01:38 +03:00
[image] Allow download job to complete before acting upon image
Allow the monojob controlling the download to complete before calling register_image() and friends. This allows the trailing "ok" from monojob.c to be printed before the image starts executing (and possibly printing output of its own). Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -40,11 +40,11 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
*
|
||||
* @v image Image
|
||||
* @v uri URI
|
||||
* @v image_register Action to take upon a successful download
|
||||
* @v action Action to take upon a successful download
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int imgdownload ( struct image *image, struct uri *uri,
|
||||
int ( * image_register ) ( struct image *image ) ) {
|
||||
int ( * action ) ( struct image *image ) ) {
|
||||
size_t len = ( unparse_uri ( NULL, 0, uri, URI_ALL ) + 1 );
|
||||
char uri_string_redacted[len];
|
||||
const char *password;
|
||||
@@ -62,14 +62,18 @@ int imgdownload ( struct image *image, struct uri *uri,
|
||||
uri->password = password;
|
||||
|
||||
/* Create downloader */
|
||||
if ( ( rc = create_downloader ( &monojob, image, image_register,
|
||||
LOCATION_URI, uri ) ) != 0 )
|
||||
if ( ( rc = create_downloader ( &monojob, image, LOCATION_URI,
|
||||
uri ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Wait for download to complete */
|
||||
if ( ( rc = monojob_wait ( uri_string_redacted ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Act upon downloaded image */
|
||||
if ( ( rc = action ( image ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -78,18 +82,18 @@ int imgdownload ( struct image *image, struct uri *uri,
|
||||
*
|
||||
* @v image Image
|
||||
* @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
|
||||
* @v image_register Action to take upon a successful fetch
|
||||
* @v action Action to take upon a successful download
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int imgfetch ( struct image *image, const char *uri_string,
|
||||
int ( * image_register ) ( struct image *image ) ) {
|
||||
int ( * action ) ( struct image *image ) ) {
|
||||
struct uri *uri;
|
||||
int rc;
|
||||
|
||||
if ( ! ( uri = parse_uri ( uri_string ) ) )
|
||||
return -ENOMEM;
|
||||
|
||||
rc = imgdownload ( image, uri, image_register );
|
||||
rc = imgdownload ( image, uri, action );
|
||||
|
||||
uri_put ( uri );
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user