[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] fix consistency issues in set_program_name()
From: |
Pádraig Brady |
Subject: |
Re: [PATCH] fix consistency issues in set_program_name() |
Date: |
Sun, 12 Jan 2025 20:01:42 +0000 |
User-agent: |
Mozilla Thunderbird Beta |
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
progname.patch
Description: Text Data