static char *sccsid
= "@(#)docmd.c 4.17 (Berkeley) 84/03/14";
FILE *lfp
; /* log file for recording files updated */
struct subcmd
*special
; /* list of special commands */
* Do the commands in cmds (initialized by yyparse).
signal(SIGQUIT
, cleanup
);
signal(SIGTERM
, cleanup
);
for (c
= cmds
; c
!= NULL
; c
= c
->c_next
) {
doarrow(c
->c_files
, c
->c_name
, c
->c_cmds
);
dodcolon(c
->c_files
, c
->c_name
, c
->c_cmds
);
fatal("illegal command type %d\n", c
->c_type
);
* Process commands for sending files to other machines.
doarrow(files
, rhost
, cmds
)
register struct namelist
*f
;
register struct subcmd
*sc
;
printf("doarrow(%x, %s, %x)\n", files
, rhost
, cmds
);
error("no files to be updated\n");
ddir
= files
->n_next
!= NULL
; /* destination is a directory */
printf("updating host %s\n", rhost
);
signal(SIGPIPE
, lostconn
);
if ((lfp
= fopen(tmpfile
, "w")) == NULL
) {
fatal("cannot open %s\n", tmpfile
);
for (f
= files
; f
!= NULL
; f
= f
->n_next
) {
for (cpp
= filev
; *cpp
; cpp
++)
if (!strcmp(f
->b_name
, *cpp
))
for (sc
= cmds
; sc
!= NULL
; sc
= sc
->sc_next
) {
if (sc
->sc_type
!= INSTALL
)
install(f
->n_name
, sc
->sc_name
,
sc
->sc_name
== NULL
? 0 : ddir
, sc
->sc_options
);
install(f
->n_name
, NULL
, 0, options
);
(void) signal(SIGPIPE
, cleanup
);
for (sc
= cmds
; sc
!= NULL
; sc
= sc
->sc_next
)
if (sc
->sc_type
== NOTIFY
)
notify(tmpfile
, rhost
, sc
->sc_args
, 0);
* Create a connection to the rdist server on the machine rhost.
register char *ruser
, *cp
;
static char *cur_host
= NULL
;
printf("makeconn(%s)\n", rhost
);
if (cur_host
!= NULL
&& rem
>= 0) {
if (strcmp(cur_host
, rhost
) == 0)
ruser
= rindex(rhost
, '.');
printf("updating host %s\n", rhost
);
(void) sprintf(buf
, "/usr/local/rdist -Server%s", qflag
? " -q" : "");
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");
* Signal end of previous connection.
(void) write(rem
, "\2\n", 2);
log(lfp
, "rdist: lost connection\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.
dodcolon(files
, stamp
, cmds
)
register struct subcmd
*sc
;
register struct namelist
*f
;
error("no files to be updated\n");
if (stat(stamp
, &stb
) < 0) {
error("%s: %s\n", stamp
, sys_errlist
[errno
]);
printf("%s: %d\n", stamp
, stb
.st_mtime
);
if (nflag
|| (options
& VERIFY
))
if ((tfp
= fopen(tmpfile
, "w")) == NULL
) {
error("%s: %s\n", stamp
, sys_errlist
[errno
]);
(void) gettimeofday(&tv
[0], &tz
);
(void) utimes(stamp
, tv
);
for (f
= files
; f
!= NULL
; f
= f
->n_next
) {
for (cpp
= filev
; *cpp
; cpp
++)
if (!strcmp(b
->b_name
, *cpp
))
for (sc
= cmds
; sc
!= NULL
; sc
= sc
->sc_next
)
if (sc
->sc_type
== NOTIFY
)
notify(tmpfile
, NULL
, sc
->sc_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 namelist
*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
->n_name
) && rhost
!= NULL
)
fprintf(pf
, " %s@%s", to
->n_name
, rhost
);
fprintf(pf
, " %s", to
->n_name
);
if (!any('@', to
->n_name
) && rhost
!= NULL
)
fprintf(pf
, ", %s@%s", to
->n_name
, rhost
);
fprintf(pf
, ", %s", to
->n_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 namelist
*except
; /* list of files to exclude */
* Return true if name is in the list.
register struct namelist
*nl
;
for (nl
= list
; nl
!= NULL
; nl
= nl
->n_next
)
if (!strcmp(file
, nl
->n_name
))
* Build the exception list from the EXCEPT commands.
register struct subcmd
*sc
;
register struct namelist
*el
, *nl
;
printf("mkexceptlist()\n");
for (sc
= cmds
; sc
!= NULL
; sc
= sc
->sc_next
) {
if (sc
->sc_type
!= EXCEPT
)
for (nl
= sc
->sc_args
; nl
!= NULL
; nl
= nl
->n_next
) {
except
= el
= makenl(nl
->n_name
);
el
->n_next
= makenl(nl
->n_name
);