How to compile seccomp test program

ساخت وبلاگ

I am running 16.04 LTS.

I am trying to compile the seccomp test program that is in the man page for seccomp. The test program is at the bottom of the man page http://man7.org/linux/man-pages/man2/seccomp.2.html


When I try to compile the program I get the following error message:

Code:

chen@consulting-VirtualBox:~/work/seccompTest$ gcc seccompTest.c
seccompTest.c: In function ‘install_filter’:
seccompTest.c:65:7: warning: implicit declaration of function ‘seccomp’ [-Wimplicit-function-declaration] if (seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog)) { ^
/tmp/cc5KwI6o.o: In function `install_filter':
seccompTest.c:(.text+0x108): undefined reference to `seccomp'
collect2: error: ld returned 1 exit status
If you go and look at the line it complains about it is in the function install_filter and we are trying to make a system call to secomp.

Code:

 if (seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog)) { perror("seccomp"); return 1; }
Looking at the error message there are several things going on here
  1. It looks like my paths are not setup properly and the compiler cannot find <linux/seccomp.h>
  2. Due to the inability of finding the header the system call is not being properly made and the compiler thinks that seccomp is a function and not a system call.

I tried to fix this problem by downloading the kernel headers and modifying my build line to search for the headers properly. But this just seems to make the problem worse

Code:

chen@consulting-VirtualBox:~/work/seccompTest$ gcc -I/usr/src/linux-headers-4.4.0-34/include seccompTest.c
In file included from /usr/src/linux-headers-4.4.0-34/include/uapi/linux/capability.h:16:0, from /usr/src/linux-headers-4.4.0-34/include/linux/capability.h:15, from /usr/src/linux-headers-4.4.0-34/include/linux/sched.h:15, from /usr/src/linux-headers-4.4.0-34/include/linux/audit.h:26, from seccompTest.c:6:
/usr/src/linux-headers-4.4.0-34/include/linux/types.h:14:26: error: conflicting types for ‘fd_set’ typedef __kernel_fd_set fd_set; ^
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:219:0, from /usr/include/stdlib.h:314, from seccompTest.c:4:
I can verify that seccomp is installed in the kernel because I can run the program (listed here https://outflux.net/teach-seccomp/autodetect.html) to detect the version of seccomp that is installed on my machine.

I'm pretty sure that I'm doing something silly wrong here. Just need some pointers to where to look.

feed all...
ما را در سایت feed all دنبال می کنید

برچسب : how to compile java,how to compile c,how to compile python,how to compile java in cmd,how to compile in eclipse,how to compile c, on mac,how to compile in visual studio,how to compile c, on windows,how to compile,how to compile a java program, نویسنده : استخدام کار feedoll بازدید : 383 تاريخ : چهارشنبه 10 شهريور 1395 ساعت: 4:52