public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Pipes Again -- a simple test case
@ 2016-01-04  8:03 Houder
  2016-01-04  8:52 ` Marco Atzeri
  0 siblings, 1 reply; 11+ messages in thread
From: Houder @ 2016-01-04  8:03 UTC (permalink / raw)
  To: cygwin

Hi Corinna,

I have been looking for an STC to show why cmp fails on Cygwin (and to 
show the
difference between Cygwin and Linux).

The STC below creates a pipe (pipe() is used), followed by calls to 
fstat() and
stat() for both the read end and the write end of the pipe.

(I also tested with popen()/pclose(): same result)

Regards,
Henri

Btw, I am using W7 prof.; Cygwin-32 and Cygwin-64; 2.3.1 and 2.4.0

=====

The code for the STC is basically as follows:

int
main()
{
     struct stat sb[2];
     int pfd[2];

     pid_t pid = getpid();
     if (pipe(pfd) != 0)
         errExit("pipe");

     for (int f = 0; f < 2; f++) // step over the read end and write end 
of the pipe
     {
         char symlnk[64];

         if (sprintf(symlnk, "/proc/%d/fd/%d", pid, pfd[0 + f]) <= 0)
             errExit("sprintf");
         !f ? printf("... %s (symbolic link to the  read end of the 
pipe)\n", symlnk)
            : printf("... %s (symbolic link to the write end of the 
pipe)\n", symlnk);

         printf("... using  stat()\n");
         if (stat(symlnk, sb) != 0)
             errExit("stat");
         displayStatInfo(sb);

         printf("... using fstat()\n");
         if ( fstat(pfd[0 + f], sb + 1) != 0 )
             errExit("fstat");
         displayStatInfo(sb + 1);
     }
     exit(EXIT_SUCCESS);
}

Linux shows:
@@ ./t_stat2
... /proc/968/fd/3 (symbolic link to the  read end of the pipe)
... using  stat()
File type:                FIFO or pipe
Device containing i-node: (8)   major=0   minor=8
I-node number:            53bc - decimal: 21436
File size:                0 bytes
... using  stat()
File type:                FIFO or pipe
Device containing i-node: (8)   major=0   minor=8
I-node number:            53bc - decimal: 21436
File size:                0 bytes
... /proc/968/fd/4 (symbolic link to the write end of the pipe)
... using  stat()
File type:                FIFO or pipe
Device containing i-node: (8)   major=0   minor=8
I-node number:            53bc - decimal: 21436
File size:                0 bytes
... using  stat()
File type:                FIFO or pipe
Device containing i-node: (8)   major=0   minor=8
I-node number:            53bc - decimal: 21436
File size:                0 bytes

Cygwin shows:
@@ ./t_stat2
... /proc/2864/fd/3 (symbolic link to the  read end of the pipe)
... using  stat()
File type:                FIFO or pipe
Device containing i-node: (c7)   major=0   minor=199
I-node number:            a325e1ba495b63cf - decimal: 
11756050592531440591
File size:                0 bytes
... using fstat()
File type:                FIFO or pipe
Device containing i-node: (c6)   major=0   minor=198
I-node number:            0 - decimal: 0              <==== zero, the 
non-existing i-node ...
File size:                0 bytes
... /proc/2864/fd/4 (symbolic link to the write end of the pipe)
... using  stat()
File type:                FIFO or pipe
Device containing i-node: (c7)   major=0   minor=199
I-node number:            a325e1ba495f64cb - decimal: 
11756050592531702987 <==== Linux shows the same i-node
File size:                0 bytes
... using fstat()
File type:                FIFO or pipe
Device containing i-node: (c5)   major=0   minor=197
I-node number:            0 - decimal: 0              <==== ditto
File size:                0 bytes

=====

--
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-04  8:03 Pipes Again -- a simple test case Houder
@ 2016-01-04  8:52 ` Marco Atzeri
  2016-01-04  9:24   ` Houder
  0 siblings, 1 reply; 11+ messages in thread
From: Marco Atzeri @ 2016-01-04  8:52 UTC (permalink / raw)
  To: cygwin

On 04/01/2016 09:03, Houder wrote:
> Hi Corinna,
>
> I have been looking for an STC to show why cmp fails on Cygwin (and to
> show the
> difference between Cygwin and Linux).
>
> The STC below creates a pipe (pipe() is used), followed by calls to
> fstat() and
> stat() for both the read end and the write end of the pipe.
>
> (I also tested with popen()/pclose(): same result)
>
> Regards,
> Henri
>
> Btw, I am using W7 prof.; Cygwin-32 and Cygwin-64; 2.3.1 and 2.4.0
>
> =====
>
> The code for the STC is basically as follows:

in general a STC should be complete and attached as file.

I know where you took errExit and displayStatInfo, but
it is anyway a extra effort time consuming for the others.

Regards
Marco

--
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-04  8:52 ` Marco Atzeri
@ 2016-01-04  9:24   ` Houder
  2016-01-08 16:13     ` Corinna Vinschen
  0 siblings, 1 reply; 11+ messages in thread
