pipe(2) and fstat(2)

59 views
Skip to first unread message

Takuya ASADA

unread,
Oct 12, 2014, 6:02:48 PM10/12/14
to Osv Dev, Minoru KANATSU
Hi,

Minoru is trying to extend Ruby standard API coverage on OSv, by porting testsuite of Ruby API to OSv.
He reported that on some tests fails on Ruby's pipe API (IO.pipe).
I looked into Ruby source code, it's something like this:

int pipes[2];
struct stat buf;

pipe(pipes);
if (fstat(pipes[0], &buf) != 0 && errno == EBADF)
    abort();
if (fstat(pipes[1], &buf) != 0 && errno == EBADF)
    abort();

The testcase seems to getting EBADF on fstat(2).
Can we currently able to stat pipe file descriptor, or do we have any limitation on pipe(2)?

Nadav Har'El

unread,
Oct 13, 2014, 2:25:31 AM10/13/14
to Takuya ASADA, Osv Dev, Minoru KANATSU
Sadly, this is a known issue, but was never documented in the bug tracker (and not fixed...), because we hadn't seen (yet) any program that cared about this behavior. I'll open an issue for it now.

pipe_file (see pipe.cc) does not reimplements the "stat()" method, so it inherits the default special_file::stat(). This has a FIXME:

int special_file::stat(struct stat* s)
{
    /* FIXME: There is no reasonable errno to return here; Posix, Linux and
     * BSD all seem to support fstat() on all kinds of file descriptors,
     * offering some partial information (such as the user id of the object's
     * owner) as much as it makes sense. We should do the same.
     */
    return EBADF;
}

I'll open an issue for this. Should not be hard to fix to behave more like Linux - any volunteers? :-)
Reply all
Reply to author
Forward
0 new messages