Bug#1001542: perl: Hurd: sysread() fails with a "Bad file descriptor" error
Peter Pentchev
roam at ringlet.net
Wed Mar 2 13:46:13 GMT 2022
On Tue, Mar 01, 2022 at 07:26:24PM +0200, Niko Tyni wrote:
> Hi, sorry for the delay.
>
> On Sun, Dec 12, 2021 at 12:15:50AM +0200, Peter Pentchev wrote:
> > Package: perl
> > Version: 5.32.1-6
> > Severity: normal
>
> > [roam at exodar ~]$ perl -e 'use v5.10; use strict; use warnings; sysopen my $fh, "/bin/ls", 0 or die "sysopen: $!\n"; say "fd ".fileno $fh; my $data; sysread $fh, $data, 32 or die "sysread: $!\n"; say length $data;'
> > fd 3
> > sysread: Bad file descriptor
>
> Quoting https://www.gnu.org/software/libc/manual/html_node/Access-Modes.html
>
> On GNU/Hurd systems (but not on other systems), O_RDONLY and O_WRONLY
> are independent bits that can be bitwise-ORed together, and it is
> valid for either bit to be set or clear. This means that O_RDWR is the
> same as O_RDONLY|O_WRONLY. A file access mode of zero is permissible;
> it allows no operations that do input or output to the file, but does
> allow other operations such as fchmod.
>
> Indeed, using Fcntl::O_RDONLY instead of 0 works fine for me on exodar.
>
> Python behaves the same btw:
>
> exodar% python3 -c 'import os; print(len(os.read(os.open("/bin/ls", 0), 32)))'
> Traceback (most recent call last):
> File "<string>", line 1, in <module>
> OSError: [Errno 1073741833] Bad file descriptor
>
> Closing, but let me know if there are still issues.
Oh wow. That was embarrassing. Thanks a *lot* for looking at this and
for pointing out the blindingly obvious.
I really have no idea how that happened... I mean, I *never* write
open(..., 0) in C; I have no idea why I wrote it there and why
I did not notice it afterwards.
Thanks again, sorry for wasting your time, and keep up the great work!
G'luck,
Peter
--
Peter Pentchev roam at ringlet.net roam at debian.org pp at storpool.com
PGP key: http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/perl-maintainers/attachments/20220302/e569a2cd/attachment.sig>
More information about the Perl-maintainers
mailing list