4.4BSD-Lite2

This commit is contained in:
mrg 1993-06-10 05:50:01 +00:00
parent 98d05222e5
commit bfbb5d82d8
7 changed files with 257 additions and 134 deletions

View File

@ -1 +1 @@
30 3 * * * /usr/local/rdist -f /usr/local/Distfile >& /usr/src/local/rdist/Errs 2>&1
30 3 * * * /usr/bin/rdist -f /etc/Distfile >& /var/log/rdist/rdist.err 2>&1

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,7 +32,7 @@
*/
#ifndef lint
static char sccsid[] = "@(#)docmd.c 5.8 (Berkeley) 3/1/91";
static char sccsid[] = "@(#)docmd.c 8.1 (Berkeley) 6/9/93";
#endif /* not lint */
#include "defs.h"
@ -43,11 +43,21 @@ FILE *lfp; /* log file for recording files updated */
struct subcmd *subcmds; /* list of sub-commands for current cmd */
jmp_buf env;
void cleanup(), lostconn();
static int makeconn __P((char *));
static int okname __P((char *));
static void closeconn __P((void));
static void cmptime __P((char *));
static void doarrow __P((char **,
struct namelist *, char *, struct subcmd *));
static void dodcolon __P((char **,
struct namelist *, char *, struct subcmd *));
static void notify __P((char *, char *, struct namelist *, time_t));
static void rcmptime __P((struct stat *));
/*
* Do the commands in cmds (initialized by yyparse).
*/
void
docmds(dhosts, argc, argv)
char **dhosts;
int argc;
@ -103,6 +113,7 @@ docmds(dhosts, argc, argv)
/*
* Process commands for sending files to other machines.
*/
static void
doarrow(filev, files, rhost, cmds)
char **filev;
struct namelist *files;
@ -183,6 +194,7 @@ done:
/*
* Create a connection to the rdist server on the machine rhost.
*/
static int
makeconn(rhost)
char *rhost;
{
@ -235,18 +247,18 @@ makeconn(rhost)
}
fflush(stdout);
setreuid(userid, 0);
seteuid(0);
rem = rcmd(&rhost, port, user, ruser, buf, 0);
setreuid(0, userid);
seteuid(userid);
if (rem < 0)
return(0);
cp = buf;
if (read(rem, cp, 1) != 1)
lostconn();
lostconn(0);
if (*cp == 'V') {
do {
if (read(rem, cp, 1) != 1)
lostconn();
lostconn(0);
} while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
*--cp = '\0';
cp = buf;
@ -256,8 +268,13 @@ makeconn(rhost)
if (*cp == '\0' && n == VERSION)
return(1);
error("connection failed: version numbers don't match (local %d, remote %d)\n", VERSION, n);
} else
} else {
error("connection failed: version numbers don't match\n");
error("got unexpected input:");
do {
error("%c", *cp);
} while (*cp != '\n' && read(rem, cp, 1) == 1);
}
closeconn();
return(0);
}
@ -265,6 +282,7 @@ makeconn(rhost)
/*
* Signal end of previous connection.
*/
static void
closeconn()
{
if (debug)
@ -278,14 +296,16 @@ closeconn()
}
void
lostconn()
lostconn(signo)
int signo;
{
if (iamremote)
cleanup();
cleanup(0);
log(lfp, "rdist: lost connection\n");
longjmp(env, 1);
}
static int
okname(name)
register char *name;
{
@ -313,6 +333,7 @@ extern char target[], *tp;
/*
* Process commands for comparing files to time stamp files.
*/
static void
dodcolon(filev, files, stamp, cmds)
char **filev;
struct namelist *files;
@ -338,7 +359,7 @@ dodcolon(filev, files, stamp, cmds)
return;
}
if (debug)
printf("%s: %d\n", stamp, stb.st_mtime);
printf("%s: %ld\n", stamp, stb.st_mtime);
subcmds = cmds;
lastmod = stb.st_mtime;
@ -378,6 +399,7 @@ dodcolon(filev, files, stamp, cmds)
/*
* Compare the mtime of file to the list of time stamps.
*/
static void
cmptime(name)
char *name;
{
@ -426,6 +448,7 @@ cmptime(name)
log(tfp, "new: %s\n", name);
}
static void
rcmptime(st)
struct stat *st;
{
@ -469,14 +492,15 @@ rcmptime(st)
* rhost == NULL if we are mailing a list of changes compared to at time
* stamp file.
*/
static void
notify(file, rhost, to, lmod)
char *file, *rhost;
register struct namelist *to;
time_t lmod;
{
register int fd, len;
FILE *pf, *popen();
struct stat stb;
FILE *pf;
if ((options & VERIFY) || to == NULL)
return;
@ -546,6 +570,7 @@ notify(file, rhost, to, lmod)
/*
* Return true if name is in the list.
*/
int
inlist(list, file)
struct namelist *list;
char *file;
@ -561,6 +586,7 @@ inlist(list, file)
/*
* Return TRUE if file is in the exception list.
*/
int
except(file)
char *file;
{
@ -579,7 +605,8 @@ except(file)
return(1);
continue;
}
if (regexec(file, regcomp(nl->n_name)) > 0)
re_comp(nl->n_name);
if (re_exec(file) > 0)
return(1);
}
}

