From 9cedf3e1ac7dbdddefb7e172156e9000de7d80c2 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 25 Aug 2009 01:02:32 +0200 Subject: [PATCH] progname: also set global program_invocation_name, when possible. Before this change, a libtool-enabled program that calls glibc's error function would report the program name as "/abs/dir/.libs/lt-program_name" rather than the desired program_name. * modules/progname (configure.ac): Check for a declaration of program_invocation_name. * lib/progname.c: Include . (set_program_name) [HAVE_DECL_PROGRAM_INVOCATION_NAME]: Set program_invocation_name. --- ChangeLog | 12 ++++++++++++ lib/progname.c | 8 ++++++++ modules/progname | 1 + 3 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index 21e02a21ab..6ad5647205 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-08-24 Jim Meyering + + progname: also set global program_invocation_name, when possible + Before this change, a libtool-enabled program that calls glibc's + error function would report the program name as + "/abs/dir/.libs/lt-program_name" rather than the desired program_name. + * modules/progname (configure.ac): Check for a declaration of + program_invocation_name. + * lib/progname.c: Include . + (set_program_name) [HAVE_DECL_PROGRAM_INVOCATION_NAME]: + Set program_invocation_name. + 2009-08-23 Bruno Haible * lib/dup3.c: Include . diff --git a/lib/progname.c b/lib/progname.c index 9854b5e7cc..19df10ad71 100644 --- a/lib/progname.c +++ b/lib/progname.c @@ -22,6 +22,7 @@ #undef ENABLE_RELOCATABLE /* avoid defining set_program_name as a macro */ #include "progname.h" +#include /* get program_invocation_name declaration */ #include @@ -60,4 +61,11 @@ set_program_name (const char *argv0) */ program_name = argv0; + + /* On glibc systems, when the gnulib module 'error' is not used, the error() + function comes from libc and uses the variable program_invocation_name, + not program_name. So set this variable as well. */ +#if HAVE_DECL_PROGRAM_INVOCATION_NAME + program_invocation_name = (char *) argv0; +#endif } diff --git a/modules/progname b/modules/progname index eacc4529ca..0877801525 100644 --- a/modules/progname +++ b/modules/progname @@ -8,6 +8,7 @@ lib/progname.c Depends-on: configure.ac: +AC_CHECK_DECLS([program_invocation_name], [], [], [#include ]) Makefile.am: lib_SOURCES += progname.h progname.c -- 2.30.2