extern int verbose;
-/****************************************************************************
-Set a fd into nonblocking mode. Uses POSIX O_NONBLOCK if available,
-else
-if SYSV use O_NDELAY
-if BSD use FNDELAY
-****************************************************************************/
-int set_nonblocking(int fd)
+/* create a file descriptor - like pipe() but use socketpair if
+ possible (because of blocking issues on pipes */
+int fd_pair(int fd[2])
{
- int val;
-#ifdef O_NONBLOCK
-#define FLAG_TO_SET O_NONBLOCK
+#if HAVE_SOCKETPAIR
+ return socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
#else
-#ifdef SYSV
-#define FLAG_TO_SET O_NDELAY
-#else /* BSD */
-#define FLAG_TO_SET FNDELAY
-#endif
+ return pipe(fd);
#endif
-
- if((val = fcntl(fd, F_GETFL, 0)) == -1)
- return -1;
- val |= FLAG_TO_SET;
- return fcntl( fd, F_SETFL, val);
-#undef FLAG_TO_SET
}
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);
}
*f_in = from_child_pipe[0];
*f_out = to_child_pipe[1];
- set_nonblocking(*f_in);
- set_nonblocking(*f_out);
-
return pid;
}
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);
}
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);
}
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;
}
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);
+}