Subject: bug#54286: [PATCH] Fix ls -l triggering automounts.

From: Pádraig Brady <[email-masked]>
Date: Mon, 7 Mar 2022 14:26:27 +0000

Updated patch for ls attached as per discussion.
Added a NEWS entry.

From e4c7fccc0c057a772b6be3f002003ba005cc89d7 Mon Sep 17 00:00:00 2001
From: Rohan Sable <[email-masked]>
Date: Mon, 7 Mar 2022 14:14:13 +0000
Subject: [PATCH] ls: avoid triggering automounts

statx() has different defaults wrt automounting
compared to stat() or lstat(), so explicitly
set the AT_NO_AUTOMOUNT flag to suppress that behavior,
and avoid unintended operations or potential errors.

* src/ls.c (do_statx): Pass AT_NO_AUTOMOUNT to avoid this behavior.
* NEWS: Mention the bug fix.

Signed-off-by: Rohan Sable <[email-masked]>
---
 NEWS     | 4 ++++
 src/ls.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index af6596b06..12051cd15 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   and the documentation has been clarified for unusual cases.
   [bug introduced in coreutils-7.0]
 
+  ls no longer tries to automount files, reverting to the behavior
+  before the statx() call was introduced.
+  [bug introduced in coreutils-8.32]
+
   On macOS, 'mv A B' no longer fails with "Operation not supported"
   when A and B are in the same tmpfs file system.
   [bug introduced in coreutils-9.0]
diff --git a/src/ls.c b/src/ls.c
index 1930e4abb..255789061 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1177,7 +1177,7 @@ do_statx (int fd, char const *name, struct stat *st, int flags,
 {
   struct statx stx;
   bool want_btime = mask & STATX_BTIME;
-  int ret = statx (fd, name, flags, mask, &stx);
+  int ret = statx (fd, name, flags | AT_NO_AUTOMOUNT, mask, &stx);
   if (ret >= 0)
     {
       statx_to_stat (&stx, st);
-- 
2.26.2