summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorgrant <grant@pkgsrc.org>2003-09-23 13:22:37 +0000
committergrant <grant@pkgsrc.org>2003-09-23 13:22:37 +0000
commitdbe2b165b6372a5248bdcc802fc13b950addfa73 (patch)
treef92ea66a2e24a406ec9f524728fcdc509469d64e /pkgtools
parent09086b97998f93d40e62030e4d5750e41f6a3654 (diff)
downloadpkgsrc-dbe2b165b6372a5248bdcc802fc13b950addfa73.tar.gz
sync with NetBSD-current after updates from wiz.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkg_install/files/add/extract.c6
-rw-r--r--pkgtools/pkg_install/files/add/futil.c16
-rw-r--r--pkgtools/pkg_install/files/add/perform.c85
-rw-r--r--pkgtools/pkg_install/files/add/verify.c6
-rw-r--r--pkgtools/pkg_install/files/delete/perform.c43
-rw-r--r--pkgtools/pkg_install/files/info/perform.c8
-rw-r--r--pkgtools/pkg_install/files/lib/exec.c5
-rw-r--r--pkgtools/pkg_install/files/lib/fexec.c26
-rw-r--r--pkgtools/pkg_install/files/lib/file.c129
-rw-r--r--pkgtools/pkg_install/files/lib/ftpio.c17
-rw-r--r--pkgtools/pkg_install/files/lib/lib.h5
-rw-r--r--pkgtools/pkg_install/files/lib/plist.c10
12 files changed, 216 insertions, 140 deletions
diff --git a/pkgtools/pkg_install/files/add/extract.c b/pkgtools/pkg_install/files/add/extract.c
index 3ae10c6fa17..a9fda32f92a 100644
--- a/pkgtools/pkg_install/files/add/extract.c
+++ b/pkgtools/pkg_install/files/add/extract.c
@@ -1,4 +1,4 @@
-/* $NetBSD: extract.c,v 1.6 2003/09/02 08:28:22 jlam Exp $ */
+/* $NetBSD: extract.c,v 1.7 2003/09/23 13:22:37 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "FreeBSD - Id: extract.c,v 1.17 1997/10/08 07:45:35 charnier Exp";
#else
-__RCSID("$NetBSD: extract.c,v 1.6 2003/09/02 08:28:22 jlam Exp $");
+__RCSID("$NetBSD: extract.c,v 1.7 2003/09/23 13:22:37 grant Exp $");
#endif
#endif
@@ -195,6 +195,8 @@ extract_plist(char *home, package_t *pkg)
"unable to back up %s to %s, aborting pkg_add",
try, pf);
rollback(PkgName, home, pkg->head, p);
+ free(perm_args);
+ free(where_args);
return 0;
}
}
diff --git a/pkgtools/pkg_install/files/add/futil.c b/pkgtools/pkg_install/files/add/futil.c
index f0560a36061..28802b01ea2 100644
--- a/pkgtools/pkg_install/files/add/futil.c
+++ b/pkgtools/pkg_install/files/add/futil.c
@@ -1,4 +1,4 @@
-/* $NetBSD: futil.c,v 1.4 2003/09/23 07:13:46 grant Exp $ */
+/* $NetBSD: futil.c,v 1.5 2003/09/23 13:22:38 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: futil.c,v 1.7 1997/10/08 07:45:39 charnier Exp";
#else
-__RCSID("$NetBSD: futil.c,v 1.4 2003/09/23 07:13:46 grant Exp $");
+__RCSID("$NetBSD: futil.c,v 1.5 2003/09/23 13:22:38 grant Exp $");
#endif
#endif
@@ -81,6 +81,7 @@ void
apply_perms(char *dir, char *arg)
{
char *cd_to;
+ char owner_group[128];
if (!dir || *arg == '/')/* absolute path? */
cd_to = "/";
@@ -92,9 +93,14 @@ apply_perms(char *dir, char *arg)
warnx("couldn't change modes of '%s' to '%s'", arg,
Mode);
if (Owner != NULL && Group != NULL) {
- if (vsystem("cd %s && %s -R %s.%s %s", cd_to, CHOWN_CMD, Owner,
- Group, arg))
- warnx("couldn't change owner/group of '%s' to '%s.%s'",
+ if (snprintf(owner_group, sizeof(owner_group),
+ "%s:%s", Owner, Group) > sizeof(owner_group)) {
+ warnx("'%s:%s' is too long (%d max)",
+ Owner, Group, sizeof(owner_group));
+ return;
+ }
+ if (fcexec(cd_to, CHOWN_CMD, "-R", owner_group, arg))
+ warnx("couldn't change owner/group of '%s' to '%s:%s'",
arg, Owner, Group);
return;
}
diff --git a/pkgtools/pkg_install/files/add/perform.c b/pkgtools/pkg_install/files/add/perform.c
index 7b210b75b93..a3be2f50bd8 100644
--- a/pkgtools/pkg_install/files/add/perform.c
+++ b/pkgtools/pkg_install/files/add/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.11 2003/09/23 07:13:46 grant Exp $ */
+/* $NetBSD: perform.c,v 1.12 2003/09/23 13:22:38 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.11 2003/09/23 07:13:46 grant Exp $");
+__RCSID("$NetBSD: perform.c,v 1.12 2003/09/23 13:22:38 grant Exp $");
#endif
#endif
@@ -80,26 +80,21 @@ sanity_check(const char *pkg)
static int
installprereq(const char *name, int *errc)
{
- int ret;
+ int ret;
ret = 0;
if (Verbose)
printf("Loading it from %s.\n", name);
path_setenv("PKG_PATH");
- if (vsystem("%s/pkg_add -K %s -s %s %s%s%s %s%s %s%s%s %s%s",
- BINDIR,
- _pkgdb_getPKGDB_DIR(),
- get_verification(),
- NoView ? "-L " : "",
- View ? "-w " : "",
- View ? View : "",
- Viewbase ? "-W " : "",
- Viewbase ? Viewbase : "",
- Force ? "-f " : "",
- Prefix ? "-p " : "",
- Prefix ? Prefix : "",
- Verbose ? "-v " : "",
- name)) {
+
+ if (fexec_skipempty(BINDIR "/pkg_add", "-K", _pkgdb_getPKGDB_DIR(),
+ "-s", get_verification(),
+ NoView ? "-L" : "",
+ View ? "-w" : "", View ? View : "",
+ Viewbase ? "-W" : "", Viewbase ? Viewbase : "",
+ Force ? "-f" : "",
+ Prefix ? "-p" : "", Prefix ? Prefix : "",
+ Verbose ? "-v" : "", name, NULL)) {
warnx("autoload of dependency `%s' failed%s",
name, Force ? " (proceeding anyway)" : "!");
if (!Force)
@@ -119,14 +114,13 @@ static int
pkg_do(const char *pkg)
{
char playpen[FILENAME_MAX];
- char extract_contents[FILENAME_MAX];
char replace_from[FILENAME_MAX];
char replace_via[FILENAME_MAX];
char replace_to[FILENAME_MAX];
int replacing = 0;
- char *where_to, *extract;
+ char *where_to;
char dbdir[FILENAME_MAX];
- const char *exact;
+ const char *exact, *extra1, *extra2;
FILE *cfile;
int errc;
plist_t *p;
@@ -191,11 +185,11 @@ pkg_do(const char *pkg)
goto bomb;
}
}
- (void) snprintf(extract_contents, sizeof(extract_contents), "--fast-read %s", CONTENTS_FNAME);
- extract = extract_contents;
+ extra1 = "--fast-read";
+ extra2 = CONTENTS_FNAME;
} else {
/* some values for stdin */
- extract = NULL;
+ extra1 = extra2 = NULL;
sb.st_size = 100000; /* Make up a plausible average size */
}
Home = make_playpen(playpen, sizeof(playpen), sb.st_size * 4);
@@ -203,7 +197,7 @@ pkg_do(const char *pkg)
warnx("unable to make playpen for %ld bytes",
(long) (sb.st_size * 4));
where_to = Home;
- if (unpack(pkg, extract)) {
+ if (unpack(pkg, extra1, extra2)) {
warnx("unable to extract table of contents file from `%s' - not a package?",
pkg);
goto bomb;
@@ -264,7 +258,7 @@ pkg_do(const char *pkg)
goto success;
/* Finally unpack the whole mess */
- if (unpack(pkg, NULL)) {
+ if (unpack(pkg, NULL, NULL)) {
warnx("unable to extract `%s'!", pkg);
goto bomb;
}
@@ -465,11 +459,7 @@ ignore_replace_depends_check:
dbdir,
installed);
}
- vsystem("%s/pkg_delete -K %s '%s'\n",
- BINDIR,
- dbdir,
- installed);
-
+ fexec(BINDIR "/pkg_delete", "-K", dbdir, installed, NULL);
} else {
warnx("other version '%s' already installed", installed);
@@ -612,7 +602,7 @@ ignore_replace_depends_check:
(void) fexec(CHMOD_CMD, "+x", REQUIRE_FNAME, NULL); /* be sure */
if (Verbose)
printf("Running requirements file first for %s.\n", PkgName);
- if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, PkgName)) {
+ if (!Fake && fexec("./" REQUIRE_FNAME, PkgName, "INSTALL", NULL)) {
warnx("package %s fails requirements %s", pkg,
Force ? "installing anyway" : "- not installed");
if (!Force) {
@@ -627,7 +617,7 @@ ignore_replace_depends_check:
(void) fexec(CHMOD_CMD, "+x", INSTALL_FNAME, NULL); /* make sure */
if (Verbose)
printf("Running install with PRE-INSTALL for %s.\n", PkgName);
- if (!Fake && vsystem("./%s %s PRE-INSTALL", INSTALL_FNAME, PkgName)) {
+ if (!Fake && fexec("./" INSTALL_FNAME, PkgName, "PRE-INSTALL", NULL)) {
warnx("install script returned error status");
errc = 1;
goto success; /* nothing to uninstall yet */
@@ -654,7 +644,8 @@ ignore_replace_depends_check:
if (Verbose)
printf("mtree -U -f %s -d -e -p %s\n", MTREE_FNAME, p ? p->name : "/");
if (!Fake) {
- if (vsystem("%s -U -f %s -d -e -p %s", MTREE_CMD, MTREE_FNAME, p ? p->name : "/"))
+ if (fexec(MTREE_CMD, "-U", "-f", MTREE_FNAME, "-d", "-e", "-p",
+ p ? p->name : "/", NULL))
warnx("mtree returned a non-zero status - continuing");
}
unlink(MTREE_FNAME); /* remove this line to tar up pkg later - HF */
@@ -664,7 +655,7 @@ ignore_replace_depends_check:
if (!NoInstall && fexists(INSTALL_FNAME)) {
if (Verbose)
printf("Running install with POST-INSTALL for %s.\n", PkgName);
- if (!Fake && vsystem("./%s %s POST-INSTALL", INSTALL_FNAME, PkgName)) {
+ if (!Fake && fexec("./" INSTALL_FNAME, PkgName, "POST-INSTALL", NULL)) {
warnx("install script returned error status");
errc = 1;
goto fail;
@@ -792,24 +783,16 @@ ignore_replace_depends_check:
if (!Fake && !NoView && is_depoted_pkg) {
if (Verbose) {
printf("%s/pkg_view -d %s %s%s %s%s %sadd %s\n",
- BINDIR,
- dbdir,
- View ? "-w " : "",
- View ? View : "",
- Viewbase ? "-W " : "",
- Viewbase ? Viewbase : "",
- Verbose ? "-v " : "",
- PkgName);
+ BINDIR, dbdir,
+ View ? "-w " : "", View ? View : "",
+ Viewbase ? "-W " : "", Viewbase ? Viewbase : "",
+ Verbose ? "-v " : "", PkgName);
}
- vsystem("%s/pkg_view -d %s %s%s %s%s %sadd %s",
- BINDIR,
- dbdir,
- View ? "-w " : "",
- View ? View : "",
- Viewbase ? "-W " : "",
- Viewbase ? Viewbase : "",
- Verbose ? "-v " : "",
- PkgName);
+
+ fexec_skipempty(BINDIR "/pkg_view", "-d", dbdir,
+ View ? "-w " : "", View ? View : "",
+ Viewbase ? "-W " : "", Viewbase ? Viewbase : "",
+ Verbose ? "-v " : "", "add", PkgName, NULL);
}
goto success;
diff --git a/pkgtools/pkg_install/files/add/verify.c b/pkgtools/pkg_install/files/add/verify.c
index bf28ebb352e..e6b1c95d9b6 100644
--- a/pkgtools/pkg_install/files/add/verify.c
+++ b/pkgtools/pkg_install/files/add/verify.c
@@ -1,4 +1,4 @@
-/* $NetBSD: verify.c,v 1.4 2003/09/23 07:13:47 grant Exp $ */
+/* $NetBSD: verify.c,v 1.5 2003/09/23 13:22:38 grant Exp $ */
/*
* Copyright (c) 2001 Alistair G. Crooks. All rights reserved.
@@ -41,7 +41,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1999 \
The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: verify.c,v 1.4 2003/09/23 07:13:47 grant Exp $");
+__RCSID("$NetBSD: verify.c,v 1.5 2003/09/23 13:22:38 grant Exp $");
#endif
#if HAVE_SYS_TYPES_H
@@ -100,7 +100,7 @@ do_verify(const char *pkgname, const char *cmd, const char *const *extensions)
(void) snprintf(f, sizeof(f), "%s%s", pkgname, *ep);
if (stat(f, &st) == 0) {
(void) fprintf(stderr, "pkg_add: Using signature file: %s\n", f);
- if (vsystem(cmd, f) != 0) {
+ if (fexec(cmd, f, NULL) != 0) {
(void) fprintf(stderr, "*** WARNING ***: `%s' has a bad signature\n", f);
return 0;
}
diff --git a/pkgtools/pkg_install/files/delete/perform.c b/pkgtools/pkg_install/files/delete/perform.c
index 51e44e93132..c0a963d2c50 100644
--- a/pkgtools/pkg_install/files/delete/perform.c
+++ b/pkgtools/pkg_install/files/delete/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.8 2003/09/23 07:13:50 grant Exp $ */
+/* $NetBSD: perform.c,v 1.9 2003/09/23 13:22:39 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.8 2003/09/23 07:13:50 grant Exp $");
+__RCSID("$NetBSD: perform.c,v 1.9 2003/09/23 13:22:39 grant Exp $");
#endif
#endif
@@ -321,16 +321,15 @@ require_delete(char *home, int tryall)
if (Fake)
rv = 0;
else
- rv = vsystem("%s -K %s %s %s %s %s %s %s %s %s", ProgramPath,
- _pkgdb_getPKGDB_DIR(),
- Prefix ? "-p" : "",
- Prefix ? Prefix : "",
- Verbose ? "-v" : "",
- (Force > 1) ? "-f -f" : (Force == 1) ? "-f" : "",
- NoDeInstall ? "-D" : "",
- CleanDirs ? "-d" : "",
- Fake ? "-n" : "",
- rm_installed?installed:lpp->lp_name);
+ rv = fexec_skipempty(ProgramPath, "-K",
+ _pkgdb_getPKGDB_DIR(),
+ Prefix ? "-p" : "", Prefix ? Prefix : "",
+ Verbose ? "-v" : "",
+ (Force > 1) ? "-f -f" : (Force == 1) ? "-f" : "",
+ NoDeInstall ? "-D" : "",
+ CleanDirs ? "-d" : "",
+ Fake ? "-n" : "",
+ rm_installed ? installed : lpp->lp_name, NULL);
/* check for delete failure */
if (rv && !tryall) {
@@ -710,9 +709,9 @@ pkg_do(char *pkg)
if (Verbose) {
printf("Deleting package %s instance from `%s' view\n", pkg, view);
}
- if (vsystem("%s -K %s %s%s", ProgramPath, view,
- (Force > 1) ? "-f -f " : (Force == 1) ? "-f " : "",
- pkg) != 0) {
+ if (fexec_skipempty(ProgramPath, "-K", view,
+ (Force > 1) ? "-f -f " : (Force == 1) ? "-f " : "",
+ pkg, NULL) != 0) {
warnx("unable to delete package %s from view %s", pkg, view);
(void) fclose(fp);
return 1;
@@ -741,7 +740,7 @@ pkg_do(char *pkg)
if (Verbose)
printf("Executing 'require' script.\n");
(void) fexec(CHMOD_CMD, "+x", REQUIRE_FNAME, NULL); /* be sure */
- if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) {
+ if (fexec("./" REQUIRE_FNAME, pkg, "DEINSTALL", NULL)) {
warnx("package %s fails requirements %s", pkg,
Force ? "" : "- not deleted");
if (!Force)
@@ -756,8 +755,8 @@ pkg_do(char *pkg)
if (Fake) {
printf("Would execute view de-install script at this point (arg: VIEW-DEINSTALL).\n");
} else {
- vsystem("%s +x %s", CHMOD_CMD, DEINSTALL_FNAME); /* make sure */
- if (vsystem("./%s %s VIEW-DEINSTALL", DEINSTALL_FNAME, pkg)) {
+ (void) fexec(CHMOD_CMD, "+x", DEINSTALL_FNAME, NULL); /* make sure */
+ if (fexec("./" DEINSTALL_FNAME, pkg, "VIEW-DEINSTALL", NULL)) {
warnx("view deinstall script returned error status");
if (!Force) {
return 1;
@@ -769,8 +768,8 @@ pkg_do(char *pkg)
if (Fake)
printf("Would execute de-install script at this point (arg: DEINSTALL).\n");
else {
- (void ) fexec(CHMOD_CMD, "+x", DEINSTALL_FNAME, NULL); /* make sure */
- if (vsystem("./%s %s DEINSTALL", DEINSTALL_FNAME, pkg)) {
+ (void) fexec(CHMOD_CMD, "+x", DEINSTALL_FNAME, NULL); /* make sure */
+ if (fexec("./" DEINSTALL_FNAME, pkg, "DEINSTALL", NULL)) {
warnx("deinstall script returned error status");
if (!Force)
return 1;
@@ -819,8 +818,8 @@ pkg_do(char *pkg)
if (Fake)
printf("Would execute post-de-install script at this point (arg: POST-DEINSTALL).\n");
else {
- (void ) fexec(CHMOD_CMD, "+x", DEINSTALL_FNAME, NULL); /* make sure */
- if (vsystem("./%s %s POST-DEINSTALL", DEINSTALL_FNAME, pkg)) {
+ (void) fexec(CHMOD_CMD, "+x", DEINSTALL_FNAME, NULL); /* make sure */
+ if (fexec("./" DEINSTALL_FNAME, pkg, "POST-DEINSTALL", NULL)) {
warnx("post-deinstall script returned error status");
if (!Force)
return 1;
diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c
index c6f53738d0b..82a7ed80dfb 100644
--- a/pkgtools/pkg_install/files/info/perform.c
+++ b/pkgtools/pkg_install/files/info/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.12 2003/09/23 07:13:51 grant Exp $ */
+/* $NetBSD: perform.c,v 1.13 2003/09/23 13:22:40 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.12 2003/09/23 07:13:51 grant Exp $");
+__RCSID("$NetBSD: perform.c,v 1.13 2003/09/23 13:22:40 grant Exp $");
#endif
#endif
@@ -124,7 +124,7 @@ pkg_do(char *pkg)
goto bail;
}
Home = make_playpen(PlayPen, PlayPenSize, sb.st_size / 2);
- if (unpack(fname, "+*")) {
+ if (unpack(fname, "+*", NULL)) {
warnx("error during unpacking, no info for '%s' available", pkg);
code = 1;
goto bail;
@@ -179,7 +179,7 @@ pkg_do(char *pkg)
plist.head = plist.tail = NULL;
fp = fopen(CONTENTS_FNAME, "r");
if (!fp) {
- warnx("unable to open %s file", CONTENTS_FNAME);
+ warn("unable to open %s file", CONTENTS_FNAME);
code = 1;
goto bail;
}
diff --git a/pkgtools/pkg_install/files/lib/exec.c b/pkgtools/pkg_install/files/lib/exec.c
index 218a27834cd..5f0a47752c8 100644
--- a/pkgtools/pkg_install/files/lib/exec.c
+++ b/pkgtools/pkg_install/files/lib/exec.c
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.4 2003/09/23 07:13:52 grant Exp $ */
+/* $NetBSD: exec.c,v 1.5 2003/09/23 13:22:40 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: exec.c,v 1.6 1997/10/08 07:47:50 charnier Exp";
#else
-__RCSID("$NetBSD: exec.c,v 1.4 2003/09/23 07:13:52 grant Exp $");
+__RCSID("$NetBSD: exec.c,v 1.5 2003/09/23 13:22:40 grant Exp $");
#endif
#endif
@@ -63,6 +63,7 @@ vsystem(const char *fmt,...)
if (vsnprintf(cmd, maxargs, fmt, args) >= maxargs) {
warnx("vsystem args are too long");
va_end(args);
+ free(cmd);
return 1;
}
#ifdef VSYSTEM_DEBUG
diff --git a/pkgtools/pkg_install/files/lib/fexec.c b/pkgtools/pkg_install/files/lib/fexec.c
index 6461a622f43..008db2c7004 100644
--- a/pkgtools/pkg_install/files/lib/fexec.c
+++ b/pkgtools/pkg_install/files/lib/fexec.c
@@ -65,13 +65,13 @@
#include "lib.h"
#ifndef lint
-__RCSID("$NetBSD: fexec.c,v 1.3 2003/09/23 07:13:52 grant Exp $");
+__RCSID("$NetBSD: fexec.c,v 1.4 2003/09/23 13:22:41 grant Exp $");
#endif
-static int vfcexec(const char *, const char *, va_list);
+static int vfcexec(const char *, int, const char *, va_list);
static int
-vfcexec(const char *path, const char *arg, va_list ap)
+vfcexec(const char *path, int skipempty, const char *arg, va_list ap)
{
static unsigned int max = 4;
static const char **argv = NULL;
@@ -99,12 +99,15 @@ vfcexec(const char *path, const char *arg, va_list ap)
ptr = realloc(argv, new * sizeof(const char *));
if (ptr == NULL) {
warnx("vfcexec can't alloc arg space");
+ free(argv);
return -1;
}
argv = ptr;
max = new;
}
arg = va_arg(ap, const char *);
+ if (skipempty && arg && strlen(arg) == 0)
+ continue;
argv[argc++] = arg;
} while (arg != NULL);
@@ -139,7 +142,20 @@ fexec(const char *arg, ...)
int result;
va_start(ap, arg);
- result = vfcexec(NULL, arg, ap);
+ result = vfcexec(NULL, 0, arg, ap);
+ va_end(ap);
+
+ return result;
+}
+
+int
+fexec_skipempty(const char *arg, ...)
+{
+ va_list ap;
+ int result;
+
+ va_start(ap, arg);
+ result = vfcexec(NULL, 1, arg, ap);
va_end(ap);
return result;
@@ -152,7 +168,7 @@ fcexec(const char *path, const char *arg, ...)
int result;
va_start(ap, arg);
- result = vfcexec(path, arg, ap);
+ result = vfcexec(path, 0, arg, ap);
va_end(ap);
return result;
diff --git a/pkgtools/pkg_install/files/lib/file.c b/pkgtools/pkg_install/files/lib/file.c
index fcd2e5e1534..18a3d74593a 100644
--- a/pkgtools/pkg_install/files/lib/file.c
+++ b/pkgtools/pkg_install/files/lib/file.c
@@ -1,4 +1,4 @@
-/* $NetBSD: file.c,v 1.7 2003/09/23 07:13:53 grant Exp $ */
+/* $NetBSD: file.c,v 1.8 2003/09/23 13:22:41 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
#else
-__RCSID("$NetBSD: file.c,v 1.7 2003/09/23 07:13:53 grant Exp $");
+__RCSID("$NetBSD: file.c,v 1.8 2003/09/23 13:22:41 grant Exp $");
#endif
#endif
@@ -508,30 +508,30 @@ write_file(char *name, char *str)
void
copy_file(char *dir, char *fname, char *to)
{
- char cmd[FILENAME_MAX];
+ char fpath[FILENAME_MAX];
- if (fname[0] == '/')
- (void) snprintf(cmd, sizeof(cmd), "cp -r %s %s", fname, to);
- else
- (void) snprintf(cmd, sizeof(cmd), "cp -r %s/%s %s", dir, fname, to);
- if (vsystem("%s", cmd)) {
+ (void) snprintf(fpath, sizeof(fpath), "%s%s%s",
+ (fname[0] != '/') ? dir : "",
+ (fname[0] != '/') ? "/" : "",
+ fname);
+ if (fexec("cp", "-r", fpath, to, NULL)) {
cleanup(0);
- errx(2, "could not perform '%s'", cmd);
+ errx(2, "could not perform 'cp -r %s %s'", fpath, to);
}
}
void
move_file(char *dir, char *fname, char *to)
{
- char cmd[FILENAME_MAX];
+ char fpath[FILENAME_MAX];
- if (fname[0] == '/')
- (void) snprintf(cmd, sizeof(cmd), "mv %s %s", fname, to);
- else
- (void) snprintf(cmd, sizeof(cmd), "mv %s/%s %s", dir, fname, to);
- if (vsystem("%s", cmd)) {
+ (void) snprintf(fpath, sizeof(fpath), "%s%s%s",
+ (fname[0] != '/') ? dir : "",
+ (fname[0] != '/') ? "/" : "",
+ fname);
+ if (fexec("mv", fpath, to, NULL)) {
cleanup(0);
- errx(2, "could not perform '%s'", cmd);
+ errx(2, "could not perform 'mv %s %s'", fpath, to);
}
}
@@ -539,29 +539,98 @@ move_file(char *dir, char *fname, char *to)
* Unpack a tar file
*/
int
-unpack(const char *pkg, const char *flist)
+unpack(const char *pkg, const char *extra1, const char *extra2)
{
- char args[10] = "-";
- const char *decompress_cmd;
+ const char *decompress_cmd[3];
const char *suf;
+ int pipefds[2];
+ pid_t pid;
+ int state;
if (!IS_STDIN(pkg)) {
suf = suffix_of(pkg);
- if (!strcmp(suf, "tbz") || !strcmp(suf, "bz2"))
- decompress_cmd = BZIP2_CMD " -c -d";
- else if (!strcmp(suf, "tgz") || !strcmp(suf, "gz"))
- decompress_cmd = GZIP_CMD " -c -d";
- else if (!strcmp(suf, "tar"))
- decompress_cmd = "cat";
+ if (!strcmp(suf, "tbz") || !strcmp(suf, "bz2")) {
+ decompress_cmd[0] = BZIP2_CMD;
+ decompress_cmd[1] = "-c";
+ decompress_cmd[2] = "-d";
+ }
+ else if (!strcmp(suf, "tgz") || !strcmp(suf, "gz")) {
+ decompress_cmd[0] = GZIP_CMD;
+ decompress_cmd[1] = "-c";
+ decompress_cmd[2] = "-d";
+ }
+ else if (!strcmp(suf, "tar")) {
+ decompress_cmd[0] = "cat";
+ decompress_cmd[1] = NULL;
+ decompress_cmd[2] = NULL;
+ }
else
errx(EXIT_FAILURE, "don't know how to decompress %s, sorry", pkg);
- } else
- decompress_cmd = GZIP_CMD " -c -d";
- strlcat(args, "xpf -", sizeof(args));
- if (vsystem("%s %s | %s %s %s", decompress_cmd, pkg, TAR_CMD, args, flist ? flist : "")) {
- warnx("%s extract of %s failed!", TAR_CMD, pkg);
+ } else {
+ decompress_cmd[0] = GZIP_CMD;
+ decompress_cmd[1] = "-c";
+ decompress_cmd[2] = "-d";
+ }
+
+ /* Set up a pipe for passing the extracted contents, and fork off a decompress process. */
+ if (pipe(pipefds) == -1) {
+ warnx("cannot create pipe -- %s extract of %s failed!", TAR_CMD, pkg);
+ return 1;
+ }
+ if ((pid = fork()) == -1) {
+ warnx("cannot fork process for %s -- %s extract of %s failed!",
+ decompress_cmd[0], TAR_CMD, pkg);
return 1;
}
+ if (pid == 0) { /* The child */
+ if (dup2(pipefds[1], STDOUT_FILENO) == -1) {
+ warnx("dup2 failed before executing %s command",
+ decompress_cmd[0]);
+ _exit(2);
+ }
+ close(pipefds[0]);
+ close(pipefds[1]);
+ if (decompress_cmd[1] != NULL)
+ execlp(decompress_cmd[0], decompress_cmd[0],
+ decompress_cmd[1], decompress_cmd[2],
+ pkg, NULL);
+ else
+ execlp(decompress_cmd[0], decompress_cmd[0],
+ pkg, NULL);
+ warnx("failed to execute %s command", decompress_cmd[0]);
+ _exit(2);
+ }
+
+ /* Meanwhile, back in the parent process ... */
+ /* fork off an untar process */
+ if ((pid = fork()) == -1) {
+ warnx("cannot fork process for %s -- %s extract of %s failed!",
+ TAR_CMD, TAR_CMD, pkg);
+ return 1;
+ }
+ if (pid == 0) { /* The child */
+ if (dup2(pipefds[0], STDIN_FILENO) == -1) {
+ warnx("dup2 failed before executing %s command",
+ TAR_CMD);
+ _exit(2);
+ }
+ close(pipefds[0]);
+ close(pipefds[1]);
+ execlp(TAR_CMD, TAR_CMD, "-xpf", "-", extra1, extra2, NULL);
+ warnx("failed to execute %s command", TAR_CMD);
+ _exit(2);
+ }
+
+
+ close(pipefds[0]);
+ close(pipefds[1]);
+
+ /* wait for tar exit so we are sure the needed files exist */
+ if (waitpid(pid, &state, 0) < 0) {
+ /* error has been reported by child */
+ return 1;
+ }
+
return 0;
}
diff --git a/pkgtools/pkg_install/files/lib/ftpio.c b/pkgtools/pkg_install/files/lib/ftpio.c
index 8187bd96ecc..b298185bdd7 100644
--- a/pkgtools/pkg_install/files/lib/ftpio.c
+++ b/pkgtools/pkg_install/files/lib/ftpio.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ftpio.c,v 1.5 2003/09/03 14:05:59 jlam Exp $ */
+/* $NetBSD: ftpio.c,v 1.6 2003/09/23 13:22:42 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: ftpio.c,v 1.5 2003/09/03 14:05:59 jlam Exp $");
+__RCSID("$NetBSD: ftpio.c,v 1.6 2003/09/23 13:22:42 grant Exp $");
#endif
/*
@@ -841,7 +841,7 @@ miscstuff(const char *url)
}
if (access("/var/tmp/xxx", R_OK)==0) {
- system("cat /var/tmp/xxx");
+ fexec("cat", "/var/tmp/xxx", NULL);
{
/* count lines - >0 -> fexists() == true */
@@ -877,9 +877,9 @@ miscstuff(const char *url)
(void) snprintf(buf, sizeof(buf),"%d", atoi(s)-1);
setenv(PKG_FTPIO_CNT, buf, 1);
- (void) snprintf(buf, sizeof(buf), "%s \"%s/%s\"", argv0, url, pkg);
- printf("%s>>> %s\n", s, buf);
- system(buf);
+ (void) snprintf(buf, sizeof(buf), "%s/%s", url, pkg);
+ printf("%s>>> %s %s\n", s, argv0, buf);
+ fexec(argv0, buf, NULL);
}
}
#endif
@@ -937,9 +937,8 @@ main(int argc, char *argv[])
(void) snprintf(buf, sizeof(buf),"%d", atoi(s)-1);
setenv(PKG_FTPIO_CNT, buf, 1);
- (void) snprintf(buf, sizeof(buf), "%s -v '%s'", argv0, argv[0]);
- printf("%s>>> %s\n", s, buf);
- system(buf);
+ printf("%s>>> %s -v %s\n", s, argv0, argv[0]);
+ fexec(argv0, "-v", argv[0], NULL);
}
}
diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h
index 831808ed210..7a686bd9bec 100644
--- a/pkgtools/pkg_install/files/lib/lib.h
+++ b/pkgtools/pkg_install/files/lib/lib.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.4 2003/09/23 07:13:53 grant Exp $ */
+/* $NetBSD: lib.h,v 1.5 2003/09/23 13:22:42 grant Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -237,6 +237,7 @@ void save_dirs(char **, char **);
void restore_dirs(char *, char *);
void show_version(void);
int fexec(const char *, ...);
+int fexec_skipempty(const char *, ...);
int fcexec(const char *, const char *, ...);
/* String */
@@ -277,7 +278,7 @@ void write_file(char *, char *);
void copy_file(char *, char *, char *);
void move_file(char *, char *, char *);
int delete_hierarchy(char *, Boolean, Boolean);
-int unpack(const char *, const char *);
+int unpack(const char *, const char *, const char *);
void format_cmd(char *, size_t, char *, char *, char *);
/* ftpio.c: FTP handling */
diff --git a/pkgtools/pkg_install/files/lib/plist.c b/pkgtools/pkg_install/files/lib/plist.c
index 575d095bdeb..c8f93c48f16 100644
--- a/pkgtools/pkg_install/files/lib/plist.c
+++ b/pkgtools/pkg_install/files/lib/plist.c
@@ -1,4 +1,4 @@
-/* $NetBSD: plist.c,v 1.6 2003/09/23 07:13:54 grant Exp $ */
+/* $NetBSD: plist.c,v 1.7 2003/09/23 13:22:42 grant Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp";
#else
-__RCSID("$NetBSD: plist.c,v 1.6 2003/09/23 07:13:54 grant Exp $");
+__RCSID("$NetBSD: plist.c,v 1.7 2003/09/23 13:22:42 grant Exp $");
#endif
#endif
@@ -467,8 +467,8 @@ delete_package(Boolean ign_err, Boolean nukedirs, package_t *pkg)
}
#ifdef DEBUG
-#define RMDIR(dir) vsystem("%s %s", RMDIR_CMD, dir)
-#define REMOVE(dir,ie) vsystem("%s %s%s", REMOVE_CMD, (ie ? "-f " : ""), dir)
+#define RMDIR(dir) fexec(RMDIR_CMD, dir, NULL)
+#define REMOVE(dir,ie) fexec_skipemtpy(REMOVE_CMD, (ie) ? "-f " : "", dir, NULL)
#else
#define RMDIR rmdir
#define REMOVE(file,ie) (remove(file) && !(ie))
@@ -490,7 +490,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
isdir(dir) ? "directory" : "file", dir);
return !ign_err;
} else if (nukedirs) {
- if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir))
+ if (fexec_skipempty(REMOVE_CMD, "-r", ign_err ? "-f" : "", dir, NULL))
return 1;
} else if (isdir(dir)) {
if (RMDIR(dir) && !ign_err)