fix multiple connections to same (down) host and loss of connection.
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Thu, 15 Mar 1984 03:46:59 +0000 (19:46 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Thu, 15 Mar 1984 03:46:59 +0000 (19:46 -0800)
SCCS-vsn: usr.bin/rdist/docmd.c 4.17
SCCS-vsn: usr.bin/rdist/server.c 4.16

usr/src/usr.bin/rdist/docmd.c
usr/src/usr.bin/rdist/server.c

index 60c09bd..a6d5e66 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)docmd.c     4.16 (Berkeley) 84/03/13";
+static char *sccsid = "@(#)docmd.c     4.17 (Berkeley) 84/03/14";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -70,7 +70,7 @@ doarrow(files, rhost, cmds)
        if (nflag)
                printf("updating host %s\n", rhost);
        else {
        if (nflag)
                printf("updating host %s\n", rhost);
        else {
-               if (setjmp(env) != 0)
+               if (setjmp(env))
                        goto done;
                signal(SIGPIPE, lostconn);
                if (!makeconn(rhost))
                        goto done;
                signal(SIGPIPE, lostconn);
                if (!makeconn(rhost))
@@ -107,7 +107,7 @@ doarrow(files, rhost, cmds)
        }
 done:
        if (!nflag) {
        }
 done:
        if (!nflag) {
-               (void) signal(SIGPIPE, SIG_DFL);
+               (void) signal(SIGPIPE, cleanup);
                (void) fclose(lfp);
                lfp = NULL;
        }
                (void) fclose(lfp);
                lfp = NULL;
        }
@@ -132,10 +132,12 @@ makeconn(rhost)
        if (debug)
                printf("makeconn(%s)\n", rhost);
 
        if (debug)
                printf("makeconn(%s)\n", rhost);
 
-       if (cur_host != NULL && strcmp(cur_host, rhost) == 0)
-               return(1);
-
-       closeconn();
+       if (cur_host != NULL && rem >= 0) {
+               if (strcmp(cur_host, rhost) == 0)
+                       return(1);
+               closeconn();
+               cur_host = NULL;
+       }
 
        ruser = rindex(rhost, '.');
        if (ruser != NULL) {
 
        ruser = rindex(rhost, '.');
        if (ruser != NULL) {
@@ -146,7 +148,6 @@ makeconn(rhost)
                ruser = user;
        if (!qflag)
                printf("updating host %s\n", rhost);
                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) {
        (void) sprintf(buf, "/usr/local/rdist -Server%s", qflag ? " -q" : "");
 
        if (debug) {
@@ -171,8 +172,10 @@ makeconn(rhost)
                n = 0;
                while (*cp >= '0' && *cp <= '9')
                        n = (n * 10) + (*cp++ - '0');
                n = 0;
                while (*cp >= '0' && *cp <= '9')
                        n = (n * 10) + (*cp++ - '0');
-               if (*cp == '\0' && n == VERSION)
+               if (*cp == '\0' && n == VERSION) {
+                       cur_host = rhost;
                        return(1);
                        return(1);
+               }
        }
        error("connection failed: version numbers don't match\n");
        return(0);
        }
        error("connection failed: version numbers don't match\n");
        return(0);
@@ -195,8 +198,9 @@ closeconn()
 
 lostconn()
 {
 
 lostconn()
 {
-       fflush(stdout);
-       fprintf(stderr, "rdist: lost connection\n");
+       if (iamremote)
+               cleanup();
+       log(lfp, "rdist: lost connection\n");
        longjmp(env, 1);
 }
 
        longjmp(env, 1);
 }
 
index 887fc61..792412d 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)server.c    4.15 (Berkeley) 84/02/09";
+static char *sccsid = "@(#)server.c    4.16 (Berkeley) 84/03/14";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -428,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)
-                       cleanup();
+                       lostconn();
        } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
        switch (*s++) {
        } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
        switch (*s++) {
@@ -883,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)
-                               cleanup();
+                               lostconn();
                } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
                switch (*s++) {
                } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
                switch (*s++) {
@@ -928,7 +928,7 @@ rmchk(opts)
                                        (void) fwrite(s, 1, cp - s, lfp);
                        }
                        if (buf[0] == '\2')
                                        (void) fwrite(s, 1, cp - s, lfp);
                        }
                        if (buf[0] == '\2')
-                               cleanup();
+                               lostconn();
                        break;
 
                default:
                        break;
 
                default:
@@ -1202,7 +1202,7 @@ response()
        cp = s = buf;
        do {
                if (read(rem, cp, 1) != 1)
        cp = s = buf;
        do {
                if (read(rem, cp, 1) != 1)
-                       cleanup();
+                       lostconn();
        } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
        switch (*s++) {
        } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
 
        switch (*s++) {
@@ -1229,7 +1229,7 @@ response()
                                (void) fwrite(s, 1, cp - s, lfp);
                }
                if (buf[0] == '\2')
                                (void) fwrite(s, 1, cp - s, lfp);
                }
                if (buf[0] == '\2')
-                       cleanup();
+                       lostconn();
                return(-1);
        }
 }
                return(-1);
        }
 }