read entire distfile and sort entries by host.
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Fri, 10 Feb 1984 08:22:02 +0000 (00:22 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Fri, 10 Feb 1984 08:22:02 +0000 (00:22 -0800)
SCCS-vsn: usr.bin/rdist/defs.h 4.10
SCCS-vsn: usr.bin/rdist/expand.c 4.10
SCCS-vsn: usr.bin/rdist/gram.y 4.8
SCCS-vsn: usr.bin/rdist/lookup.c 4.4
SCCS-vsn: usr.bin/rdist/main.c 4.10
SCCS-vsn: usr.bin/rdist/server.c 4.15
SCCS-vsn: usr.bin/rdist/docmd.c 4.13

usr/src/usr.bin/rdist/defs.h
usr/src/usr.bin/rdist/docmd.c
usr/src/usr.bin/rdist/expand.c
usr/src/usr.bin/rdist/gram.y
usr/src/usr.bin/rdist/lookup.c
usr/src/usr.bin/rdist/main.c
usr/src/usr.bin/rdist/server.c

index 0d03930..ab6c9c4 100644 (file)
@@ -1,4 +1,4 @@
-/*     defs.h  4.9     83/11/29        */
+/*     defs.h  4.10    84/02/09        */
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -13,7 +13,7 @@
 #include <netinet/in.h>
 
 /*
 #include <netinet/in.h>
 
 /*
- * The version number should be changed whenever the protocols change.
+ * The version number should be changed whenever the protocol changes.
  */
 #define VERSION         2
 
  */
 #define VERSION         2
 
@@ -33,7 +33,6 @@
 #define EXCEPT 11
 #define SPECIAL        12
 #define OPTION 13
 #define EXCEPT 11
 #define SPECIAL        12
 #define OPTION 13
-#define VAR    14
 
        /* lexical definitions */
 #define        QUOTE   0200            /* used internally for quoted characters */
 
        /* lexical definitions */
 #define        QUOTE   0200            /* used internally for quoted characters */
@@ -44,7 +43,6 @@
 #define INMAX  3500
 #define NCARGS 10240
 #define GAVSIZ NCARGS / 6
 #define INMAX  3500
 #define NCARGS 10240
 #define GAVSIZ NCARGS / 6
-#define NSTAMPS        15
 
        /* option flags */
 #define VERIFY 0x1
 
        /* option flags */
 #define VERIFY 0x1
 #define E_TILDE        0x4
 #define E_ALL  0x7
 
 #define E_TILDE        0x4
 #define E_ALL  0x7
 
+       /* actions for lookup() */
+#define LOOKUP 0
+#define INSERT 1
+#define REPLACE        2
+
 #define ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 
 #define ALLOC(x) (struct x *) malloc(sizeof(struct x))
 
 #define ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 
 #define ALLOC(x) (struct x *) malloc(sizeof(struct x))
 
-struct block {
-       short   b_type;
-       short   b_options;
-       char    *b_name;
-       struct  block *b_next;
-       struct  block *b_args;
+struct namelist {      /* for making lists of strings */
+       char    *n_name;
+       struct  namelist *n_next;
+};
+
+struct subcmd {
+       short   sc_type;        /* type - INSTALL,NOTIFY,EXCEPT,SPECIAL */
+       short   sc_options;
+       char    *sc_name;
+       struct  namelist *sc_args;
+       struct  subcmd *sc_next;
 };
 
 };
 
+struct cmd {
+       int     c_type;         /* type - ARROW,DCOLON */
+       char    *c_name;        /* hostname or time stamp file name */
+       struct  namelist *c_files;
+       struct  subcmd *c_cmds;
+       struct  cmd *c_next;
+};
+       
 extern int debug;              /* debugging flag */
 extern int nflag;              /* NOP flag, don't execute commands */
 extern int qflag;              /* Quiet. don't print messages */
 extern int options;            /* global options */
 
 extern int debug;              /* debugging flag */
 extern int nflag;              /* NOP flag, don't execute commands */
 extern int qflag;              /* Quiet. don't print messages */
 extern int options;            /* global options */
 
-extern int errs;               /* number of errors seen */
+extern int nerrs;              /* number of errors seen */
 extern int rem;                        /* remote file descriptor */
 extern int iamremote;          /* acting as remote server */
 extern int filec;              /* number of files to update */
 extern int rem;                        /* remote file descriptor */
 extern int iamremote;          /* acting as remote server */
 extern int filec;              /* number of files to update */
@@ -86,14 +102,16 @@ extern struct passwd *pw;  /* pointer to static area used by getpwent */
 extern struct group *gr;       /* pointer to static area used by getgrent */
 extern char host[];            /* host name of master copy */
 extern char *rhost;            /* host name of remote being updated */
 extern struct group *gr;       /* pointer to static area used by getgrent */
 extern char host[];            /* host name of master copy */
 extern char *rhost;            /* host name of remote being updated */
-extern struct block *except;   /* list of files to exclude */
+extern struct namelist *except;        /* list of files to exclude */
 extern char buf[];             /* general purpose buffer */
 extern int errno;              /* system error number */
 extern char *sys_errlist[];
 
 extern char buf[];             /* general purpose buffer */
 extern int errno;              /* system error number */
 extern char *sys_errlist[];
 
-struct block *lookup();
-struct block *makeblock();
-struct block *expand();
+char *makestr();
+struct namelist *makenl();
+struct subcmd *makesubcmd();
+struct namelist *lookup();
+struct namelist *expand();
 char *exptilde();
 char *malloc();
 char *rindex();
 char *exptilde();
 char *malloc();
 char *rindex();
index 44eba96..e00eed3 100644 (file)
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)docmd.c     4.12 (Berkeley) 84/01/04";
+static char *sccsid = "@(#)docmd.c     4.13 (Berkeley) 84/02/09";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
+#include <setjmp.h>
 
 
-FILE   *lfp;           /* log file for recording files updated */
-struct block *special; /* list of special commands */
+FILE   *lfp;                   /* log file for recording files updated */
+struct subcmd *special;        /* list of special commands */
+jmp_buf        env;
+
+int    cleanup();
+int    lostconn();
+
+/*
+ * Do the commands in cmds (initialized by yyparse).
+ */
+docmds(argc, argv)
+       int argc;
+       char **argv;
+{
+       register struct cmd *c;
+       extern struct cmd *cmds;
+
+       signal(SIGHUP, cleanup);
+       signal(SIGINT, cleanup);
+       signal(SIGQUIT, cleanup);
+       signal(SIGTERM, cleanup);
+
+       for (c = cmds; c != NULL; c = c->c_next) {
+               switch (c->c_type) {
+               case ARROW:
+                       doarrow(c->c_files, c->c_name, c->c_cmds);
+                       break;
+               case DCOLON:
+                       dodcolon(c->c_files, c->c_name, c->c_cmds);
+                       break;
+               default:
+                       fatal("illegal command type %d\n", c->c_type);
+               }
+       }
+       closeconn();
+}
 
 /*
  * Process commands for sending files to other machines.
  */
 
 /*
  * Process commands for sending files to other machines.
  */
