On 2019-06-02, Hiltjo Posthuma <hil...@codemadness.org> wrote:

> I noticed when using openrsync with a remote and a ssh_prog set (-e option) 
> the
> socket is closed twice also.

Yes, we need to decide whether rsync_socket() should close the
socket itself or not.  Since rsync_socket() doesn't open the socket,
I guess it shouldn't close it either.  Matches rsync_client().

ok?

Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/rsync/main.c,v
retrieving revision 1.46
diff -u -p -r1.46 main.c
--- main.c      28 May 2019 18:20:30 -0000      1.46
+++ main.c      3 Jun 2019 14:30:06 -0000
@@ -428,8 +428,10 @@ main(int argc, char *argv[])
 
        if (fargs->remote && opts.ssh_prog == NULL) {
                assert(fargs->mode == FARGS_RECEIVER);
-               if ((rc = rsync_connect(&opts, &sd, fargs)) == 0)
+               if ((rc = rsync_connect(&opts, &sd, fargs)) == 0) {
                        rc = rsync_socket(&opts, sd, fargs);
+                       close(sd);
+               }
                exit(rc);
        }
 
@@ -484,14 +486,7 @@ main(int argc, char *argv[])
                break;
        }
 
-       /*
-        * If the client has an error and exits, the server may be
-        * sitting around waiting to get data while we waitpid().
-        * So close the connection here so that they don't hang.
-        */
-
-       if (rc)
-               close(fds[0]);
+       close(fds[0]);
 
        if (waitpid(child, &st, 0) == -1)
                err(1, "waitpid");
Index: socket.c
===================================================================
RCS file: /cvs/src/usr.bin/rsync/socket.c,v
retrieving revision 1.24
diff -u -p -r1.24 socket.c
--- socket.c    8 May 2019 21:30:11 -0000       1.24
+++ socket.c    3 Jun 2019 14:26:44 -0000
@@ -455,6 +455,5 @@ rsync_socket(const struct opts *opts, in
        rc = 0;
 out:
        free(args);
-       close(sd);
        return rc;
 }
-- 
Christian "naddy" Weisgerber                          na...@mips.inka.de

Reply via email to