]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lib/randutils: use getrandom(2) when it is available
authorSami Kerola <kerolasa@iki.fi>
Sun, 11 Dec 2016 11:43:37 +0000 (11:43 +0000)
committerSami Kerola <kerolasa@iki.fi>
Sun, 11 Dec 2016 11:46:54 +0000 (11:46 +0000)
commitcc01c2dca4f62e36505570d5cb15f868aa44bf54
treebe88427c58172fd094fa135852fd3acb236aaf51
parent08595712f3b6c96944987b82ec85e295dc924850
lib/randutils: use getrandom(2) when it is available

System call getrandom(2) is relatively new, available since kernel 3.17 but
not supported by glibc 2.24.  That in mind autotools is made to check
availability of this function and keep old code as fallback.  It is
reasonable assume it will take years before the syscall(2) and fallback are
unproblematic to remove.

One might ask why bother using getrandom(2).  Main reason is to avoid
unnecessary system calls to achieve exactly same end result.  That
demonstrated with 'strace -c ./mcookie' showing 36 calls before, and 32
after this change.  Secondly the getrandom(2) function got to kernel with
promise it can be used to avoid file descriptor run down, and since uuidd
uses random_get_bytes() it should fulfill it's promise here.

Reference: http://man7.org/linux/man-pages/man2/getrandom.2.html
Reference: https://lwn.net/Articles/606141/
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
configure.ac
lib/randutils.c