mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-22 04:04:51 +02:00
Merge branch '3272-disable-assert-debugging' into 'main'
tests: Only change the behaviour of getpwuid() inside each test function Closes #3272 See merge request GNOME/glib!4519
This commit is contained in:
commit
3662159809
@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#include <glib.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -58,12 +59,23 @@
|
|||||||
|
|
||||||
#undef getpwuid
|
#undef getpwuid
|
||||||
|
|
||||||
|
/* Only modify the result if running inside a GLib test. Otherwise, we risk
|
||||||
|
* breaking test harness code, or test wrapper processes (as this binary is
|
||||||
|
* loaded via LD_PRELOAD, it will affect all wrapper processes). */
|
||||||
|
static inline int
|
||||||
|
should_modify_result (void)
|
||||||
|
{
|
||||||
|
const char *path = g_test_get_path ();
|
||||||
|
return (path != NULL && *path != '\0');
|
||||||
|
}
|
||||||
|
|
||||||
static struct passwd my_pw;
|
static struct passwd my_pw;
|
||||||
|
|
||||||
DEFINE_WRAPPER (struct passwd *, getpwuid, (uid_t uid))
|
DEFINE_WRAPPER (struct passwd *, getpwuid, (uid_t uid))
|
||||||
{
|
{
|
||||||
struct passwd *pw = GET_REAL (getpwuid) (uid);
|
struct passwd *pw = GET_REAL (getpwuid) (uid);
|
||||||
my_pw = *pw;
|
my_pw = *pw;
|
||||||
|
if (should_modify_result ())
|
||||||
my_pw.pw_name = NULL;
|
my_pw.pw_name = NULL;
|
||||||
return &my_pw;
|
return &my_pw;
|
||||||
}
|
}
|
||||||
@ -75,6 +87,7 @@ DEFINE_WRAPPER (int, getpwnam_r, (const char *name,
|
|||||||
struct passwd **result))
|
struct passwd **result))
|
||||||
{
|
{
|
||||||
int code = GET_REAL (getpwnam_r) (name, pwd, buf, buflen, result);
|
int code = GET_REAL (getpwnam_r) (name, pwd, buf, buflen, result);
|
||||||
|
if (should_modify_result ())
|
||||||
pwd->pw_name = NULL;
|
pwd->pw_name = NULL;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
@ -86,6 +99,7 @@ DEFINE_WRAPPER (int, getpwuid_r, (uid_t uid,
|
|||||||
struct passwd **result))
|
struct passwd **result))
|
||||||
{
|
{
|
||||||
int code = GET_REAL (getpwuid_r) (uid, pwd, buf, buflen, result);
|
int code = GET_REAL (getpwuid_r) (uid, pwd, buf, buflen, result);
|
||||||
|
if (should_modify_result ())
|
||||||
pwd->pw_name = NULL;
|
pwd->pw_name = NULL;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,7 @@ else
|
|||||||
getpwuid_preload = shared_library('getpwuid-preload',
|
getpwuid_preload = shared_library('getpwuid-preload',
|
||||||
'getpwuid-preload.c',
|
'getpwuid-preload.c',
|
||||||
name_prefix : '',
|
name_prefix : '',
|
||||||
dependencies: libdl_dep,
|
dependencies: [libdl_dep, libglib_dep],
|
||||||
install_dir : installed_tests_execdir,
|
install_dir : installed_tests_execdir,
|
||||||
install_tag : 'tests',
|
install_tag : 'tests',
|
||||||
install: installed_tests_enabled)
|
install: installed_tests_enabled)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user