瀏覽代碼

LibCore: Make singleton process helpers public

Andrew Kaster 1 年之前
父節點
當前提交
12a9702acb
共有 2 個文件被更改,包括 11 次插入7 次删除
  1. 3 7
      Userland/Libraries/LibCore/Process.cpp
  2. 8 0
      Userland/Libraries/LibCore/Process.h

+ 3 - 7
Userland/Libraries/LibCore/Process.cpp

@@ -379,7 +379,7 @@ ErrorOr<IPCProcess::ProcessAndIPCSocket> IPCProcess::spawn_and_connect_to_proces
     return ProcessAndIPCSocket { move(process), move(ipc_socket) };
 }
 
-static ErrorOr<Optional<pid_t>> get_process_pid(StringView process_name, StringView pid_path)
+ErrorOr<Optional<pid_t>> IPCProcess::get_process_pid(StringView process_name, StringView pid_path)
 {
     if (System::stat(pid_path).is_error())
         return OptionalNone {};
@@ -416,7 +416,7 @@ static ErrorOr<Optional<pid_t>> get_process_pid(StringView process_name, StringV
 }
 
 // This is heavily based on how SystemServer's Service creates its socket.
-static ErrorOr<int> create_ipc_socket(ByteString const& socket_path)
+ErrorOr<int> IPCProcess::create_ipc_socket(ByteString const& socket_path)
 {
     if (!System::stat(socket_path).is_error())
         TRY(System::unlink(socket_path));
@@ -444,11 +444,7 @@ static ErrorOr<int> create_ipc_socket(ByteString const& socket_path)
     return socket_fd;
 }
 
-struct ProcessPaths {
-    ByteString socket_path;
-    ByteString pid_path;
-};
-static ErrorOr<ProcessPaths> paths_for_process(StringView process_name)
+ErrorOr<IPCProcess::ProcessPaths> IPCProcess::paths_for_process(StringView process_name)
 {
     auto runtime_directory = TRY(StandardPaths::runtime_directory());
     auto socket_path = ByteString::formatted("{}/{}.socket", runtime_directory, process_name);

+ 8 - 0
Userland/Libraries/LibCore/Process.h

@@ -138,6 +138,14 @@ public:
         return ProcessAndIPCClient<ClientType> { move(process), move(client) };
     }
 
+    struct ProcessPaths {
+        ByteString socket_path;
+        ByteString pid_path;
+    };
+    static ErrorOr<ProcessPaths> paths_for_process(StringView process_name);
+    static ErrorOr<Optional<pid_t>> get_process_pid(StringView process_name, StringView pid_path);
+    static ErrorOr<int> create_ipc_socket(ByteString const& socket_path);
+
     pid_t pid() const { return m_process.pid(); }
 
 private: