mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibCore: Port SystemServerTakeover.cpp to Windows
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2022, sin-ack <sin-ack@protonmail.com>
|
||||
* Copyright (c) 2025, stasoid <stasoid@yahoo.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "SystemServerTakeover.h"
|
||||
#include <LibCore/Environment.h>
|
||||
#include <LibCore/Socket.h>
|
||||
#include <LibCore/System.h>
|
||||
|
||||
@@ -17,14 +19,14 @@ static void parse_sockets_from_system_server()
|
||||
{
|
||||
VERIFY(!s_overtaken_sockets_parsed);
|
||||
|
||||
constexpr auto socket_takeover = "SOCKET_TAKEOVER";
|
||||
char const* sockets = getenv(socket_takeover);
|
||||
if (!sockets) {
|
||||
constexpr auto socket_takeover = "SOCKET_TAKEOVER"sv;
|
||||
auto sockets = Environment::get(socket_takeover);
|
||||
if (!sockets.has_value()) {
|
||||
s_overtaken_sockets_parsed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto const socket : StringView { sockets, strlen(sockets) }.split_view(';')) {
|
||||
for (auto socket : sockets->split_view(';')) {
|
||||
auto params = socket.split_view(':');
|
||||
VERIFY(params.size() == 2);
|
||||
s_overtaken_sockets.set(params[0].to_byte_string(), params[1].to_number<int>().value());
|
||||
@@ -33,7 +35,7 @@ static void parse_sockets_from_system_server()
|
||||
s_overtaken_sockets_parsed = true;
|
||||
// We wouldn't want our children to think we're passing
|
||||
// them a socket either, so unset the env variable.
|
||||
unsetenv(socket_takeover);
|
||||
MUST(Environment::unset(socket_takeover));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Core::LocalSocket>> take_over_socket_from_system_server(ByteString const& socket_path)
|
||||
@@ -54,10 +56,8 @@ ErrorOr<NonnullOwnPtr<Core::LocalSocket>> take_over_socket_from_system_server(By
|
||||
}
|
||||
|
||||
// Sanity check: it has to be a socket.
|
||||
auto stat = TRY(Core::System::fstat(fd));
|
||||
|
||||
if (!S_ISSOCK(stat.st_mode))
|
||||
return Error::from_string_literal("The fd we got from SystemServer is not a socket");
|
||||
if (!System::is_socket(fd))
|
||||
return Error::from_string_literal("The fd or handle we got from SystemServer is not a socket");
|
||||
|
||||
auto socket = TRY(Core::LocalSocket::adopt_fd(fd));
|
||||
// It had to be !CLOEXEC for obvious reasons, but we
|
||||
|
||||
Reference in New Issue
Block a user