From: Lucas De Marchi Date: Wed, 25 Jan 2012 00:04:46 +0000 (-0200) Subject: testsuite: trap calls to uname X-Git-Tag: v5~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68cc44937653da88e8d5b72ad3d5eb86b5c7a424;p=thirdparty%2Fkmod.git testsuite: trap calls to uname --- diff --git a/Makefile.am b/Makefile.am index 257575cd..42bf0b3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -128,6 +128,18 @@ ${noinst_SCRIPTS}: tools/kmod-nolib $(LN_S) $(notdir $<) $@) endif +# libtool will not create a shared library that is not installed. Workaround +# this by creating it by ourselves +CREATE_SHARED_OVERRIDE_LIB = \ + $(AM_V_CCLD)gcc -fPIC $(AM_CPPFLAGS) $(AM_CFLAGS) -shared $^ \ + -o $@ $(AM_LDFLAGS) -ldl + +testsuite/uname.so: testsuite/uname.c + $(CREATE_SHARED_OVERRIDE_LIB) + +EXTRA_DIST += testsuite/uname.c +CLEANFILES += testsuite/uname.so + check_LTLIBRARIES = testsuite/libtestsuite.la testsuite_libtestsuite_la_SOURCES = testsuite/testsuite.c \ testsuite/testsuite.h diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index 919bc6e7..d7f81203 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -13,6 +13,9 @@ enum test_config { _TC_LAST, }; +#define S_TC_UNAME_R "TESTSUITE_UNAME_R" + + struct test { const char *name; const char *description; diff --git a/testsuite/uname.c b/testsuite/uname.c new file mode 100644 index 00000000..9a9cf63f --- /dev/null +++ b/testsuite/uname.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include + +#include "testsuite.h" + +TS_EXPORT int uname(struct utsname *u) +{ + static void *nextlib = NULL; + static int (*nextlib_uname)(struct utsname *u); + const char *release = getenv(S_TC_UNAME_R); + int err; + size_t sz; + + if (release == NULL) { + fprintf(stderr, "TRAP uname(): missing export %s?\n", + S_TC_UNAME_R); + errno = EFAULT; + return -1; + } + + if (nextlib == NULL) { +#ifdef RTLD_NEXT + nextlib = RTLD_NEXT; +#else + nextlib = dlopen("libc.so.6", RTLD_LAZY); +#endif + nextlib_uname = dlsym(nextlib, "uname"); + } + + err = nextlib_uname(u); + if (err < 0) + return err; + + sz = strlen(release) + 1; + if (sz > sizeof(u->release)) { + fprintf(stderr, "uname(): sizeof release (%s) " + "is greater than available space: %lu", + release, sizeof(u->release)); + errno = -EFAULT; + return -1; + } + + memcpy(u->release, release, sz); + return 0; +}