diff options
author | Sven Eden <yamakuzure@gmx.net> | 2017-03-12 12:34:34 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-14 10:23:22 +0100 |
commit | a56317566353ab14adc5f68da93af51d880b6ffd (patch) | |
tree | 6b4de762f36eba8adf95026b51396ac0e1c18871 /src | |
parent | 34c7fcb14d705141c71b5b63a2f044a51ffbd92b (diff) |
Fix bug that program_invocation_name is NULL when backgrounding
This is a weird issue. When elogind is started from a tty, everything
works just fine. But since adding the fixes to build elogind against
the musl libc, which does not provide program_invocation_name and
program_invocation_short_name, glibc does not set them when elogind
is background. Neither when done manually, nor when doing it using a
system init tool like openrc /sbin/start-stop-daemon.
The "workaround" is to allow elogind_set_program_name() to (re-)set
both globals if they are either NULL, or not set to the correct
value.
This should work fine with both glibc and musl-libc.
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/musl_missing.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/basic/musl_missing.c b/src/basic/musl_missing.c index bdec82222..f1fbb8ca6 100644 --- a/src/basic/musl_missing.c +++ b/src/basic/musl_missing.c @@ -1,7 +1,7 @@ -#ifndef __GLIBC__ #include <string.h> #include "util.h" +#ifndef __GLIBC__ char *program_invocation_name = NULL; char *program_invocation_short_name = NULL; #endif // __GLIBC__ @@ -9,20 +9,27 @@ char *program_invocation_short_name = NULL; #include "musl_missing.h" static void elogind_free_program_name(void) { -#ifndef __GLIBC__ if (program_invocation_name) program_invocation_name = mfree(program_invocation_name); if (program_invocation_short_name) program_invocation_short_name = mfree(program_invocation_short_name); -#endif // __GLIBC__ } void elogind_set_program_name(const char* pcall) { assert(pcall && pcall[0]); - elogind_free_program_name(); + + if ( ( program_invocation_name + && strcmp(program_invocation_name, pcall)) + || ( program_invocation_short_name + && strcmp(program_invocation_short_name, basename(pcall)) ) ) + elogind_free_program_name(); + + if (NULL == program_invocation_name) + program_invocation_name = strdup(pcall); + if (NULL == program_invocation_short_name) + program_invocation_short_name = strdup(basename(pcall)); + #ifndef __GLIBC__ - program_invocation_name = strdup(pcall); - program_invocation_short_name = strdup(basename(pcall)); atexit(elogind_free_program_name); #endif // __GLIBC__ } |