summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorSven Eden <yamakuzure@gmx.net>2018-10-16 19:57:45 +0200
committerSven Eden <yamakuzure@gmx.net>2018-10-16 19:57:45 +0200
commit7f1e80bff4967f9a7b0d7ff79e02856ab94b6c1d (patch)
treef86e60b9f37f5b0bb255d0024dec951da96c6124 /src/shared
parente143b8013b96fca5d5ef4a73fe255daed3aa1ec3 (diff)
Prep v239: Fix an issue with program_invocation[_short]_name :
The old implementation was done assuming that only glibc provides both program_invocation_name and program_invocation_short_name. This worked well for users using musl-libc with the library having been built without -D_GNU_SOURCE. However, alternative libc implementations that actually do provide these variables, could cause elogind to crash. To be on the safe side, we now actually check whether both these variables are present by letting meson check whether a code snippet accessing these compiles and links.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/musl_missing.c8
-rw-r--r--src/shared/musl_missing.h5
2 files changed, 4 insertions, 9 deletions
diff --git a/src/shared/musl_missing.c b/src/shared/musl_missing.c
index ffa0ff78f..0f8b4d1ad 100644
--- a/src/shared/musl_missing.c
+++ b/src/shared/musl_missing.c
@@ -23,10 +23,10 @@
#include "alloc-util.h"
-#ifndef __GLIBC__
+#if HAVE_PROGRAM_INVOCATION_NAME == 0
char *program_invocation_name = NULL;
char *program_invocation_short_name = NULL;
-#endif // __GLIBC__
+#endif // libc does not provide these variables
const char *program_arg_name = NULL;
@@ -55,8 +55,8 @@ void elogind_set_program_name(const char* pcall) {
program_invocation_name = strdup(program_arg_name);
if (NULL == program_invocation_short_name)
program_invocation_short_name = strdup(basename(program_arg_name));
-#ifndef __GLIBC__
+#if HAVE_PROGRAM_INVOCATION_NAME == 0
atexit(elogind_free_program_name);
-#endif // __GLIBC__
+#endif // libc does not provide these variables
}
diff --git a/src/shared/musl_missing.h b/src/shared/musl_missing.h
index 15f5f8473..cf5a01481 100644
--- a/src/shared/musl_missing.h
+++ b/src/shared/musl_missing.h
@@ -27,11 +27,6 @@ void elogind_set_program_name(const char* pcall);
#define strerror_r(e, m, k) (strerror_r(e, m, k) < 0 ? strdup("strerror_r() failed") : m);
-#ifndef _ERRNO_H
-extern char *program_invocation_name;
-extern char *program_invocation_short_name;
-#endif // errno.h included beforehand
-
/*
* Possibly TODO according to http://man7.org/linux/man-pages/man3/getenv.3.html
* + test if the process's effective user ID does not match its real user ID or