]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite: trap calls to uname
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 25 Jan 2012 00:04:46 +0000 (22:04 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 26 Jan 2012 18:05:04 +0000 (16:05 -0200)
Makefile.am
testsuite/testsuite.h
testsuite/uname.c [new file with mode: 0644]

index 257575cd5dba38e6e4ba6f11837094010fdbba7a..42bf0b3db013043cdd9638f90443f52a89686169 100644 (file)
@@ -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
index 919bc6e74aff6ccde1bc128a03d1cb69282a7b0a..d7f81203cf3d2389d2d0534131b1cf0a85bff544 100644 (file)
@@ -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 (file)
index 0000000..9a9cf63
--- /dev/null
@@ -0,0 +1,49 @@
+#include <errno.h>
+#include <dlfcn.h>
+#include <sys/utsname.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#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;
+}