Skip to contentSkip to conversation

problem opening multiple pipes with pipe(2) in 2.4.1[78]

DISCUSSION sean finney 4 participants 5 messages Oct 22, 2002

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

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

Quoted 9 lines · sean finney
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-----

#2 lore raw
Quoted 4 lines · Ulrich Drepper

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

#3 lore raw
Quoted 7 lines · sean finney

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

#4 lore raw
Quoted 11 lines · Doug McNaught
Quoted 7 lines · sean finney

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)