View File

@ -1,7 +1,7 @@
%{
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -33,7 +33,7 @@
*/
#ifndef lint
static char sccsid[] = "@(#)gram.y 5.6 (Berkeley) 6/1/90";
static char sccsid[] = "@(#)gram.y 8.1 (Berkeley) 6/9/93";
#endif /* not lint */
#include "defs.h"
@ -43,6 +43,8 @@ struct cmd *last_cmd;
struct namelist *last_n;
struct subcmd *last_sc;
static char *makestr __P((char *));
%}
%term EQUAL 1
@ -161,13 +163,11 @@ cmd: INSTALL options opt_namelist SM = {
}
| PATTERN namelist SM = {
struct namelist *nl;
#ifdef nope
char *cp, *re_comp();
for (nl = $2; nl != NULL; nl = nl->n_next)
if ((cp = re_comp(nl->n_name)) != NULL)
yyerror(cp);
#endif
$1->sc_args = expand($2, E_VARS);
$$ = $1;
}
@ -200,6 +200,7 @@ opt_namelist: /* VOID */ = {
int yylineno = 1;
extern FILE *fin;
int
yylex()
{
static char yytext[INMAX];
@ -350,6 +351,7 @@ again:
return(c);
}
int
any(c, str)
register int c;
register char *str;
@ -363,6 +365,7 @@ any(c, str)
/*
* Insert or append ARROW command to list of hosts to be updated.
*/
void
insert(label, files, hosts, subcmds)
char *label;
struct namelist *files, *hosts;
@ -413,6 +416,7 @@ insert(label, files, hosts, subcmds)
* Append DCOLON command to the end of the command list since these are always
* executed in the order they appear in the distfile.
*/
void
append(label, files, stamp, subcmds)
char *label;
struct namelist *files;
@ -441,12 +445,11 @@ append(label, files, stamp, subcmds)
/*
* Error printing routine in parser.
*/
void
yyerror(s)
char *s;
{
extern int yychar;
nerrs++;
++nerrs;
fflush(stdout);
fprintf(stderr, "rdist: line %d: %s\n", yylineno, s);
}
@ -454,7 +457,7 @@ yyerror(s)
/*
* Return a copy of the string.
*/
char *
static char *
makestr(str)
char *str;
{
@ -489,11 +492,9 @@ makenl(name)
* Make a sub command for lists of variables, commands, etc.
*/
struct subcmd *
makesubcmd(type, name)
makesubcmd(type)
int type;
register char *name;
{
register char *cp;
register struct subcmd *sc;
sc = ALLOC(subcmd);

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,7 +32,7 @@
*/
#ifndef lint
static char sccsid[] = "@(#)lookup.c 5.5 (Berkeley) 6/1/90";
static char sccsid[] = "@(#)lookup.c 8.1 (Berkeley) 6/9/93";
#endif /* not lint */
#include "defs.h"
@ -53,6 +53,7 @@ static struct syment *hashtab[HASHSIZE];
/*
* Define a variable from a command line argument.
*/
void
define(name)
char *name;
{

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,13 +32,13 @@
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
All rights reserved.\n";
static char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)main.c 5.6 (Berkeley) 8/27/90";
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/9/93";
#endif /* not lint */
#include "defs.h"
@ -72,6 +72,10 @@ int groupid; /* user's group ID */
struct passwd *pw; /* pointer to static area used by getpwent */
struct group *gr; /* pointer to static area used by getgrent */
static void usage __P((void));
static void docmdargs __P((int, char *[]));
int
main(argc, argv)
int argc;
char *argv[];
@ -185,7 +189,7 @@ main(argc, argv)
}
*hp = NULL;
setreuid(0, userid);
seteuid(userid);
mktemp(tempfile);
if (iamremote) {
@ -215,6 +219,7 @@ main(argc, argv)
exit(nerrs != 0);
}
static void
usage()
{
printf("Usage: rdist [-nqbhirvwyD] [-f distfile] [-d var=value] [-m host] [file ...]\n");
@ -225,6 +230,7 @@ usage()
/*
* rcp like interface for distributing files.
*/
static void
docmdargs(nargs, args)
int nargs;
char *args[];
@ -280,6 +286,7 @@ docmdargs(nargs, args)
/*
* Print a list of NAME blocks (mostly for debugging).
*/
void
prnames(nl)
register struct namelist *nl;
{
@ -291,13 +298,30 @@ prnames(nl)
printf(")\n");
}
/*VARARGS*/
warn(fmt, a1, a2,a3)
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
void
#if __STDC__
warn(const char *fmt, ...)
#else
warn(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
extern int yylineno;
fprintf(stderr, "rdist: line %d: Warning: ", yylineno);
fprintf(stderr, fmt, a1, a2, a3);
fputc('\n', stderr);
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
(void)fprintf(stderr, "rdist: line %d: Warning: ", yylineno);
(void)vfprintf(stderr, fmt, ap);
(void)fprintf(stderr, "\n");
va_end(ap);
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)pathnames.h 5.4 (Berkeley) 8/27/90
* @(#)pathnames.h 8.1 (Berkeley) 6/9/93
*/
#include <paths.h>

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,9 +32,10 @@
*/
#ifndef lint
static char sccsid[] = "@(#)server.c 5.15 (Berkeley) 3/1/91";
static char sccsid[] = "@(#)server.c 8.1 (Berkeley) 6/9/93";
#endif /* not lint */
#include <sys/wait.h>
#include "defs.h"
#define ack() (void) write(rem, "\0\n", 2)
@ -51,8 +52,22 @@ int oumask; /* old umask for creating files */
extern FILE *lfp; /* log file for mailing changes */
void cleanup();
struct linkbuf *savelink();
static int chkparent __P((char *));
static void clean __P((char *));
static void comment __P((char *));
static void dospecial __P((char *));
static int fchog __P((int, char *, char *, char *, int));
static void hardlink __P((char *));
static void note __P((const char *, ...));
static void query __P((char *));
static void recvf __P((char *, int));
static void removeit __P((struct stat *));
static int response __P((void));
static void rmchk __P((int));
static struct linkbuf *
savelink __P((struct stat *));
static void sendf __P((char *, int));
static int update __P((char *, int, struct stat *));
/*
* Server routine to read requests and process them.
@ -61,6 +76,7 @@ struct linkbuf *savelink();
* Vname - Verify if file out of date or not
* Qname - Query if file exists. Return mtime & size if it does.
*/
void
server()
{
char cmdbuf[BUFSIZ];
@ -87,7 +103,7 @@ server()
}
do {
if (read(rem, cp, 1) != 1)
cleanup();
cleanup(0);
} while (*cp++ != '\n' && cp < &cmdbuf[BUFSIZ]);
*--cp = '\0';
cp = cmdbuf;
@ -209,6 +225,7 @@ server()
* destdir = 1 if destination should be a directory
* (i.e., more than one source is being copied to the same destination).
*/
void
install(src, dest, destdir, opts)
char *src, *dest;
int destdir, opts;
@ -279,6 +296,7 @@ install(src, dest, destdir, opts)
* Transfer the file or directory in target[].
* rname is the name of the file on the remote host.
*/
static void
sendf(rname, opts)
char *rname;
int opts;
@ -313,14 +331,14 @@ sendf(rname, opts)
log(lfp, "%s: no password entry for uid %d \n",
target, stb.st_uid);
pw = NULL;
sprintf(user, ":%d", stb.st_uid);
(void)sprintf(user, ":%lu", stb.st_uid);
}
if (gr == NULL || gr->gr_gid != stb.st_gid)
if ((gr = getgrgid(stb.st_gid)) == NULL) {
log(lfp, "%s: no name for group %d\n",
target, stb.st_gid);
gr = NULL;
sprintf(group, ":%d", stb.st_gid);
(void)sprintf(group, ":%lu", stb.st_gid);
}
if (u == 1) {
if (opts & VERIFY) {
@ -397,7 +415,7 @@ sendf(rname, opts)
return;
}
}
(void) sprintf(buf, "K%o %o %ld %ld %s %s %s\n", opts,
(void) sprintf(buf, "K%o %o %qd %ld %s %s %s\n", opts,
stb.st_mode & 07777, stb.st_size, stb.st_mtime,
protoname(), protogroup(), rname);
if (debug)
@ -446,11 +464,11 @@ sendf(rname, opts)
}
}
if ((f = open(target, 0)) < 0) {
if ((f = open(target, O_RDONLY, 0)) < 0) {
error("%s: %s\n", target, strerror(errno));
return;
}
(void) sprintf(buf, "R%o %o %ld %ld %s %s %s\n", opts,
(void) sprintf(buf, "R%o %o %qd %ld %s %s %s\n", opts,
stb.st_mode & 07777, stb.st_size, stb.st_mtime,
protoname(), protogroup(), rname);
if (debug)
@ -497,12 +515,11 @@ dospecial:
}
}
struct linkbuf *
static struct linkbuf *
savelink(stp)
struct stat *stp;
{
struct linkbuf *lp;
int found = 0;
for (lp = ihead; lp != NULL; lp = lp->nextp)
if (lp->inum == stp->st_ino && lp->devnum == stp->st_dev) {
@ -532,6 +549,7 @@ savelink(stp)
* Returns 0 if no update, 1 if remote doesn't exist, 2 if out of date
* and 3 if comparing binaries to determine if out of date.
*/
static int
update(rname, opts, stp)
char *rname;
int opts;
@ -555,7 +573,7 @@ again:
cp = s = buf;
do {
if (read(rem, cp, 1) != 1)
lostconn();
lostconn(0);
} while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
switch (*s++) {
@ -631,6 +649,7 @@ again:
* Y\n - exists and its a directory or symbolic link
* ^Aerror message\n
*/
static void
query(name)
char *name;
{
@ -650,7 +669,7 @@ query(name)
switch (stb.st_mode & S_IFMT) {
case S_IFREG:
(void) sprintf(buf, "Y%ld %ld\n", stb.st_size, stb.st_mtime);
(void) sprintf(buf, "Y%qd %ld\n", stb.st_size, stb.st_mtime);
(void) write(rem, buf, strlen(buf));
break;
@ -666,6 +685,7 @@ query(name)
*tp = '\0';
}
static void
recvf(cmd, type)
char *cmd;
int type;
@ -759,7 +779,7 @@ recvf(cmd, type)
errno = ENOTDIR;
} else if (errno == ENOENT && (mkdir(target, mode) == 0 ||
chkparent(target) == 0 && mkdir(target, mode) == 0)) {
if (chog(target, owner, group, mode) == 0)
if (fchog(-1, target, owner, group, mode) == 0)
ack();
return;
}
@ -789,7 +809,7 @@ recvf(cmd, type)
cp = buf;
for (i = 0; i < size; i += j) {
if ((j = read(rem, cp, size - i)) <= 0)
cleanup();
cleanup(0);
cp += j;
}
*cp = '\0';
@ -800,7 +820,7 @@ recvf(cmd, type)
if (symlink(buf, new) < 0) {
if (errno != ENOENT || chkparent(new) < 0 ||
symlink(buf, new) < 0)
goto badn;
goto badnew1;
}
mode &= 0777;
if (opts & COMPARE) {
@ -821,7 +841,7 @@ recvf(cmd, type)
if ((f = creat(new, mode)) < 0) {
if (errno != ENOENT || chkparent(new) < 0 ||
(f = creat(new, mode)) < 0)
goto badn;
goto badnew1;
}
ack();
@ -838,7 +858,7 @@ recvf(cmd, type)
if (j <= 0) {
(void) close(f);
(void) unlink(new);
cleanup();
cleanup(0);
}
amt -= j;
cp += j;
@ -851,70 +871,62 @@ recvf(cmd, type)
wrerr++;
}
}
(void) close(f);
if (response() < 0) {
err();
(void) unlink(new);
return;
}
if (wrerr) {
error("%s:%s: %s\n", host, new, strerror(errno));
(void) unlink(new);
return;
goto badnew2;
}
if (wrerr)
goto badnew1;
if (opts & COMPARE) {
FILE *f1, *f2;
int c;
if ((f1 = fopen(target, "r")) == NULL)
goto badt;
goto badtarget;
if ((f2 = fopen(new, "r")) == NULL) {
badn:
error("%s:%s: %s\n", host, new, strerror(errno));
(void) unlink(new);
return;
badnew1: error("%s:%s: %s\n", host, new, strerror(errno));
goto badnew2;
}
while ((c = getc(f1)) == getc(f2))
if (c == EOF) {
(void) fclose(f1);
(void) fclose(f2);
(void) unlink(new);
ack();
return;
goto badnew2;
}
(void) fclose(f1);
(void) fclose(f2);
if (opts & VERIFY) {
differ:
(void) unlink(new);
buf[0] = '\0';
differ: buf[0] = '\0';
(void) sprintf(buf + 1, "need to update: %s\n",target);
(void) write(rem, buf, strlen(buf + 1) + 1);
return;
goto badnew2;
}
}
/*
* Set last modified time
*/
tvp[0].tv_sec = stb.st_atime; /* old atime from target */
tvp[0].tv_sec = time(0);
tvp[0].tv_usec = 0;
tvp[1].tv_sec = mtime;
tvp[1].tv_usec = 0;
if (utimes(new, tvp) < 0) {
note("%s:utimes failed %s: %s\n", host, new, strerror(errno));
}
if (chog(new, owner, group, mode) < 0) {
if (utimes(new, tvp) < 0)
note("%s: utimes failed %s: %s\n", host, new, strerror(errno));
if (fchog(f, new, owner, group, mode) < 0) {
badnew2: (void) close(f);
(void) unlink(new);
return;
}
fixup:
if (rename(new, target) < 0) {
badt:
error("%s:%s: %s\n", host, target, strerror(errno));
(void) close(f);
fixup: if (rename(new, target) < 0) {
badtarget: error("%s:%s: %s\n", host, target, strerror(errno));
(void) unlink(new);
return;
}
if (opts & COMPARE) {
buf[0] = '\0';
(void) sprintf(buf + 1, "updated %s\n", target);
@ -926,6 +938,7 @@ badt:
/*
* Creat a hard link to existing file.
*/
static void
hardlink(cmd)
char *cmd;
{
@ -983,6 +996,7 @@ hardlink(cmd)
/*
* Check to see if parent directory exists and create one if not.
*/
static int
chkparent(name)
char *name;
{
@ -1010,7 +1024,9 @@ chkparent(name)
/*
* Change owner, group and mode of file.
*/
chog(file, owner, group, mode)
static int
fchog(fd, file, owner, group, mode)
int fd;
char *file, *owner, *group;
int mode;
{
@ -1060,16 +1076,11 @@ chog(file, owner, group, mode)
mode &= ~02000;
gid = -1;
}
ok:
if (userid)
setreuid(userid, 0);
if (chown(file, uid, gid) < 0 ||
(mode & 07000) && chmod(file, mode) < 0) {
note("%s: chown or chmod failed: file %s: %s",
host, file, strerror(errno));
}
if (userid)
setreuid(0, userid);
ok: if (fd != -1 && fchown(fd, uid, gid) < 0 || chown(file, uid, gid) < 0)
note("%s: %s chown: %s", host, file, strerror(errno));
else if (mode & 07000 &&
(fd != -1 && fchmod(fd, mode) < 0 || chmod(file, mode) < 0))
note("%s: %s chmod: %s", host, file, strerror(errno));
return(0);
}
@ -1077,6 +1088,7 @@ ok:
* Check for files on the machine being updated that are not on the master
* machine and remove them.
*/
static void
rmchk(opts)
int opts;
{
@ -1099,7 +1111,7 @@ rmchk(opts)
cp = s = buf;
do {
if (read(rem, cp, 1) != 1)
lostconn();
lostconn(0);
} while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
switch (*s++) {
@ -1144,7 +1156,7 @@ rmchk(opts)
(void) fwrite(s, 1, cp - s, lfp);
}
if (buf[0] == '\2')
lostconn();
lostconn(0);
break;
default:
@ -1158,6 +1170,7 @@ rmchk(opts)
* Check the current directory (initialized by the 'T' command to server())
* for extraneous files and remove them.
*/
static void
clean(cp)
register char *cp;
{
@ -1205,7 +1218,7 @@ clean(cp)
cp = buf;
do {
if (read(rem, cp, 1) != 1)
cleanup();
cleanup(0);
} while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
*--cp = '\0';
cp = buf;
@ -1230,6 +1243,7 @@ clean(cp)
* Remove a file or directory (recursively) and send back an acknowledge
* or an error message.
*/
static void
removeit(stp)
struct stat *stp;
{
@ -1298,6 +1312,7 @@ removed:
/*
* Execute a shell command to handle special cases.
*/
static void
dospecial(cmd)
char *cmd;
{
@ -1365,78 +1380,117 @@ dospecial(cmd)
ack();
}
/*VARARGS2*/
log(fp, fmt, a1, a2, a3)
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
void
#if __STDC__
log(FILE *fp, const char *fmt, ...)
#else
log(fp, fmt, va_alist)
FILE *fp;
char *fmt;
int a1, a2, a3;
va_dcl
#endif
{
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
/* Print changes locally if not quiet mode */
if (!qflag)
printf(fmt, a1, a2, a3);
(void)vprintf(fmt, ap);
/* Save changes (for mailing) if really updating files */
if (!(options & VERIFY) && fp != NULL)
fprintf(fp, fmt, a1, a2, a3);
(void)vfprintf(fp, fmt, ap);
va_end(ap);
}
/*VARARGS1*/
error(fmt, a1, a2, a3)
void
#if __STDC__
error(const char *fmt, ...)
#else
error(fmt, va_alist)
char *fmt;
int a1, a2, a3;
va_dcl
#endif
{
static FILE *fp;
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
++nerrs;
if (!fp && !(fp = fdopen(rem, "w")))
return;
if (iamremote) {
(void)fprintf(fp, "%crdist: ", 0x01);
(void)fprintf(fp, fmt, a1, a2, a3);
(void)vfprintf(fp, fmt, ap);
fflush(fp);
}
else {
fflush(stdout);
(void)fprintf(stderr, "rdist: ");
(void)fprintf(stderr, fmt, a1, a2, a3);
(void)vfprintf(stderr, fmt, ap);
fflush(stderr);
}
if (lfp != NULL) {
(void)fprintf(lfp, "rdist: ");
(void)fprintf(lfp, fmt, a1, a2, a3);
(void)vfprintf(lfp, fmt, ap);
fflush(lfp);
}
va_end(ap);
}
/*VARARGS1*/
fatal(fmt, a1, a2,a3)
void
#if __STDC__
fatal(const char *fmt, ...)
#else
fatal(fmt, va_alist)
char *fmt;
int a1, a2, a3;
va_dcl
#endif
{
static FILE *fp;
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
++nerrs;
if (!fp && !(fp = fdopen(rem, "w")))
return;
if (iamremote) {
(void)fprintf(fp, "%crdist: ", 0x02);
(void)fprintf(fp, fmt, a1, a2, a3);
(void)vfprintf(fp, fmt, ap);
fflush(fp);
}
else {
fflush(stdout);
(void)fprintf(stderr, "rdist: ");
(void)fprintf(stderr, fmt, a1, a2, a3);
(void)vfprintf(stderr, fmt, ap);
fflush(stderr);
}
if (lfp != NULL) {
(void)fprintf(lfp, "rdist: ");
(void)fprintf(lfp, fmt, a1, a2, a3);
(void)vfprintf(lfp, fmt, ap);
fflush(lfp);
}
cleanup();
cleanup(0);
}
static int
response()
{
char *cp, *s;
@ -1448,7 +1502,7 @@ response()
cp = s = resp;
do {
if (read(rem, cp, 1) != 1)
lostconn();
lostconn(0);
} while (*cp++ != '\n' && cp < &resp[BUFSIZ]);
switch (*s++) {
@ -1479,7 +1533,7 @@ response()
(void) fwrite(s, 1, cp - s, lfp);
}
if (resp[0] == '\2')
lostconn();
lostconn(0);
return(-1);
}
}
@ -1488,25 +1542,41 @@ response()
* Remove temporary files and do any cleanup operations before exiting.
*/
void
cleanup()
cleanup(signo)
int signo;
{
(void) unlink(tempfile);
exit(1);
}
note(fmt, a1, a2, a3)
static void
#if __STDC__
note(const char *fmt, ...)
#else
note(fmt, va_alist)
char *fmt;
int a1, a2, a3;
va_dcl
#endif
{
static char buf[BUFSIZ];
sprintf(buf, fmt, a1, a2, a3);
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
(void)vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
comment(buf);
}
static void
comment(s)
char *s;
char *s;
{
char c = '\3';
char c;
c = '\3';
write(rem, &c, 1);
write(rem, s, strlen(s));
c = '\n';