X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/951e826b75c4a4e6bc066e248d7489fb6eba6fde..9411292489496984c8d5d9a446bf071afac3866d:/socket.c diff --git a/socket.c b/socket.c index 2b3271cf..0ad766d2 100644 --- a/socket.c +++ b/socket.c @@ -25,7 +25,7 @@ * emulate it using the KAME implementation. */ #include "rsync.h" -#include "ifuncs.h" +#include "itypes.h" #include #include #include @@ -823,6 +823,7 @@ static int socketpair_tcp(int fd[2]) **/ int sock_exec(const char *prog) { + pid_t pid; int fd[2]; if (socketpair_tcp(fd) != 0) { @@ -831,14 +832,23 @@ int sock_exec(const char *prog) } if (DEBUG_GTE(CMD, 1)) rprintf(FINFO, "Running socket program: \"%s\"\n", prog); - if (fork() == 0) { + + pid = fork(); + if (pid < 0) { + rsyserr(FERROR, errno, "fork"); + exit_cleanup(RERR_IPC); + } + + if (pid == 0) { close(fd[0]); - close(0); - close(1); - dup(fd[1]); - dup(fd[1]); + if (dup2(fd[1], STDIN_FILENO) < 0 + || dup2(fd[1], STDOUT_FILENO) < 0) { + fprintf(stderr, "Failed to run \"%s\"\n", prog); + exit(1); + } exit(system(prog)); } + close(fd[1]); return fd[0]; }