summaryrefslogtreecommitdiff
path: root/socket.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2008-11-09 18:46:55 -0800
committerWayne Davison <wayned@samba.org>2008-11-09 18:56:21 -0800
commit9411292489496984c8d5d9a446bf071afac3866d (patch)
treea68d29f7e1387a01ecbd0daaff821b3fe3d3b799 /socket.c
parentb4de848d75b5bc289f13c4f47a4f78d4c876b1a2 (diff)
downloadrsync-9411292489496984c8d5d9a446bf071afac3866d.tar.gz
rsync-9411292489496984c8d5d9a446bf071afac3866d.tar.bz2
rsync-9411292489496984c8d5d9a446bf071afac3866d.zip
Fixed a bunch of "warn_unused_result" compiler warnings.
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/socket.c b/socket.c
index 87b1ec34..0ad766d2 100644
--- a/socket.c
+++ b/socket.c
@@ -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];
}