Skip to content

Check whether "getrandom" exists#23805

Open
glassez wants to merge 1 commit intoqbittorrent:masterfrom
glassez:termux
Open

Check whether "getrandom" exists#23805
glassez wants to merge 1 commit intoqbittorrent:masterfrom
glassez:termux

Conversation

@glassez
Copy link
Member

@glassez glassez commented Feb 2, 2026

Under some Linux environments (e.g. Termux) "getrandom" may not actually exist.

Under some Linux environments (e.g. Termux) "getrandom" may not actually exist.
@glassez glassez added this to the 5.2 milestone Feb 2, 2026
@glassez glassez requested a review from a team February 2, 2026 08:21
@glassez glassez added OS: Linux Issues specific to Linux distributions Build system Issue with the build configuration or scripts (but not the code itself) labels Feb 2, 2026
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
include(CheckSymbolExists)
check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM)
Copy link
Member

@Chocobo1 Chocobo1 Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the actual problem with Termux?
Is this system header not present?

Under some Linux environments (e.g. Termux) "getrandom" may not actually exist.

randomlayer_linux.cpp have fallback path, is it not working?

if (unsigned char buf = 0; ::getrandom(&buf, sizeof(buf), 0) < 0)
{
if (errno == ENOSYS)
{
// underlying kernel does not implement this system call
// fallback to `urandom`
m_randDev = fopen("/dev/urandom", "rb");
if (!m_randDev)
qFatal("Failed to open /dev/urandom. Reason: \"%s\". Error code: %d.", std::strerror(errno), errno);
}

I guess the function simply doesn't exist...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the function simply doesn't exist...

Yes. The sys/random.h header exists but it defines getrandom function depending on Android API version which is not satisfied by Termux (Termux is built for a lower API version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Build system Issue with the build configuration or scripts (but not the code itself) OS: Linux Issues specific to Linux distributions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants