diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-10 10:32:54 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-10 10:34:45 +0100 |
commit | d38b9916c99543a40d0c297ac92815f2ad1a7508 (patch) | |
tree | 8dd85af4fe99b2930207902df0a6aea65dbcbe9f | |
parent | 795bccbf697a805eaece48e1c554fc5fe1ab09fc (diff) | |
download | serenity-d38b9916c99543a40d0c297ac92815f2ad1a7508.zip |
SystemServer+LibCore: Move /tmp/rpc/ directory creation to SystemServer
This doesn't solve half of the problems with /tmp/rpc, but this way we
can at least make it sticky instead of having it fully world-writable
and owned by whoever was the first to bind an RPC socket.
-rw-r--r-- | Libraries/LibCore/EventLoop.cpp | 18 | ||||
-rw-r--r-- | Services/SystemServer/main.cpp | 13 |
2 files changed, 15 insertions, 16 deletions
diff --git a/Libraries/LibCore/EventLoop.cpp b/Libraries/LibCore/EventLoop.cpp index 656bfae152..31aa8fb118 100644 --- a/Libraries/LibCore/EventLoop.cpp +++ b/Libraries/LibCore/EventLoop.cpp @@ -314,22 +314,8 @@ EventLoop::~EventLoop() bool EventLoop::start_rpc_server() { - // Create /tmp/rpc if it doesn't exist. - int rc = mkdir("/tmp/rpc", 0777); - if (rc == 0) { - // Ensure it gets created as 0777 despite our umask. - rc = chmod("/tmp/rpc", 0777); - if (rc < 0) { - perror("chmod /tmp/rpc"); - // Continue further. - } - } else if (errno != EEXIST) { - perror("mkdir /tmp/rpc"); - return false; - } - - auto rpc_path = String::format("/tmp/rpc/%d", getpid()); - rc = unlink(rpc_path.characters()); + auto rpc_path = String::formatted("/tmp/rpc/{}", getpid()); + auto rc = unlink(rpc_path.characters()); if (rc < 0 && errno != ENOENT) { perror("unlink"); return false; diff --git a/Services/SystemServer/main.cpp b/Services/SystemServer/main.cpp index 56179e86b5..19cf7b2895 100644 --- a/Services/SystemServer/main.cpp +++ b/Services/SystemServer/main.cpp @@ -180,6 +180,18 @@ static void mount_all_filesystems() } } +static void create_tmp_rpc_directory() +{ + dbgln("Creating /tmp/rpc directory"); + auto old_umask = umask(0); + auto rc = mkdir("/tmp/rpc", 01777); + if (rc < 0) { + perror("mkdir(/tmp/rpc)"); + ASSERT_NOT_REACHED(); + } + umask(old_umask); +} + int main(int, char**) { prepare_devfs(); @@ -190,6 +202,7 @@ int main(int, char**) } mount_all_filesystems(); + create_tmp_rpc_directory(); parse_boot_mode(); Core::EventLoop event_loop; |