From: Houder @ 2016-01-04  9:24 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 903 bytes --]

On 2016-01-04 09:52, Marco Atzeri wrote:
> On 04/01/2016 09:03, Houder wrote:
>> Hi Corinna,
>> 
>> I have been looking for an STC to show why cmp fails on Cygwin (and to
>> show the
>> difference between Cygwin and Linux).
>> 
>> The STC below creates a pipe (pipe() is used), followed by calls to
>> fstat() and
>> stat() for both the read end and the write end of the pipe.
>> 
>> (I also tested with popen()/pclose(): same result)
>> 
>> Regards,
>> Henri
>> 
>> Btw, I am using W7 prof.; Cygwin-32 and Cygwin-64; 2.3.1 and 2.4.0
>> 
>> =====
>> 
>> The code for the STC is basically as follows:
> 
> in general a STC should be complete and attached as file.
> 
> I know where you took errExit and displayStatInfo, but
> it is anyway a extra effort time consuming for the others.

Yup ... find it attached to this post ... (I hope).

(I was busy "compiling" everyting in one file :-)

Regards,
Henri

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: t_stat2.c --]
[-- Type: text/x-c; name=t_stat2.c, Size: 7010 bytes --]

/*************************************************************************\
*                  Copyright (C) Michael Kerrisk, 2014.                   *
*                                                                         *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU Affero General Public License as published   *
* by the Free Software Foundation, either version 3 or (at your option)   *
* any later version. This program is distributed without any warranty.    *
* See the file COPYING.agpl-v3 for details.                               *
\*************************************************************************/

/* Listing 15-1 */

/* t_stat.c -- heavily modified
 - using fstat: minor: 198/7 ... i-node: both (mostly) zero <==== my guess is that Cygwin is "in error"
 - using  stat: minor: 199 ... i-node: numbers are different from one another (and non-zero)
*/
#define _BSD_SOURCE     /* Get major() and minor() from <sys/types.h> */
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
//#include "file_perms.h"
//#include "tlpi_hdr.h"

#include <stdio.h>      /* Standard I/O functions */
#include <stdlib.h>     /* Prototypes of commonly used library functions,
                           plus EXIT_SUCCESS and EXIT_FAILURE constants */
#include <unistd.h>     /* Prototypes for many system calls */
#include <errno.h>      /* Declares errno and defines error constants */
#include <string.h>     /* Commonly used string-handling functions */

#include <stdarg.h>

#ifdef TRUE
#undef TRUE
#endif

#ifdef FALSE
#undef FALSE
#endif

typedef enum { FALSE, TRUE } Boolean;

static char *ename[] = {
    /*   0 */ "", 
    /*   1 */ "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO", 
    /*   7 */ "E2BIG", "ENOEXEC", "EBADF", "ECHILD", 
    /*  11 */ "EAGAIN/EWOULDBLOCK", "ENOMEM", "EACCES", "EFAULT", 
    /*  15 */ "ENOTBLK", "EBUSY", "EEXIST", "EXDEV", "ENODEV", 
    /*  20 */ "ENOTDIR", "EISDIR", "EINVAL", "ENFILE", "EMFILE", 
    /*  25 */ "ENOTTY", "ETXTBSY", "EFBIG", "ENOSPC", "ESPIPE", 
    /*  30 */ "EROFS", "EMLINK", "EPIPE", "EDOM", "ERANGE", "ENOMSG", 
    /*  36 */ "EIDRM", "ECHRNG", "EL2NSYNC", "EL3HLT", "EL3RST", 
    /*  41 */ "ELNRNG", "EUNATCH", "ENOCSI", "EL2HLT", "EDEADLK", 
    /*  46 */ "ENOLCK", "", "", "", "EBADE", "EBADR", "EXFULL", 
    /*  53 */ "ENOANO", "EBADRQC", "EBADSLT", "EDEADLOCK", "EBFONT", 
    /*  58 */ "", "", "ENOSTR", "ENODATA", "ETIME", "ENOSR", "ENONET", 
    /*  65 */ "ENOPKG", "EREMOTE", "ENOLINK", "EADV", "ESRMNT", 
    /*  70 */ "ECOMM", "EPROTO", "", "", "EMULTIHOP", "ELBIN", 
    /*  76 */ "EDOTDOT", "EBADMSG", "", "EFTYPE", "ENOTUNIQ", "EBADFD", 
    /*  82 */ "EREMCHG", "ELIBACC", "ELIBBAD", "ELIBSCN", "ELIBMAX", 
    /*  87 */ "ELIBEXEC", "ENOSYS", "ENMFILE", "ENOTEMPTY", 
    /*  91 */ "ENAMETOOLONG", "ELOOP", "", "", "EOPNOTSUPP", 
    /*  96 */ "EPFNOSUPPORT", "", "", "", "", "", "", "", "ECONNRESET", 
    /* 105 */ "ENOBUFS", "EAFNOSUPPORT", "EPROTOTYPE", "ENOTSOCK", 
    /* 109 */ "ENOPROTOOPT", "ESHUTDOWN", "ECONNREFUSED", "EADDRINUSE", 
    /* 113 */ "ECONNABORTED", "ENETUNREACH", "ENETDOWN", "ETIMEDOUT", 
    /* 117 */ "EHOSTDOWN", "EHOSTUNREACH", "EINPROGRESS", "EALREADY", 
    /* 121 */ "EDESTADDRREQ", "EMSGSIZE", "EPROTONOSUPPORT", 
    /* 124 */ "ESOCKTNOSUPPORT", "EADDRNOTAVAIL", "ENETRESET", 
    /* 127 */ "EISCONN", "ENOTCONN", "ETOOMANYREFS", "EPROCLIM", 
    /* 131 */ "EUSERS", "EDQUOT", "ESTALE", "ENOTSUP", "ENOMEDIUM", 
    /* 136 */ "ENOSHARE", "ECASECLASH", "EILSEQ", "EOVERFLOW", 
    /* 140 */ "ECANCELED", "ENOTRECOVERABLE", "EOWNERDEAD", "ESTRPIPE"
};

