delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/08/13/21:58:00

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <4A84C48E.9070006@sipxx.com>
Date: Thu, 13 Aug 2009 21:57:34 -0400
From: cygwin <karl AT sipxx DOT com>
Reply-To: cygwin AT sipxx DOT com
User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
CC: cygwin AT sipxx DOT com
Subject: Re: Cygwin1.dll 1.7.0-5x: RSYNC failures in close() system call on pipe file descriptors
References: <4A844A97 DOT 1050809 AT sipxx DOT com> <20090813183053 DOT GU13438 AT calimero DOT vinschen DOT de> <4A848D0A DOT 1000900 AT sipxx DOT com>
In-Reply-To: <4A848D0A.1000900@sipxx.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

I wrote a small test program to isolate the problem from RSYNC.
The problem occurs when a file descriptor obtained from socketpair()  is 
dup2()'ed into STDIN and then closed. The close call fails.
Output from the program is as follows:

socket 1 = 3
socket 2 = 4
dup2 socket 1...
closing socket 1...
close: Socket operation on non-socket
closing socket 1 failed


It is interesting to note that the close() is successful when the dup2 
calling sequence is omitted.
Since socketpair() in cygwin appears to use AF_INET sockets to simulate 
AF_UNIX it might be interesting to try this on a single INET socket.



===============================================
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>

main()
{
        int fd[2];
        int res = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
        if (res < 0) {
                perror("socketpair");
                fprintf(stderr, "socketpair failed\n");
                exit(1);
        }

        fprintf(stderr, "socket 1 = %d\n", fd[0]);
        fprintf(stderr, "socket 2 = %d\n", fd[1]);

        fprintf(stderr, "dup2 socket 1...\n");
        res = dup2(fd[0], STDIN_FILENO);
        if (res < 0) {
                perror("dup2");
                fprintf(stderr, "dup2 failed\n");
        }

        fprintf(stderr, "closing socket 1...\n");
        res = close(fd[0] < 0);
        if (res < 0) {
                perror("close");
                fprintf(stderr, "closing socket 1 failed\n");
        }
}
=====================================================







cygwin wrote:
>
> After updating 2 other systems to cygwin 1.7, I find that they also 
> work fine in the same test.
> However, that doesn't help much debugging this.
>
> I found that the problem on the failing system is related to using 
> Unix domain sockets for the IPC pipes.
> If I replace the socketpair() call  in fd_pair() in file util.c with 
> pipe(), everything works fine.
>
> int fd_pair(int fd[2])
> {
>        int ret;
>
> //#ifdef HAVE_SOCKETPAIR
> //      ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
> //#else
>        ret = pipe(fd);
> //#endif
>
>        if (ret == 0) {
>                set_nonblocking(fd[0]);
>                set_nonblocking(fd[1]);
>        }
>
>        return ret;
> }
>
> The fact that cygwin 1.5 works fine on this system indicates that 
> something is going wrong in 1.7 cygwin1.dll triggered by some 
> conditions on this particular system.
>
>
>
>
> Corinna Vinschen wrote:
>> On Aug 13 13:17, cygwin wrote:
>>  
>>> The RSYNC application fails in close() on the pipe streams to and 
>>> from  child processes created when rsync starts.
>>> When running rsync.exe and cygwin1.dll from cygwin 1.5 within the 
>>> 1.7  installation on the same system (WinXP pro),
>>> the identical invocation completes without errors.
>>>
>>> The problems appears to be a bug in the cygwin.dll
>>>
>>> For example,
>>>
>>> $ rsync -a /etc /test
>>>
>>> produces the following messages:
>>>
>>> rsync: Failed to dup/close: Socket operation on non-socket (108)
>>> rsync error: error in IPC code (code 14) at pipe.c(147) 
>>> [receiver=3.0.5]
>>> rsync: read error: Connection reset by peer (104)
>>> rsync error: error in IPC code (code 14) at io.c(759) [sender=3.0.5]
>>>     
>>
>> I tested the exact above command with cygwin 1.7-0-58 and rsync-3.0.5-1
>> on Windows 7, WIndows Server 2008 SP2, as well as on XP SP3.
>>
>> Works fine for me on all three systems.
>>
>>
>> Corinna
>>
>>   
>
>


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019