Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning: sysctl is not implemented and will always fail #890

Closed
Jingzhao123 opened this issue Sep 1, 2019 · 4 comments
Closed

warning: sysctl is not implemented and will always fail #890

Jingzhao123 opened this issue Sep 1, 2019 · 4 comments
Labels

Comments

@Jingzhao123
Copy link

Hi,
When i build the libevent, there is always a warning. Just like that:

CMakeFiles/event_core_shared.dir/evutil_rand.c.o: In function `arc4_stir':
evutil_rand.c:(.text+0x460): warning: sysctl is not implemented and will always fail

I check the document carefully. I found that the official doc does not suggest using the "sysctl" function:
http://man7.org/linux/man-pages/man2/sysctl.2.html
They suggest that "Glibc does not provide a wrapper for this system call; call it using syscall(2)."
Is any one encounter this problem ?
Configurations:
OS:Ubuntu 18.04
Kernel: 4.18.20
arch: aarch64

@ploxiln
Copy link
Contributor

ploxiln commented Sep 1, 2019

It's a fallback that is typically never attempted on linux:

arc4_seed(void)
{
	int ok = 0;
	/* We try every method that might work, and don't give up even if one
	 * does seem to work.  There's no real harm in over-seeding, and if
	 * one of these sources turns out to be broken, that would be bad. */
#ifdef TRY_SEED_WIN32
	if (0 == arc4_seed_win32())
		ok = 1;
#endif
#ifdef TRY_SEED_URANDOM
	if (0 == arc4_seed_urandom())
		ok = 1;
#endif
#ifdef TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID
	if (arc4random_urandom_filename == NULL &&
	    0 == arc4_seed_proc_sys_kernel_random_uuid())
		ok = 1;
#endif
#ifdef TRY_SEED_SYSCTL_LINUX
	/* Apparently Linux is deprecating sysctl, and spewing warning
	 * messages when you try to use it. */
	if (!ok && 0 == arc4_seed_sysctl_linux())
		ok = 1;
#endif

So if /dev/urandom is accessible, or if /proc/sys/kernel/random/uuid is accessible, it doesn't actually try the sysctl libc call. So if you can ignore the compiler warning, it's fine :)

Anyway, that sysctl strategy should probably be replaced by getrandom() if available.

@azat azat closed this as completed in 86f55b0 Sep 2, 2019
@azat
Copy link
Member

azat commented Sep 2, 2019

Replaced with getrandom, @ploxiln thanks for the suggestion and @Jingzhao123 thanks for the report!

@ploxiln
Copy link
Contributor

ploxiln commented Sep 2, 2019

very nice, thanks @azat

By the way, OpenBSD and MacOS have a getentropy() syscall that is very similar, and I just noticed that glibc also offers this function, for which it uses getrandom() underneath: http://manpages.ubuntu.com/manpages/bionic/man3/getentropy.3.html

But arc4_seed() is probably fine as-is if the bsd sysctl method still works fine on those OS anyway.

@azat
Copy link
Member

azat commented Sep 3, 2019

MacOS have a getentropy()

There are some issues on osx sierra at least (see #398), so let's keep it as-is for now, to avoid introducing yet another build switch.

@azat azat added the os:linux label Sep 3, 2019
azat added a commit to azat/libevent that referenced this issue Jun 28, 2020
Since sysctl() is deprecated for a long-long time, according to
sysctl(2):

    Since Linux 2.6.24, uses of this system call result in warnings in the kernel log.

Fixes: libevent#890
Suggested-by: Pierce Lopez
(cherry picked from commit 86f55b0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants