added labels for partial updates.
[unix-history] / usr / src / usr.bin / rdist / main.c
index dc8bc82..2ec01c8 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      4.7 (Berkeley) 83/10/26";
+static char *sccsid = "@(#)main.c      4.11 (Berkeley) 84/04/09";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -9,9 +9,8 @@ static  char *sccsid = "@(#)main.c      4.7 (Berkeley) 83/10/26";
  */
 
 char   *distfile = "distfile";
  */
 
 char   *distfile = "distfile";
-char   tmpfile[] = "/tmp/rdistAXXXXXX";
+char   tmpfile[] = "/tmp/rdistXXXXXX";
 char   *tmpname = &tmpfile[5];
 char   *tmpname = &tmpfile[5];
-char   *tmpinc = &tmpfile[10];
 
 int    debug;          /* debugging flag */
 int    nflag;          /* NOP flag, just print commands without executing */
 
 int    debug;          /* debugging flag */
 int    nflag;          /* NOP flag, just print commands without executing */
@@ -19,26 +18,23 @@ int qflag;          /* Quiet. Don't print messages */
 int    options;        /* global options */
 int    iamremote;      /* act as remote server for transfering files */
 
 int    options;        /* global options */
 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 */
 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 */
 int    groupid;        /* user's group ID */
 
 char   user[10];       /* user's name */
 char   homedir[128];   /* user's home directory */
 int    userid;         /* user's user ID */
 int    groupid;        /* user's group ID */
 
-int    cleanup();
-int    lostconn();
+struct passwd *pw;     /* pointer to static area used by getpwent */
+struct group *gr;      /* pointer to static area used by getgrent */
 
 main(argc, argv)
        int argc;
        char *argv[];
 {
        register char *arg;
 
 main(argc, argv)
        int argc;
        char *argv[];
 {
        register char *arg;
-       register struct passwd *pw;
        int cmdargs = 0;
 
        pw = getpwuid(userid = getuid());
        int cmdargs = 0;
 
        pw = getpwuid(userid = getuid());
@@ -81,6 +77,10 @@ main(argc, argv)
                                break;
 
                        case 'n':
                                break;
 
                        case 'n':
+                               if (options & VERIFY) {
+                                       printf("rdist: -n overrides -v\n");
+                                       options &= ~VERIFY;
+                               }
                                nflag++;
                                break;
 
                                nflag++;
                                break;
 
@@ -92,11 +92,15 @@ main(argc, argv)
                                options |= COMPARE;
                                break;
 
                                options |= COMPARE;
                                break;
 
-                       case 'r':
+                       case 'R':
                                options |= REMOVE;
                                break;
 
                        case 'v':
                                options |= REMOVE;
                                break;
 
                        case 'v':
+                               if (nflag) {
+                                       printf("rdist: -n overrides -v\n");
+                                       break;
+                               }
                                options |= VERIFY;
                                break;
 
                                options |= VERIFY;
                                break;
 
@@ -114,30 +118,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()
@@ -154,45 +153,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';
+       cp = args[i];
+       if ((dest = index(cp, ':')) != NULL)
+               *dest++ = '\0';
+       tnl.n_name = cp;
+       hosts = expand(&tnl, E_ALL);
 
 
-       hosts = expand(hosts, 0);
-
-       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) {
@@ -201,31 +195,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()
-{
-       do {
-               (void) unlink(tmpfile);
-               (*tmpinc)--;
-       } while (*tmpinc >= 'A');
-       exit(1);
+       insert(NULL, 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");
 }