homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author neologix
Recipients ezio.melotti, georg.brandl, gregory.p.smith, ideasman42, neologix
Date 2011年03月08日.10:11:32
SpamBayes Score 2.220446e-16
Marked as misclassified No
Message-id <1299579093.56.0.343403942568.issue11432@psf.upfronthosting.co.za>
In-reply-to
Content
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...).
History
Date User Action Args
2011年03月08日 10:11:33neologixsetrecipients: + neologix, georg.brandl, gregory.p.smith, ezio.melotti, ideasman42
2011年03月08日 10:11:33neologixsetmessageid: <1299579093.56.0.343403942568.issue11432@psf.upfronthosting.co.za>
2011年03月08日 10:11:33neologixlinkissue11432 messages
2011年03月08日 10:11:32neologixcreate

AltStyle によって変換されたページ (->オリジナル) /