diff options
Diffstat (limited to 'release/sysinstall/package.c')
-rw-r--r-- | release/sysinstall/package.c | 202 |
1 files changed, 35 insertions, 167 deletions
diff --git a/release/sysinstall/package.c b/release/sysinstall/package.c index 201fb3d..5e936c7 100644 --- a/release/sysinstall/package.c +++ b/release/sysinstall/package.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: package.c,v 1.27 1995/11/12 20:47:15 jkh Exp $ + * $Id: package.c,v 1.28 1995/12/04 02:22:02 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -50,8 +50,6 @@ #include <sys/stat.h> #include "sysinstall.h" -static char *make_playpen(char *pen, size_t sz); - /* Like package_extract, but assumes current media device */ int package_add(char *name) @@ -66,8 +64,6 @@ int package_extract(Device *dev, char *name) { char path[511]; - char pen[FILENAME_MAX]; - char *where; int fd, ret; /* If necessary, initialize the ldconfig hints */ @@ -92,94 +88,51 @@ package_extract(Device *dev, char *name) if (!variable_get("PKG_TMPDIR")) { Mkdir("/usr/tmp", NULL); Mkdir("/var/tmp", NULL); + /* Set it to a location with as much space as possible */ + variable_set2("PKG_TMPDIR", "/usr/tmp"); } sprintf(path, "packages/All/%s%s", name, strstr(name, ".tgz") ? "" : ".tgz"); msgNotify("Adding %s\nfrom %s", path, dev->name); fd = dev->get(dev, path, TRUE); if (fd >= 0) { - pen[0] = '\0'; - if ((where = make_playpen(pen, 0)) != NULL) { - if (mediaExtractDist(pen, fd)) { - if (file_readable("+CONTENTS")) { - /* Set some hints for pkg_add so that it knows how we got here in case of any depends */ - switch (mediaDevice->type) { - case DEVICE_TYPE_FTP: - if (variable_get(VAR_FTP_PATH)) { - char ftppath[512]; - - /* Special case to leave hint for pkg_add that this is an FTP install */ - sprintf(ftppath, "%spackages/All/", variable_get(VAR_FTP_PATH)); - variable_set2("PKG_ADD_BASE", ftppath); - } - break; - - case DEVICE_TYPE_DOS: - variable_set2("PKG_PATH", "/dos/freebsd/packages/All:/dos/packages/All"); - break; - - case DEVICE_TYPE_CDROM: - variable_set2("PKG_PATH", "/cdrom/packages/All:/cdrom/usr/ports/packages/All"); - break; - - default: - variable_set2("PKG_PATH", "/dist/packages/All:/dist/freebsd/packages/All"); - break; - } - - if (vsystem("(pwd; cat +CONTENTS) | pkg_add %s-S", - !strcmp(variable_get(VAR_CPIO_VERBOSITY), "high") ? "-v " : "")) { - dialog_clear(); - if (!variable_get(VAR_NO_CONFIRM)) - msgConfirm("An error occurred while trying to pkg_add %s.\n" - "Please check debugging screen for possible further details.", name); - else - msgNotify("An error occurred while trying to pkg_add %s.", name); - } - else { - msgNotify("Package %s added successfully!", name); - ret = RET_SUCCESS; - } - } - else { - dialog_clear(); - if (!variable_get(VAR_NO_CONFIRM)) - msgConfirm("The package specified (%s) has no CONTENTS file. This means\n" - "that there was either a media error of some sort or the package\n" - "file itself is corrupted. It is also possible that you simply\n" - "ran out of temporary space and need to go to the options editor\n" - "to select a package temp directory with more space. Either way,\n" - "you may wish to look into the problem and try again.", name); - else - msgNotify("The package specified (%s) has no CONTENTS file. Skipping.", name); - } - } - else { - ret = RET_FAIL; - if (!variable_get(VAR_NO_CONFIRM)) - msgConfirm("Unable to extract the contents of package %s. This means\n" - "that there was either a media error of some sort or the package\n" - "file itself is corrupted.\n" - "You may wish to look into this and try again.", name); - else - msgNotify("Unable to extract the contents of package %s. Skipping.", name); - } - if (chdir(where) == -1) - msgFatal("Unable to get back to where I was before, Jojo! (That was: %s)", where); - vsystem("rm -rf %s", pen); + int i, tot, pfd[2]; + pid_t pid; + + pipe(pfd); + pid = fork(); + if (!pid) { + dup2(pfd[0], 0); close(pfd[0]); + dup2(DebugFD, 1); + dup2(DebugFD, 2); + close(pfd[1]); + i = execl("/usr/sbin/pkg_add", "/usr/sbin/pkg_add", "-", 0); if (isDebug()) - msgDebug("Nuked pen: %s\n", pen); + msgDebug("pkg_add returns %d status\n", i); } else { + char buf[BUFSIZ]; + dialog_clear(); - msgConfirm("Unable to find a temporary location to unpack this stuff in.\n" - "You must simply not have enough space or you've configured your\n" - "system oddly. Sorry!"); - ret = RET_FAIL; + tot = 0; + while ((i = read(fd, buf, BUFSIZ)) > 0) { + write(pfd[1], buf, i); + tot += i; + mvprintw(0, 0, "%d bytes read from package %s", tot, name); + clrtoeol(); + refresh(); + } + close(fd); + close(pfd[1]); + dialog_clear(); + i = waitpid(pid, &tot, 0); + if (i < 0 || WEXITSTATUS(tot)) { + msgNotify("Add of package %s aborted due to some error -\n" + "Please check the debug screen for more info."); + } + else + msgNotify("Package %s was added successfully", name); } - dev->close(dev, fd); - if (dev->type == DEVICE_TYPE_TAPE) - unlink(path); } else { msgDebug("pkg_extract: get operation returned %d\n", fd); @@ -194,88 +147,3 @@ package_extract(Device *dev, char *name) } return ret; } - -static size_t -min_free(char *tmpdir) -{ - struct statfs buf; - - if (statfs(tmpdir, &buf) != 0) { - msgDebug("Error in statfs, errno = %d\n", errno); - return -1; - } - return buf.f_bavail * buf.f_bsize; -} - -/* Find a good place to play. */ -static char * -find_play_pen(char *pen, size_t sz) -{ - struct stat sb; - - if (pen[0] && stat(pen, &sb) != RET_FAIL && (min_free(pen) >= sz)) - return pen; - else if (stat("/var/tmp", &sb) != RET_FAIL && min_free("/var/tmp") >= sz) - strcpy(pen, "/var/tmp/instmp.XXXXXX"); - else if (stat("/tmp", &sb) != RET_FAIL && min_free("/tmp") >= sz) - strcpy(pen, "/tmp/instmp.XXXXXX"); - else if ((stat("/usr/tmp", &sb) == RET_SUCCESS || mkdir("/usr/tmp", 01777) == RET_SUCCESS) && - min_free("/usr/tmp") >= sz) - strcpy(pen, "/usr/tmp/instmp.XXXXXX"); - else { - dialog_clear(); - msgConfirm("Can't find enough temporary space to extract the files, please try\n" - "This again after your system is up (you can run /stand/sysinstall\n" - "directly) and you've had a chance to point /var/tmp somewhere with\n" - "sufficient temporary space available."); - return NULL; - } - return pen; -} - -/* - * Make a temporary directory to play in and chdir() to it, returning - * pathname of previous working directory. - */ -static char * -make_playpen(char *pen, size_t sz) -{ - static char Previous[FILENAME_MAX]; - - if (!find_play_pen(pen, sz)) - return NULL; - - if (!mktemp(pen)) { - dialog_clear(); - msgConfirm("Can't mktemp '%s'.", pen); - return NULL; - } - if (mkdir(pen, 0755) == RET_FAIL) { - dialog_clear(); - msgConfirm("Can't mkdir '%s'.", pen); - return NULL; - } - if (isDebug()) { - if (sz) - msgDebug("Requested space: %d bytes, free space: %d bytes in %s\n", (int)sz, min_free(pen), pen); - } - if (min_free(pen) < sz) { - rmdir(pen); - dialog_clear(); - msgConfirm("Not enough free space to create: `%s'\n" - "Please try this again after your system is up (you can run\n" - "/stand/sysinstall directly) and you've had a chance to point\n" - "/var/tmp somewhere with sufficient temporary space available."); - return NULL; - } - if (!getcwd(Previous, FILENAME_MAX)) { - dialog_clear(); - msgConfirm("getcwd"); - return NULL; - } - if (chdir(pen) == RET_FAIL) { - dialog_clear(); - msgConfirm("Can't chdir to '%s'.", pen); - } - return Previous; -} |