Browse Source

[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>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
246624cdb8
1 changed files with 34 additions and 27 deletions
  1. 34
    27
      src/usr/autoboot.c

+ 34
- 27
src/usr/autoboot.c View File

@@ -77,17 +77,21 @@ int boot_next_server_and_filename ( struct in_addr next_server,
77 77
 
78 78
 	/* Construct URI */
79 79
 	uri = parse_uri ( filename );
80
-	if ( ! uri )
81
-		return -ENOMEM;
80
+	if ( ! uri ) {
81
+		printf ( "Could not parse \"%s\"\n", filename );
82
+		rc = -ENOMEM;
83
+		goto err_parse_uri;
84
+	}
82 85
 	filename_is_absolute = uri_is_absolute ( uri );
83 86
 	uri_put ( uri );
87
+
88
+	/* Construct a tftp:// URI for the filename, if applicable.
89
+	 * We can't just rely on the current working URI, because the
90
+	 * relative URI resolution will remove the distinction between
91
+	 * filenames with and without initial slashes, which is
92
+	 * significant for TFTP.
93
+	 */
84 94
 	if ( ! filename_is_absolute ) {
85
-		/* Construct a tftp:// URI for the filename.  We can't
86
-		 * just rely on the current working URI, because the
87
-		 * relative URI resolution will remove the distinction
88
-		 * between filenames with and without initial slashes,
89
-		 * which is significant for TFTP.
90
-		 */
91 95
 		snprintf ( buf, sizeof ( buf ), "tftp://%s/",
92 96
 			   inet_ntoa ( next_server ) );
93 97
 		uri_encode ( filename, buf + strlen ( buf ),
@@ -95,18 +99,32 @@ int boot_next_server_and_filename ( struct in_addr next_server,
95 99
 		filename = buf;
96 100
 	}
97 101
 
102
+	/* Download and boot image */
98 103
 	image = alloc_image();
99
-	if ( ! image )
100
-		return -ENOMEM;
104
+	if ( ! image ) {
105
+		printf ( "Could not allocate image\n" );
106
+		rc = -ENOMEM;
107
+		goto err_alloc_image;
108
+	}
101 109
 	if ( ( rc = imgfetch ( image, filename,
102 110
 			       register_and_autoload_image ) ) != 0 ) {
103
-		goto done;
111
+		printf ( "Could not fetch image: %s\n", strerror ( rc ) );
112
+		goto err_imgfetch;
113
+	}
114
+	if ( ( rc = imgexec ( image ) ) != 0 ) {
115
+		printf ( "Could not execute image: %s\n", strerror ( rc ) );
116
+		goto err_imgexec;
104 117
 	}
105
-	if ( ( rc = imgexec ( image ) ) != 0 )
106
-		goto done;
107 118
 
108
- done:
119
+	/* Drop image reference */
120
+	image_put ( image );
121
+	return 0;
122
+
123
+ err_imgexec:
124
+ err_imgfetch:
109 125
 	image_put ( image );
126
+ err_alloc_image:
127
+ err_parse_uri:
110 128
 	return rc;
111 129
 }
112 130
 
@@ -229,25 +247,14 @@ static int netboot ( struct net_device *netdev ) {
229 247
 	fetch_string_setting ( NULL, &filename_setting, buf, sizeof ( buf ) );
230 248
 	if ( buf[0] ) {
231 249
 		printf ( "Booting from filename \"%s\"\n", buf );
232
-		if ( ( rc = boot_next_server_and_filename ( next_server,
233
-							    buf ) ) != 0 ) {
234
-			printf ( "Could not boot from filename \"%s\": %s\n",
235
-				 buf, strerror ( rc ) );
236
-			return rc;
237
-		}
238
-		return 0;
250
+		return boot_next_server_and_filename ( next_server, buf );
239 251
 	}
240 252
 	
241 253
 	/* No filename; try the root path */
242 254
 	fetch_string_setting ( NULL, &root_path_setting, buf, sizeof ( buf ) );
243 255
 	if ( buf[0] ) {
244 256
 		printf ( "Booting from root path \"%s\"\n", buf );
245
-		if ( ( rc = boot_root_path ( buf ) ) != 0 ) {
246
-			printf ( "Could not boot from root path \"%s\": %s\n",
247
-				 buf, strerror ( rc ) );
248
-			return rc;
249
-		}
250
-		return 0;
257
+		return boot_root_path ( buf );
251 258
 	}
252 259
 
253 260
 	printf ( "No filename or root path specified\n" );

Loading…
Cancel
Save