diff options
| author | christos <christos@NetBSD.org> | 2002-10-17 03:31:33 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2002-10-17 03:31:33 +0000 |
| commit | 590fa669c8d8dee326e9540fdae461ef4c9d6f59 (patch) | |
| tree | fc5354671378d5829a709c25be360e28577e936a /usr.sbin/pkg_install | |
| parent | fe9dc5bbfc2256202a8a237372215c5b9008bebe (diff) | |
- eliminate the hard-coding of pathnames in the default install.
- all command executions now use the path [execvp/execlp/system].
- normalize the macro names as <COMMAND>_CMD.
- in some OS's full pathnames for commands can still be provided, but this
is not the default.
This was needed to fix -DTAR_FULLPATHNAME="/usr/bin/tar"
Diffstat (limited to 'usr.sbin/pkg_install')
| -rw-r--r-- | usr.sbin/pkg_install/Makefile.inc | 32 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/extract.c | 14 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/futil.c | 12 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 10 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 15 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 8 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 6 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/ftpio.c | 15 | ||||
| -rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 20 |
9 files changed, 70 insertions, 62 deletions
diff --git a/usr.sbin/pkg_install/Makefile.inc b/usr.sbin/pkg_install/Makefile.inc index b7c43e83087..19cb25239cf 100644 --- a/usr.sbin/pkg_install/Makefile.inc +++ b/usr.sbin/pkg_install/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.21 2002/09/16 00:12:54 thorpej Exp $ +# $NetBSD: Makefile.inc,v 1.22 2002/10/17 03:31:33 christos Exp $ # Original from FreeBSD, no rcs id. .include <bsd.own.mk> @@ -8,33 +8,31 @@ CPPFLAGS+=-I${.CURDIR}/../lib ${DEBUG} -DBINDIR='"${BINDIR}"' # If building for Zoularis on Solaris, some other Makefile should do: #LOCALBASE?= /usr/pkg -#TAR_CMD?= tar -#FTP_CMD?= ftp #ZOULARISBASE?= ${LOCALBASE}/bsd -#TAR_FULLPATHNAME?= ${ZOULARISBASE}/bin/${TAR_CMD} -#FTP_FULLPATHNAME?= ${ZOULARISBASE}/bin/${FTP_CMD} -#CPPFLAGS+=-DTAR_CMD='"${TAR_CMD}"' -DTAR_FULLPATHNAME='"${TAR_FULLPATHNAME}"' -#CPPFLAGS+=-DFTP_CMD='"${FTP_CMD}"' -DFTP_FULLPATHNAME='"${FTP_FULLPATHNAME}"' #BINDIR=${ZOULARISBASE}/bin -#CHMOD?= /usr/bin/chmod -#CHOWN?= /usr/bin/chown -#CHGRP?= /usr/bin/chgrp +#TAR_CMD?= ${BINDIR}/tar +#FTP_CMD?= ${BINDIR}/ftp +#CPPFLAGS+=-DTAR_CMD='"${TAR_CMD}"' -DFTP_CMD='"${FTP_CMD}"' +#CHMOD_CMD?= /usr/bin/chmod +#CHOWN_CMD?= /usr/bin/chown +#CHGRP_CMD?= /usr/bin/chgrp #WARNS=0 # If building for Zoularis on Linux, some other Makefile should do: -#CHMOD?= /bin/chmod -#CHOWN?= /bin/chown -#CHGRP?= /bin/chgrp +#CHMOD_CMD?= /bin/chmod +#CHOWN_CMD?= /bin/chown +#CHGRP_CMD?= /bin/chgrp # UNDER NO CIRCUMSTANCES SHOULD THIS MAKEFILE TEST THE OUTPUT OF uname!! # DOING SO BREAKS CROSS COMPILING. -CHMOD?= /bin/chmod -CHOWN?= /usr/sbin/chown -CHGRP?= /usr/bin/chgrp +#CHMOD_CMD?= /bin/chmod +#CHOWN_CMD?= /usr/sbin/chown +#CHGRP_CMD?= /usr/bin/chgrp WARNS=2 -CPPFLAGS+= -DCHMOD='"${CHMOD}"' -DCHOWN='"${CHOWN}"' -DCHGRP='"${CHGRP}"' +#CPPFLAGS+= -DCHMOD_CMD='"${CHMOD_CMD}"' -DCHOWN_CMD='"${CHOWN_CMD}"' +#CPPFLAGS+= -DCHGRP_CMD='"${CHGRP_CMD}"' DPADD+= ${LIBINSTALL}/libinstall.a LDADD+= -L${LIBINSTALL} -linstall diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c index 8ac5540bd8b..b8a43ee4df2 100644 --- a/usr.sbin/pkg_install/add/extract.c +++ b/usr.sbin/pkg_install/add/extract.c @@ -1,11 +1,11 @@ -/* $NetBSD: extract.c,v 1.23 2001/09/26 13:48:27 hubertf Exp $ */ +/* $NetBSD: extract.c,v 1.24 2002/10/17 03:31:33 christos Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.23 2001/09/26 13:48:27 hubertf Exp $"); +__RCSID("$NetBSD: extract.c,v 1.24 2002/10/17 03:31:33 christos Exp $"); #endif #endif @@ -34,7 +34,7 @@ __RCSID("$NetBSD: extract.c,v 1.23 2001/09/26 13:48:27 hubertf Exp $"); #include "add.h" #define TAR_ARGS " cf - " -#define TARX_CMD "|" TAR_FULLPATHNAME " xf - -C " +#define TARX_CMD "|" TAR_CMD " xf - -C " /* * This macro is used to determine if the 'where_args' buffer is big enough to add the @@ -50,16 +50,16 @@ __RCSID("$NetBSD: extract.c,v 1.23 2001/09/26 13:48:27 hubertf Exp $"); || (strlen(str) + 3 + perm_count >= maxargs)) #define PUSHOUT(todir) /* push out string */ \ - if (where_count > sizeof(TAR_FULLPATHNAME) + sizeof(TAR_ARGS)-1) { \ + if (where_count > sizeof(TAR_CMD) + sizeof(TAR_ARGS)-1) { \ strcat(where_args, TARX_CMD); \ strcat(where_args, todir); \ if (system(where_args)) { \ cleanup(0); \ errx(2, "can not invoke %lu byte %s pipeline: %s", \ - (u_long)strlen(where_args), TAR_FULLPATHNAME, \ + (u_long)strlen(where_args), TAR_CMD, \ where_args); \ } \ - strcpy(where_args, TAR_FULLPATHNAME TAR_ARGS); \ + strcpy(where_args, TAR_CMD TAR_ARGS); \ where_count = strlen(where_args); \ } \ if (perm_count) { \ @@ -118,7 +118,7 @@ extract_plist(char *home, package_t *pkg) cleanup(0); errx(2, "can't get argument list space"); } - strcpy(where_args, TAR_FULLPATHNAME TAR_ARGS); + strcpy(where_args, TAR_CMD TAR_ARGS); /* * we keep track of how many characters are stored in 'where_args' with 'where_count'. * Note this doesn't include the trailing null character. diff --git a/usr.sbin/pkg_install/add/futil.c b/usr.sbin/pkg_install/add/futil.c index f1f38fcf33d..5c02a93cf2a 100644 --- a/usr.sbin/pkg_install/add/futil.c +++ b/usr.sbin/pkg_install/add/futil.c @@ -1,11 +1,11 @@ -/* $NetBSD: futil.c,v 1.8 1999/08/24 00:48:38 hubertf Exp $ */ +/* $NetBSD: futil.c,v 1.9 2002/10/17 03:31:33 christos Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.8 1999/08/24 00:48:38 hubertf Exp $"); +__RCSID("$NetBSD: futil.c,v 1.9 2002/10/17 03:31:33 christos Exp $"); #endif #endif @@ -80,19 +80,19 @@ apply_perms(char *dir, char *arg) cd_to = dir; if (Mode) - if (vsystem("cd %s && %s -R %s %s", cd_to, CHMOD, Mode, arg)) + if (vsystem("cd %s && %s -R %s %s", cd_to, CHMOD_CMD, Mode, arg)) warnx("couldn't change modes of '%s' to '%s'", arg, Mode); if (Owner && Group) { - if (vsystem("cd %s && %s -R %s.%s %s", cd_to, CHOWN, Owner, Group, arg)) + 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'", arg, Owner, Group); return; } if (Owner) { - if (vsystem("cd %s && %s -R %s %s", cd_to, CHOWN, Owner, arg)) + if (vsystem("cd %s && %s -R %s %s", cd_to, CHOWN_CMD, Owner, arg)) warnx("couldn't change owner of '%s' to '%s'", arg, Owner); return; } else if (Group) - if (vsystem("cd %s && %s -R %s %s", cd_to, CHGRP, Group, arg)) + if (vsystem("cd %s && %s -R %s %s", cd_to, CHGRP_CMD, Group, arg)) warnx("couldn't change group of '%s' to '%s'", arg, Group); } diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index 69257d7e6dd..91622060131 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.73 2002/08/29 21:46:33 abs Exp $ */ +/* $NetBSD: perform.c,v 1.74 2002/10/17 03:31:33 christos Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.73 2002/08/29 21:46:33 abs Exp $"); +__RCSID("$NetBSD: perform.c,v 1.74 2002/10/17 03:31:33 christos Exp $"); #endif #endif @@ -482,7 +482,7 @@ pkg_do(const char *pkg) /* Look for the requirements file */ if (fexists(REQUIRE_FNAME)) { - vsystem("%s +x %s", CHMOD, REQUIRE_FNAME); /* be sure */ + vsystem("%s +x %s", CHMOD_CMD, REQUIRE_FNAME); /* be sure */ if (Verbose) printf("Running requirements file first for %s.\n", PkgName); if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, PkgName)) { @@ -497,7 +497,7 @@ pkg_do(const char *pkg) /* If we're really installing, and have an installation file, run it */ if (!NoInstall && fexists(INSTALL_FNAME)) { - vsystem("%s +x %s", CHMOD, INSTALL_FNAME); /* make sure */ + vsystem("%s +x %s", CHMOD_CMD, INSTALL_FNAME); /* make sure */ if (Verbose) printf("Running install with PRE-INSTALL for %s.\n", PkgName); if (!Fake && vsystem("./%s %s PRE-INSTALL", INSTALL_FNAME, PkgName)) { @@ -562,7 +562,7 @@ pkg_do(const char *pkg) goto success; /* close enough for government work */ } /* Make sure pkg_info can read the entry */ - vsystem("%s a+rx %s", CHMOD, LogDir); + vsystem("%s a+rx %s", CHMOD_CMD, LogDir); if (fexists(DEINSTALL_FNAME)) move_file(".", DEINSTALL_FNAME, LogDir); if (fexists(REQUIRE_FNAME)) diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index b18dfc077d8..d534bde938c 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.33 2002/07/19 19:04:36 yamt Exp $ */ +/* $NetBSD: perform.c,v 1.34 2002/10/17 03:31:34 christos Exp $ */ #include <sys/cdefs.h> #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.38 1997/10/13 15:03:51 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.33 2002/07/19 19:04:36 yamt Exp $"); +__RCSID("$NetBSD: perform.c,v 1.34 2002/10/17 03:31:34 christos Exp $"); #endif #endif @@ -46,12 +46,15 @@ make_dist(const char *home, const char *pkg, const char *suffix, const package_t const plist_t *p; int ret; char *args[50]; /* Much more than enough. */ - int nargs = 0; + int nargs = 1; int pipefds[2]; FILE *totar; pid_t pid; - args[nargs++] = TAR_CMD;/* argv[0] */ + if ((args[0] = strrchr(TAR_CMD, '/')) == NULL) + args[0] = TAR_CMD; + else + args[0]++; if (*pkg == '/') (void) snprintf(tball, sizeof(tball), "%s.%s", pkg, suffix); @@ -86,13 +89,13 @@ make_dist(const char *home, const char *pkg, const char *suffix, const package_t } if ((pid = fork()) == -1) { cleanup(0); - errx(2, "cannot fork process for %s", TAR_FULLPATHNAME); + errx(2, "cannot fork process for %s", TAR_CMD); } if (pid == 0) { /* The child */ dup2(pipefds[0], 0); close(pipefds[0]); close(pipefds[1]); - execv(TAR_FULLPATHNAME, args); + execvp(TAR_CMD, args); cleanup(0); errx(2, "failed to execute %s command", TAR_CMD); } diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index 09aaedbe1df..af240e0ab48 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.36 2002/06/10 09:14:27 yamt Exp $ */ +/* $NetBSD: perform.c,v 1.37 2002/10/17 03:31:34 christos Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.36 2002/06/10 09:14:27 yamt Exp $"); +__RCSID("$NetBSD: perform.c,v 1.37 2002/10/17 03:31:34 christos Exp $"); #endif #endif @@ -588,7 +588,7 @@ pkg_do(char *pkg) if (fexists(REQUIRE_FNAME)) { if (Verbose) printf("Executing 'require' script.\n"); - vsystem("%s +x %s", CHMOD, REQUIRE_FNAME); /* be sure */ + vsystem("%s +x %s", CHMOD_CMD, REQUIRE_FNAME); /* be sure */ if (vsystem("./%s %s DEINSTALL", REQUIRE_FNAME, pkg)) { warnx("package %s fails requirements %s", pkg, Force ? "" : "- not deleted"); @@ -600,7 +600,7 @@ pkg_do(char *pkg) if (Fake) printf("Would execute de-install script at this point (arg: DEINSTALL).\n"); else { - vsystem("%s +x %s", CHMOD, DEINSTALL_FNAME); /* make sure */ + vsystem("%s +x %s", CHMOD_CMD, DEINSTALL_FNAME); /* make sure */ if (vsystem("./%s %s DEINSTALL", DEINSTALL_FNAME, pkg)) { warnx("deinstall script returned error status"); if (!Force) diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 37acb2a30ee..55c42af7e98 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,11 +1,11 @@ -/* $NetBSD: file.c,v 1.55 2002/07/20 08:40:19 grant Exp $ */ +/* $NetBSD: file.c,v 1.56 2002/10/17 03:31:34 christos Exp $ */ #include <sys/cdefs.h> #ifndef lint #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.55 2002/07/20 08:40:19 grant Exp $"); +__RCSID("$NetBSD: file.c,v 1.56 2002/10/17 03:31:34 christos Exp $"); #endif #endif @@ -542,7 +542,7 @@ unpack(const char *pkg, const char *flist) } else strcat(args, "z"); strcat(args, "xpf"); - if (vsystem("%s %s %s %s", TAR_FULLPATHNAME, args, pkg, flist ? flist : "")) { + if (vsystem("%s %s %s %s", TAR_CMD, args, pkg, flist ? flist : "")) { warnx("%s extract of %s failed!", TAR_CMD, pkg); return 1; } diff --git a/usr.sbin/pkg_install/lib/ftpio.c b/usr.sbin/pkg_install/lib/ftpio.c index d6339917dfd..dc16dac13fe 100644 --- a/usr.sbin/pkg_install/lib/ftpio.c +++ b/usr.sbin/pkg_install/lib/ftpio.c @@ -1,8 +1,8 @@ -/* $NetBSD: ftpio.c,v 1.42 2002/09/19 02:13:57 mycroft Exp $ */ +/* $NetBSD: ftpio.c,v 1.43 2002/10/17 03:31:35 christos Exp $ */ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: ftpio.c,v 1.42 2002/09/19 02:13:57 mycroft Exp $"); +__RCSID("$NetBSD: ftpio.c,v 1.43 2002/10/17 03:31:35 christos Exp $"); #endif /* @@ -255,6 +255,11 @@ setupCoproc(const char *base) int answer_pipe[2]; int rc1, rc2; char buf[20]; + char *argv0 = strrchr(FTP_CMD, '/'); + if (argv0 == NULL) + argv0 = FTP_CMD; + else + argv0++; rc1 = pipe(command_pipe); rc2 = pipe(answer_pipe); @@ -300,8 +305,8 @@ setupCoproc(const char *base) if (Verbose) fprintf(stderr, "[1mftp -detv %s[0m\n", base); - rc1 = execl(FTP_FULLPATHNAME, FTP_CMD, "-detv", base, NULL); - warn("setupCoproc: execl() failed"); + rc1 = execlp(FTP_CMD, argv0, "-detv", base, NULL); + warn("setupCoproc: execlp() failed"); exit(1); break; default: @@ -689,7 +694,7 @@ unpackURL(const char *url, const char *dir) printf("unpackURL '%s' to '%s'\n", url, dir); /* yes, this is gross, but needed for borken ftp(1) */ - (void) snprintf(cmd, sizeof(cmd), "get %s \"| ( cd %s ; gunzip 2>/dev/null | " TAR_FULLPATHNAME " -%sx -f - | tee /dev/stderr )\"\n", pkg, dir, Verbose?"vv":""); + (void) snprintf(cmd, sizeof(cmd), "get %s \"| ( cd %s ; gunzip 2>/dev/null | " TAR_CMD " -%sx -f - | tee /dev/stderr )\"\n", pkg, dir, Verbose?"vv":""); rc = ftp_cmd(cmd, "\n(226|550).*\n"); if (rc != 226) { warnx("Cannot fetch file (%d!=226)!", rc); diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 2f13835134a..a06e533b133 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -1,4 +1,4 @@ -/* $NetBSD: lib.h,v 1.43 2002/07/19 19:04:40 yamt Exp $ */ +/* $NetBSD: lib.h,v 1.44 2002/10/17 03:31:35 christos Exp $ */ /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ @@ -63,19 +63,21 @@ #define TAR_CMD "tar" #endif -/* Full path name of TAR_CMD */ -#ifndef TAR_FULLPATHNAME -#define TAR_FULLPATHNAME "/usr/bin/tar" -#endif - /* Define ftp as a string, in case the ftp client is called something else */ #ifndef FTP_CMD #define FTP_CMD "ftp" #endif -/* Full path name of FTP_CMD */ -#ifndef FTP_FULLPATHNAME -#define FTP_FULLPATHNAME "/usr/bin/ftp" +#ifndef CHOWN_CMD +#define CHOWN_CMD "chown" +#endif + +#ifndef CHMOD_CMD +#define CHMOD_CMD "chmod" +#endif + +#ifndef CHGRP_CMD +#define CHGRP_CMD "chgrp" #endif /* Where we put logging information by default, else ${PKG_DBDIR} if set */ |
