Browse Source

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.
tags/debian-devuan_common
Sven Eden Mark Hindley <mark@hindley.org.uk> 3 years ago
parent
commit
94b8b3d652
4 changed files with 25 additions and 9 deletions
  1. +5
    -0
      cb/elogind.cbp
  2. +16
    -0
      meson.build
  3. +4
    -4
      src/shared/musl_missing.c
  4. +0
    -5
      src/shared/musl_missing.h

+ 5
- 0
cb/elogind.cbp View File

@@ -1118,6 +1118,11 @@
<Option target="all" />
<Option target="clean" />
</Unit>
<Unit filename="../tools/meson-build.sh" />
<Unit filename="../tools/meson-check-compilation.sh" />
<Unit filename="../tools/meson-link-test.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<envvars />
<code_completion />


+ 16
- 0
meson.build View File

@@ -589,6 +589,22 @@ else
conf.set10('HAVE_GETRANDOM', have)
endif

#if 1 /// elogind shall be usable with non-glibc libc variations
#####################################################################
# Find out whether program_invocation[_short]_name is supported
have_pisn = cc.links('''
#define _GNU_SOURCE 1
#include <errno.h>
int main(void) {
if (program_invocation_name && program_invocation_short_name)
return 0;
return 1;
}
''', name : 'program_invocation[_short]_name test')
conf.set10('HAVE_PROGRAM_INVOCATION_NAME', have_pisn,
description : 'program_invocation[_short]_name is provided by libc')

#endif // 1
#####################################################################

sed = find_program('sed')


+ 4
- 4
src/shared/musl_missing.c View File

@@ -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
}


+ 0
- 5
src/shared/musl_missing.h View File

@@ -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


Loading…
Cancel
Save