summaryrefslogtreecommitdiff
path: root/Services/SystemServer/Service.cpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2020-09-28 10:09:05 +0300
committerAndreas Kling <kling@serenityos.org>2020-09-30 21:46:59 +0200
commitfec4152220753b6a2b7b4a9329b5393fe4d3e5b6 (patch)
tree7362a652bbea702e97dcafc68a4537786209d230 /Services/SystemServer/Service.cpp
parentc1fc27cab2782ac12a270882129586d9a124af12 (diff)
downloadserenity-fec4152220753b6a2b7b4a9329b5393fe4d3e5b6.zip
LibCore: Add ensure_parent_directories to LibCore::File
Moved the implementation in SystemServer/Service.cpp to LibCore.
Diffstat (limited to 'Services/SystemServer/Service.cpp')
-rw-r--r--Services/SystemServer/Service.cpp28
1 files changed, 3 insertions, 25 deletions
diff --git a/Services/SystemServer/Service.cpp b/Services/SystemServer/Service.cpp
index f581c0c83d..acc06062a3 100644
--- a/Services/SystemServer/Service.cpp
+++ b/Services/SystemServer/Service.cpp
@@ -29,6 +29,7 @@
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <LibCore/ConfigFile.h>
+#include <LibCore/File.h>
#include <LibCore/Socket.h>
#include <grp.h>
#include <libgen.h>
@@ -84,36 +85,13 @@ Service* Service::find_by_pid(pid_t pid)
return (*it).value;
}
-static int ensure_parent_directories(const char* path)
-{
- ASSERT(path[0] == '/');
-
- char* parent_buffer = strdup(path);
- const char* parent = dirname(parent_buffer);
-
- int rc = 0;
- while (true) {
- int rc = mkdir(parent, 0755);
-
- if (rc == 0)
- break;
-
- if (errno != ENOENT)
- break;
-
- ensure_parent_directories(parent);
- };
-
- free(parent_buffer);
- return rc;
-}
-
void Service::setup_socket()
{
ASSERT(!m_socket_path.is_null());
ASSERT(m_socket_fd == -1);
- ensure_parent_directories(m_socket_path.characters());
+ auto ok = Core::File::ensure_parent_directories(m_socket_path);
+ ASSERT(ok);
// Note: we use SOCK_CLOEXEC here to make sure we don't leak every socket to
// all the clients. We'll make the one we do need to pass down !CLOEXEC later