#define MAX_ENAME 143

static void
displayStatInfo(const struct stat *sb)
{
    printf("File type:                ");

    switch (sb->st_mode & S_IFMT) {
    case S_IFREG:  printf("regular file\n");            break;
    case S_IFDIR:  printf("directory\n");               break;
    case S_IFCHR:  printf("character device\n");        break;
    case S_IFBLK:  printf("block device\n");            break;
    case S_IFLNK:  printf("symbolic (soft) link\n");    break;
    case S_IFIFO:  printf("FIFO or pipe\n");            break;
    case S_IFSOCK: printf("socket\n");                  break;
    default:       printf("unknown file type?\n");      break;
    }

    printf("Device containing i-node: (%lx)   major=%lu   minor=%lu\n",
                (long) sb->st_dev, (long) major(sb->st_dev), (long) minor(sb->st_dev));

    printf("I-node number:            %llx - decimal: %llu\n", sb->st_ino, sb->st_ino);

    if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode))
        printf(" **** Device number (st_rdev):  major=%ld; minor=%ld\n",
                (long) major(sb->st_rdev), (long) minor(sb->st_rdev));

    printf("File size:                %lld bytes\n", (long long) sb->st_size);
}

void errExit(const char *format, ...);

int
main(int argc, char *argv[])
{
    struct stat sb[2];
    int pfd[2];

    pid_t pid = getpid();
    if (pipe(pfd) != 0)
        errExit("pipe");

    for (int f = 0; f < 2; f++)
    {
        char symlnk[64];

        if (sprintf(symlnk, "/proc/%d/fd/%d", pid, pfd[0 + f]) <= 0)
            errExit("sprintf");
        !f ? printf("... %s (symbolic link to the  read end of the pipe)\n", symlnk)
           : printf("... %s (symbolic link to the write end of the pipe)\n", symlnk);

        printf("... using  stat()\n");
        if (stat(symlnk, sb) != 0)
            errExit("stat");
        displayStatInfo(sb);

        printf("... using fstat()\n");
        if ( fstat(pfd[0 + f], sb + 1) != 0 )
            errExit("fstat");
        displayStatInfo(sb + 1);
    }
    exit(EXIT_SUCCESS);
}

static void
terminate(Boolean useExit3)
{
    char *s;

    /* Dump core if EF_DUMPCORE environment variable is defined and
       is a nonempty string; otherwise call exit(3) or _exit(2),
       depending on the value of 'useExit3'. */

    s = getenv("EF_DUMPCORE");

    if (s != NULL && *s != '\0')
        abort();
    else if (useExit3)
        exit(EXIT_FAILURE);
    else
        _exit(EXIT_FAILURE);
}

static void
outputError(Boolean useErr, int err, Boolean flushStdout,
        const char *format, va_list ap)
{
#define BUF_SIZE 500
    char buf[BUF_SIZE], userMsg[BUF_SIZE], errText[BUF_SIZE];

    vsnprintf(userMsg, BUF_SIZE, format, ap);

    if (useErr)
        snprintf(errText, BUF_SIZE, " [%s %s]",
                (err > 0 && err <= MAX_ENAME) ?
                ename[err] : "?UNKNOWN?", strerror(err));
    else
        snprintf(errText, BUF_SIZE, ":");

    snprintf(buf, BUF_SIZE, "ERROR%s %s\n", errText, userMsg);

    if (flushStdout)
        fflush(stdout);       /* Flush any pending stdout */
    fputs(buf, stderr);
    fflush(stderr);           /* In case stderr is not line-buffered */
}

void
errExit(const char *format, ...)
{
    va_list argList;

    va_start(argList, format);
    outputError(TRUE, errno, TRUE, format, argList);
    va_end(argList);

    terminate(TRUE);
}

//=====

