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
 
77
 
78
 	/* Construct URI */
78
 	/* Construct URI */
79
 	uri = parse_uri ( filename );
79
 	uri = parse_uri ( filename );
80
-	if ( ! uri )
80
+	if ( ! uri ) {
81
-		return -ENOMEM;
81
+		printf ( "Could not parse \"%s\"\n", filename );
82
+		rc = -ENOMEM;
83
+		goto err_parse_uri;
84
+	}
82
 	filename_is_absolute = uri_is_absolute ( uri );
85
 	filename_is_absolute = uri_is_absolute ( uri );
83
 	uri_put ( uri );
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
 	if ( ! filename_is_absolute ) {
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
 		snprintf ( buf, sizeof ( buf ), "tftp://%s/",
95
 		snprintf ( buf, sizeof ( buf ), "tftp://%s/",
92
 			   inet_ntoa ( next_server ) );
96
 			   inet_ntoa ( next_server ) );
93
 		uri_encode ( filename, buf + strlen ( buf ),
97
 		uri_encode ( filename, buf + strlen ( buf ),
95
 		filename = buf;
99
 		filename = buf;
96
 	}
100
 	}
97
 
101
 
102
+	/* Download and boot image */
98
 	image = alloc_image();
103
 	image = alloc_image();
99
-	if ( ! image )
104
+	if ( ! image ) {
100
-		return -ENOMEM;
105
+		printf ( "Could not allocate image\n" );
106
+		rc = -ENOMEM;
107
+		goto err_alloc_image;
108
+	}
101
 	if ( ( rc = imgfetch ( image, filename,
109
 	if ( ( rc = imgfetch ( image, filename,
102
 			       register_and_autoload_image ) ) != 0 ) {
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
 	image_put ( image );
125
 	image_put ( image );
126
+ err_alloc_image:
127
+ err_parse_uri:
110
 	return rc;
128
 	return rc;
111
 }
129
 }
112
 
130
 
229
 	fetch_string_setting ( NULL, &filename_setting, buf, sizeof ( buf ) );
247
 	fetch_string_setting ( NULL, &filename_setting, buf, sizeof ( buf ) );
230
 	if ( buf[0] ) {
248
 	if ( buf[0] ) {
231
 		printf ( "Booting from filename \"%s\"\n", buf );
249
 		printf ( "Booting from filename \"%s\"\n", buf );
232
-		if ( ( rc = boot_next_server_and_filename ( next_server,
250
+		return boot_next_server_and_filename ( next_server, buf );
233
-							    buf ) ) != 0 ) {
234
-			printf ( "Could not boot from filename \"%s\": %s\n",
235
-				 buf, strerror ( rc ) );
236
-			return rc;
237
-		}
238
-		return 0;
239
 	}
251
 	}
240
 	
252
 	
241
 	/* No filename; try the root path */
253
 	/* No filename; try the root path */
242
 	fetch_string_setting ( NULL, &root_path_setting, buf, sizeof ( buf ) );
254
 	fetch_string_setting ( NULL, &root_path_setting, buf, sizeof ( buf ) );
243
 	if ( buf[0] ) {
255
 	if ( buf[0] ) {
244
 		printf ( "Booting from root path \"%s\"\n", buf );
256
 		printf ( "Booting from root path \"%s\"\n", buf );
245
-		if ( ( rc = boot_root_path ( buf ) ) != 0 ) {
257
+		return boot_root_path ( buf );
246
-			printf ( "Could not boot from root path \"%s\": %s\n",
247
-				 buf, strerror ( rc ) );
248
-			return rc;
249
-		}
250
-		return 0;
251
 	}
258
 	}
252
 
259
 
253
 	printf ( "No filename or root path specified\n" );
260
 	printf ( "No filename or root path specified\n" );

Loading…
Cancel
Save