progname: also set global program_invocation_name, when possible.
authorJim Meyering <meyering@redhat.com>
Mon, 24 Aug 2009 23:02:32 +0000 (01:02 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 24 Aug 2009 23:03:33 +0000 (01:03 +0200)
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 <errno.h>.
(set_program_name) [HAVE_DECL_PROGRAM_INVOCATION_NAME]:
Set program_invocation_name.

ChangeLog
lib/progname.c
modules/progname

index 21e02a21ab0519f6dbcedc357e1cf8f78ee8b7d7..6ad5647205de490910cd46d9b59d717a976fd8e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-08-24  Jim Meyering  <meyering@redhat.com>
+
+       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 <errno.h>.
+       (set_program_name) [HAVE_DECL_PROGRAM_INVOCATION_NAME]:
+       Set program_invocation_name.
+
 2009-08-23  Bruno Haible  <bruno@clisp.org>
 
        * lib/dup3.c: Include <string.h>.
index 9854b5e7ccbb73cbac054802940a55528b61fbac..19df10ad7169d43016a12e5bfc1dc1f5fcbb9d9a 100644 (file)
@@ -22,6 +22,7 @@
 #undef ENABLE_RELOCATABLE /* avoid defining set_program_name as a macro */
 #include "progname.h"
 
+#include <errno.h> /* get program_invocation_name declaration */
 #include <string.h>
 
 
@@ -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
 }
index eacc4529cac280aba516884a56cc1012e3910f0f..0877801525054653064d5f90bef768ddd2f7c01a 100644 (file)
@@ -8,6 +8,7 @@ lib/progname.c
 Depends-on:
 
 configure.ac:
+AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])
 
 Makefile.am:
 lib_SOURCES += progname.h progname.c