switch to using socketpair instead of pipe if possible. This fixes the
[rsync/rsync.git] / util.c
diff --git a/util.c b/util.c
index a010165..a0e2707 100644 (file)
--- a/util.c
+++ b/util.c
 
 extern int verbose;
 
+/* create a file descriptor - like pipe() but use socketpair if
+   possible (because of blocking issues on pipes */
+int fd_pair(int fd[2])
+{
+#if HAVE_SOCKETPAIR
+       return socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
+#else
+       return pipe(fd);
+#endif
+}
+
+
 /* this is taken from CVS */
 int piped_child(char **command,int *f_in,int *f_out)
 {
@@ -33,8 +45,8 @@ int piped_child(char **command,int *f_in,int *f_out)
   int to_child_pipe[2];
   int from_child_pipe[2];
 
-  if (pipe(to_child_pipe) < 0 ||
-      pipe(from_child_pipe) < 0) {
+  if (fd_pair(to_child_pipe) < 0 ||
+      fd_pair(from_child_pipe) < 0) {
     rprintf(FERROR,"pipe: %s\n",strerror(errno));
     exit_cleanup(RERR_IPC);
   }
@@ -83,8 +95,8 @@ int local_child(int argc, char **argv,int *f_in,int *f_out)
        int to_child_pipe[2];
        int from_child_pipe[2];
 
-       if (pipe(to_child_pipe) < 0 ||
-           pipe(from_child_pipe) < 0) {
+       if (fd_pair(to_child_pipe) < 0 ||
+           fd_pair(from_child_pipe) < 0) {
                rprintf(FERROR,"pipe: %s\n",strerror(errno));
                exit_cleanup(RERR_IPC);
        }
@@ -367,17 +379,6 @@ int robust_rename(char *from, char *to)
                return -1;
        return do_rename(from, to);
 #endif
-    }
-
-
-/* sleep for a while via select */
-void u_sleep(int usec)
-{
-       struct timeval tv;
-
-       tv.tv_sec = 0;
-       tv.tv_usec = usec;
-       select(0, NULL, NULL, NULL, &tv);
 }
 
 
@@ -778,12 +779,12 @@ int u_strcmp(const char *cs1, const char *cs2)
 
 static OFF_T last_ofs;
 
-void end_progress(void)
+void end_progress(OFF_T size)
 {
        extern int do_progress, am_server;
 
        if (do_progress && !am_server) {
-               rprintf(FINFO,"\n");
+               rprintf(FINFO,"%.0f (100%%)\n", (double)size);
        }
        last_ofs = 0;
 }
@@ -870,3 +871,15 @@ char *timestring(time_t t)
        return(TimeBuf);
 }
 
+
+/****************************************************************************
+ like waitpid but does the WEXITSTATUS
+****************************************************************************/
+#ifndef WEXITSTATUS
+#define        WEXITSTATUS(stat)       ((int)(((stat)>>8)&0xFF))
+#endif
+void wait_process(pid_t pid, int *status)
+{
+       waitpid(pid, status, 0);
+       *status = WEXITSTATUS(*status);
+}