On 28/11/2026 16:21, Pádraig Brady wrote:
On 27/11/2026 17:22, Pádraig Brady wrote:
* configure.ac: Accept and validate --program-prefix
with --enable-single-binary={symlinks,hardlinks}.
* src/coreutils.c: Also match the prefixed name.
Note this is done before the standard name match
so edge cases like --prefix=un are handled wrt "link" and "unlink".
* NEWS: Mention the Build-related change.
In retrospect I'm going to drop this one,
because there are other issues with argv[0] dispatch,
i.e. with --enable-single-binary={symlinks,hardlinks}.

While this patch works fine, it might encourage use
of these non-recommended install modes.

We could plug some of the argv[0] generality issues
with readlink(/proc/self/exe) or getauxval(AT_EXECFN),
but these are either not mounted, non supported,
prone to TOCTOU races, and have added complexity.

For reference, some of the issues with argv[0] dispatch:

    `env -a` etc. can set argv to anything,
    which might bypass path based rules like with apparmor etc.

    You can't copy/link symlinks or hardlinks to other
    non standard names as they'll lose their mapping.

    symlink1 -> symlink2 -> dispatch loses intent of symlink2

For completeness shebangs also has an issue
though it's less of a problem in practice.

    `env -a foo CMD` loses the argv[0] foo.
    E.g. `env -a myjob timeout 10 sleep 10`
    is then not found with e.g. `pgrep -f myjob`

I'll document these in the texi I think.
Done with the attached.
From 94b84d75b851127472afb3fbb26e4b7286fe3666 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Sat, 28 Nov 2026 17:35:57 +0000
Subject: [PATCH] doc: recommend --enable-single-binary=shebangs mode

* configure.ac: Explicitly say --enable-single-binary[=shebangs]
is the recommended single binary installation mode.
* doc/coreutils.texi (Multi-call invocation): List the limitations
of each single binary mode, and restate that "shebang" scripts
are the recommended invocation method.
---
 configure.ac       |  3 ++-
 doc/coreutils.texi | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 4d1c81576..eeb766f22 100644
--- a/configure.ac
+++ b/configure.ac
@@ -113,7 +113,8 @@ AC_ARG_ENABLE([single-binary],
   [AS_HELP_STRING([--enable-single-binary@<:@=shebangs|symlinks|hardlinks@:>@],
      [Compile all the tools in a single binary, reducing the overall size.
       When compiled this way, shebangs (default when enabled), symlinks, or
-      hardlinks are installed for each tool, which point to a single binary])],
+      hardlinks are installed for each tool. "shebangs" is the recommended
+      method, and most closely mimics standalone tools])],
   [gl_single_binary=no ;
    case $enableval in
      yes) gl_single_binary=shebangs ;;
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 6b2194b31..fb464fc29 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -1706,6 +1706,43 @@ one per line.
 The @command{coreutils} command is not installed by default, so
 portable scripts should not rely on its existence.
 
+Where @command{coreutils} is installed, by default the main binary
+is referenced with small @samp{shebang} scripts for each utility.
+This is the most robust and recommended invocation method, allowing
+arbitrary naming and copying of commands, but has these limitations:
+
+@itemize @w{}
+@item
+Any explicit @code{argv[0]} set e.g. with @code{env --argv0}
+will be lost in the invocation through the @samp{shebang} script.
+
+@item
+On the BSDs and macOS, a shebang wrapper cannot itself serve
+as the interpreter named in another script’s shebang.
+@end itemize
+
+Note individual commands can be installed as a standalone utility,
+to alleviate these edge cases.
+E.g., configure with @code{--enable-single-binary-exceptions=env}.
+
+Invoking the @command{coreutils} command through a symlink or hardlink,
+has these limitations:
+
+@itemize @w{}
+@item
+The link must identify a built-in command name.
+I.e., @code{argv[0]} can't be arbitrarily set with @command{env} @option{-a},
+nor can the links be named or copied to non standard names.
+
+@item
+Having potentially different utility run depending on @code{argv[0]}
+than might otherwise be implied with the invocation file name,
+is problematic in the context of file name based security like e.g. AppArmor.
+
+@item
+The intent of any intermediate names in symlink chains is lost.
+@end itemize
+
 @node Output of entire files
 @chapter Output of entire files
 
-- 
2.56.0

Reply via email to