summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sysinstall/dist.c
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2003-01-09 17:44:29 +0000
committerobrien <obrien@FreeBSD.org>2003-01-09 17:44:29 +0000
commita41e13b44bdda3eae007b97ab9e6951cf98cddec (patch)
tree4b4249efe4c5eb8c083ebd8a5b005acd666bbabb /usr.sbin/sysinstall/dist.c
parent4d794ccfd8bc57fb8a000747c7fba044b0b0150c (diff)
downloadFreeBSD-src-a41e13b44bdda3eae007b97ab9e6951cf98cddec.zip
FreeBSD-src-a41e13b44bdda3eae007b97ab9e6951cf98cddec.tar.gz
Separate the uses of a buffer and make it dynamically sized.
Approved by: scottl(re), jhb(re) Reviewed by: kuriyama
Diffstat (limited to 'usr.sbin/sysinstall/dist.c')
-rw-r--r--usr.sbin/sysinstall/dist.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/usr.sbin/sysinstall/dist.c b/usr.sbin/sysinstall/dist.c
index d9b6ef7..4b131fd 100644
--- a/usr.sbin/sysinstall/dist.c
+++ b/usr.sbin/sysinstall/dist.c
@@ -581,7 +581,7 @@ distExtract(char *parent, Distribution *me)
{
int i,j, status, total, intr, unmounted_dev;
int cpid, zpid, fd2, chunk, numchunks;
- char *path, *dist, buf[300000];
+ char *path, *dist, *buf = NULL, fname[PATH_MAX];
const char *tmp;
FILE *fp;
WINDOW *w = savescr();
@@ -628,15 +628,15 @@ distExtract(char *parent, Distribution *me)
* info file which tells us how many we need for this distribution.
*/
numchunks = 0;
- snprintf(buf, sizeof buf, "%s/%s.inf", path, dist);
+ snprintf(fname, sizeof fname, "%s/%s.inf", path, dist);
getinfo:
- fp = DEVICE_GET(mediaDevice, buf, TRUE);
+ fp = DEVICE_GET(mediaDevice, fname, TRUE);
intr = check_for_interrupt();
if (fp == (FILE *)IO_ERROR || intr || !mediaDevice) {
/* Hard error, can't continue */
if (!msgYesNo("Unable to open %s: %s.\nReinitialize media?",
- buf, !intr ? "I/O error." : "User interrupt.")) {
+ fname, !intr ? "I/O error." : "User interrupt.")) {
DEVICE_SHUTDOWN(mediaDevice);
if (!DEVICE_INIT(mediaDevice)) {
status = FALSE;
@@ -672,21 +672,21 @@ distExtract(char *parent, Distribution *me)
}
else {
/* Try to get the distribution as a single file */
- snprintf(buf, sizeof buf, "%s/%s.%s", path, dist,
+ snprintf(fname, sizeof fname, "%s/%s.%s", path, dist,
USE_GZIP ? "tgz" : "tbz");
/*
* Passing TRUE as 3rd parm to get routine makes this a "probing"
* get, for which errors are not considered too significant.
*/
getsingle:
- fp = DEVICE_GET(mediaDevice, buf, TRUE);
+ fp = DEVICE_GET(mediaDevice, fname, TRUE);
intr = check_for_interrupt();
if (fp == (FILE *)IO_ERROR || intr || !mediaDevice) {
/* Hard error, can't continue */
if (intr) /* result of an interrupt */
- msgConfirm("Unable to open %s: User interrupt", buf);
+ msgConfirm("Unable to open %s: User interrupt", fname);
else
- msgConfirm("Unable to open %s: I/O error", buf);
+ msgConfirm("Unable to open %s: I/O error", fname);
DEVICE_SHUTDOWN(mediaDevice);
if (!DEVICE_INIT(mediaDevice)) {
status = FALSE;
@@ -738,24 +738,24 @@ distExtract(char *parent, Distribution *me)
last_msg = 0;
getchunk:
- snprintf(buf, sizeof buf, "cksum.%c%c", (chunk / 26) + 'a', (chunk % 26) + 'a');
- tmp = property_find(dist_attr, buf);
+ snprintf(fname, sizeof fname, "cksum.%c%c", (chunk / 26) + 'a', (chunk % 26) + 'a');
+ tmp = property_find(dist_attr, fname);
chunksize = 0;
if (tmp) {
tmp=index(tmp, ' ');
chunksize = strtol(tmp, 0, 0);
}
- snprintf(buf, sizeof buf, "%s/%s.%c%c", path, dist, (chunk / 26) + 'a', (chunk % 26) + 'a');
+ snprintf(fname, sizeof fname, "%s/%s.%c%c", path, dist, (chunk / 26) + 'a', (chunk % 26) + 'a');
if (isDebug())
- msgDebug("trying for piece %d of %d: %s\n", chunk + 1, numchunks, buf);
- fp = DEVICE_GET(mediaDevice, buf, FALSE);
+ msgDebug("trying for piece %d of %d: %s\n", chunk + 1, numchunks, fname);
+ fp = DEVICE_GET(mediaDevice, fname, FALSE);
intr = check_for_interrupt();
if (fp <= (FILE *)0 || intr) {
if (fp == (FILE *)0)
- msgConfirm("Failed to find %s on this media. Reinitializing media.", buf);
+ msgConfirm("Failed to find %s on this media. Reinitializing media.", fname);
else
msgConfirm("failed to retreive piece file %s.\n"
- "%s: Reinitializing media.", buf, !intr ? "I/O error" : "User interrupt");
+ "%s: Reinitializing media.", fname, !intr ? "I/O error" : "User interrupt");
DEVICE_SHUTDOWN(mediaDevice);
if (!DEVICE_INIT(mediaDevice))
goto punt;
@@ -770,6 +770,7 @@ distExtract(char *parent, Distribution *me)
while (1) {
int seconds;
+ buf = safe_realloc(buf, chunksize);
n = fread(buf + realsize, 1, BUFSIZ, fp);
if (check_for_interrupt()) {
msgConfirm("Media read error: User interrupt.");
OpenPOWER on IntegriCloud