diff options
author | Sven Eden <yamakuzure@gmx.net> | 2017-06-07 12:10:11 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-06-16 10:12:58 +0200 |
commit | 955baa81f8239cb338f53c7707d6d2c656c32c33 (patch) | |
tree | d06f6a9f9b0c8199527a0023c8bee88aeb5bb10a /src/shared/musl_missing.c | |
parent | e1a3886b1048af543e67f4af0c02bb8d0abb9ca9 (diff) |
Prep v230: Move musl_missing and parse-printf-format to libshared.
Diffstat (limited to 'src/shared/musl_missing.c')
-rw-r--r-- | src/shared/musl_missing.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/shared/musl_missing.c b/src/shared/musl_missing.c new file mode 100644 index 000000000..5ce787beb --- /dev/null +++ b/src/shared/musl_missing.c @@ -0,0 +1,36 @@ +#include <string.h> +#include "alloc-util.h" + +#ifndef __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) { + 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]); + + 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__ + atexit(elogind_free_program_name); +#endif // __GLIBC__ +} + |