Message130312
The problem lies here:
/* Close pipe fds. Make sure we don't close the same fd more than */
/* once, or standard fds. */
if (p2cread > 2) {
POSIX_CALL(close(p2cread));
}
(c2pwrite > 2) {
POSIX_CALL(close(c2pwrite));
}
if (errwrite != c2pwrite && errwrite > 2) {
POSIX_CALL(close(errwrite));
}
If p2cread == c2pwrite (which is the case here since /dev/null is passed as stdin and stderr), we end up closing the same FD twice, hence the EBADF.
Just passing
-(c2pwrite > 2) {
+(c2pwrite > 2 && c2pwrite != p2cread) {
POSIX_CALL(close(c2pwrite));
}
Solves this (but you probably also want to check for (errwrite != p2cread) when closing c2pwrite).
Note that the Python implementation uses a set to avoid closing the same FD twice:
# Close pipe fds. Make sure we don't close the
# same fd more than once, or standard fds.
closed = set()
for fd in [p2cread, c2pwrite, errwrite]:
if fd > 2 and fd not in closed:
os.close(fd)
closed.add(fd)
It might be cleaner to use a fd_set, i.e.:
fd_set set;
FD_ZERO(&set);
FD_SET(0, &set);
FD_SET(1, &set);
FD_SET(2, &set);
if (!FD_ISSET(p2cread, &set)) {
POSIX_CALL(close(p2cread));
FD_SET(p2cread, &fd);
}
if (!FD_ISSET(c2pwrite, &set)) {
POSIX_CALL(close(c2pwrite));
FD_SET(c2pwrite, &fd);
}
if (!FD_ISSET(errwrite, &set)) {
POSIX_CALL(close(errwrite));
FD_SET(errwrite, &fd);
}
But maybe it's just too much (and also, fd_set can be defined in different header files, and while I'm sure it's async-safe on Linux, I don't know if it's required as part of a standard...). |
|
Date |
User |
Action |
Args |
2011-03-08 10:11:33 | neologix | set | recipients:
+ neologix, georg.brandl, gregory.p.smith, ezio.melotti, ideasman42 |
2011-03-08 10:11:33 | neologix | set | messageid: <1299579093.56.0.343403942568.issue11432@psf.upfronthosting.co.za> |
2011-03-08 10:11:33 | neologix | link | issue11432 messages |
2011-03-08 10:11:32 | neologix | create | |
|