Define TAR_CMD and TAR_FULLPATHNAME, and use them in preference to

hardcoded strings "tar" and "/usr/bin/tar". This allows the package
tools to use GNU tar with a different name (it's often installed as
gtar), and from a directory other than /usr/bin.
This commit is contained in:
agc 1999-03-09 11:10:39 +00:00
parent 69d3eeb52c
commit 530dddb95a
4 changed files with 45 additions and 30 deletions

View File

@ -1,11 +1,11 @@
/* $NetBSD: extract.c,v 1.14 1999/03/02 10:32:23 agc Exp $ */
/* $NetBSD: extract.c,v 1.15 1999/03/09 11:10:39 agc 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.14 1999/03/02 10:32:23 agc Exp $");
__RCSID("$NetBSD: extract.c,v 1.15 1999/03/09 11:10:39 agc Exp $");
#endif
#endif
@ -33,22 +33,26 @@ __RCSID("$NetBSD: extract.c,v 1.14 1999/03/02 10:32:23 agc Exp $");
#include "lib.h"
#include "add.h"
#define TAR_ARGS " cf - "
#define STARTSTRING "tar cf - "
#define TOOBIG(str) ((strlen(str) + 22 + strlen(home) + where_count > maxargs) \
|| (strlen(str) + 6 + strlen(home) + perm_count > maxargs))
#define PUSHOUT(todir) /* push out string */ \
if (where_count > sizeof(STARTSTRING)-1) { \
strcat(where_args, "|tar xf - -C "); \
if (where_count > sizeof(TAR_CMD) + sizeof(TAR_ARGS)-1) { \
strcat(where_args, "|"); \
strcat(where_args, TAR_CMD); \
strcat(where_args, " xf - -C "); \
strcat(where_args, todir); \
if (system(where_args)) { \
cleanup(0); \
errx(2, "can not invoke %lu byte tar pipeline: %s", \
(u_long)strlen(where_args), where_args); \
errx(2, "can not invoke %lu byte %s pipeline: %s", \
(u_long)strlen(where_args), TAR_CMD, \
where_args); \
} \
strcpy(where_args, STARTSTRING); \
where_count = sizeof(STARTSTRING)-1; \
strcpy(where_args, TAR_CMD); \
strcpy(where_args, TAR_ARGS); \
where_count = sizeof(TAR_CMD) + sizeof(TAR_ARGS)-1; \
} \
if (perm_count) { \
apply_perms(todir, perm_args); \
@ -102,8 +106,9 @@ extract_plist(char *home, package_t *pkg)
cleanup(0);
errx(2, "can't get argument list space");
}
strcpy(where_args, STARTSTRING);
where_count = sizeof(STARTSTRING)-1;
strcpy(where_args, TAR_CMD);
strcpy(where_args, TAR_ARGS);
where_count = sizeof(TAR_CMD) + sizeof(TAR_ARGS) - 1;
perm_args[0] = 0;
last_chdir = 0;

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.15 1999/01/19 17:01:59 hubertf Exp $ */
/* $NetBSD: perform.c,v 1.16 1999/03/09 11:10:40 agc 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.15 1999/01/19 17:01:59 hubertf Exp $");
__RCSID("$NetBSD: perform.c,v 1.16 1999/03/09 11:10:40 agc Exp $");
#endif
#endif
@ -52,7 +52,7 @@ make_dist(char *home, char *pkg, char *suffix, package_t *plist)
FILE *totar;
pid_t pid;
args[nargs++] = "tar"; /* argv[0] */
args[nargs++] = TAR_CMD; /* argv[0] */
if (*pkg == '/')
snprintf(tball, FILENAME_MAX, "%s.%s", pkg, suffix);
@ -75,7 +75,7 @@ make_dist(char *home, char *pkg, char *suffix, package_t *plist)
args[nargs] = NULL;
if (Verbose)
printf("Creating gzip'd tar ball in '%s'\n", tball);
printf("Creating gzip'd %s ball in '%s'\n", TAR_CMD, tball);
/* Set up a pipe for passing the filenames, and fork off a tar process. */
if (pipe(pipefds) == -1) {
@ -84,15 +84,15 @@ make_dist(char *home, char *pkg, char *suffix, package_t *plist)
}
if ((pid = fork()) == -1) {
cleanup(0);
errx(2, "cannot fork process for tar");
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("/usr/bin/tar", args);
execv(TAR_FULLPATHNAME, args);
cleanup(0);
errx(2, "failed to execute tar command");
errx(2, "failed to execute %s command", TAR_CMD);
}
/* Meanwhile, back in the parent process ... */
@ -142,7 +142,7 @@ make_dist(char *home, char *pkg, char *suffix, package_t *plist)
/* assume either signal or bad exit is enough for us */
if (ret) {
cleanup(0);
errx(2, "tar command failed with code %d", ret);
errx(2, "%s command failed with code %d", TAR_CMD, ret);
}
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: file.c,v 1.23 1999/01/26 14:47:32 hubertf Exp $ */
/* $NetBSD: file.c,v 1.24 1999/03/09 11:10:40 agc 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.23 1999/01/26 14:47:32 hubertf Exp $");
__RCSID("$NetBSD: file.c,v 1.24 1999/03/09 11:10:40 agc Exp $");
#endif
#endif
@ -311,7 +311,7 @@ fileGetURL(char *base, char *spec)
tpid = fork();
if (!tpid) {
dup2(fileno(ftp), 0);
i = execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0);
i = execl(TAR_CMD, TAR_CMD, Verbose ? "-xzvf" : "-xzf", "-", 0);
exit(i);
}
else {
@ -320,7 +320,7 @@ fileGetURL(char *base, char *spec)
fclose(ftp);
tpid = waitpid(tpid, &pstat, 0);
if (Verbose)
printf("tar command returns %d status\n", WEXITSTATUS(pstat));
printf("%s command returns %d status\n", TAR_CMD, WEXITSTATUS(pstat));
}
}
else
@ -549,12 +549,12 @@ copy_hierarchy(char *dir, char *fname, Boolean to)
/* If absolute path, use it */
if (*fname == '/')
dir = "/";
snprintf(cmd, FILENAME_MAX * 3, "tar cf - -C %s %s | tar xpf -",
dir, fname);
snprintf(cmd, sizeof(cmd), "%s cf - -C %s %s | %s xpf -",
TAR_CMD, dir, fname, TAR_CMD);
}
else
snprintf(cmd, FILENAME_MAX * 3, "tar cf - %s | tar xpf - -C %s",
fname, dir);
snprintf(cmd, sizeof(cmd), "%s cf - %s | %s xpf - -C %s",
TAR_CMD, fname, dir, TAR_CMD);
#ifdef DEBUG
printf("Using '%s' to copy trees.\n", cmd);
#endif
@ -586,8 +586,8 @@ unpack(char *pkg, char *flist)
else
strcpy(args, "z");
strcat(args, "xpf");
if (vsystem("tar %s %s %s", args, pkg, flist ? flist : "")) {
warnx("tar extract of %s failed!", pkg);
if (vsystem("%s %s %s %s", TAR_CMD, args, pkg, flist ? flist : "")) {
warnx("%s extract of %s failed!", TAR_CMD, pkg);
return 1;
}
return 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: lib.h,v 1.19 1999/01/19 17:02:01 hubertf Exp $ */
/* $NetBSD: lib.h,v 1.20 1999/03/09 11:10:40 agc Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@ -55,6 +55,16 @@
/* Usually "rm", but often "echo" during debugging! */
#define RMDIR_CMD "rmdir"
/* define tar as a string, in case it's called gtar or something */
#ifndef TAR_CMD
#define TAR_CMD "tar"
#endif
/* full path name of TAR_CMD */
#ifndef TAR_FULLPATHNAME
#define TAR_FULLPATHNAME "/usr/bin/tar"
#endif
/* Where we put logging information by default, else ${PKG_DBDIR} if set */
#define DEF_LOG_DIR "/var/db/pkg"
/* just in case we change the environment variable name */