Index: usr.sbin/bsdinstall/distfetch/distfetch.c =================================================================== --- usr.sbin/bsdinstall/distfetch/distfetch.c (revision 243747) +++ usr.sbin/bsdinstall/distfetch/distfetch.c (working copy) @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -41,34 +42,41 @@ char **urls; int i, nfetched, ndists = 0; - if (getenv("DISTRIBUTIONS") == NULL) { - fprintf(stderr, "DISTRIBUTIONS variable is not set\n"); - return (1); - } + if (getenv("BSDINSTALL_DISTDIR") == NULL) + errx(1, "BSDINSTALL_DISTDIR variable is not set"); + if (getenv("BSDINSTALL_DISTSITE") == NULL) + errx(1, "BSDINSTALL_DISTSITE variable is not set"); + + if (getenv("DISTRIBUTIONS") == NULL) + errx(1, "DISTRIBUTIONS variable is not set"); + diststring = strdup(getenv("DISTRIBUTIONS")); + if (diststring == NULL) + errx(1, "Out of memory!"); + for (i = 0; diststring[i] != 0; i++) if (isspace(diststring[i]) && !isspace(diststring[i+1])) ndists++; ndists++; /* Last one */ urls = calloc(ndists, sizeof(const char *)); - if (urls == NULL) { - fprintf(stderr, "Out of memory!\n"); - free(diststring); - return (1); - } + if (urls == NULL) + errx(1, "Out of memory!"); - init_dialog(stdin, stdout); - dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer"); - dlg_put_backtitle(); - for (i = 0; i < ndists; i++) { urls[i] = malloc(PATH_MAX); + if (urls[i] == NULL) + errx(1, "Out of memory!"); sprintf(urls[i], "%s/%s", getenv("BSDINSTALL_DISTSITE"), strsep(&diststring, " \t")); } + free(diststring); + init_dialog(stdin, stdout); + dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer"); + dlg_put_backtitle(); + if (chdir(getenv("BSDINSTALL_DISTDIR")) != 0) { char error[512]; sprintf(error, "Could could change to directory %s: %s\n", @@ -82,7 +90,6 @@ end_dialog(); - free(diststring); for (i = 0; i < ndists; i++) free(urls[i]); free(urls); @@ -109,7 +116,7 @@ /* Make the transfer list for dialog */ items = calloc(sizeof(char *), nfiles * 2); if (items == NULL) { - fprintf(stderr, "Out of memory!\n"); + warnx("Out of memory!"); return (-1); } @@ -127,7 +134,16 @@ /* Try to stat all the files */ total_bytes = 0; for (i = 0; i < nfiles; i++) { - if (fetchStatURL(urls[i], &ustat, "") == 0 && ustat.size > 0) + if (fetchStatURL(urls[i], &ustat, "") == -1) { + snprintf(errormsg, sizeof(errormsg), + "Error while determining file size for %s: %s\n", + urls[i], fetchLastErrString); + items[i*2 + 1] = "Failed"; + dialog_msgbox("Fetch Error", errormsg, 0, 0, + TRUE); + return (-1); + } + if (ustat.size > 0) total_bytes += ustat.size; } @@ -146,12 +162,12 @@ items[i*2 + 1] = "Failed"; dialog_msgbox("Fetch Error", errormsg, 0, 0, TRUE); - continue; + break; } items[i*2 + 1] = "In Progress"; fsize = 0; - file_out = fopen(items[i*2], "w+"); + file_out = fopen(items[i*2], "w"); if (file_out == NULL) { snprintf(errormsg, sizeof(errormsg), "Error while fetching %s: %s\n", @@ -160,7 +176,7 @@ dialog_msgbox("Fetch Error", errormsg, 0, 0, TRUE); fclose(fetch_out); - continue; + break; } while ((chunk = fread(block, 1, sizeof(block), fetch_out)) @@ -173,7 +189,7 @@ if (total_bytes > 0) { last_progress = progress; - progress = (current_bytes*100)/total_bytes; + progress = (current_bytes*100)/total_bytes; } if (ustat.size > 0) { @@ -200,6 +216,7 @@ items[i*2 + 1] = "Failed"; dialog_msgbox("Fetch Error", errormsg, 0, 0, TRUE); + break; } else { items[i*2 + 1] = "Done"; nsuccess++;