The problem was resolved by upgrading the C library.
I would like to use the syscall getrandom (http://man7.org/linux/man-pages/man2/getrandom.2.html)
gcc-5 -std=c11 test.c
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <linux/random.h>
#include <sys/syscall.h>
int main(void)
{
void *buf = NULL;
size_t l = 5;
unsigned int o = 1;
int r = syscall(SYS_getrandom, buf, l, o);
return 0;
}
or
int main(void)
{
void *buf = NULL;
size_t l = 5;
unsigned int o = 1;
int r = getrandom(buf, l, o);
return 0;
}
Anyway when I try to compile it with gcc-5:
test.c: In function ‘main’:
test.c:14:17: warning: implicit declaration of function ‘getrandom’ [-Wimplicit-function-declaration]
int r = getrandom(buf, l, o);
^
/tmp/ccqFdJAJ.o: In function `main':
test.c:(.text+0x36): undefined reference to `getrandom'
collect2: error: ld returned 1 exit status
I am using Ubuntu 14.04, what can I do to use getrandom? As it is a "new" syscall, how can I use it?
edit:
uname -r
-> 4.0.3-040003-generic #201505131441 SMP Wed May 13 13:43:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
when I replace r by int r = syscall(SYS_getrandom, buf, l, o);
or r = getrandom(buf, l, o) it is the same..
The
getrandom()
syscall was introduced in the linux kernel 3.17. Ubuntu 14.04 gets shipped with kernel 3.13, so you have to update to a more recent kernel to get the syscall.To get .deb packages of the linux kernel for Ubuntu, have a look at kernel.ubuntu.com. This problem was also discussed at askubuntu.com.