mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:17:35 +00:00
LibCore: Default to a temp directory for runtime directory on non-Linux
/run/user/$uid is a systemd-ism, and is not present on other platforms.
This commit is contained in:
parent
053e4d5e64
commit
0c025c7d7e
1 changed files with 15 additions and 1 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <LibCore/SessionManagement.h>
|
#include <LibCore/SessionManagement.h>
|
||||||
#include <LibCore/StandardPaths.h>
|
#include <LibCore/StandardPaths.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -109,9 +110,22 @@ ErrorOr<ByteString> StandardPaths::runtime_directory()
|
||||||
builder.append("/Library/Application Support"sv);
|
builder.append("/Library/Application Support"sv);
|
||||||
#elif defined(AK_OS_HAIKU)
|
#elif defined(AK_OS_HAIKU)
|
||||||
builder.append("/boot/system/var/shared_memory"sv);
|
builder.append("/boot/system/var/shared_memory"sv);
|
||||||
#else
|
#elif defined(AK_OS_LINUX)
|
||||||
auto uid = getuid();
|
auto uid = getuid();
|
||||||
builder.appendff("/run/user/{}", uid);
|
builder.appendff("/run/user/{}", uid);
|
||||||
|
#else
|
||||||
|
// Just create a directory in /tmp that's owned by us with 0700
|
||||||
|
auto uid = getuid();
|
||||||
|
builder.appendff("/tmp/runtime_{}", uid);
|
||||||
|
auto error_or_stat = System::stat(builder.string_view());
|
||||||
|
if (error_or_stat.is_error()) {
|
||||||
|
MUST(System::mkdir(builder.string_view(), 0700));
|
||||||
|
} else {
|
||||||
|
auto stat = error_or_stat.release_value();
|
||||||
|
VERIFY(S_ISDIR(stat.st_mode));
|
||||||
|
if ((stat.st_mode & 0777) != 0700)
|
||||||
|
warnln("{} has unexpected mode flags {}", builder.string_view(), stat.st_mode);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return LexicalPath::canonicalized_path(builder.to_byte_string());
|
return LexicalPath::canonicalized_path(builder.to_byte_string());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue