static char *sccsid
= "@(#)docmd.c 4.12 (Berkeley) 84/01/04";
FILE *lfp
; /* log file for recording files updated */
struct block
*special
; /* list of special commands */
* 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
, E_VARS
|E_SHELL
);
error("no files to be updated\n");
hosts
= expand(hosts
, E_VARS
|E_SHELL
);
error("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
,
c
->b_name
== NULL
? 0 : ddir
,
install(f
->b_name
, NULL
, 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 char *ruser
, *cp
;
(void) sprintf(buf
, "/usr/local/rdist -Server%s", 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);
if (read(rem
, cp
, 1) != 1)
if (read(rem
, cp
, 1) != 1)
} while (*cp
++ != '\n' && cp
< &buf
[BUFSIZ
]);
while (*cp
>= '0' && *cp
<= '9')
n
= (n
* 10) + (*cp
++ - '0');
if (*cp
== '\0' && n
== VERSION
)
error("connection failed: version numbers don't match\n");
register char *cp
= name
;
if (!isalpha(c
) && !isdigit(c
) && c
!= '_' && c
!= '-')
error("invalid user name %s\n", name
);
extern char target
[], *tp
;
* Process commands for comparing files to time stamp files.
dofcmds(files
, stamp
, cmds
)
struct block
*files
, *stamp
, *cmds
;
register struct block
*b
;
files
= expand(files
, E_ALL
);
error("no files to be updated\n");
stamp
= expand(stamp
, E_ALL
);
if (stamp
== NULL
|| stamp
->b_next
!= NULL
) {
error("Only one time stamp file allowed\n");
if (stat(stamp
->b_name
, &stb
) < 0) {
error("%s: %s\n", stamp
->b_name
, sys_errlist
[errno
]);
printf("%s: %d\n", stamp
->b_name
, stb
.st_mtime
);
(void) gettimeofday(&tv
[0], &tz
);
(void) utimes(stamp
->b_name
, tv
);
else if ((tfp
= fopen(tmpfile
, "w")) == NULL
) {
error("%s: %s\n", stamp
->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 (b
= cmds
; b
!= NULL
; b
= b
->b_next
)
notify(tmpfile
, NULL
, b
->b_args
, lastmod
);
if (!nflag
&& !(options
& VERIFY
))
* Compare the mtime of file to the list of time stamps.
printf("cmptime(%s)\n", name
);
if (inlist(except
, name
))
printf("comparing dates: %s\n", name
);
* first time cmptime() is called?
if (exptilde(target
, name
) == NULL
)
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
);
if (stb
.st_mtime
> lastmod
)
log(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 ((options
& VERIFY
) || to
== NULL
)
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
) && rhost
!= NULL
)
fprintf(pf
, " %s@%s", to
->b_name
, rhost
);
fprintf(pf
, " %s", to
->b_name
);
if (!any('@', to
->b_name
) && rhost
!= 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 the list.
register struct block
*c
;
for (c
= list
; c
!= NULL
; c
= c
->b_next
)
if (!strcmp(file
, c
->b_name
))
* Build the exception list from an unexpanded list of commands.
register struct block
*f
, *a
, *c
;
printf("mkexceptlist()\n");
for (c
= cmds
; c
!= NULL
; c
= c
->b_next
) {
for (a
= c
->b_args
; a
!= NULL
; a
= a
->b_next
) {
except
= f
= expand(makeblock(NAME
, a
->b_name
), E_ALL
);
f
->b_next
= expand(makeblock(NAME
, a
->b_name
), E_ALL
);
while (f
->b_next
!= NULL
)