[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

--
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-04  9:24   ` Houder
@ 2016-01-08 16:13     ` Corinna Vinschen
  2016-01-08 16:29       ` Houder
  0 siblings, 1 reply; 11+ messages in thread
From: Corinna Vinschen @ 2016-01-08 16:13 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]

On Jan  4 10:24, Houder wrote:
> On 2016-01-04 09:52, Marco Atzeri wrote:
> >On 04/01/2016 09:03, Houder wrote:
> >>Hi Corinna,
> >>
> >>I have been looking for an STC to show why cmp fails on Cygwin (and to
> >>show the
> >>difference between Cygwin and Linux).
> >>
> >>The STC below creates a pipe (pipe() is used), followed by calls to
> >>fstat() and
> >>stat() for both the read end and the write end of the pipe.
> >>
> >>(I also tested with popen()/pclose(): same result)
> >>
> >>Regards,
> >>Henri

Thanks for the STC.  However, given how this stuff works internally,
I have no good solution off the top of my head.  I played with various
ideas but to no avail.  I add this to my TODO list, but I probably
won't have a quick solution :(


Thanks,
Corinna


P.S: It would be really helpful if you could stick to the original
     thread and simply use "reply-to" once a discussion has started.
     It's very confusing having to connect the various threads.  Thanks.

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-08 16:13     ` Corinna Vinschen
@ 2016-01-08 16:29       ` Houder
  2016-01-08 18:44         ` Corinna Vinschen
  0 siblings, 1 reply; 11+ messages in thread
From: Houder @ 2016-01-08 16:29 UTC (permalink / raw)
  To: cygwin

On 2016-01-08 16:19, Corinna Vinschen wrote:
> On Jan  4 10:24, Houder wrote:
>> On 2016-01-04 09:52, Marco Atzeri wrote:
>> >On 04/01/2016 09:03, Houder wrote:
>> >>Hi Corinna,
>> >>
>> >>I have been looking for an STC to show why cmp fails on Cygwin (and to
>> >>show the
>> >>difference between Cygwin and Linux).
>> >>
>> >>The STC below creates a pipe (pipe() is used), followed by calls to
>> >>fstat() and
>> >>stat() for both the read end and the write end of the pipe.
>> >>
>> >>(I also tested with popen()/pclose(): same result)
>> >>
>> >>Regards,
>> >>Henri
> 
> Thanks for the STC.  However, given how this stuff works internally,
> I have no good solution off the top of my head.  I played with various
> ideas but to no avail.  I add this to my TODO list, but I probably
> won't have a quick solution :(
> 
> 
> Thanks,
> Corinna
> 
> 
> P.S: It would be really helpful if you could stick to the original
>      thread and simply use "reply-to" once a discussion has started.
>      It's very confusing having to connect the various threads.  
> Thanks.

Perhaps David B. can be helped by a Cygwin-specific patching to "cmp"? 
Eric?

... replacing the call to fstat() by a call to stat() ...
(as shown in https://cygwin.com/ml/cygwin/2015-12/msg00348.html)

By the way, thank you for reporting back to "us" about this. I already
feared that a "general" solution would have to wait ... You have already
too much on your plate.

As a final point, I also tested FIFOs and (unix domain) sockets.

FIFOs pass the test, sockets do not.

Regards,

Henri

--
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-08 16:29       ` Houder
@ 2016-01-08 18:44         ` Corinna Vinschen
  2016-01-11 15:40           ` Corinna Vinschen
  0 siblings, 1 reply; 11+ messages in thread
From: Corinna Vinschen @ 2016-01-08 18:44 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2040 bytes --]

On Jan  8 17:12, Houder wrote:
> On 2016-01-08 16:19, Corinna Vinschen wrote:
> >On Jan  4 10:24, Houder wrote:
> >>On 2016-01-04 09:52, Marco Atzeri wrote:
> >>>On 04/01/2016 09:03, Houder wrote:
> >>>>Hi Corinna,
> >>>>
> >>>>I have been looking for an STC to show why cmp fails on Cygwin (and to
> >>>>show the
> >>>>difference between Cygwin and Linux).
> >>>>
> >>>>The STC below creates a pipe (pipe() is used), followed by calls to
> >>>>fstat() and
> >>>>stat() for both the read end and the write end of the pipe.
> >>>>
> >>>>(I also tested with popen()/pclose(): same result)
> >>>>
> >>>>Regards,
> >>>>Henri
> >
> >Thanks for the STC.  However, given how this stuff works internally,
> >I have no good solution off the top of my head.  I played with various
> >ideas but to no avail.  I add this to my TODO list, but I probably
> >won't have a quick solution :(
> >
> >
> >Thanks,
> >Corinna
> >
> >
> >P.S: It would be really helpful if you could stick to the original
> >     thread and simply use "reply-to" once a discussion has started.
> >     It's very confusing having to connect the various threads.  Thanks.
> 
> Perhaps David B. can be helped by a Cygwin-specific patching to "cmp"? Eric?
> 
> ... replacing the call to fstat() by a call to stat() ...
> (as shown in https://cygwin.com/ml/cygwin/2015-12/msg00348.html)
> 
> By the way, thank you for reporting back to "us" about this. I already
> feared that a "general" solution would have to wait ... You have already
> too much on your plate.
> 
> As a final point, I also tested FIFOs and (unix domain) sockets.
> 
> FIFOs pass the test, sockets do not.

Yes, that's expected.  The underlying hack^Wmethod is the same for sockets
and pipes, while FIFOs have a real path on a real filesystem and thus have
a real inode number to fetch in stat/fstat.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-08 18:44         ` Corinna Vinschen
@ 2016-01-11 15:40           ` Corinna Vinschen
  2016-01-11 15:47             ` Henri
  0 siblings, 1 reply; 11+ messages in thread
From: Corinna Vinschen @ 2016-01-11 15:40 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2317 bytes --]

On Jan  8 17:30, Corinna Vinschen wrote:
> On Jan  8 17:12, Houder wrote:
> > On 2016-01-08 16:19, Corinna Vinschen wrote:
> > >On Jan  4 10:24, Houder wrote:
> > >>On 2016-01-04 09:52, Marco Atzeri wrote:
> > >>>On 04/01/2016 09:03, Houder wrote:
> > >>>>Hi Corinna,
> > >>>>
> > >>>>I have been looking for an STC to show why cmp fails on Cygwin (and to
> > >>>>show the
> > >>>>difference between Cygwin and Linux).
> > >>>>
> > >>>>The STC below creates a pipe (pipe() is used), followed by calls to
> > >>>>fstat() and
> > >>>>stat() for both the read end and the write end of the pipe.
> > >>>>
> > >>>>(I also tested with popen()/pclose(): same result)
> > >>>>
> > >>>>Regards,
> > >>>>Henri
> > >
> > >Thanks for the STC.  However, given how this stuff works internally,
> > >I have no good solution off the top of my head.  I played with various
> > >ideas but to no avail.  I add this to my TODO list, but I probably
> > >won't have a quick solution :(
> > >
> > >
> > >Thanks,
> > >Corinna
> > >
> > >
> > >P.S: It would be really helpful if you could stick to the original
> > >     thread and simply use "reply-to" once a discussion has started.
> > >     It's very confusing having to connect the various threads.  Thanks.
> > 
> > Perhaps David B. can be helped by a Cygwin-specific patching to "cmp"? Eric?
> > 
> > ... replacing the call to fstat() by a call to stat() ...
> > (as shown in https://cygwin.com/ml/cygwin/2015-12/msg00348.html)
> > 
> > By the way, thank you for reporting back to "us" about this. I already
> > feared that a "general" solution would have to wait ... You have already
> > too much on your plate.
> > 
> > As a final point, I also tested FIFOs and (unix domain) sockets.
> > 
> > FIFOs pass the test, sockets do not.
> 
> Yes, that's expected.  The underlying hack^Wmethod is the same for sockets
> and pipes, while FIFOs have a real path on a real filesystem and thus have
> a real inode number to fetch in stat/fstat.

I applied a patch to make this work.  Please give the latest developer
snapshot from https://cygwin.com/snapshots/ a try.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-11 15:40           ` Corinna Vinschen
@ 2016-01-11 15:47             ` Henri
  2016-01-11 16:20               ` Corinna Vinschen
  0 siblings, 1 reply; 11+ messages in thread
From: Henri @ 2016-01-11 15:47 UTC (permalink / raw)
  To: cygwin

Corinna Vinschen <corinna-cygwin <at> cygwin.com> writes:

> > > As a final point, I also tested FIFOs and (unix domain) sockets.
> > > 
> > > FIFOs pass the test, sockets do not.
> > 
> > Yes, that's expected.  The underlying hack^Wmethod is the same for sockets
> > and pipes, while FIFOs have a real path on a real filesystem and thus have
> > a real inode number to fetch in stat/fstat.
> 
> I applied a patch to make this work.  Please give the latest developer
> snapshot from https://cygwin.com/snapshots/ a try.

Thank you!

Down with flue on this side. Did a quick verification (32-bits Cygwin).
Pipes look good. The problem with cmp apperas to be gone.
Sockets still leave wanting, as shown here:

@@ ./t_henri
1st socket
... /proc/4896/fd/3 (symbolic link to the socket)
... socket:[252] (target of symbolic link to the socket)
... using  stat() on symbolic link: /proc/4896/fd/3
File type:                socket
Device containing i-node: (1e0000)   major=30   minor=0
I-node number:            38037da0d28c3faf - decimal: 4036207820734742447
File size:                0 bytes
... using fstat()
File type:                socket
Device containing i-node: (1e0000)   major=30   minor=0
I-node number:            1 - decimal: 1
File size:                0 bytes

2nd socket
... /proc/4896/fd/4 (symbolic link to the socket)
... socket:[272] (target of symbolic link to the socket)
... using  stat() on symbolic link: /proc/4896/fd/4
File type:                socket
Device containing i-node: (1e0000)   major=30   minor=0
I-node number:            38037da2d3885eb1 - decimal: 4036207829341200049
File size:                0 bytes
... using fstat()
File type:                socket
Device containing i-node: (1e0000)   major=30   minor=0
I-node number:            2 - decimal: 2
File size:                0 bytes
@@ 

Regards,
Henri


--
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-11 15:47             ` Henri
@ 2016-01-11 16:20               ` Corinna Vinschen
  2016-01-11 16:25                 ` Henri
  0 siblings, 1 reply; 11+ messages in thread
From: Corinna Vinschen @ 2016-01-11 16:20 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2218 bytes --]

On Jan 11 15:35, Henri wrote:
> Corinna Vinschen <corinna-cygwin <at> cygwin.com> writes:
> 
> > > > As a final point, I also tested FIFOs and (unix domain) sockets.
> > > > 
> > > > FIFOs pass the test, sockets do not.
> > > 
> > > Yes, that's expected.  The underlying hack^Wmethod is the same for sockets
> > > and pipes, while FIFOs have a real path on a real filesystem and thus have
> > > a real inode number to fetch in stat/fstat.
> > 
> > I applied a patch to make this work.  Please give the latest developer
> > snapshot from https://cygwin.com/snapshots/ a try.
> 
> Thank you!
> 
> Down with flue on this side. Did a quick verification (32-bits Cygwin).
> Pipes look good. The problem with cmp apperas to be gone.
> Sockets still leave wanting, as shown here:
> 
> @@ ./t_henri
> 1st socket
> ... /proc/4896/fd/3 (symbolic link to the socket)
> ... socket:[252] (target of symbolic link to the socket)
> ... using  stat() on symbolic link: /proc/4896/fd/3
> File type:                socket
> Device containing i-node: (1e0000)   major=30   minor=0
> I-node number:            38037da0d28c3faf - decimal: 4036207820734742447
> File size:                0 bytes
> ... using fstat()
> File type:                socket
> Device containing i-node: (1e0000)   major=30   minor=0
> I-node number:            1 - decimal: 1
> File size:                0 bytes
> 
> 2nd socket
> ... /proc/4896/fd/4 (symbolic link to the socket)
> ... socket:[272] (target of symbolic link to the socket)
> ... using  stat() on symbolic link: /proc/4896/fd/4
> File type:                socket
> Device containing i-node: (1e0000)   major=30   minor=0
> I-node number:            38037da2d3885eb1 - decimal: 4036207829341200049
> File size:                0 bytes
> ... using fstat()
> File type:                socket
> Device containing i-node: (1e0000)   major=30   minor=0
> I-node number:            2 - decimal: 2
> File size:                0 bytes
> @@ 

Can you please provide the socket testcase?


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-11 16:20               ` Corinna Vinschen
@ 2016-01-11 16:25                 ` Henri
  2016-01-11 19:48                   ` Corinna Vinschen
  0 siblings, 1 reply; 11+ messages in thread
From: Henri @ 2016-01-11 16:25 UTC (permalink / raw)
  To: cygwin

Corinna Vinschen <corinna-cygwin <at> cygwin.com> writes:
> Can you please provide the socket testcase?

Trying to send you what you ask for (using gmane.org, I have to copy/paste)

----- t_stat3.c:
/*************************************************************************\
*                  Copyright (C) Michael Kerrisk, 2014.                   *
*                                                                         *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU Affero General Public License as published   *
* by the Free Software Foundation, either version 3 or (at your option)   *
* any later version. This program is distributed without any warranty.    *
* See the file COPYING.agpl-v3 for details.                               *
\*************************************************************************/

/* Listing 15-1 */ // t_stat.c -- heavily modified

#define _BSD_SOURCE     /* Get major() and minor() from <sys/types.h> */
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
//#include "file_perms.h"
//#include "tlpi_hdr.h"

#include <stdio.h>      /* Standard I/O functions */
#include <stdlib.h>     /* Prototypes of commonly used library functions,
                           plus EXIT_SUCCESS and EXIT_FAILURE constants */
#include <unistd.h>     /* Prototypes for many system calls */
#include <string.h>     /* Commonly used string-handling functions */

static void
displayStatInfo(const struct stat *sb)
{
    printf("File type:                ");

    switch (sb->st_mode & S_IFMT) {
    case S_IFREG:  printf("regular file\n");            break;
    case S_IFDIR:  printf("directory\n");               break;
    case S_IFCHR:  printf("character device\n");        break;
    case S_IFBLK:  printf("block device\n");            break;
    case S_IFLNK:  printf("symbolic (soft) link\n");    break;
    case S_IFIFO:  printf("FIFO or pipe\n");            break;
    case S_IFSOCK: printf("socket\n");                  break;
    default:       printf("unknown file type?\n");      break;
    }

    printf("Device containing i-node: (%lx)   major=%lu   minor=%lu\n",
                (long) sb->st_dev, (long) major(sb->st_dev), (long)
minor(sb->st_dev));

    printf("I-node number:            %llx - decimal: %llu\n", sb->st_ino,
sb->st_ino);

    if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode))
        printf(" **** Device number (st_rdev):  major=%ld; minor=%ld\n",
                (long) major(sb->st_rdev), (long) minor(sb->st_rdev));

    printf("File size:                %lld bytes\n", (long long) sb->st_size);
}

