[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/55836: popen(3)'s type "r+" doesn't work correctly
The following reply was made to PR lib/55836; it has been noted by GNATS.
From: Wolfgang Solfrank <Wolfgang%Solfrank.net@localhost>
To: gnats-bugs%netbsd.org@localhost, lib-bug-people%netbsd.org@localhost, gnats-admin%netbsd.org@localhost,
Subject: Re: lib/55836: popen(3)'s type "r+" doesn't work correctly
Date: Wed, 2 Dec 2020 16:55:44 +0100
> While I was playing with read/write pipes with popen(command, "r+") I
> realized that this doesn't work as expected. The plus triggers creating
> the pipe object with socketpair(2) instead of pipe2(2) in
> src/lib/libc/gen/popen.c, but socketpair doesn't seem to work properly.
This seems to be a problem with your expectations. The "r+" tells
popen to open the pipe "for reading and writing" (see popen(3)).
I.e. with your test program, the forked "cat" gets its stdin *and*
stdout connected to the one end of the socketpair. So the cat
doesn't read the output from the ls command, but sits there waiting
for your program to write something into fp.
So this works exactly as designed.
Wolfgang%Solfrank.net@localhost Wolfgang Solfrank
Main Index |
Thread Index |