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.
#include <string.h>
#include "util.h"
#include <string.h>
#include "util.h"
char *program_invocation_name = NULL;
char *program_invocation_short_name = NULL;
#endif // __GLIBC__
char *program_invocation_name = NULL;
char *program_invocation_short_name = NULL;
#endif // __GLIBC__
#include "musl_missing.h"
static void elogind_free_program_name(void) {
#include "musl_missing.h"
static void elogind_free_program_name(void) {
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);
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);
}
void elogind_set_program_name(const char* pcall) {
assert(pcall && pcall[0]);
}
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));
+
- program_invocation_name = strdup(pcall);
- program_invocation_short_name = strdup(basename(pcall));
atexit(elogind_free_program_name);
#endif // __GLIBC__
}
atexit(elogind_free_program_name);
#endif // __GLIBC__
}