Fix --remove-source-files sanity check w/--copy-links the right way.
[rsync.git] / socket.c
index c19412d256b4e14d87f2f8312703308ee731f1bd..4cc88fde52dd7928b1499a57404fc1be06fac500 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1992-2001 Andrew Tridgell <tridge@samba.org>
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2009 Wayne Davison
+ * Copyright (C) 2003-2018 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 #include "rsync.h"
 #include "itypes.h"
+#ifdef HAVE_NETINET_IN_SYSTM_H
 #include <netinet/in_systm.h>
+#endif
+#ifdef HAVE_NETINET_IP_H
 #include <netinet/ip.h>
+#endif
 #include <netinet/tcp.h>
 
 extern char *bind_address;
@@ -157,7 +161,7 @@ int try_bind_local(int s, int ai_family, int ai_socktype,
 }
 
 /* connect() timeout handler based on alarm() */
-static RETSIGTYPE contimeout_handler(UNUSED(int val))
+static void contimeout_handler(UNUSED(int val))
 {
        connect_timeout = -1;
 }
@@ -297,22 +301,29 @@ int open_socket_out(char *host, int port, const char *bind_addr,
                        s = -1;
                        continue;
                }
+               if (DEBUG_GTE(CONNECT, 2)) {
+                       char buf[2048];
+                       if ((error = getnameinfo(res->ai_addr, res->ai_addrlen, buf, sizeof buf, NULL, 0, NI_NUMERICHOST)) != 0)
+                               snprintf(buf, sizeof buf, "*getnameinfo failure: %s*", gai_strerror(error));
+                       rprintf(FINFO, "Connected to %s (%s)\n", h, buf);
+               }
                break;
        }
-       freeaddrinfo(res0);
 
-       if (s < 0) {
+       if (s < 0 || DEBUG_GTE(CONNECT, 2)) {
                char buf[2048];
                for (res = res0, j = 0; res; res = res->ai_next, j++) {
                        if (errnos[j] == 0)
                                continue;
-                       if (inet_ntop(res->ai_family, res->ai_addr->sa_data + 2, buf, sizeof buf) == NULL)
-                               strlcpy(buf, "*inet_ntop failed*", sizeof buf);
+                       if ((error = getnameinfo(res->ai_addr, res->ai_addrlen, buf, sizeof buf, NULL, 0, NI_NUMERICHOST)) != 0)
+                               snprintf(buf, sizeof buf, "*getnameinfo failure: %s*", gai_strerror(error));
                        rsyserr(FERROR, errnos[j], "failed to connect to %s (%s)", h, buf);
                }
-               s = -1;
+               if (s < 0)
+                       s = -1;
        }
 
+       freeaddrinfo(res0);
        free(errnos);
 
        return s;
@@ -518,7 +529,7 @@ int is_a_socket(int fd)
 }
 
 
-static RETSIGTYPE sigchld_handler(UNUSED(int val))
+static void sigchld_handler(UNUSED(int val))
 {
 #ifdef WNOHANG
        while (waitpid(-1, NULL, WNOHANG) > 0) {}
@@ -635,7 +646,9 @@ struct
 } socket_options[] = {
   {"SO_KEEPALIVE",      SOL_SOCKET,    SO_KEEPALIVE,    0,                 OPT_BOOL},
   {"SO_REUSEADDR",      SOL_SOCKET,    SO_REUSEADDR,    0,                 OPT_BOOL},
+#ifdef SO_BROADCAST
   {"SO_BROADCAST",      SOL_SOCKET,    SO_BROADCAST,    0,                 OPT_BOOL},
+#endif
 #ifdef TCP_NODELAY
   {"TCP_NODELAY",       IPPROTO_TCP,   TCP_NODELAY,     0,                 OPT_BOOL},
 #endif
@@ -834,7 +847,7 @@ static int sock_exec(const char *prog)
                        fprintf(stderr, "Failed to run \"%s\"\n", prog);
                        exit(1);
                }
-               exit(system(prog));
+               exit(shell_exec(prog));
        }
 
        close(fd[1]);