Changeset View
Changeset View
Standalone View
Standalone View
source/lib/sysdep/os/unix/unix.cpp
Show All 32 Lines | |||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#define GNU_SOURCE | #define GNU_SOURCE | ||||
#include <dlfcn.h> | #include <dlfcn.h> | ||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#if OS_LINUX | |||||
#include <sys/random.h> | |||||
#endif | |||||
#if OS_MACOSX | #if OS_MACOSX | ||||
#define URL_OPEN_COMMAND "open" | #define URL_OPEN_COMMAND "open" | ||||
#else | #else | ||||
#define URL_OPEN_COMMAND "xdg-open" | #define URL_OPEN_COMMAND "xdg-open" | ||||
#endif | #endif | ||||
bool sys_IsDebuggerPresent() | bool sys_IsDebuggerPresent() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | if (getlogin_r(buf, ARRAY_SIZE(buf)) == 0) | ||||
return std::wstring(buf, buf + strlen(buf)); | return std::wstring(buf, buf + strlen(buf)); | ||||
#endif | #endif | ||||
return L""; | return L""; | ||||
} | } | ||||
Status sys_generate_random_bytes(u8* buf, size_t count) | Status sys_generate_random_bytes(u8* buf, size_t count) | ||||
{ | { | ||||
#if OS_LINUX | |||||
while (count) | |||||
{ | |||||
ssize_t numread = getrandom(buf, count, GRND_NONBLOCK); | |||||
vladislavbelov: > getrandom() was introduced in version 3.17
We have about 0.4% of users with version less than… | |||||
if (numread == count) | |||||
return INFO::OK; | |||||
if (numread < 0 && errno != EINTR) | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsIs it possible to have numread == 0? Also what's going to happen in case we have EAGAIN? vladislavbelov: Is it possible to have `numread == 0`? Also what's going to happen in case we have `EAGAIN`? | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsOr we have EINTR. vladislavbelov: Or we have `EINTR`. | |||||
// If anything happens here, fall back to the /dev/urandom codepath. | |||||
break; | |||||
buf += numread; | |||||
count -= numread; | |||||
} | |||||
#endif | |||||
FILE* f = fopen("/dev/urandom", "rb"); | FILE* f = fopen("/dev/urandom", "rb"); | ||||
if (!f) | if (!f) | ||||
WARN_RETURN(ERR::FAIL); | WARN_RETURN(ERR::FAIL); | ||||
while (count) | while (count) | ||||
{ | { | ||||
size_t numread = fread(buf, 1, count, f); | size_t numread = fread(buf, 1, count, f); | ||||
if (numread == 0) | if (numread == 0) | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
We have about 0.4% of users with version less than 3.17, are we ready to drop them?
const ssize_t numread. Also I suppose we need to limit the count by IOSIZE_MAX somehow.