]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/uname.c
testsuite: create additional pipe to monitor child
[thirdparty/kmod.git] / testsuite / uname.c
CommitLineData
e701e381
LDM
1/*
2 * Copyright (C) 2012 ProFUSION embedded systems
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
68cc4493
LDM
18#include <errno.h>
19#include <dlfcn.h>
20#include <sys/utsname.h>
21#include <stdlib.h>
22#include <string.h>
23#include <stdio.h>
24
25#include "testsuite.h"
26
27TS_EXPORT int uname(struct utsname *u)
28{
29 static void *nextlib = NULL;
30 static int (*nextlib_uname)(struct utsname *u);
31 const char *release = getenv(S_TC_UNAME_R);
32 int err;
33 size_t sz;
34
35 if (release == NULL) {
36 fprintf(stderr, "TRAP uname(): missing export %s?\n",
37 S_TC_UNAME_R);
38 errno = EFAULT;
39 return -1;
40 }
41
42 if (nextlib == NULL) {
43#ifdef RTLD_NEXT
44 nextlib = RTLD_NEXT;
45#else
46 nextlib = dlopen("libc.so.6", RTLD_LAZY);
47#endif
48 nextlib_uname = dlsym(nextlib, "uname");
49 }
50
51 err = nextlib_uname(u);
52 if (err < 0)
53 return err;
54
55 sz = strlen(release) + 1;
56 if (sz > sizeof(u->release)) {
57 fprintf(stderr, "uname(): sizeof release (%s) "
d3f159bb 58 "is greater than available space: %zu",
68cc4493
LDM
59 release, sizeof(u->release));
60 errno = -EFAULT;
61 return -1;
62 }
63
64 memcpy(u->release, release, sz);
65 return 0;
66}