]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/uname.c
testsuite: trap calls to delete_module() including simple test
[thirdparty/kmod.git] / testsuite / uname.c
CommitLineData
68cc4493
LDM
1#include <errno.h>
2#include <dlfcn.h>
3#include <sys/utsname.h>
4#include <stdlib.h>
5#include <string.h>
6#include <stdio.h>
7
8#include "testsuite.h"
9
10TS_EXPORT int uname(struct utsname *u)
11{
12 static void *nextlib = NULL;
13 static int (*nextlib_uname)(struct utsname *u);
14 const char *release = getenv(S_TC_UNAME_R);
15 int err;
16 size_t sz;
17
18 if (release == NULL) {
19 fprintf(stderr, "TRAP uname(): missing export %s?\n",
20 S_TC_UNAME_R);
21 errno = EFAULT;
22 return -1;
23 }
24
25 if (nextlib == NULL) {
26#ifdef RTLD_NEXT
27 nextlib = RTLD_NEXT;
28#else
29 nextlib = dlopen("libc.so.6", RTLD_LAZY);
30#endif
31 nextlib_uname = dlsym(nextlib, "uname");
32 }
33
34 err = nextlib_uname(u);
35 if (err < 0)
36 return err;
37
38 sz = strlen(release) + 1;
39 if (sz > sizeof(u->release)) {
40 fprintf(stderr, "uname(): sizeof release (%s) "
41 "is greater than available space: %lu",
42 release, sizeof(u->release));
43 errno = -EFAULT;
44 return -1;
45 }
46
47 memcpy(u->release, release, sz);
48 return 0;
49}