-dohcmds(files, hosts, cmds)
-       struct block *files, *hosts, *cmds;
+doarrow(files, host, cmds)
+       struct namelist *files;
+       char *host;
+       struct subcmd *cmds;
 {
 {
-       register struct block *h, *f, *c;
-       register char **cpp;
+       register struct namelist *f;
+       register struct subcmd *sc;
        int n, ddir;
 
        if (debug)
        int n, ddir;
 
        if (debug)
-               printf("dohcmds(%x, %x, %x)\n", files, hosts, cmds);
+               printf("doarrow(%x, %s, %x)\n", files, host, cmds);
 
 
-       files = expand(files, E_VARS|E_SHELL);
        if (files == NULL) {
                error("no files to be updated\n");
                return;
        }
        if (files == NULL) {
                error("no files to be updated\n");
                return;
        }
-       hosts = expand(hosts, E_VARS|E_SHELL);
-       if (hosts == NULL) {
-               error("empty list of hosts to be updated\n");
-               return;
-       }
        if (!mkexceptlist(cmds))
                return;
        special = cmds;
 
        if (!mkexceptlist(cmds))
                return;
        special = cmds;
 
-       ddir = files->b_next != NULL;
+       ddir = files->n_next != NULL;   /* destination is a directory */
 
 
-       for (h = hosts; h != NULL; h = h->b_next) {
-               if (!qflag)
-                       printf("updating host %s\n", h->b_name);
-               if (!nflag) {
-                       if (!makeconn(h->b_name))
-                               continue;
-                       if ((lfp = fopen(tmpfile, "w")) == NULL) {
-                               fatal("cannot open %s\n", tmpfile);
-                               exit(1);
-                       }
+       if (!nflag) {
+               if (setjmp(env) != 0)
+                       goto done;
+               signal(SIGPIPE, lostconn);
+               if (!makeconn(host))
+                       return;
+               if ((lfp = fopen(tmpfile, "w")) == NULL) {
+                       fatal("cannot open %s\n", tmpfile);
+                       exit(1);
                }
                }
-               for (f = files; f != NULL; f = f->b_next) {
-                       if (filec) {
-                               for (cpp = filev; *cpp; cpp++)
-                                       if (!strcmp(f->b_name, *cpp))
-                                               goto found;
-                               if (!nflag)
-                                       (void) fclose(lfp);
-                               continue;
-                       }
-               found:
-                       n = 0;
-                       for (c = cmds; c != NULL; c = c->b_next) {
-                               if (c->b_type != INSTALL)
-                                       continue;
-                               n++;
-                               install(f->b_name, c->b_name,
-                                       c->b_name == NULL ? 0 : ddir,
-                                       c->b_options);
-                       }
-                       if (n == 0)
-                               install(f->b_name, NULL, 0, options);
+       }
+       for (f = files; f != NULL; f = f->n_next) {
+#ifdef notdef
+               if (filec) {
+                       register char **cpp;
+
+                       for (cpp = filev; *cpp; cpp++)
+                               if (!strcmp(f->b_name, *cpp))
+                                       goto found;
+                       if (!nflag)
+                               (void) fclose(lfp);
+                       continue;
                }
                }
-               if (!nflag) {
-                       /* signal end of connection */
-                       (void) write(rem, "\2\n", 2);
-                       (void) close(rem);
-                       (void) fclose(lfp);
+       found:
+#endif
+               n = 0;
+               for (sc = cmds; sc != NULL; sc = sc->sc_next) {
+                       if (sc->sc_type != INSTALL)
+                               continue;
+                       n++;
+                       install(f->n_name, sc->sc_name,
+                               sc->sc_name == NULL ? 0 : ddir, sc->sc_options);
                }
                }
-               for (c = cmds; c != NULL; c = c->b_next)
-                       if (c->b_type == NOTIFY)
-                               notify(tmpfile, h->b_name, c->b_args, 0);
+               if (n == 0)
+                       install(f->n_name, NULL, 0, options);
        }
        }
+done:
+       if (!nflag) {
+               (void) signal(SIGPIPE, SIG_DFL);
+               (void) fclose(lfp);
+               lfp = NULL;
+       }
+       for (sc = cmds; sc != NULL; sc = sc->sc_next)
+               if (sc->sc_type == NOTIFY)
+                       notify(tmpfile, host, sc->sc_args, 0);
        if (!nflag)
                (void) unlink(tmpfile);
 }
        if (!nflag)
                (void) unlink(tmpfile);
 }
@@ -90,10 +123,17 @@ makeconn(rhost)
        char *rhost;
 {
        register char *ruser, *cp;
        char *rhost;
 {
        register char *ruser, *cp;
+       static char *cur_host = NULL;
        int n;
        extern char user[];
 
        int n;
        extern char user[];
 
-       (void) sprintf(buf, "/usr/local/rdist -Server%s", qflag ? " -q" : "");
+       if (debug)
+               printf("makeconn(%s)\n", rhost);
+
+       if (cur_host != NULL && strcmp(cur_host, rhost) == 0)
+               return;
+
+       closeconn();
 
        ruser = rindex(rhost, '.');
        if (ruser != NULL) {
 
        ruser = rindex(rhost, '.');
        if (ruser != NULL) {
@@ -102,9 +142,12 @@ makeconn(rhost)
                        return(0);
        } else
                ruser = user;
                        return(0);
        } else
                ruser = user;
+       if (!qflag)
+               printf("updating host %s\n", rhost);
+       cur_host = rhost;
+       (void) sprintf(buf, "/usr/local/rdist -Server%s", qflag ? " -q" : "");
 
        if (debug) {
 
        if (debug) {
-               printf("makeconn(%s)\n", rhost);
                printf("luser = %s, ruser = %s\n", user, ruser);
                printf("buf = %s\n", buf);
        }
                printf("luser = %s, ruser = %s\n", user, ruser);
                printf("buf = %s\n", buf);
        }
@@ -133,6 +176,25 @@ makeconn(rhost)
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Signal end of previous connection.
+ */
+closeconn()
+{
+       if (rem >= 0) {
+               (void) write(rem, "\2\n", 2);
+               (void) close(rem);
+               rem = -1;
+       }
+}
+
+lostconn()
+{
+       fflush(stdout);
+       fprintf(stderr, "rdist: lost connection\n");
+       longjmp(env, 1);
+}
+
 okname(name)
        register char *name;
 {
 okname(name)
        register char *name;
 {
@@ -160,52 +222,50 @@ extern    char target[], *tp;
 /*
  * Process commands for comparing files to time stamp files.
  */
 /*
  * Process commands for comparing files to time stamp files.
  */
-dofcmds(files, stamp, cmds)
-       struct block *files, *stamp, *cmds;
+dodcolon(files, stamp, cmds)
+       struct namelist *files;
+       char *stamp;
+       struct subcmd *cmds;
 {
 {
-       register struct block *b;
+       register struct subcmd *sc;
+       register struct namelist *f;
        register char **cpp;
        struct timeval tv[2];
        struct timezone tz;
        struct stat stb;
 
        if (debug)
        register char **cpp;
        struct timeval tv[2];
        struct timezone tz;
        struct stat stb;
 
        if (debug)
-               printf("dofcmds()\n");
+               printf("dodcolon()\n");
 
 
-       files = expand(files, E_ALL);
        if (files == NULL) {
                error("no files to be updated\n");
                return;
        }
        if (files == NULL) {
                error("no files to be updated\n");
                return;
        }
-       stamp = expand(stamp, E_ALL);
-       if (stamp == NULL || stamp->b_next != NULL) {
-               error("Only one time stamp file allowed\n");
-               return;
-       }
        if (!mkexceptlist(cmds))
                return;
 
        if (!mkexceptlist(cmds))
                return;
 
-       if (stat(stamp->b_name, &stb) < 0) {
-               error("%s: %s\n", stamp->b_name, sys_errlist[errno]);
+       if (stat(stamp, &stb) < 0) {
+               error("%s: %s\n", stamp, sys_errlist[errno]);
                return;
        }
        if (debug)
                return;
        }
        if (debug)
-               printf("%s: %d\n", stamp->b_name, stb.st_mtime);
+               printf("%s: %d\n", stamp, stb.st_mtime);
        if (!nflag) {
                lastmod = stb.st_mtime;
                (void) gettimeofday(&tv[0], &tz);
                tv[1] = tv[0];
        if (!nflag) {
                lastmod = stb.st_mtime;
                (void) gettimeofday(&tv[0], &tz);
                tv[1] = tv[0];
-               (void) utimes(stamp->b_name, tv);
+               (void) utimes(stamp, tv);
                if (options & VERIFY)
                        tfp = NULL;
                else if ((tfp = fopen(tmpfile, "w")) == NULL) {
                if (options & VERIFY)
                        tfp = NULL;
                else if ((tfp = fopen(tmpfile, "w")) == NULL) {
-                       error("%s: %s\n", stamp->b_name, sys_errlist[errno]);
+                       error("%s: %s\n", stamp, sys_errlist[errno]);
                        return;
                }
        } else
                tfp = NULL;
 
                        return;
                }
        } else
                tfp = NULL;
 
-       for (b = files; b != NULL; b = b->b_next) {
+       for (f = files; f != NULL; f = f->n_next) {
+#ifdef notdef
                if (filec) {
                        for (cpp = filev; *cpp; cpp++)
                                if (!strcmp(b->b_name, *cpp))
                if (filec) {
                        for (cpp = filev; *cpp; cpp++)
                                if (!strcmp(b->b_name, *cpp))
@@ -213,15 +273,16 @@ dofcmds(files, stamp, cmds)
                        continue;
                }
        found:
                        continue;
                }
        found:
+#endif
                tp = NULL;
                tp = NULL;
-               cmptime(b->b_name);
+               cmptime(f->n_name);
        }
 
        if (tfp != NULL)
                (void) fclose(tfp);
        }
 
        if (tfp != NULL)
                (void) fclose(tfp);
-       for (b = cmds; b != NULL; b = b->b_next)
-               if (b->b_type == NOTIFY)
-                       notify(tmpfile, NULL, b->b_args, lastmod);
+       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))
                (void) unlink(tmpfile);
 }
        if (!nflag && !(options & VERIFY))
                (void) unlink(tmpfile);
 }
@@ -322,7 +383,7 @@ rcmptime(st)
  */
 notify(file, rhost, to, lmod)
        char *file, *rhost;
  */
 notify(file, rhost, to, lmod)
        char *file, *rhost;
-       register struct block *to;
+       register struct namelist *to;
        time_t lmod;
 {
        register int fd, len;
        time_t lmod;
 {
        register int fd, len;
@@ -367,17 +428,17 @@ notify(file, rhost, to, lmod)
         */
        fprintf(pf, "From: rdist (Remote distribution program)\n");
        fprintf(pf, "To:");
         */
        fprintf(pf, "From: rdist (Remote distribution program)\n");
        fprintf(pf, "To:");
-       if (!any('@', to->b_name) && rhost != NULL)
-               fprintf(pf, " %s@%s", to->b_name, rhost);
+       if (!any('@', to->n_name) && rhost != NULL)
+               fprintf(pf, " %s@%s", to->n_name, rhost);
        else
        else
-               fprintf(pf, " %s", to->b_name);
-       to = to->b_next;
+               fprintf(pf, " %s", to->n_name);
+       to = to->n_next;
        while (to != NULL) {
        while (to != NULL) {
-               if (!any('@', to->b_name) && rhost != NULL)
-                       fprintf(pf, ", %s@%s", to->b_name, rhost);
+               if (!any('@', to->n_name) && rhost != NULL)
+                       fprintf(pf, ", %s@%s", to->n_name, rhost);
                else
                else
-                       fprintf(pf, ", %s", to->b_name);
-               to = to->b_next;
+                       fprintf(pf, ", %s", to->n_name);
+               to = to->n_next;
        }
        putc('\n', pf);
        if (rhost != NULL)
        }
        putc('\n', pf);
        if (rhost != NULL)
@@ -393,49 +454,52 @@ notify(file, rhost, to, lmod)
        (void) pclose(pf);
 }
 
        (void) pclose(pf);
 }
 
-struct block *except;          /* list of files to exclude */
+struct namelist *except;               /* list of files to exclude */
 
 /*
  * Return true if name is in the list.
  */
 inlist(list, file)
 
 /*
  * Return true if name is in the list.
  */
 inlist(list, file)
-       struct block *list;
+       struct namelist *list;
        char *file;
 {
        char *file;
 {
-       register struct block *c;
+       register struct namelist *nl;
 
 
-       for (c = list; c != NULL; c = c->b_next)
-               if (!strcmp(file, c->b_name))
+       for (nl = list; nl != NULL; nl = nl->n_next)
+               if (!strcmp(file, nl->n_name))
                        return(1);
        return(0);
 }
 
 /*
                        return(1);
        return(0);
 }
 
 /*
- * Build the exception list from an unexpanded list of commands.
+ * Build the exception list from the EXCEPT commands.
  */
 mkexceptlist(cmds)
  */
 mkexceptlist(cmds)
-       struct block *cmds;
+       struct subcmd *cmds;
 {
 {
-       register struct block *f, *a, *c;
+       register struct subcmd *sc;
+       register struct namelist *el, *nl;
 
        if (debug)
                printf("mkexceptlist()\n");
 
 
        if (debug)
                printf("mkexceptlist()\n");
 
-       except = f = NULL;
-       for (c = cmds; c != NULL; c = c->b_next) {
-               if (c->b_type != EXCEPT)
+       except = el = NULL;
+       for (sc = cmds; sc != NULL; sc = sc->sc_next) {
+               if (sc->sc_type != EXCEPT)
                        continue;
                        continue;
-               for (a = c->b_args; a != NULL; a = a->b_next) {
-                       if (f == NULL)
-                               except = f = expand(makeblock(NAME, a->b_name), E_ALL);
-                       else
-                               f->b_next = expand(makeblock(NAME, a->b_name), E_ALL);
-                       while (f->b_next != NULL)
-                               f = f->b_next;
+               for (nl = sc->sc_args; nl != NULL; nl = nl->n_next) {
+                       if (el == NULL)
+                               except = el = makenl(nl->n_name);
+                       else {
+                               el->n_next = makenl(nl->n_name);
+                               el = el->n_next;
+                       }
                }
        }
                }
        }
-       if (debug)
+       if (debug) {
+               printf("except = ");
                prnames(except);
                prnames(except);
+       }
        return(1);
 }
 
        return(1);
 }
 
index 8886045..73110ab 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)expand.c    4.9 (Berkeley) 83/12/19";
+static char *sccsid = "@(#)expand.c    4.10 (Berkeley) 84/02/09";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -9,22 +9,21 @@ static        char *sccsid = "@(#)expand.c    4.9 (Berkeley) 83/12/19";
 
 static char    shchars[] = "${[*?";
 
 
 static char    shchars[] = "${[*?";
 
-static int     which;          /* bit mask of types to expand */
-static int     argc;           /* expanded arg count */
-static char    **argv;         /* expanded arg vectors */
-static char    *path;
-static char    *pathp;
-static char    *lastpathp;
-static char    *tilde;         /* "~user" if not expanding tilde, else "" */
-static char    *tpathp;
-static int     nleft;
+int    which;          /* bit mask of types to expand */
+int    eargc;          /* expanded arg count */
+char   **eargv;        /* expanded arg vectors */
+char   *path;
+char   *pathp;
+char   *lastpathp;
+char   *tilde;         /* "~user" if not expanding tilde, else "" */
+char   *tpathp;
+int    nleft;
 
 
-static int     expany;         /* any expansions done? */
-static char    *entp;
-static char    **sortbase;
+int    expany;         /* any expansions done? */
+char   *entp;
+char   **sortbase;
 
 char   *index();
 
 char   *index();
-struct block *copy();
 
 /*
  * Take a list of names and expand any macros, etc.
 
 /*
  * Take a list of names and expand any macros, etc.
@@ -33,12 +32,12 @@ struct block *copy();
  * wh = E_TILDE if expanding `~'.
  * or any of these or'ed together.
  */
  * wh = E_TILDE if expanding `~'.
  * or any of these or'ed together.
  */
-struct block *
+struct namelist *
 expand(list, wh)
 expand(list, wh)
-       struct block *list;
+       struct namelist *list;
        int wh;
 {
        int wh;
 {
-       register struct block *bp, *prev;
+       register struct namelist *nl, *prev;
        register int n;
        char pathbuf[BUFSIZ];
        char *argvbuf[GAVSIZ];
        register int n;
        char pathbuf[BUFSIZ];
        char *argvbuf[GAVSIZ];
@@ -56,34 +55,27 @@ expand(list, wh)
        *pathp = '\0';
        lastpathp = &path[sizeof pathbuf - 2];
        tilde = "";
        *pathp = '\0';
        lastpathp = &path[sizeof pathbuf - 2];
        tilde = "";
-       argc = 0;
-       argv = sortbase = argvbuf;
-       *argv = 0;
+       eargc = 0;
+       eargv = sortbase = argvbuf;
+       *eargv = 0;
        nleft = NCARGS - 4;
        /*
        nleft = NCARGS - 4;
        /*
-        * Walk the block list and expand names into argv[];
+        * Walk the name list and expand names into eargv[];
         */
         */
-       for (bp = list; bp != NULL; bp = bp->b_next) {
-               expstr(bp->b_name);
-               free(bp->b_name);
-               free(bp);
-       }
+       for (nl = list; nl != NULL; nl = nl->n_next)
+               expstr(nl->n_name);
        /*
        /*
-        * Take expanded list of names from argv[] and build a block list.
+        * Take expanded list of names from eargv[] and build a new list.
         */
        list = prev = NULL;
         */
        list = prev = NULL;
-       for (n = 0; n < argc; n++) {
-               bp = ALLOC(block);
-               if (bp == NULL)
-                       fatal("ran out of memory\n");
-               bp->b_type = NAME;
-               bp->b_next = bp->b_args = NULL;
-               bp->b_name = argv[n];
+       for (n = 0; n < eargc; n++) {
+               nl = makenl(NULL);
+               nl->n_name = eargv[n];
                if (prev == NULL)
                if (prev == NULL)
-                       list = prev = bp;
+                       list = prev = nl;
                else {
                else {
-                       prev->b_next = bp;
-                       prev = bp;
+                       prev->n_next = nl;
+                       prev = nl;
                }
        }
        if (debug) {
                }
        }
        if (debug) {
@@ -97,10 +89,10 @@ expstr(s)
        char *s;
 {
        register char *cp, *cp1;
        char *s;
 {
        register char *cp, *cp1;
-       register struct block *tp;
+       register struct namelist *tp;
        char *tail;
        char buf[BUFSIZ];
        char *tail;
        char buf[BUFSIZ];
-       int savec, oargc;
+       int savec, oeargc;
        extern char homedir[];
 
        if (s == NULL || *s == '\0')
        extern char homedir[];
 
        if (s == NULL || *s == '\0')
@@ -131,9 +123,9 @@ expstr(s)
                tp = lookup(cp, NULL, 0);
                if (savec != '\0')
                        *tail = savec;
                tp = lookup(cp, NULL, 0);
                if (savec != '\0')
                        *tail = savec;
-               if ((tp = tp->b_args) != NULL) {
-                       for (; tp != NULL; tp = tp->b_next) {
-                               sprintf(buf, "%s%s%s", s, tp->b_name, tail);
+               if (tp != NULL) {
+                       for (; tp != NULL; tp = tp->n_next) {
+                               sprintf(buf, "%s%s%s", s, tp->n_name, tail);
                                expstr(buf);
                        }
                        return;
                                expstr(buf);
                        }
                        return;
@@ -184,10 +176,10 @@ expstr(s)
                sort();
                return;
        }
                sort();
                return;
        }
-       oargc = argc;
+       oeargc = eargc;
        expany = 0;
        expsh(s);
        expany = 0;
        expsh(s);
-       if (argc != oargc)
+       if (eargc != oeargc)
                sort();
 }
 
                sort();
 }
 
@@ -197,7 +189,7 @@ expstr(s)
 sort()
 {
        register char **p1, **p2, *c;
 sort()
 {
        register char **p1, **p2, *c;
-       char **ap = &argv[argc];
+       char **ap = &eargv[eargc];
 
        p1 = sortbase;
        while (p1 < ap-1) {
 
        p1 = sortbase;
        while (p1 < ap-1) {
@@ -532,10 +524,10 @@ Cat(s1, s2)
        register char *s;
 
        nleft -= len;
        register char *s;
 
        nleft -= len;
-       if (nleft <= 0 || ++argc >= GAVSIZ)
+       if (nleft <= 0 || ++eargc >= GAVSIZ)
                error("Arguments too long\n");
                error("Arguments too long\n");
-       argv[argc] = 0;
-       argv[argc - 1] = s = malloc(len);
+       eargv[eargc] = 0;
+       eargv[eargc - 1] = s = malloc(len);
        if (s == NULL)
                fatal("ran out of memory\n");
        while (*s++ = *s1++ & TRIM)
        if (s == NULL)
                fatal("ran out of memory\n");
        while (*s++ = *s1++ & TRIM)
index 323a3ec..0920c64 100644 (file)
@@ -1,12 +1,14 @@
 %{
 #ifndef lint
 %{
 #ifndef lint
-static char *sccsid = "@(#)gram.y      4.7 (Berkeley) 83/11/29";
+static char *sccsid = "@(#)gram.y      4.8 (Berkeley) 84/02/09";
 #endif
 
 #include "defs.h"
 
 #endif
 
 #include "defs.h"
 
-struct block *lastn;
-struct block *lastc;
+struct cmd *cmds = NULL;
+struct cmd *last_cmd;
+struct namelist *last_n;
+struct subcmd *last_sc;
 
 %}
 
 
 %}
 
@@ -25,15 +27,16 @@ struct      block *lastc;
 %term OPTION   13
 
 %union {
 %term OPTION   13
 
 %union {
-       struct block *blk;
        int intval;
        char *string;
        int intval;
        char *string;
+       struct subcmd *subcmd;
+       struct namelist *namel;
 }
 
 }
 
-%type <blk> NAME, INSTALL, NOTIFY, EXCEPT, SPECIAL
-%type <blk> namelist, names, opt_name, opt_namelist, cmdlist, cmd
 %type <intval> OPTION, options
 %type <intval> OPTION, options
-%type <string> STRING
+%type <string> NAME, STRING
+%type <subcmd> INSTALL, NOTIFY, EXCEPT, SPECIAL, cmdlist, cmd
+%type <namel> namelist, names, opt_namelist
 
 %%
 
 
 %%
 
@@ -42,20 +45,19 @@ file:                 /* VOID */
                ;
 
 command:         NAME EQUAL namelist = {
                ;
 
 command:         NAME EQUAL namelist = {
-                       $1->b_args = $3;
-                       (void) lookup($1->b_name, $1, 1);
+                       (void) lookup($1, INSERT, $3);
                }
                | namelist ARROW namelist cmdlist = {
                }
                | namelist ARROW namelist cmdlist = {
-                       dohcmds($1, $3, $4);
+                       insert($1, $3, $4);
                }
                | namelist DCOLON NAME cmdlist = {
                }
                | namelist DCOLON NAME cmdlist = {
-                       dofcmds($1, $3, $4);
+                       append($1, $3, $4);
                }
                | error
                ;
 
 namelist:        NAME = {
                }
                | error
                ;
 
 namelist:        NAME = {
-                       $$ = $1;
+                       $$ = makenl($1);
                }
                | LP names RP = {
                        $$ = $2;
                }
                | LP names RP = {
                        $$ = $2;
@@ -63,57 +65,60 @@ namelist:     NAME = {
                ;
 
 names:           /* VOID */ {
                ;
 
 names:           /* VOID */ {
-                       $$ = lastn = NULL;
+                       $$ = last_n = NULL;
                }
                | names NAME = {
                }
                | names NAME = {
-                       if (lastn == NULL)
-                               $$ = lastn = $2;
+                       if (last_n == NULL)
+                               $$ = last_n = makenl($2);
                        else {
                        else {
-                               lastn->b_next = $2;
-                               lastn = $2;
+                               last_n->n_next = makenl($2);
+                               last_n = last_n->n_next;
                                $$ = $1;
                        }
                }
                ;
 
 cmdlist:         /* VOID */ {
                                $$ = $1;
                        }
                }
                ;
 
 cmdlist:         /* VOID */ {
-                       $$ = lastc = NULL;
+                       $$ = last_sc = NULL;
                }
                | cmdlist cmd = {
                }
                | cmdlist cmd = {
-                       if (lastc == NULL)
-                               $$ = lastc = $2;
+                       if (last_sc == NULL)
+                               $$ = last_sc = $2;
                        else {
                        else {
-                               lastc->b_next = $2;
-                               lastc = $2;
+                               last_sc->sc_next = $2;
+                               last_sc = $2;
                                $$ = $1;
                        }
                }
                ;
 
                                $$ = $1;
                        }
                }
                ;
 
-cmd:             INSTALL options opt_name SM = {
-                       register struct block *b;
+cmd:             INSTALL options opt_namelist SM = {
+                       register struct namelist *nl;
 
 
-                       $1->b_options = $2 | options;
+                       $1->sc_options = $2 | options;
                        if ($3 != NULL) {
                        if ($3 != NULL) {
-                               b = expand($3, E_VARS|E_SHELL);
-                               if (b->b_next != NULL)
+                               nl = expand($3, E_VARS);
+                               if (nl->n_next != NULL)
                                        yyerror("only one name allowed\n");
                                        yyerror("only one name allowed\n");
-                               $1->b_name = b->b_name;
+                               $1->sc_name = nl->n_name;
+                               free(nl);
                        }
                        $$ = $1;
                }
                | NOTIFY namelist SM = {
                        }
                        $$ = $1;
                }
                | NOTIFY namelist SM = {
-                       $1->b_args = expand($2, E_VARS);
+                       if ($2 != NULL)
+                               $1->sc_args = expand($2, E_VARS);
                        $$ = $1;
                }
                | EXCEPT namelist SM = {
                        $$ = $1;
                }
                | EXCEPT namelist SM = {
-                       $1->b_args = $2;
+                       if ($2 != NULL)
+                               $1->sc_args = expand($2, E_ALL);
                        $$ = $1;
                }
                | SPECIAL opt_namelist STRING SM = {
                        if ($2 != NULL)
                        $$ = $1;
                }
                | SPECIAL opt_namelist STRING SM = {
                        if ($2 != NULL)
-                               $1->b_args = expand($2, E_ALL);
-                       $1->b_name = $3;
+                               $1->sc_args = expand($2, E_ALL);
+                       $1->sc_name = $3;
                        $$ = $1;
                }
                ;
                        $$ = $1;
                }
                ;
@@ -126,14 +131,6 @@ options:     /* VOID */ = {
                }
                ;
 
                }
                ;
 
-opt_name:        /* VOID */ = {
-                       $$ = NULL;
-               }
-               | NAME = {
-                       $$ = $1;
-               }
-               ;
-
 opt_namelist:    /* VOID */ = {
                        $$ = NULL;
                }
 opt_namelist:    /* VOID */ = {
                        $$ = NULL;
                }
@@ -212,13 +209,8 @@ again:
                }
                if (c != '"')
                        yyerror("missing closing '\"'\n");
                }
                if (c != '"')
                        yyerror("missing closing '\"'\n");
-               *cp1++ = '\0';
-               yylval.string = cp2 = malloc(cp1 - yytext);
-               if (cp2 == NULL)
-                       fatal("ran out of memory\n");
-               cp1 = yytext;
-               while (*cp2++ = *cp1++)
-                       ;
+               *cp1 = '\0';
+               yylval.string = makestr(yytext);
                return(STRING);
 
        case ':':  /* :: */
                return(STRING);
 
        case ':':  /* :: */
@@ -282,9 +274,11 @@ again:
                c = EXCEPT;
        else if (!strcmp(yytext, "special"))
                c = SPECIAL;
                c = EXCEPT;
        else if (!strcmp(yytext, "special"))
                c = SPECIAL;
-       else
-               c = NAME;
-       yylval.blk = makeblock(c, yytext);
+       else {
+               yylval.string = makestr(yytext);
+               return(NAME);
+       }
+       yylval.subcmd = makesubcmd(c);
        return(c);
 }
 
        return(c);
 }
 
@@ -298,6 +292,80 @@ any(c, str)
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Insert or append ARROW command to list of hosts to be updated.
+ */
+insert(files, hosts, subcmds)
+       struct namelist *files, *hosts;
+       struct subcmd *subcmds;
+{
+       register struct cmd *c, *prev, *nc;
+       register struct namelist *h;
+
+       files = expand(files, E_VARS|E_SHELL);
+       hosts = expand(hosts, E_ALL);
+       for (h = hosts; h != NULL; free(h), h = h->n_next) {
+               /*
+                * Search command list for an update to the same host.
+                */
+               for (prev = NULL, c = cmds; c!=NULL; prev = c, c = c->c_next) {
+                       if (strcmp(c->c_name, h->n_name) == 0) {
+                               do {
+                                       prev = c;
+                                       c = c->c_next;
+                               } while (c != NULL &&
+                                       strcmp(c->c_name, h->n_name) == 0);
+                               break;
+                       }
+               }
+               /*
+                * Insert new command to update host.
+                */
+               nc = ALLOC(cmd);
+               if (nc == NULL)
+                       fatal("ran out of memory\n");
+               nc->c_type = ARROW;
+               nc->c_name = h->n_name;
+               nc->c_files = files;
+               nc->c_cmds = subcmds;
+               nc->c_next = c;
+               if (prev == NULL)
+                       cmds = nc;
+               else
+                       prev->c_next = nc;
+               /* update last_cmd if appending nc to cmds */
+               if (c == NULL)
+                       last_cmd = nc;
+       }
+}
+
+/*
+ * Append DCOLON command to the end of the command list since these are always
+ * executed in the order they appear in the distfile.
+ */
+append(files, stamp, subcmds)
+       struct namelist *files;
+       char *stamp;
+       struct subcmd *subcmds;
+{
+       register struct cmd *c;
+
+       c = ALLOC(cmd);
+       if (c == NULL)
+               fatal("ran out of memory\n");
+       c->c_type = DCOLON;
+       c->c_name = stamp;
+       c->c_files = expand(files, E_ALL);
+       c->c_cmds = subcmds;
+       c->c_next = NULL;
+       if (cmds == NULL)
+               cmds = last_cmd = c;
+       else {
+               last_cmd->c_next = c;
+               last_cmd = c;
+       }
+}
+
 /*
  * Error printing routine in parser.
  */
 /*
  * Error printing routine in parser.
  */
@@ -306,7 +374,62 @@ yyerror(s)
 {
        extern int yychar;
 
 {
        extern int yychar;
 
-       errs++;
+       nerrs++;
        fflush(stdout);
        fprintf(stderr, "rdist: line %d: %s\n", yylineno, s);
 }
        fflush(stdout);
        fprintf(stderr, "rdist: line %d: %s\n", yylineno, s);
 }
+
+/*
+ * Return a copy of the string.
+ */
+char *
+makestr(str)
+       char *str;
+{
+       register char *cp, *s;
+
+       str = cp = malloc(strlen(s = str) + 1);
+       if (cp == NULL)
+               fatal("ran out of memory\n");
+       while (*cp++ = *s++)
+               ;
+       return(str);
+}
+
+/*
+ * Allocate a namelist structure.
+ */
+struct namelist *
+makenl(name)
+       char *name;
+{
+       register struct namelist *nl;
+
+       nl = ALLOC(namelist);
+       if (nl == NULL)
+               fatal("ran out of memory\n");
+       nl->n_name = name;
+       nl->n_next = NULL;
+       return(nl);
+}
+
+/*
+ * Make a sub command for lists of variables, commands, etc.
+ */
+struct subcmd *
+makesubcmd(type, name)
+       int type;
+       register char *name;
+{
+       register char *cp;
+       register struct subcmd *sc;
+
+       sc = ALLOC(subcmd);
+       if (sc == NULL)
+               fatal("ran out of memory\n");
+       sc->sc_type = type;
+       sc->sc_args = NULL;
+       sc->sc_next = NULL;
+       sc->sc_name = NULL;
+       return(sc);
+}
index 4fbba69..cebbb6f 100644 (file)
@@ -1,9 +1,22 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lookup.c    4.3 (Berkeley) 83/10/10";
+static char *sccsid = "@(#)lookup.c    4.4 (Berkeley) 84/02/09";
 #endif
 
 #include "defs.h"
 
 #endif
 
 #include "defs.h"
 
+       /* symbol types */
+#define VAR    1
+#define CONST  2
+
+struct syment {
+       int     s_type;
+       char    *s_name;
+       struct  namelist *s_value;
+       struct  syment *s_next;
+};
+
+static struct syment *hashtab[HASHSIZE];
+
 /*
  * Define a variable from a command line argument.
  */
 /*
  * Define a variable from a command line argument.
  */
@@ -11,7 +24,8 @@ define(name)
        char *name;
 {
        register char *cp, *s;
        char *name;
 {
        register char *cp, *s;
-       register struct block *bp, *value;
+       register struct namelist *nl;
+       struct namelist *value;
 
        if (debug)
                printf("define(%s)\n", name);
 
        if (debug)
                printf("define(%s)\n", name);
@@ -20,13 +34,13 @@ define(name)
        if (cp == NULL)
                value = NULL;
        else if (cp[1] == '\0') {
        if (cp == NULL)
                value = NULL;
        else if (cp[1] == '\0') {
-               *cp++ = '\0';
+               *cp = '\0';
                value = NULL;
        } else if (cp[1] != '(') {
                *cp++ = '\0';
                value = NULL;
        } else if (cp[1] != '(') {
                *cp++ = '\0';
-               value = makeblock(NAME, cp);
+               value = makenl(name);
        } else {
        } else {
-               bp = NULL;
+               nl = NULL;
                *cp++ = '\0';
                do
                        cp++;
                *cp++ = '\0';
                do
                        cp++;
@@ -48,95 +62,69 @@ define(name)
                        default:
                                continue;
                        }
                        default:
                                continue;
                        }
-                       if (bp == NULL)
-                               value = bp = makeblock(NAME, cp);
+                       if (nl == NULL)
+                               value = nl = makenl(cp);
                        else {
                        else {
-                               bp->b_next = makeblock(NAME, cp);
-                               bp = bp->b_next;
+                               nl->n_next = makenl(cp);
+                               nl = nl->n_next;
                        }
                        if (*s == '\0')
                                break;
                        cp = s;
                }
        }
                        }
                        if (*s == '\0')
                                break;
                        cp = s;
                }
        }
-       bp = makeblock(VAR, name);
-       bp->b_args = value;
-       (void) lookup(bp->b_name, bp, 1);
+       (void) lookup(name, REPLACE, value);
 }
 
 }
 
-static struct block *hashtab[HASHSIZE];
-
 /*
  * Lookup name in the table and return a pointer to it.
 /*
  * Lookup name in the table and return a pointer to it.
- * Insert == 0 - just do lookup, return NULL if not found.
- * insert == 1 - insert name with value, error if already defined.
- * insert == 2 - replace name with value if not entered with insert == 1.
+ * LOOKUP - just do lookup, return NULL if not found.
+ * INSERT - insert name with value, error if already defined.
+ * REPLACE - insert or replace name with value.
  */
 
  */
 
-struct block *
-lookup(name, value, insert)
+struct namelist *
+lookup(name, action, value)
        char *name;
        char *name;
-       struct block *value;
-       int insert;
+       int action;
+       struct namelist *value;
 {
        register unsigned n;
        register char *cp;
 {
        register unsigned n;
        register char *cp;
-       register struct block *b, *f;
+       register struct syment *s;
 
        if (debug)
 
        if (debug)
-               printf("lookup(%s, %x, %d)\n", name, value, insert);
+               printf("lookup(%s, %d, %x)\n", name, action, value);
 
        n = 0;
        for (cp = name; *cp; )
                n += *cp++;
        n %= HASHSIZE;
 
 
        n = 0;
        for (cp = name; *cp; )
                n += *cp++;
        n %= HASHSIZE;
 
-       for (b = hashtab[n]; b != NULL; b = b->b_next) {
-               if (strcmp(name, b->b_name))
+       for (s = hashtab[n]; s != NULL; s = s->s_next) {
+               if (strcmp(name, s->s_name))
                        continue;
                        continue;
-               if (insert) {
-                       if (b->b_type == NAME) {
-                               warn("%s redefined\n", name);
-                               f = b->b_args;
-                               b->b_args = value->b_args;
-                               value->b_args = f;
-                       } else if (value->b_type == VAR)
+               if (action != LOOKUP) {
+                       if (s->s_type == CONST)
                                fatal("%s redefined\n", name);
                                fatal("%s redefined\n", name);
+                       if (action == INSERT) {
+                               warn("%s redefined\n", name);
+                               s->s_value = value;
+                       }
                }
                }
-               return(b);
+               return(s->s_value);
        }
 
        }
 
-       if (!insert)
+       if (action == LOOKUP)
                fatal("%s not defined", name);
 
                fatal("%s not defined", name);
 
-       value->b_next = hashtab[n];
-       hashtab[n] = value;
-       return(value);
-}
-
-/*
- * Make a block for lists of variables, commands, etc.
- */
-struct block *
-makeblock(type, name)
-       int type;
-       register char *name;
-{
-       register char *cp;
-       register struct block *bp;
-
-       bp = ALLOC(block);
-       if (bp == NULL)
+       s = ALLOC(syment);
+       if (s == NULL)
                fatal("ran out of memory\n");
                fatal("ran out of memory\n");
-       bp->b_type = type;
-       bp->b_next = bp->b_args = NULL;
-       if (type == NAME || type == VAR) {
-               bp->b_name = cp = malloc(strlen(name) + 1);
-               if (cp == NULL)
-                       fatal("ran out of memory\n");
-               while (*cp++ = *name++)
-                       ;
-       } else
-               bp->b_name = NULL;
-       return(bp);
+       s->s_next = hashtab[n];
+       hashtab[n] = s;
+       s->s_type = action == INSERT ? VAR : CONST;
+       s->s_name = name;
+       s->s_value = value;
+       return(value);
 }
 }
index 6d1af62..8ab9ba8 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      4.9 (Berkeley) 83/11/29";
+static char *sccsid = "@(#)main.c      4.10 (Berkeley) 84/02/09";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -21,9 +21,9 @@ int   iamremote;      /* act as remote server for transfering files */
 int    filec;          /* number of files to update */
 char   **filev;        /* list of files/directories to update */
 FILE   *fin = NULL;    /* input file pointer */
 int    filec;          /* number of files to update */
 char   **filev;        /* list of files/directories to update */
 FILE   *fin = NULL;    /* input file pointer */
-int    rem = 0;        /* file descriptor to remote source/sink process */
+int    rem = -1;       /* file descriptor to remote source/sink process */
 char   host[32];       /* host name */
 char   host[32];       /* host name */
-int    errs;           /* number of errors while sending/receiving */
+int    nerrs;          /* number of errors while sending/receiving */
 char   user[10];       /* user's name */
 char   homedir[128];   /* user's home directory */
 int    userid;         /* user's user ID */
 char   user[10];       /* user's name */
 char   homedir[128];   /* user's home directory */
 int    userid;         /* user's user ID */
@@ -32,9 +32,6 @@ 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 */
 
 struct passwd *pw;     /* pointer to static area used by getpwent */
 struct group *gr;      /* pointer to static area used by getgrent */
 
-int    cleanup();
-int    lostconn();
-
 main(argc, argv)
        int argc;
        char *argv[];
 main(argc, argv)
        int argc;
        char *argv[];
@@ -123,30 +120,25 @@ main(argc, argv)
        }
 
        mktemp(tmpfile);
        }
 
        mktemp(tmpfile);
-       signal(SIGPIPE, lostconn);
+
        if (iamremote) {
                server();
        if (iamremote) {
                server();
-               exit(errs);
+               exit(nerrs);
        }
 
        }
 
-       signal(SIGHUP, cleanup);
-       signal(SIGINT, cleanup);
-       signal(SIGQUIT, cleanup);
-       signal(SIGTERM, cleanup);
-
        if (cmdargs)
                docmdargs(argc, argv);
        else {
        if (cmdargs)
                docmdargs(argc, argv);
        else {
-               filec = argc;
-               filev = argv;
                if (fin == NULL && (fin = fopen(distfile, "r")) == NULL) {
                        perror(distfile);
                        exit(1);
                }
                yyparse();
                if (fin == NULL && (fin = fopen(distfile, "r")) == NULL) {
                        perror(distfile);
                        exit(1);
                }
                yyparse();
+               if (nerrs == 0)
+                       docmds(argc, argv);
        }
 
        }
 
-       exit(errs);
+       exit(nerrs);
 }
 
 usage()
 }
 
 usage()
@@ -163,45 +155,40 @@ docmdargs(nargs, args)
        int nargs;
        char *args[];
 {
        int nargs;
        char *args[];
 {
-       struct block *bp, *files, *hosts, *cmds, *prev;
+       register struct namelist *nl, *prev;
+       register char *cp;
+       struct namelist *files, *hosts;
+       struct subcmd *cmds;
+       char *dest;
+       static struct namelist tnl = { NULL, NULL };
        int i;
        int i;
-       char *pos, dest[BUFSIZ];
 
        if (nargs < 2)
                usage();
 
        prev = NULL;
 
        if (nargs < 2)
                usage();
 
        prev = NULL;
-       bp = files = ALLOC(block);
-       for (i = 0; i < nargs - 1; bp = ALLOC(block), i++) {
-               bp->b_type = NAME;
-               bp->b_name = args[i];
-               if (prev != NULL)
-                       prev->b_next = bp;
-               bp->b_next = bp->b_args = NULL;
-               prev = bp;
+       for (i = 0; i < nargs - 1; i++) {
+               nl = makenl(args[i]);
+               if (prev == NULL)
+                       files = prev = nl;
+               else {
+                       prev->n_next = nl;
+                       prev = nl;
+               }
        }
 
        }
 
-       hosts = ALLOC(block);
-       hosts->b_type = NAME;
-       hosts->b_name = args[i];
-       hosts->b_name = args[i];
-       hosts->b_next = hosts->b_args = NULL;
-       if ((pos = index(hosts->b_name, ':')) != NULL) {
-               *pos++ = '\0';
-               strcpy(dest, pos);
-       } else
-               dest[0] = '\0';
-
-       hosts = expand(hosts, 1);
+       cp = args[i];
+       if ((dest = index(cp, ':')) != NULL)
+               *dest++ = '\0';
+       tnl.n_name = cp;
+       hosts = expand(&tnl, E_ALL);
 
 
-       if (dest[0] == '\0')
+       if (dest == NULL || *dest == '\0')
                cmds = NULL;
        else {
                cmds = NULL;
        else {
-               cmds = ALLOC(block);
-               cmds->b_type = INSTALL;
-               cmds->b_options = options;
-               cmds->b_name = dest;
-               cmds->b_next = cmds->b_args = NULL;
+               cmds = makesubcmd(INSTALL);
+               cmds->sc_options = options;
+               cmds->sc_name = dest;
        }
 
        if (debug) {
        }
 
        if (debug) {
@@ -210,28 +197,20 @@ docmdargs(nargs, args)
                printf("hosts = ");
                prnames(hosts);
        }
                printf("hosts = ");
                prnames(hosts);
        }
-       dohcmds(files, hosts, cmds);
-}
-
-/*
- * Remove temporary files and do any cleanup operations before exiting.
- */
-cleanup()
-{
-       (void) unlink(tmpfile);
-       exit(1);
+       insert(files, hosts, cmds);
+       docmds(0, NULL);
 }
 
 /*
  * Print a list of NAME blocks (mostly for debugging).
  */
 }
 
 /*
  * Print a list of NAME blocks (mostly for debugging).
  */
-prnames(bp)
-       register struct block *bp;
+prnames(nl)
+       register struct namelist *nl;
 {
        printf("( ");
 {
        printf("( ");
-       while (bp != NULL) {
-               printf("%s ", bp->b_name);
-               bp = bp->b_next;
+       while (nl != NULL) {
+               printf("%s ", nl->n_name);
+               nl = nl->n_next;
        }
        printf(")\n");
 }
        }
        printf(")\n");
 }
index f2ac3fe..887fc61 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)server.c    4.14 (Berkeley) 84/01/04";
+static char *sccsid = "@(#)server.c    4.15 (Berkeley) 84/02/09";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -16,6 +16,8 @@ int   oumask;                 /* old umask for creating files */
 
 extern FILE *lfp;              /* log file for mailing changes */
 
 
 extern FILE *lfp;              /* log file for mailing changes */
 
+int    cleanup();
+
 /*
  * Server routine to read requests and process them.
  * Commands are:
 /*
  * Server routine to read requests and process them.
  * Commands are:
@@ -28,6 +30,13 @@ server()
        char cmdbuf[BUFSIZ];
        register char *cp;
 
        char cmdbuf[BUFSIZ];
        register char *cp;
 
+       signal(SIGHUP, cleanup);
+       signal(SIGINT, cleanup);
+       signal(SIGQUIT, cleanup);
+       signal(SIGTERM, cleanup);
+       signal(SIGPIPE, cleanup);
+
+       rem = 0;
        oumask = umask(0);
        (void) sprintf(buf, "V%d\n", VERSION);
        (void) write(rem, buf, strlen(buf));
        oumask = umask(0);
        (void) sprintf(buf, "V%d\n", VERSION);
        (void) write(rem, buf, strlen(buf));
@@ -42,7 +51,7 @@ server()
                }
                do {
                        if (read(rem, cp, 1) != 1)
                }
                do {
                        if (read(rem, cp, 1) != 1)
-                               lostconn();
+                               cleanup();
                } while (*cp++ != '\n' && cp < &cmdbuf[BUFSIZ]);
                *--cp = '\0';
                cp = cmdbuf;
                } while (*cp++ != '\n' && cp < &cmdbuf[BUFSIZ]);
                *--cp = '\0';
                cp = cmdbuf;
@@ -137,7 +146,7 @@ server()
 #endif
 
                case '\1':
 #endif
 
                case '\1':
-                       errs++;
+                       nerrs++;
                        continue;
 
                case '\2':
                        continue;
 
                case '\2':
@@ -222,11 +231,11 @@ sendf(rname, opts)
        char *rname;
        int opts;
 {
        char *rname;
        int opts;
 {
-       register struct block *c;
+       register struct subcmd *sc;
        struct stat stb;
        int sizerr, f, u;
        off_t i;
        struct stat stb;
        int sizerr, f, u;
        off_t i;
-       extern struct block *special;
+       extern struct subcmd *special;
 
        if (debug)
                printf("sendf(%s, %x)\n", rname, opts);
 
        if (debug)
                printf("sendf(%s, %x)\n", rname, opts);
@@ -319,15 +328,15 @@ sendf(rname, opts)
        if (response() == 0 && (opts & COMPARE))
                return;
 dospecial:
        if (response() == 0 && (opts & COMPARE))
                return;
 dospecial:
-       for (c = special; c != NULL; c = c->b_next) {
-               if (c->b_type != SPECIAL)
+       for (sc = special; sc != NULL; sc = sc->sc_next) {
+               if (sc->sc_type != SPECIAL)
                        continue;
                        continue;
-               if (!inlist(c->b_args, target))
+               if (!inlist(sc->sc_args, target))
                        continue;
                        continue;
-               log(lfp, "special \"%s\"\n", c->b_name);
+               log(lfp, "special \"%s\"\n", sc->sc_name);
                if (opts & VERIFY)
                        continue;
                if (opts & VERIFY)
                        continue;
-               (void) sprintf(buf, "S%s\n", c->b_name);
+               (void) sprintf(buf, "S%s\n", sc->sc_name);
                if (debug)
                        printf("buf = %s", buf);
                (void) write(rem, buf, strlen(buf));
                if (debug)
                        printf("buf = %s", buf);
                (void) write(rem, buf, strlen(buf));
@@ -419,7 +428,7 @@ update(rname, opts, st)
        cp = s = buf;
        do {
                if (read(rem, cp, 1) != 1)
        cp = s = buf;
        do {
                if (read(rem, cp, 1) != 1)
-                       lostconn();
+                       cleanup();
        } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
        switch (*s++) {
        } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
        switch (*s++) {
@@ -430,7 +439,7 @@ update(rname, opts, st)
                return(1);
 
        case '\1':
                return(1);
 
        case '\1':
-               errs++;
+               nerrs++;
                if (*s != '\n') {
                        if (!iamremote) {
                                fflush(stdout);
                if (*s != '\n') {
                        if (!iamremote) {
                                fflush(stdout);
@@ -874,7 +883,7 @@ rmchk(opts)
                cp = s = buf;
                do {
                        if (read(rem, cp, 1) != 1)
                cp = s = buf;
                do {
                        if (read(rem, cp, 1) != 1)
-                               lostconn();
+                               cleanup();
                } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
                switch (*s++) {
                } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
                switch (*s++) {
@@ -909,7 +918,7 @@ rmchk(opts)
 
                case '\1':
                case '\2':
 
                case '\1':
                case '\2':
-                       errs++;
+                       nerrs++;
                        if (*s != '\n') {
                                if (!iamremote) {
                                        fflush(stdout);
                        if (*s != '\n') {
                                if (!iamremote) {
                                        fflush(stdout);
@@ -979,7 +988,7 @@ clean(cp)
                cp = buf;
                do {
                        if (read(rem, cp, 1) != 1)
                cp = buf;
                do {
                        if (read(rem, cp, 1) != 1)
-                               lostconn();
+                               cleanup();
                } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
                *--cp = '\0';
                cp = buf;
                } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
                *--cp = '\0';
                cp = buf;
@@ -1153,7 +1162,7 @@ error(fmt, a1, a2, a3)
        char *fmt;
        int a1, a2, a3;
 {
        char *fmt;
        int a1, a2, a3;
 {
-       errs++;
+       nerrs++;
        strcpy(buf, "\1rdist: ");
        (void) sprintf(buf+8, fmt, a1, a2, a3);
        if (!iamremote) {
        strcpy(buf, "\1rdist: ");
        (void) sprintf(buf+8, fmt, a1, a2, a3);
        if (!iamremote) {
@@ -1170,7 +1179,7 @@ fatal(fmt, a1, a2,a3)
        char *fmt;
        int a1, a2, a3;
 {
        char *fmt;
        int a1, a2, a3;
 {
-       errs++;
+       nerrs++;
        strcpy(buf, "\2rdist: ");
        (void) sprintf(buf+8, fmt, a1, a2, a3);
        if (!iamremote) {
        strcpy(buf, "\2rdist: ");
        (void) sprintf(buf+8, fmt, a1, a2, a3);
        if (!iamremote) {
@@ -1193,7 +1202,7 @@ response()
        cp = s = buf;
        do {
                if (read(rem, cp, 1) != 1)
        cp = s = buf;
        do {
                if (read(rem, cp, 1) != 1)
-                       lostconn();
+                       cleanup();
        } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
        switch (*s++) {
        } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
        switch (*s++) {
@@ -1210,7 +1219,7 @@ response()
                /* fall into... */
        case '\1':
        case '\2':
                /* fall into... */
        case '\1':
        case '\2':
-               errs++;
+               nerrs++;
                if (*s != '\n') {
                        if (!iamremote) {
                                fflush(stdout);
                if (*s != '\n') {
                        if (!iamremote) {
                                fflush(stdout);
@@ -1225,11 +1234,11 @@ response()
        }
 }
 
        }
 }
 
-lostconn()
+/*
+ * Remove temporary files and do any cleanup operations before exiting.
+ */
+cleanup()
 {
 {
-       if (!iamremote) {
-               fflush(stdout);
-               fprintf(stderr, "rdist: lost connection\n");
-       }
-       cleanup();
+       (void) unlink(tmpfile);
+       exit(1);
 }
 }