summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/create/perform.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-05-10 20:46:06 +0000
committerjkh <jkh@FreeBSD.org>1995-05-10 20:46:06 +0000
commit7d860c80586254800671b56624db8e29cb7ef8de (patch)
tree94319eec69027d8479d60dbdabab36b150f5e0ce /usr.sbin/pkg_install/create/perform.c
parentebad582198ee26ad080a135bf4b32bc76f8b8b2a (diff)
downloadFreeBSD-src-7d860c80586254800671b56624db8e29cb7ef8de.zip
FreeBSD-src-7d860c80586254800671b56624db8e29cb7ef8de.tar.gz
Re-work make_dist() routine to build the tar command more reasonably.
This should eliminate the problem with truncated packages.
Diffstat (limited to 'usr.sbin/pkg_install/create/perform.c')
-rw-r--r--usr.sbin/pkg_install/create/perform.c112
1 files changed, 58 insertions, 54 deletions
diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c
index 1165278f..8d942f6 100644
--- a/usr.sbin/pkg_install/create/perform.c
+++ b/usr.sbin/pkg_install/create/perform.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: perform.c,v 1.24 1995/04/26 12:37:46 jkh Exp $";
+static const char *rcsid = "$Id: perform.c,v 1.25 1995/04/26 15:06:58 jkh Exp $";
#endif
/*
@@ -175,77 +175,81 @@ pkg_perform(char **pkgs)
return TRUE; /* Success */
}
+/*
+ * There doesn't seem to be a sysconf() datum for telling you how *many*
+ * arguments you can have, only how long the maximum list can be.
+ * Shamelessly guess at what seems to be a conservative value.
+ */
+#define MAX_NUM_ARGS 4096
+
static void
make_dist(char *home, char *pkg, char *suffix, Package *plist)
{
char tball[FILENAME_MAX];
- char *cmd;
- int ret, max, len;
PackingList p;
+ int ret, max, len;
+ char *args[MAX_NUM_ARGS];
+ int nargs = 0;
+
+ args[nargs++] = "tar"; /* argv[0] */
- max = sysconf(_SC_ARG_MAX);
- cmd = alloca(max);
- if (!cmd)
- barf("Couldn't allocate temporary storage for dist name!");
- strcpy(cmd, "tar ");
if (*pkg == '/')
- snprintf(tball, max, "%s.%s", pkg, suffix);
+ snprintf(tball, FILENAME_MAX, "%s.%s", pkg, suffix);
else
- snprintf(tball, max, "%s/%s.%s", home, pkg, suffix);
+ snprintf(tball, FILENAME_MAX, "%s/%s.%s", home, pkg, suffix);
+
+ args[nargs++] = "-c";
+ args[nargs++] = "-f";
+ args[nargs++] = tball;
if (index(suffix, 'z')) /* Compress/gzip? */
- strncat(cmd, "-z", max - strlen(cmd));
+ args[nargs++] = "-z";
if (Dereference)
- strncat(cmd, "h", max - strlen(cmd));
- if (Verbose)
- printf("Creating gzip'd tar ball in '%s'\n", tball);
- strncat(cmd, "cf ", max - strlen(cmd));
- strncat(cmd, tball, max - strlen(cmd));
+ args[nargs++] = "-h";
if (ExcludeFrom) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " -X %s", ExcludeFrom);
- }
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " %s %s %s", CONTENTS_FNAME,
- COMMENT_FNAME, DESC_FNAME);
- if (Install) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " %s", INSTALL_FNAME);
- }
- if (DeInstall) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " %s", DEINSTALL_FNAME);
- }
- if (Require) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " %s", REQUIRE_FNAME);
- }
- if (Display) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " %s", DISPLAY_FNAME);
- }
- if (Mtree) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " %s", MTREE_FNAME);
+ args[nargs++] = "-X";
+ args[nargs++] = ExcludeFrom;
}
+
+ if (Verbose)
+ printf("Creating gzip'd tar ball in '%s'\n", tball);
+
+ args[nargs++] = CONTENTS_FNAME;
+ args[nargs++] = COMMENT_FNAME;
+ args[nargs++] = DESC_FNAME;
+
+ if (Install)
+ args[nargs++] = INSTALL_FNAME;
+ if (DeInstall)
+ args[nargs++] = DEINSTALL_FNAME;
+ if (Require)
+ args[nargs++] = REQUIRE_FNAME;
+ if (Display)
+ args[nargs++] = DISPLAY_FNAME;
+ if (Mtree)
+ args[nargs++] = MTREE_FNAME;
+
for (p = plist->head; p; p = p->next) {
- if (p->type == PLIST_FILE) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " %s", p->name);
- }
- else if (p->type == PLIST_CWD) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " -C %s", p->name);
- }
- else if (p->type == PLIST_SRC) {
- len = strlen(cmd);
- snprintf(&cmd[len], max -= len, " -C %s", p->name);
+ if (nargs == (MAX_NUM_ARGS - 1))
+ barf("More than %d arguments given in plist! :-(", MAX_NUM_ARGS);
+ if (p->type == PLIST_FILE)
+ args[nargs++] = p->name;
+ else if (p->type == PLIST_CWD || p->type == PLIST_SRC) {
+ args[nargs++] = "-C";
+ args[nargs++] = p->name;
}
else if (p->type == PLIST_IGNORE)
p = p->next;
}
- ret = vsystem(cmd);
+ args[nargs] = NULL;
+ if (fork() == 0) {
+ execv("/usr/bin/tar", args);
+ barf("Failed to execute tar command!");
+ }
+ else
+ wait(&ret);
+ /* assume either signal or bad exit is enough for us */
if (ret)
- barf("tar command `%s' failed with code %d", cmd, ret);
+ barf("tar command failed with code %d", ret);
}
static void
OpenPOWER on IntegriCloud