void errExit(const char *format, ...);

#include <sys/un.h>
#include <sys/socket.h>

int
main()
{
    char symlnk[64];

    pid_t pid = getpid();

    int sfd[2];

    for (int f = 0; f < 2; f++) // step over the 1st and 2nd socket
    {
        if (!f) {
            sfd[f] = socket(AF_UNIX, SOCK_STREAM, 0);
            //sfd[f] = socket(AF_INET, SOCK_STREAM, 0);
            if (sfd[f] == -1)
                errExit("socket");
        } else {
            sfd[f] = socket(AF_UNIX, SOCK_STREAM, 0);
            //sfd[f] = socket(AF_INET, SOCK_STREAM, 0);
            if (sfd[f] == -1)
                errExit("socket");
        }
    }

    struct stat sb[2]; // one buffer for the 1st socket, one for the 2nd
    int f;

    char target[128];
    ssize_t num;

    printf("1st socket\n");
    f = 0;
    if (sprintf(symlnk, "/proc/%d/fd/%d", pid, sfd[f]) <= 0)
        errExit("sprintf");
    printf("... %s (symbolic link to the socket)\n", symlnk);

    if ( (num = readlink( (const char *)symlnk, target, 128) ) == -1)
       errExit("readlink");
    if (num < 128) {
        target[num] = '\0';
        printf("... %s (target of symbolic link to the socket)\n", target);

        printf("... using  stat() on symbolic link: %s\n", symlnk);
        //if (stat(target, sb + f) != 0) // not possible: target is NOT a
filename ...
        if (stat(symlnk, sb + f) != 0)
            errExit("stat");
        displayStatInfo(sb + f);

        printf("... using fstat()\n");
        memset(sb + f, 0, sizeof(struct stat) ); // CLEAR
        if (fstat(sfd[f], sb + f) != 0)
            errExit("fstat");
        displayStatInfo(sb + f);
    }

    #if 1
    printf("\n2nd socket\n");
    f = 1;
    if (sprintf(symlnk, "/proc/%d/fd/%d", pid, sfd[f]) <= 0)
        errExit("sprintf");
    printf("... %s (symbolic link to the socket)\n", symlnk);

    if ( (num = readlink( (const char *)symlnk, target, 128) ) == -1)
       errExit("readlink");
    if (num < 128) {
        target[num] = '\0';
        printf("... %s (target of symbolic link to the socket)\n", target);

        printf("... using  stat() on symbolic link: %s\n", symlnk);
        //if (stat(target, sb + f) != 0) // not possible: target is NOT a
filename ...
        if (stat(symlnk, sb + f) != 0)
            errExit("stat");
        displayStatInfo(sb + f);

        printf("... using fstat()\n");
        memset(sb + f, 0, sizeof(struct stat) ); // CLEAR
        if (fstat(sfd[f], sb + f) != 0)
            errExit("fstat");
        displayStatInfo(sb + f);
    }
    #endif

    close(sfd[0]);
    close(sfd[1]);
    exit(EXIT_SUCCESS);
}

#include <errno.h>      /* Declares errno and defines error constants */

#include <stdarg.h>

#ifdef TRUE
#undef TRUE
#endif

#ifdef FALSE
#undef FALSE
#endif

typedef enum { FALSE, TRUE } Boolean;

static char *ename[] = {
    /*   0 */ "",
    /*   1 */ "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO",
    /*   7 */ "E2BIG", "ENOEXEC", "EBADF", "ECHILD",
    /*  11 */ "EAGAIN/EWOULDBLOCK", "ENOMEM", "EACCES", "EFAULT",
    /*  15 */ "ENOTBLK", "EBUSY", "EEXIST", "EXDEV", "ENODEV",
    /*  20 */ "ENOTDIR", "EISDIR", "EINVAL", "ENFILE", "EMFILE",
    /*  25 */ "ENOTTY", "ETXTBSY", "EFBIG", "ENOSPC", "ESPIPE",
    /*  30 */ "EROFS", "EMLINK", "EPIPE", "EDOM", "ERANGE", "ENOMSG",
    /*  36 */ "EIDRM", "ECHRNG", "EL2NSYNC", "EL3HLT", "EL3RST",
    /*  41 */ "ELNRNG", "EUNATCH", "ENOCSI", "EL2HLT", "EDEADLK",
    /*  46 */ "ENOLCK", "", "", "", "EBADE", "EBADR", "EXFULL",
    /*  53 */ "ENOANO", "EBADRQC", "EBADSLT", "EDEADLOCK", "EBFONT",
    /*  58 */ "", "", "ENOSTR", "ENODATA", "ETIME", "ENOSR", "ENONET",
    /*  65 */ "ENOPKG", "EREMOTE", "ENOLINK", "EADV", "ESRMNT",
    /*  70 */ "ECOMM", "EPROTO", "", "", "EMULTIHOP", "ELBIN",
    /*  76 */ "EDOTDOT", "EBADMSG", "", "EFTYPE", "ENOTUNIQ", "EBADFD",
    /*  82 */ "EREMCHG", "ELIBACC", "ELIBBAD", "ELIBSCN", "ELIBMAX",
    /*  87 */ "ELIBEXEC", "ENOSYS", "ENMFILE", "ENOTEMPTY",
    /*  91 */ "ENAMETOOLONG", "ELOOP", "", "", "EOPNOTSUPP",
    /*  96 */ "EPFNOSUPPORT", "", "", "", "", "", "", "", "ECONNRESET",
    /* 105 */ "ENOBUFS", "EAFNOSUPPORT", "EPROTOTYPE", "ENOTSOCK",
    /* 109 */ "ENOPROTOOPT", "ESHUTDOWN", "ECONNREFUSED", "EADDRINUSE",
    /* 113 */ "ECONNABORTED", "ENETUNREACH", "ENETDOWN", "ETIMEDOUT",
    /* 117 */ "EHOSTDOWN", "EHOSTUNREACH", "EINPROGRESS", "EALREADY",
    /* 121 */ "EDESTADDRREQ", "EMSGSIZE", "EPROTONOSUPPORT",
    /* 124 */ "ESOCKTNOSUPPORT", "EADDRNOTAVAIL", "ENETRESET",
    /* 127 */ "EISCONN", "ENOTCONN", "ETOOMANYREFS", "EPROCLIM",
    /* 131 */ "EUSERS", "EDQUOT", "ESTALE", "ENOTSUP", "ENOMEDIUM",
    /* 136 */ "ENOSHARE", "ECASECLASH", "EILSEQ", "EOVERFLOW",
    /* 140 */ "ECANCELED", "ENOTRECOVERABLE", "EOWNERDEAD", "ESTRPIPE"
};

#define MAX_ENAME 143

static void
terminate(Boolean useExit3)
{
    char *s;

    /* Dump core if EF_DUMPCORE environment variable is defined and
       is a nonempty string; otherwise call exit(3) or _exit(2),
       depending on the value of 'useExit3'. */

    s = getenv("EF_DUMPCORE");

    if (s != NULL && *s != '\0')
        abort();
    else if (useExit3)
        exit(EXIT_FAILURE);
    else
        _exit(EXIT_FAILURE);
}

static void
outputError(Boolean useErr, int err, Boolean flushStdout,
        const char *format, va_list ap)
{
#define BUF_SIZE 500
    char buf[BUF_SIZE], userMsg[BUF_SIZE], errText[BUF_SIZE];

    vsnprintf(userMsg, BUF_SIZE, format, ap);

    if (useErr)
        snprintf(errText, BUF_SIZE, " [%s %s]",
                (err > 0 && err <= MAX_ENAME) ?
                ename[err] : "?UNKNOWN?", strerror(err));
    else
        snprintf(errText, BUF_SIZE, ":");

    snprintf(buf, BUF_SIZE, "ERROR%s %s\n", errText, userMsg);

    if (flushStdout)
        fflush(stdout);       /* Flush any pending stdout */
    fputs(buf, stderr);
    fflush(stderr);           /* In case stderr is not line-buffered */
}

void
errExit(const char *format, ...)
{
    va_list argList;

    va_start(argList, format);
    outputError(TRUE, errno, TRUE, format, argList);
    va_end(argList);

    terminate(TRUE);
}

//=====




--
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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Pipes Again -- a simple test case
  2016-01-11 16:25                 ` Henri
@ 2016-01-11 19:48                   ` Corinna Vinschen
  0 siblings, 0 replies; 11+ messages in thread
From: Corinna Vinschen @ 2016-01-11 19:48 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 600 bytes --]

On Jan 11 16:13, Henri wrote:
> Corinna Vinschen <corinna-cygwin <at> cygwin.com> writes:
> > Can you please provide the socket testcase?
> 
> Trying to send you what you ask for (using gmane.org, I have to copy/paste)

Thanks!  I applied a patch and created a new developer snapshot.  I'll
also upload a new cygwin test release later today.  That's hopefully the
last one.  I intend to release end of this week.


Thanks again,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-01-11 18:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-04  8:03 Pipes Again -- a simple test case Houder
2016-01-04  8:52 ` Marco Atzeri
2016-01-04  9:24   ` Houder
2016-01-08 16:13     ` Corinna Vinschen
2016-01-08 16:29       ` Houder
2016-01-08 18:44         ` Corinna Vinschen
2016-01-11 15:40           ` Corinna Vinschen
2016-01-11 15:47             ` Henri
2016-01-11 16:20               ` Corinna Vinschen
2016-01-11 16:25                 ` Henri
2016-01-11 19:48                   ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).