From e385b2162d34c45cec239f834e65af298563c221 Mon Sep 17 00:00:00 2001 From: Eric Allman Date: Mon, 27 Aug 1990 20:42:55 -0800 Subject: [PATCH] don't redefine _PATH_TMP; don't assume it begins "/tmp/"; tmpfile => tempfile for System V SCCS-vsn: usr.bin/rdist/main.c 5.6 SCCS-vsn: usr.bin/rdist/server.c 5.13 SCCS-vsn: usr.bin/rdist/docmd.c 5.7 SCCS-vsn: usr.bin/rdist/defs.h 5.9 SCCS-vsn: usr.bin/rdist/pathnames.h 5.4 --- usr/src/usr.bin/rdist/defs.h | 4 ++-- usr/src/usr.bin/rdist/docmd.c | 16 ++++++++-------- usr/src/usr.bin/rdist/main.c | 15 +++++++++++---- usr/src/usr.bin/rdist/pathnames.h | 4 +--- usr/src/usr.bin/rdist/server.c | 12 ++++++------ 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/usr/src/usr.bin/rdist/defs.h b/usr/src/usr.bin/rdist/defs.h index 4bbbfeb0d6..9a2b34a953 100644 --- a/usr/src/usr.bin/rdist/defs.h +++ b/usr/src/usr.bin/rdist/defs.h @@ -4,7 +4,7 @@ * * %sccs.include.redist.c% * - * @(#)defs.h 5.8 (Berkeley) %G% + * @(#)defs.h 5.9 (Berkeley) %G% */ #include @@ -113,7 +113,7 @@ extern int options; /* global options */ extern int nerrs; /* number of errors seen */ extern int rem; /* remote file descriptor */ extern int iamremote; /* acting as remote server */ -extern char tmpfile[]; /* file name for logging changes */ +extern char tempfile[]; /* file name for logging changes */ extern struct linkbuf *ihead; /* list of files with more than one link */ extern struct passwd *pw; /* pointer to static area used by getpwent */ extern struct group *gr; /* pointer to static area used by getgrent */ diff --git a/usr/src/usr.bin/rdist/docmd.c b/usr/src/usr.bin/rdist/docmd.c index 5ac37ecdfa..f7fe6c5f2e 100644 --- a/usr/src/usr.bin/rdist/docmd.c +++ b/usr/src/usr.bin/rdist/docmd.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)docmd.c 5.6 (Berkeley) %G%"; +static char sccsid[] = "@(#)docmd.c 5.7 (Berkeley) %G%"; #endif /* not lint */ #include "defs.h" @@ -107,8 +107,8 @@ doarrow(filev, files, rhost, cmds) signal(SIGPIPE, lostconn); if (!makeconn(rhost)) return; - if ((lfp = fopen(tmpfile, "w")) == NULL) { - fatal("cannot open %s\n", tmpfile); + if ((lfp = fopen(tempfile, "w")) == NULL) { + fatal("cannot open %s\n", tempfile); exit(1); } } @@ -142,9 +142,9 @@ done: } for (sc = cmds; sc != NULL; sc = sc->sc_next) if (sc->sc_type == NOTIFY) - notify(tmpfile, rhost, sc->sc_args, 0); + notify(tempfile, rhost, sc->sc_args, 0); if (!nflag) { - (void) unlink(tmpfile); + (void) unlink(tempfile); for (; ihead != NULL; ihead = ihead->nextp) { free(ihead); if ((opts & IGNLNKS) || ihead->count == 0) @@ -319,7 +319,7 @@ dodcolon(filev, files, stamp, cmds) if (nflag || (options & VERIFY)) tfp = NULL; else { - if ((tfp = fopen(tmpfile, "w")) == NULL) { + if ((tfp = fopen(tempfile, "w")) == NULL) { error("%s: %s\n", stamp, strerror(errno)); return; } @@ -344,9 +344,9 @@ dodcolon(filev, files, stamp, cmds) (void) fclose(tfp); for (sc = cmds; sc != NULL; sc = sc->sc_next) if (sc->sc_type == NOTIFY) - notify(tmpfile, NULL, sc->sc_args, lastmod); + notify(tempfile, NULL, sc->sc_args, lastmod); if (!nflag && !(options & VERIFY)) - (void) unlink(tmpfile); + (void) unlink(tempfile); } /* diff --git a/usr/src/usr.bin/rdist/main.c b/usr/src/usr.bin/rdist/main.c index a44595617a..fd426db73e 100644 --- a/usr/src/usr.bin/rdist/main.c +++ b/usr/src/usr.bin/rdist/main.c @@ -12,7 +12,7 @@ char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)main.c 5.5 (Berkeley) %G%"; +static char sccsid[] = "@(#)main.c 5.6 (Berkeley) %G%"; #endif /* not lint */ #include "defs.h" @@ -24,8 +24,9 @@ static char sccsid[] = "@(#)main.c 5.5 (Berkeley) %G%"; */ char *distfile = NULL; -char tmpfile[] = _PATH_TMP; -char *tmpname = &tmpfile[5]; +#define _RDIST_TMP "/rdistXXXXXX" +char tempfile[sizeof _PATH_TMP + sizeof _RDIST_TMP + 1]; +char *tempname; int debug; /* debugging flag */ int nflag; /* NOP flag, just print commands without executing */ @@ -62,6 +63,12 @@ main(argc, argv) strcpy(homedir, pw->pw_dir); groupid = pw->pw_gid; gethostname(host, sizeof(host)); + strcpy(tempfile, _PATH_TMP); + strcat(tempfile, _RDIST_TMP); + if ((tempname = rindex(tempfile, '/')) != 0) + tempname++; + else + tempname = tempfile; while (--argc > 0) { if ((arg = *++argv)[0] != '-') @@ -153,7 +160,7 @@ main(argc, argv) *hp = NULL; setreuid(0, userid); - mktemp(tmpfile); + mktemp(tempfile); if (iamremote) { server(); diff --git a/usr/src/usr.bin/rdist/pathnames.h b/usr/src/usr.bin/rdist/pathnames.h index 42605ad26f..9a4b290b5c 100644 --- a/usr/src/usr.bin/rdist/pathnames.h +++ b/usr/src/usr.bin/rdist/pathnames.h @@ -4,11 +4,9 @@ * * %sccs.include.redist.c% * - * @(#)pathnames.h 5.3 (Berkeley) %G% + * @(#)pathnames.h 5.4 (Berkeley) %G% */ #include #define _PATH_RDIST "rdist" -#undef _PATH_TMP -#define _PATH_TMP "/tmp/rdistXXXXXX" diff --git a/usr/src/usr.bin/rdist/server.c b/usr/src/usr.bin/rdist/server.c index 95b6693b80..534bf0943a 100644 --- a/usr/src/usr.bin/rdist/server.c +++ b/usr/src/usr.bin/rdist/server.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)server.c 5.12 (Berkeley) %G%"; +static char sccsid[] = "@(#)server.c 5.13 (Berkeley) %G%"; #endif /* not lint */ #include "defs.h" @@ -652,7 +652,7 @@ recvf(cmd, type) struct timeval tvp[2]; char *owner, *group; char new[BUFSIZ]; - extern char *tmpname; + extern char *tempname; cp = cmd; opts = 0; @@ -747,12 +747,12 @@ recvf(cmd, type) (void) sprintf(tp, "/%s", cp); cp = rindex(target, '/'); if (cp == NULL) - strcpy(new, tmpname); + strcpy(new, tempname); else if (cp == target) - (void) sprintf(new, "/%s", tmpname); + (void) sprintf(new, "/%s", tempname); else { *cp = '\0'; - (void) sprintf(new, "%s/%s", target, tmpname); + (void) sprintf(new, "%s/%s", target, tempname); *cp = '/'; } @@ -1463,7 +1463,7 @@ response() */ cleanup() { - (void) unlink(tmpfile); + (void) unlink(tempfile); exit(1); } -- 2.20.1