On 12/01/2025 18:40, Bruno Haible wrote:
Hi Pádraig,
I noticed a discrepancy in the program name output by error(),
which looks to be due to whether the gnulib or glibc version is used.
If we use gnulib's error() it uses getprogname()
which defaults to program_invocation_short_name.
The glibc error() instead uses program_invocation_name.
I don't know why gnulib differs in that regard
Here's the explanation:
- We want error() to be usable in library code or, at least, in code
that does not impose requirements on the main() function.
This was done on 2016-08-08 by Pino Toscano.
- The function that this uses, getprogname(), returns the base name,
because we like to have the same behaviour across platforms, and on
most platforms the full program name is not available. (Look at the
amount of hacks needed to get only the base name!)
The comments in progname.c indicate the intention to keep glibc's
variables in sync with what the caller is passing to set_program_name().
I've not looked into why coreutils is using the gnulib error()
given that REPLACE_ERROR=0 and HAVE_ERROR=1
It's because of
m4_ifdef([gl_HAVE_MODULE_VERROR],
[COMPILE_ERROR_C=1],
...
in m4/error_h.m4. coreutils apparently uses the module 'verror'.
Ah right thanks.
coreutils has used verror for a long time, but this new dependency
on error is recent and not yet released. It was introduced with:
https://git.sv.gnu.org/cgit/gnulib.git/commit/?id=959152ba37
It will mean a change in behavior for coreutils
with the base name being used for error(),
but the full name being used elsewhere. For example:
$ $PWD/src/mktemp 1 2
mktemp: too many templates
Try '/home/padraig/git/coreutils/src/mktemp --help' for more information.
$ ~/coreutils-9.5/src/mktemp 1 2
/home/padraig/coreutils-9.5/src/mktemp: too many templates
Try '/home/padraig/coreutils-9.5/src/mktemp --help' for more information.
That's not a problem I think, since any invocation examples
continue to use the full program_name, it's just something to be aware of.
but in any case program_invocation_name and program_invocation_short_name
should be consistent with each other.
I agree.
This is not the case because set_program_name()
only sets program_invocation_name normally.
Can you describe the circumstances where you observed the discrepancy?
It impacts the tests when we `./configure --enable-single-binary=shebangs`.
In that case "coreutils" will be initialised by glibc to
program_invocation_short_name, and then when we override with
set_program_name(actual_utility), it wasn't updated.
Then various error messages checked in the tests failed to match.
The attached patch also sets program_invocation_short_name
and results in coreutils' tests passing in all cases.
The patch would look cleaner, I think, if the fix would be placed
around line 92, not around line 71. Also there's an indentation problem.
Yes that's cleaner.
Updated version attached.
cheers,
Pádraig
From f11caad4fd70701bd1d95691a8528617623bf121 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Sun, 12 Jan 2025 16:47:57 +0000
Subject: [PATCH] progname: also set program_invocation_short_name
* lib/progname.c (set_program_name): Keep program_invocation_name
and program_invocation_short_name consistent.
---
ChangeLog | 6 ++++++
lib/progname.c | 11 +++++------
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6ccd999e80..b52a2799b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-01-12 Pádraig Brady <p...@draigbrady.com>
+
+ progname: also set program_invocation_short_name
+ * lib/progname.c (set_program_name): Keep program_invocation_name
+ and program_invocation_short_name consistent.
+
2025-01-11 Pádraig Brady <p...@draigbrady.com>
file-has-acl: handle NFSv4 ACLs with listxattr returning EACCES
diff --git a/lib/progname.c b/lib/progname.c
index ee62489285..4a45ca3490 100644
--- a/lib/progname.c
+++ b/lib/progname.c
@@ -63,12 +63,8 @@ set_program_name (const char *argv0)
argv0 = base;
if (strncmp (base, "lt-", 3) == 0)
{
- argv0 = base + 3;
- /* On glibc systems, remove the "lt-" prefix from the variable
- program_invocation_short_name. */
-#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
- program_invocation_short_name = (char *) argv0;
-#endif
+ base += 3;
+ argv0 = base;
}
}
@@ -89,4 +85,7 @@ set_program_name (const char *argv0)
#if HAVE_DECL_PROGRAM_INVOCATION_NAME
program_invocation_name = (char *) argv0;
#endif
+#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+ program_invocation_short_name = (char *) base;
+#endif
}
--
2.47.1