bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] Re: new module: progname


From: Simon Josefsson
Subject: Re: [Bug-gnulib] Re: new module: progname
Date: Thu, 21 Aug 2003 00:23:42 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Simon Josefsson wrote:
>
>> My proposal: for glibc systems, we have program_invocation_name so we
>> are done, for other systems we introduce
>>
>> char *program_invocation_name = NULL;
>>
>> and applications can set this
>
> This means you define a variable on some systems and not on others.
> I find it simpler (for maintainability) to define a variable independently
> of the system, even if it costs 4 bytes of memory on glibc systems.

It is not the wasted memory I'm worried about -- if we define
program_invocation_name = NULL, it will override the weak variable
provided by GNU ld.

In theory, this isn't a problem, since the application should
initialize the new variable using some macro, from argv, but if for
some reason (dlopen, shared library and non-cooperating application,
etc) this doesn't happen, when we use a simple extern definition on
systems that can handle it, the variable will be present and correctly
initialized on GNU systems anyway, which is nice.  Compare:

#include <errno.h>
#include <stdio.h>

#if HAVE_PROGNAME_STUFF
extern char *program_invocation_name;
#else
char *program_invocation_name;
#endif

int main ()
{
  return printf("foo %s\n", program_invocation_name);
}

If we define HAVE_PROGNAME_STUFF, then the program will print the
proper application name on glibc/gld systems.  If we don't define it,
the program will just print null (or rather, crash due to null pointer
dereference).

For non-GNU systems, HAVE_PROGNAME_STUFF would have to be 0, and the
application must call a macro passing argv[0].

Of course, the #if...#endif clause, and the macro, should be in a
gnulib header file which the application include.

Perhaps some other systems provide similar hooks to get the argv[0]
value too, perhaps by calling a function, then #if clause can be
extended with like:

char *program_invocation_name = _some_system_function();

> dlopen()'d plugins are unlucky on Unix. Really, we were better off
> if during dlopen() of a library, a hook in the library would be called,
> let's say
>           _lib_init (const char *proram_invocation_fullname,
>                      const char *shared_library_fullname)
> and if during dlclose() another hook would be called, let's say
>           _lib_close ()

This would be nice, too.

Thanks.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]