mirror of
https://github.com/fluencelabs/musl
synced 2025-06-19 09:51:44 +00:00
add support for program_invocation[_short]_name
this is a bit ugly, and the motivation for supporting it is questionable. however the main factors were: 1. it will be useful to have this for certain internal purposes anyway -- things like syslog. 2. applications can just save argv[0] in main, but it's hard to fix non-portable library code that's depending on being able to get the invocation name without the main application's help.
This commit is contained in:
10
src/env/__libc_start_main.c
vendored
10
src/env/__libc_start_main.c
vendored
@ -8,8 +8,9 @@ void __init_ldso_ctors(void);
|
||||
#define AUX_CNT 38
|
||||
|
||||
extern size_t __hwcap, __sysinfo;
|
||||
extern char *__progname, *__progname_full;
|
||||
|
||||
void __init_libc(char **envp)
|
||||
void __init_libc(char **envp, char *pn)
|
||||
{
|
||||
size_t i, *auxv, aux[AUX_CNT] = { 0 };
|
||||
__environ = envp;
|
||||
@ -19,6 +20,11 @@ void __init_libc(char **envp)
|
||||
__hwcap = aux[AT_HWCAP];
|
||||
__sysinfo = aux[AT_SYSINFO];
|
||||
|
||||
if (pn) {
|
||||
__progname = __progname_full = pn;
|
||||
for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
|
||||
}
|
||||
|
||||
__init_tls(aux);
|
||||
__init_security(aux);
|
||||
}
|
||||
@ -30,7 +36,7 @@ int __libc_start_main(
|
||||
{
|
||||
char **envp = argv+argc+1;
|
||||
|
||||
__init_libc(envp);
|
||||
__init_libc(envp, argv[0]);
|
||||
|
||||
libc.ldso_fini = ldso_fini;
|
||||
libc.fini = fini;
|
||||
|
Reference in New Issue
Block a user