summaryrefslogtreecommitdiffstats
path: root/src/usr/autoboot.c
diff options
context:
space:
mode:
authorMichael Brown2010-10-22 00:33:41 +0200
committerMichael Brown2010-10-22 00:33:41 +0200
commit246624cdb8959a68730521d8a9a488e429c3a0db (patch)
tree5f4d43070d30c48feff2ea2e6f5ce0a9daf10007 /src/usr/autoboot.c
parent[scsi] Wait for a successful TEST UNIT READY command (diff)
downloadipxe-246624cdb8959a68730521d8a9a488e429c3a0db.tar.gz
ipxe-246624cdb8959a68730521d8a9a488e429c3a0db.tar.xz
ipxe-246624cdb8959a68730521d8a9a488e429c3a0db.zip
[autoboot] Improve visibility of error messages
Improve the visibility of error messages by removing the redundant final printing of the URL being booted. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/usr/autoboot.c')
-rw-r--r--src/usr/autoboot.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index 0421dc43..3d441167 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -77,17 +77,21 @@ int boot_next_server_and_filename ( struct in_addr next_server,
/* Construct URI */
uri = parse_uri ( filename );
- if ( ! uri )
- return -ENOMEM;
+ if ( ! uri ) {
+ printf ( "Could not parse \"%s\"\n", filename );
+ rc = -ENOMEM;
+ goto err_parse_uri;
+ }
filename_is_absolute = uri_is_absolute ( uri );
uri_put ( uri );
+
+ /* Construct a tftp:// URI for the filename, if applicable.
+ * We can't just rely on the current working URI, because the
+ * relative URI resolution will remove the distinction between
+ * filenames with and without initial slashes, which is
+ * significant for TFTP.
+ */
if ( ! filename_is_absolute ) {
- /* Construct a tftp:// URI for the filename. We can't
- * just rely on the current working URI, because the
- * relative URI resolution will remove the distinction
- * between filenames with and without initial slashes,
- * which is significant for TFTP.
- */
snprintf ( buf, sizeof ( buf ), "tftp://%s/",
inet_ntoa ( next_server ) );
uri_encode ( filename, buf + strlen ( buf ),
@@ -95,18 +99,32 @@ int boot_next_server_and_filename ( struct in_addr next_server,
filename = buf;
}
+ /* Download and boot image */
image = alloc_image();
- if ( ! image )
- return -ENOMEM;
+ if ( ! image ) {
+ printf ( "Could not allocate image\n" );
+ rc = -ENOMEM;
+ goto err_alloc_image;
+ }
if ( ( rc = imgfetch ( image, filename,
register_and_autoload_image ) ) != 0 ) {
- goto done;
+ printf ( "Could not fetch image: %s\n", strerror ( rc ) );
+ goto err_imgfetch;
+ }
+ if ( ( rc = imgexec ( image ) ) != 0 ) {
+ printf ( "Could not execute image: %s\n", strerror ( rc ) );
+ goto err_imgexec;
}
- if ( ( rc = imgexec ( image ) ) != 0 )
- goto done;
- done:
+ /* Drop image reference */
+ image_put ( image );
+ return 0;
+
+ err_imgexec:
+ err_imgfetch:
image_put ( image );
+ err_alloc_image:
+ err_parse_uri:
return rc;
}
@@ -229,25 +247,14 @@ static int netboot ( struct net_device *netdev ) {
fetch_string_setting ( NULL, &filename_setting, buf, sizeof ( buf ) );
if ( buf[0] ) {
printf ( "Booting from filename \"%s\"\n", buf );
- if ( ( rc = boot_next_server_and_filename ( next_server,
- buf ) ) != 0 ) {
- printf ( "Could not boot from filename \"%s\": %s\n",
- buf, strerror ( rc ) );
- return rc;
- }
- return 0;
+ return boot_next_server_and_filename ( next_server, buf );
}
/* No filename; try the root path */
fetch_string_setting ( NULL, &root_path_setting, buf, sizeof ( buf ) );
if ( buf[0] ) {
printf ( "Booting from root path \"%s\"\n", buf );
- if ( ( rc = boot_root_path ( buf ) ) != 0 ) {
- printf ( "Could not boot from root path \"%s\": %s\n",
- buf, strerror ( rc ) );
- return rc;
- }
- return 0;
+ return boot_root_path ( buf );
}
printf ( "No filename or root path specified\n" );