diff mbox series

[2/8] lapi: Add a configure check and fallback for setns

Message ID 20200305134834.16736-3-chrubis@suse.cz
State Superseded
Headers show
Series Add basic time namespace testcases | expand

Commit Message

Cyril Hrubis March 5, 2020, 1:48 p.m. UTC
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 configure.ac         |  1 +
 include/lapi/setns.h | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 include/lapi/setns.h

Comments

Petr Vorel March 9, 2020, 10:15 a.m. UTC | #1
Hi Cyril,

your patchset looks good to me.

There is an error for old glibc on centos 06:

https://api.travis-ci.org/v3/job/659994070/log.txt

In file included from /usr/src/ltp/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c:21:

/usr/src/ltp/include/lapi/setns.h: In function 'setns':

/usr/src/ltp/include/lapi/setns.h:16: error: implicit declaration of function 'syscall'

/usr/src/ltp/include/lapi/setns.h:16: error: implicit declaration of function 'tst_brk'

/usr/src/ltp/include/lapi/setns.h:16: error: 'TCONF' undeclared (first use in this function)

/usr/src/ltp/include/lapi/setns.h:16: error: (Each undeclared identifier is reported only once

/usr/src/ltp/include/lapi/setns.h:16: error: for each function it appears in.)

In file included from /usr/src/ltp/include/tst_test.h:14,

                 from /usr/src/ltp/include/tst_safe_clocks.h:13,

                 from /usr/src/ltp/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c:22:

/usr/include/unistd.h: At top level:

/usr/include/unistd.h:1068: error: conflicting types for 'syscall'

/usr/src/ltp/include/lapi/setns.h:16: note: previous implicit declaration of 'syscall' was here


Kind regards,
Petr
Cyril Hrubis March 9, 2020, 10:34 a.m. UTC | #2
Hi!
> There is an error for old glibc on centos 06:
> 
> https://api.travis-ci.org/v3/job/659994070/log.txt
> 
> In file included from /usr/src/ltp/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c:21:
> 
> /usr/src/ltp/include/lapi/setns.h: In function 'setns':
> 
> /usr/src/ltp/include/lapi/setns.h:16: error: implicit declaration of function 'syscall'

Hmm, I guess that we can include unistd.h in the lapi/syscalls.h so that
the syscall() function has a prototype.

> /usr/src/ltp/include/lapi/setns.h:16: error: implicit declaration of function 'tst_brk'
> 
> /usr/src/ltp/include/lapi/setns.h:16: error: 'TCONF' undeclared (first use in this function)
> 
> /usr/src/ltp/include/lapi/setns.h:16: error: (Each undeclared identifier is reported only once
> 
> /usr/src/ltp/include/lapi/setns.h:16: error: for each function it appears in.)
> 
> In file included from /usr/src/ltp/include/tst_test.h:14,
> 
>                  from /usr/src/ltp/include/tst_safe_clocks.h:13,
> 
>                  from /usr/src/ltp/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c:22:

Okay, I guess that both errors could be fixed by moving the lapi/setns.h
include after the tst_test.h in the test, because tst_test.h both
includes unistd.h as well as defines the tst_brk() and TCONF.

Thanks for spotting this.
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index c9ec39fce..cd52806de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,7 @@  AC_CHECK_FUNCS([ \
     renameat2 \
     sched_getcpu \
     sendmmsg \
+    setns \
     sigpending \
     splice \
     statx \
diff --git a/include/lapi/setns.h b/include/lapi/setns.h
new file mode 100644
index 000000000..7b0a7afc4
--- /dev/null
+++ b/include/lapi/setns.h
@@ -0,0 +1,20 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+  Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef LAPI_SETNS_H__
+#define LAPI_SETNS_H__
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include <sched.h>
+
+#ifndef HAVE_SETNS
+int setns(int fd, int nstype)
+{
+	return tst_syscall(__NR_setns, fd, nstype);
+}
+#endif
+
+#endif /* LAPI_SETNS_H__ */