Replace calls to vsystem() by calls to fexec() or fcexec().

This commit is contained in:
tron 2003-08-25 10:35:28 +00:00
parent c28355d067
commit a58c832dd6
2 changed files with 28 additions and 24 deletions

View File

@ -1,11 +1,11 @@
/* $NetBSD: futil.c,v 1.10 2003/08/24 21:11:37 tron Exp $ */ /* $NetBSD: futil.c,v 1.11 2003/08/25 10:35:28 tron Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static const char *rcsid = "from FreeBSD Id: futil.c,v 1.7 1997/10/08 07:45:39 charnier Exp"; static const char *rcsid = "from FreeBSD Id: futil.c,v 1.7 1997/10/08 07:45:39 charnier Exp";
#else #else
__RCSID("$NetBSD: futil.c,v 1.10 2003/08/24 21:11:37 tron Exp $"); __RCSID("$NetBSD: futil.c,v 1.11 2003/08/25 10:35:28 tron Exp $");
#endif #endif
#endif #endif
@ -80,19 +80,25 @@ apply_perms(char *dir, char *arg)
cd_to = dir; cd_to = dir;
if (Mode) if (Mode)
if (vsystem("cd %s && %s -R %s %s", cd_to, CHMOD_CMD, Mode, arg)) if (fcexec(cd_to, CHMOD_CMD, "-R", Mode, arg, NULL))
warnx("couldn't change modes of '%s' to '%s'", arg, Mode); warnx("couldn't change modes of '%s' to '%s'", arg,
if (Owner && Group) { Mode);
if (vsystem("cd %s && %s -R %s.%s %s", cd_to, CHOWN_CMD, Owner, Group, arg)) 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'", warnx("couldn't change owner/group of '%s' to '%s.%s'",
arg, Owner, Group); arg, Owner, Group);
return; return;
} }
if (Owner) { if (Owner != NULL) {
if (vsystem("cd %s && %s -R %s %s", cd_to, CHOWN_CMD, Owner, arg)) if (fcexec(cd_to, CHOWN_CMD, "-R", Owner, arg, NULL))
warnx("couldn't change owner of '%s' to '%s'", arg, Owner); warnx("couldn't change owner of '%s' to '%s'", arg,
Owner);
return; return;
} else if (Group) }
if (vsystem("cd %s && %s -R %s %s", cd_to, CHGRP_CMD, Group, arg)) if (Group != NULL) {
warnx("couldn't change group of '%s' to '%s'", arg, Group); if (fcexec(cd_to, CHGRP_CMD, "-R", Group, arg, NULL))
warnx("couldn't change group of '%s' to '%s'", arg,
Group);
}
} }

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.84 2003/08/24 21:11:37 tron Exp $ */ /* $NetBSD: perform.c,v 1.85 2003/08/25 10:35:28 tron Exp $ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp"; static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
#else #else
__RCSID("$NetBSD: perform.c,v 1.84 2003/08/24 21:11:37 tron Exp $"); __RCSID("$NetBSD: perform.c,v 1.85 2003/08/25 10:35:28 tron Exp $");
#endif #endif
#endif #endif
@ -124,8 +124,9 @@ pkg_do(const char *pkg)
/* make sure dbdir actually exists! */ /* make sure dbdir actually exists! */
if (!(isdir(dbdir) || islinktodir(dbdir))) { if (!(isdir(dbdir) || islinktodir(dbdir))) {
if (vsystem("/bin/mkdir -p -m 755 %s", dbdir)) { if (fexec("mkdir", "-m", "755", "-p", dbdir, NULL)) {
errx(EXIT_FAILURE, "Database-dir %s cannot be generated, aborting.", errx(EXIT_FAILURE,
"Database-dir %s cannot be generated, aborting.",
dbdir); dbdir);
} }
} }
@ -219,7 +220,7 @@ pkg_do(const char *pkg)
if (!(isdir(p->name) || islinktodir(p->name)) && !Fake) { if (!(isdir(p->name) || islinktodir(p->name)) && !Fake) {
if (Verbose) if (Verbose)
printf("Desired prefix of %s does not exist, creating.\n", p->name); printf("Desired prefix of %s does not exist, creating.\n", p->name);
(void) vsystem("mkdir -p %s", p->name); (void) fexec("mkdir", "-p", p->name, NULL);
} }
if (chdir(p->name) == -1) { if (chdir(p->name) == -1) {
warn("unable to change directory to `%s'", p->name); warn("unable to change directory to `%s'", p->name);
@ -427,7 +428,7 @@ ignore_replace_depends_check:
if (Verbose) if (Verbose)
printf("pkg_delete '%s'\n", installed); printf("pkg_delete '%s'\n", installed);
vsystem("pkg_delete '%s'\n", installed); (void) fexec("pkg_delete", installed, NULL);
} else { } else {
warnx("other version '%s' already installed", installed); warnx("other version '%s' already installed", installed);
@ -448,8 +449,6 @@ ignore_replace_depends_check:
if (Verbose) if (Verbose)
printf("Package `%s' conflicts with `%s'.\n", PkgName, p->name); printf("Package `%s' conflicts with `%s'.\n", PkgName, p->name);
/* was: */
/* if (!vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
if (findmatchingname(dbdir, p->name, note_whats_installed, installed) > 0) { if (findmatchingname(dbdir, p->name, note_whats_installed, installed) > 0) {
warnx("Conflicting package `%s'installed, please use\n" warnx("Conflicting package `%s'installed, please use\n"
"\t\"pkg_delete %s\" first to remove it!", installed, installed); "\t\"pkg_delete %s\" first to remove it!", installed, installed);
@ -467,7 +466,6 @@ ignore_replace_depends_check:
continue; continue;
if (Verbose) if (Verbose)
printf("Depends pre-scan: `%s' required.\n", p->name); printf("Depends pre-scan: `%s' required.\n", p->name);
/* if (vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
if (findmatchingname(dbdir, p->name, note_whats_installed, installed) <= 0) { if (findmatchingname(dbdir, p->name, note_whats_installed, installed) <= 0) {
/* /*
* required pkg not found. look if it's available with a more liberal * required pkg not found. look if it's available with a more liberal
@ -587,7 +585,7 @@ ignore_replace_depends_check:
/* If we're really installing, and have an installation file, run it */ /* If we're really installing, and have an installation file, run it */
if (!NoInstall && fexists(INSTALL_FNAME)) { if (!NoInstall && fexists(INSTALL_FNAME)) {
vsystem("%s +x %s", CHMOD_CMD, INSTALL_FNAME); /* make sure */ (void) fexec(CHMOD_CMD, "+x", INSTALL_FNAME, NULL); /* make sure */
if (Verbose) if (Verbose)
printf("Running install with PRE-INSTALL for %s.\n", PkgName); printf("Running install with PRE-INSTALL for %s.\n", PkgName);
if (!Fake && vsystem("./%s %s PRE-INSTALL", INSTALL_FNAME, PkgName)) { if (!Fake && vsystem("./%s %s PRE-INSTALL", INSTALL_FNAME, PkgName)) {
@ -652,7 +650,7 @@ ignore_replace_depends_check:
goto success; /* close enough for government work */ goto success; /* close enough for government work */
} }
/* Make sure pkg_info can read the entry */ /* Make sure pkg_info can read the entry */
vsystem("%s a+rx %s", CHMOD_CMD, LogDir); (void) fexec(CHMOD_CMD, "a+rx", LogDir, NULL);
if (fexists(INSTALL_FNAME)) if (fexists(INSTALL_FNAME))
move_file(".", INSTALL_FNAME, LogDir); move_file(".", INSTALL_FNAME, LogDir);
if (fexists(DEINSTALL_FNAME)) if (fexists(DEINSTALL_FNAME))
@ -790,7 +788,7 @@ cleanup(int signo)
if (signo) if (signo)
printf("Signal %d received, cleaning up.\n", signo); printf("Signal %d received, cleaning up.\n", signo);
if (!Fake && zapLogDir && LogDir[0]) if (!Fake && zapLogDir && LogDir[0])
vsystem("%s -rf %s", REMOVE_CMD, LogDir); (void) fexec(REMOVE_CMD, "-fr", LogDir, NULL);
leave_playpen(Home); leave_playpen(Home);
if (signo) if (signo)
exit(1); exit(1);