static char *sccsid
= "@(#)docmd.c 4.3 (Berkeley) 83/10/10";
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
;
printf("dohcmds(%x, %x, %x)\n", files
, hosts
, cmds
);
files
= expand(files
, 0);
hosts
= expand(hosts
, 1);
fatal("no files to be updated\n");
fatal("empty list of hosts to be updated\n");
ddir
= files
->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
, c
->b_name
, ddir
, c
->b_options
);
install(f
->b_name
, f
->b_name
, 0, 0);
/* 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
);
* Create a connection to the rdist server on the machine rhost.
(void) sprintf(buf
, "/usr/local/rdist -Server%s%s%s%s%s",
vflag
? " -v" : "", qflag
? " -q" : "", nflag
? " -n" : "",
yflag
? " -y" : "", debug
? " -D" : "");
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
, options
)
printf("%s%s %s %s\n", options
& VERIFY
? "verify" : "install",
options
& WHOLE
? " -w" : "", 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
&& (options
& WHOLE
))
sendf(src
, NULL
, options
);
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);
stamps
= expand(stamps
, 1);
fatal("no files to be updated\n");
fatal("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
;
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
);
* 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
, "updating: %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.
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
);
fprintf(pf
, "Subject: files updated by rdist from %s to %s\n",
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
);