2002-10-22 01:26:14

by sean finney

[permalink] [raw]
Subject: problem opening multiple pipes with pipe(2) in 2.4.1[78]

hi everyone

i'm not sure whether i should be sending this here or to some libc
mailing list, but i couldn't seem to find the code for pipe(2) in libc
so i'm assuming it's in the kernel.

i have a simple program that illustrates a problem i'm having in a more
complex program. if i try to open multiple pipes with calls to pipe(),
Really Wierd Stuff seems to start happening:

#include <unistd.h>

int main(){
int p1[2], p2[2];
pipe(p1);
perror("p1");
pipe(p2);
perror("p2");
return 0;
}

produces the following output:

oil[~]21:22:03$ ./a.out
p1b: Success
p2b: Illegal seek

i'm really confused here. first of all, pipe's manpage doesn't say
anything about setting errno to ESPIPE (which is what it's doing), and
secondly, PIPE IS RETURNING 0. i just spent the past 4 hours trying to
figure why my program was segfaulting before i got to this, which is
even more frustrating because i was checking for errors from the result
of pipe().

so i'm hoping i've just completely overlooked something and someone will
be able to point out the error of my ways. any advice or pointers would
really be appreciated, thanks

--sean


Attachments:
(No filename) (1.11 kB)
(No filename) (232.00 B)
Download all attachments

2002-10-22 02:11:29

by Ulrich Drepper

[permalink] [raw]
Subject: Re: problem opening multiple pipes with pipe(2) in 2.4.1[78]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

sean finney wrote:

>
> int main(){
> int p1[2], p2[2];
> pipe(p1);
> perror("p1");
> pipe(p2);
> perror("p2");
> return 0;
> }


The fault is entirely yours. You're not allowed to look at errno unless
a function, which is defined to modify error on failure, is reporting it
failed. Both pipe() calls work just fine and errno has some random
value which happens to be ESPIPE for you. Read the standard.

- --
- --------------. ,-. 444 Castro Street
Ulrich Drepper \ ,-----------------' \ Mountain View, CA 94041 USA
Red Hat `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9tLUX2ijCOnn/RHQRAsAvAJoCBHjJY+Fw8ngfW2HeH8i1ozMenwCdH/Zd
49t/9uthYez2yYk4JoYgbrU=
=Ijan
-----END PGP SIGNATURE-----

2002-10-22 04:33:18

by sean finney

[permalink] [raw]
Subject: Re: problem opening multiple pipes with pipe(2) in 2.4.1[78]

On Mon, Oct 21, 2002 at 07:16:55PM -0700, Ulrich Drepper wrote:
> The fault is entirely yours. You're not allowed to look at errno unless
> a function, which is defined to modify error on failure, is reporting it
> failed. Both pipe() calls work just fine and errno has some random
> value which happens to be ESPIPE for you. Read the standard.

right. the perror() giving nonsensical results wasn't the cause of my
problem of course, i was just trying to use it to find out why the pipe
didn't seem to work. turns out that i missed the forest for the trees;
the pipe was being opened for writing from the wrong end...

(as a side note, the code in question was written on a solaris box, and
it seems to Just Work in the wrong direction there, go fig.)

thanks
--sean


Attachments:
(No filename) (773.00 B)
(No filename) (232.00 B)
Download all attachments

2002-10-22 12:37:42

by Douglas McNaught

[permalink] [raw]
Subject: Re: problem opening multiple pipes with pipe(2) in 2.4.1[78]

sean finney <[email protected]> writes:

> right. the perror() giving nonsensical results wasn't the cause of my
> problem of course, i was just trying to use it to find out why the pipe
> didn't seem to work. turns out that i missed the forest for the trees;
> the pipe was being opened for writing from the wrong end...
>
> (as a side note, the code in question was written on a solaris box, and
> it seems to Just Work in the wrong direction there, go fig.)

SysV pipes are bidirectional.

-Doug

2002-10-22 13:01:27

by Alan

[permalink] [raw]
Subject: Re: problem opening multiple pipes with pipe(2) in 2.4.1[78]

On Tue, 2002-10-22 at 13:43, Doug McNaught wrote:
> sean finney <[email protected]> writes:
>
> > right. the perror() giving nonsensical results wasn't the cause of my
> > problem of course, i was just trying to use it to find out why the pipe
> > didn't seem to work. turns out that i missed the forest for the trees;
> > the pipe was being opened for writing from the wrong end...
> >
> > (as a side note, the code in question was written on a solaris box, and
> > it seems to Just Work in the wrong direction there, go fig.)
>
> SysV pipes are bidirectional.

Only on later SYS5 8)