chiark / gitweb /
util-lib: move formats-util.h from shared/ to basic/
[elogind.git] / src / basic / musl_missing.c
index bdec822225d8e4d1e2bb80880a1651b73c16c614..f1fbb8ca6f895ba337162226f26e449500563cd1 100644 (file)
@@ -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__
 }