From: Paul Eggert <eggert@cs.ucla.edu>
To: Sergei Trofimovich <slyich@gmail.com>
Cc: 70411@debbugs.gnu.org, "Alejandro Colomar" <alx@kernel.org>,
"Eli Schwartz" <eschwartz93@gmail.com>,
"Pádraig Brady" <P@draigBrady.com>,
"Gnulib bugs" <bug-gnulib@gnu.org>
Subject: Re: bug#70411: [bug] install(1) fails to read /dev/stdin on Darwin
Date: Fri, 19 Apr 2024 00:33:52 -0700 [thread overview]
Message-ID: <b310a779-f58d-4915-8f3f-1f4fe9457e3f@cs.ucla.edu> (raw)
In-Reply-To: <20240418225232.21bf83cd@nz.home>
[-- Attachment #1: Type: text/plain, Size: 1329 bytes --]
On 2024-04-18 14:52, Sergei Trofimovich wrote:
> $ clang simple.c -o simple && echo 42 | ./simple
> 1: ino=3009428657538693161
> 2: ino=3009428657538693161
> 3: ino=1568241705
>
> Note how stat() and fstat() don't agree on inode.
>
> Apparently it's documented in
> https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fstat.2.html
> as
>
> BUGS
> Applying fstat to a socket (and thus to a pipe) returns a zero'd buffer,
> except for the blocksize field, and a unique device and inode number.
The BUGS note simply means that a pipe has a unique inode number, which
is what we want. So that's not indicating any problem.
Oh, I see the problem now. For a socket or pipe, macOS fstat returns
the full 64-bit inode number, whereas macOS stat returns only the low
order 32 bits. In your example, 3009428657538693161 % (2**32) ==
1568241705.
This is a kernel bug in macOS. Can you report it or otherwise arrange to
have the kernel bug fixed? I expect that you have better connections
with Apple than I do. A proposed patch (relative to xnu-10063.101.15) is
attached; I have not tested it as I don't use macOS. Thanks.
Also, I am documenting this macOS bug in Gnulib by installing the second
attached patch to Gnulib, and am cc'ing this email to bug-gnulib.
[-- Attachment #2: 0001-Fix-bug-with-stat-truncating-pipe-socket-st_ino.patch --]
[-- Type: text/x-patch, Size: 1330 bytes --]
From 29345117a4cf85aceb88e3901758b19a4867062e Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 19 Apr 2024 00:12:50 -0700
Subject: [PATCH] Fix bug with stat truncating pipe/socket st_ino
Problem reported by Sergei Trofimovich in:
https://bugs.gnu.org/70411
https://github.com/NixOS/nixpkgs/pull/300797
* bsd/miscfs/devfs/devfs_fdesc_support.c (fdesc_attr):
Do not truncate inode numbers to 32 bits.
---
bsd/miscfs/devfs/devfs_fdesc_support.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bsd/miscfs/devfs/devfs_fdesc_support.c b/bsd/miscfs/devfs/devfs_fdesc_support.c
index a17c6992..b4a55103 100644
--- a/bsd/miscfs/devfs/devfs_fdesc_support.c
+++ b/bsd/miscfs/devfs/devfs_fdesc_support.c
@@ -437,10 +437,10 @@ fdesc_attr(int fd, struct vnode_attr *vap, vfs_context_t a_context)
case DTYPE_PIPE:
#if SOCKETS
if (FILEGLOB_DTYPE(fp->fp_glob) == DTYPE_SOCKET) {
- error = soo_stat((struct socket *)fp_get_data(fp), (void *)&stb, 0);
+ error = soo_stat((struct socket *)fp_get_data(fp), (void *)&stb, 1);
} else
#endif /* SOCKETS */
- error = pipe_stat((struct pipe *)fp_get_data(fp), (void *)&stb, 0);
+ error = pipe_stat((struct pipe *)fp_get_data(fp), (void *)&stb, 1);
if (error == 0) {
if (FILEGLOB_DTYPE(fp->fp_glob) == DTYPE_SOCKET) {
--
2.44.0
[-- Attachment #3: 0001-fstatat-stat-document-macOS-st_ino-pipe-bug.patch --]
[-- Type: text/x-patch, Size: 2437 bytes --]
From c2174a623d33096b52f4d7fd2963f76acb3e301f Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 19 Apr 2024 00:29:32 -0700
Subject: [PATCH] fstatat, stat: document macOS st_ino pipe bug
* doc/posix-functions/fstatat.texi (fstatat):
* doc/posix-functions/stat.texi (stat):
Document macOS bug (see <https://bugs.gnu.org/70411>).
---
ChangeLog | 7 +++++++
doc/posix-functions/fstatat.texi | 5 +++++
doc/posix-functions/stat.texi | 5 +++++
3 files changed, 17 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 7ce75a98a9..1667f90c55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-04-19 Paul Eggert <eggert@cs.ucla.edu>
+
+ fstatat, stat: document macOS st_ino pipe bug
+ * doc/posix-functions/fstatat.texi (fstatat):
+ * doc/posix-functions/stat.texi (stat):
+ Document macOS bug (see <https://bugs.gnu.org/70411>).
+
2024-04-18 Bruno Haible <bruno@clisp.org>
totalordermagl: Add tests.
diff --git a/doc/posix-functions/fstatat.texi b/doc/posix-functions/fstatat.texi
index e959a5cc73..90884e2eb1 100644
--- a/doc/posix-functions/fstatat.texi
+++ b/doc/posix-functions/fstatat.texi
@@ -40,5 +40,10 @@ This function does not fail when the second argument is an empty string
on some platforms, even when @code{AT_EMPTY_PATH} is not used:
glibc 2.7, Linux 2.6.38.
@item
+This function sets @code{st_ino} only to the low-order 32 bits of
+the inode number of a socket or pipe, which thus can disagree
+with the @code{st_ino} obtained by @code{fstat}:
+macOS 14.
+@item
@xref{sys/stat.h}, for general portability problems with @code{struct stat}.
@end itemize
diff --git a/doc/posix-functions/stat.texi b/doc/posix-functions/stat.texi
index f655451392..8afd3b17bb 100644
--- a/doc/posix-functions/stat.texi
+++ b/doc/posix-functions/stat.texi
@@ -50,6 +50,11 @@ Portability problems not fixed by Gnulib:
Cygwin's @code{stat} function sometimes sets @code{errno} to @code{EACCES} when
@code{ENOENT} would be more appropriate.
@item
+This function sets @code{st_ino} only to the low-order 32 bits of
+the inode number of a socket or pipe, which thus can disagree
+with the @code{st_ino} obtained by @code{fstat}:
+macOS 14.
+@item
Because of the definition of @code{struct stat}, it is not possible to
portably replace @code{stat} via an object-like macro. Therefore,
expressions such as @code{(islnk ? lstat : stat) (name, buf)} are not
--
2.40.1
next parent reply other threads:[~2024-04-19 7:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Zh3EDgxqkzasdBMg@debian>
[not found] ` <ee3fa9ca-7c75-2cb3-6853-ff89213036f4@draigBrady.com>
[not found] ` <20240416223758.50d36dd7@nz.home>
[not found] ` <20240418225232.21bf83cd@nz.home>
2024-04-19 7:33 ` Paul Eggert [this message]
2024-04-19 21:33 ` bug#70411: [bug] install(1) fails to read /dev/stdin on Darwin Sergei Trofimovich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b310a779-f58d-4915-8f3f-1f4fe9457e3f@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=70411@debbugs.gnu.org \
--cc=P@draigBrady.com \
--cc=alx@kernel.org \
--cc=bug-gnulib@gnu.org \
--cc=eschwartz93@gmail.com \
--cc=slyich@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).