static char *sccsid
= "@(#)docmd.c 4.7 (Berkeley) 83/10/27";
FILE *lfp
; /* log file for recording files updated */
* Process commands for sending files to other machines.
dohcmds(files
, hosts
, cmds
)
struct block
*files
, *hosts
, *cmds
;
register struct block
*h
, *f
, *c
;
static struct block excpt
= { EXCEPT
};
printf("dohcmds(%x, %x, %x)\n", files
, hosts
, cmds
);
files
= expand(files
, 0);
error("no files to be updated\n");
hosts
= expand(hosts
, 1);
error("empty list of hosts to be updated\n");
ddir
= files
->b_next
!= NULL
;
for (c
= cmds
; c
!= NULL
; c
= c
->b_next
) {
for (h
= c
->b_args
; h
!= NULL
; h
= h
->b_next
) {
(void) exptilde(buf
, cp
);
except
->b_args
= f
= expand(makeblock(NAME
, cp
), 0);
f
->b_next
= expand(makeblock(NAME
, cp
), 0);
while (f
->b_next
!= NULL
)
for (h
= hosts
; h
!= NULL
; h
= h
->b_next
) {
printf("updating host %s\n", h
->b_name
);
if (!makeconn(h
->b_name
))
if ((lfp
= fopen(tmpfile
, "w")) == NULL
) {
fatal("cannot open %s\n", tmpfile
);
for (f
= files
; f
!= NULL
; f
= f
->b_next
) {
for (cpp
= filev
; *cpp
; cpp
++)
if (!strcmp(f
->b_name
, *cpp
))
for (c
= cmds
; c
!= NULL
; c
= c
->b_next
) {
if (c
->b_type
!= INSTALL
)
install(f
->b_name
, f
->b_name
, 0, c
->b_options
);
install(f
->b_name
, c
->b_name
, ddir
, c
->b_options
);
install(f
->b_name
, f
->b_name
, 0, options
);
/* signal end of connection */
(void) write(rem
, "\2\n", 2);
for (c
= cmds
; c
!= NULL
; c
= c
->b_next
)
notify(tmpfile
, h
->b_name
, c
->b_args
, 0);
* Create a connection to the rdist server on the machine rhost.
register struct block
*c
;
(void) sprintf(buf
, "/usr/local/rdist -Server%s%s",
nflag
? " -n" : "", qflag
? " -q" : "");
ruser
= rindex(rhost
, '.');
printf("makeconn(%s)\n", rhost
);
printf("luser = %s, ruser = %s\n", user
, ruser
);
printf("buf = %s\n", buf
);
rem
= rcmd(&rhost
, IPPORT_CMDSERVER
, user
, ruser
, buf
, 0);
* Update the file(s) if they are different.
* destdir = 1 if destination should be a directory
* (i.e., more than one source is being copied to the same destination).
install(src
, dest
, destdir
, opts
)
printf("%s%s%s%s%s %s %s\n", opts
& VERIFY
? "verify":"install",
opts
& WHOLE
? " -w" : "",
opts
& YOUNGER
? " -y" : "",
opts
& COMPARE
? " -b" : "",
opts
& REMOVE
? " -r" : "", src
, dest
);
* Pass the destination file/directory name to remote.
(void) sprintf(buf
, "%c%s\n", destdir
? 'T' : 't', dest
);
(void) write(rem
, buf
, strlen(buf
));
if (!destdir
&& (opts
& WHOLE
))
extern char target
[], *tp
;
* Process commands for comparing files to time stamp files.
dofcmds(files
, stamps
, cmds
)
struct block
*files
, *stamps
, *cmds
;
register struct block
*b
;
register struct tstamp
*t
;
files
= expand(files
, 0);
error("no files to be updated\n");
stamps
= expand(stamps
, 0);
error("empty time stamp file list\n");
for (b
= stamps
; b
!= NULL
; b
= b
->b_next
) {
if (stat(b
->b_name
, &stb
) < 0) {
error("%s: %s\n", b
->b_name
, sys_errlist
[errno
]);
fatal("too many time stamp files in one command\n");
printf("%s: %d\n", b
->b_name
, stb
.st_mtime
);
t
->lastmod
= stb
.st_mtime
;
(void) gettimeofday(&tv
[0], &tz
);
(void) utimes(b
->b_name
, tv
);
if (!nflag
&& !(options
& VERIFY
)) {
if ((t
->tfp
= fopen(tmpfile
, "w")) == NULL
)
error("%s: %s\n", b
->b_name
, sys_errlist
[errno
]);
for (b
= files
; b
!= NULL
; b
= b
->b_next
) {
for (cpp
= filev
; *cpp
; cpp
++)
if (!strcmp(b
->b_name
, *cpp
))
for (t
= ts
; t
< &ts
[nstamps
]; t
++) {
for (b
= cmds
; b
!= NULL
; b
= b
->b_next
)
notify(tmpfile
, NULL
, b
->b_args
, t
->lastmod
);
if (!nflag
&& !(options
& VERIFY
))
* Compare the mtime of file to the list of time stamps.
register struct tstamp
*t
;
printf("cmptime(%s)\n", name
);
* first time cmptime() is called?
if (access(name
, 4) < 0 || stat(name
, &stb
) < 0) {
error("%s: %s\n", name
, sys_errlist
[errno
]);
switch (stb
.st_mode
& S_IFMT
) {
error("%s: not a plain file\n", name
);
for (t
= ts
; t
< &ts
[nstamps
]; t
++) {
if (stb
.st_mtime
> t
->lastmod
)
log(t
->tfp
, "new: %s\n", name
);
register struct direct
*dp
;
printf("rcmptime(%x)\n", st
);
if ((d
= opendir(target
)) == NULL
) {
error("%s: %s\n", target
, sys_errlist
[errno
]);
while (dp
= readdir(d
)) {
if (!strcmp(dp
->d_name
, ".") || !strcmp(dp
->d_name
, ".."))
if (len
+ 1 + strlen(dp
->d_name
) >= BUFSIZ
- 1) {
error("%s/%s: Name too long\n", target
, dp
->d_name
);
* Notify the list of people the changes that were made.
* rhost == NULL if we are mailing a list of changes compared to at time
notify(file
, rhost
, to
, lmod
)
register struct block
*to
;
if ((fd
= open(file
, 0)) < 0) {
error("%s: %s\n", file
, sys_errlist
[errno
]);
if (fstat(fd
, &stb
) < 0) {
error("%s: %s\n", file
, sys_errlist
[errno
]);
* Create a pipe to mailling program.
pf
= popen(MAILCMD
, "w");
error("notify: \"%s\" failed\n", MAILCMD
);
* Output the proper header information.
fprintf(pf
, "From: rdist (Remote distribution program)\n");
if (!any('@', to
->b_name
) && host
!= NULL
)
fprintf(pf
, " %s@%s", to
->b_name
, rhost
);
fprintf(pf
, " %s", to
->b_name
);
if (!any('@', to
->b_name
) && host
!= NULL
)
fprintf(pf
, ", %s@%s", to
->b_name
, rhost
);
fprintf(pf
, ", %s", to
->b_name
);
fprintf(pf
, "Subject: files updated by rdist from %s to %s\n",
fprintf(pf
, "Subject: files updated after %s\n", ctime(&lmod
));
while ((len
= read(fd
, buf
, BUFSIZ
)) > 0)
(void) fwrite(buf
, 1, len
, pf
);
struct block
*except
; /* list of files to exclude */
* Return true if name is in list.
register struct block
*b
, *c
;
for (c
= except
; c
!= NULL
; c
= c
->b_next
) {
for (b
= c
->b_args
; b
!= NULL
; b
= b
->b_next
)
if (!strcmp(file
, b
->b_name
))
register char *cp
= name
;
if (!isalpha(c
) && !isdigit(c
) && c
!= '_' && c
!= '-')
error("invalid user name %s\n", name
);