Skip to content

Commit

Permalink
Revert "WebKit process termination with xpc_connection_kill does not …
Browse files Browse the repository at this point in the history
…always work"

This reverts commit 3c2c899.
  • Loading branch information
Mohsin Qureshi committed Apr 16, 2024
1 parent 168c94d commit a5376aa
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 33 deletions.
1 change: 0 additions & 1 deletion Source/WebKit/Platform/cocoa/XPCUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ enum class ReasonCode : uint64_t {
};

void terminateWithReason(xpc_connection_t, ReasonCode, const char* reason);
void handleXPCExitMessage(xpc_object_t);

}
22 changes: 0 additions & 22 deletions Source/WebKit/Platform/cocoa/XPCUtilities.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,17 @@
#include "config.h"
#include "XPCUtilities.h"

#include <wtf/WTFProcess.h>

namespace WebKit {

static constexpr auto messageNameKey = "message-name"_s;
static constexpr auto exitProcessMessage = "exit"_s;

void terminateWithReason(xpc_connection_t connection, ReasonCode, const char*)
{
// This could use ReasonSPI.h, but currently does not as the SPI is blocked by the sandbox.
// See https://bugs.webkit.org/show_bug.cgi?id=224499 rdar://76396241
if (!connection)
return;

// Give the process a chance to exit cleanly by sending a XPC message to request termination, then try xpc_connection_kill.
auto exitMessage = adoptOSObject(xpc_dictionary_create(nullptr, nullptr, 0));
xpc_dictionary_set_string(exitMessage.get(), messageNameKey, exitProcessMessage.characters());
xpc_connection_send_message(connection, exitMessage.get());

ALLOW_DEPRECATED_DECLARATIONS_BEGIN
xpc_connection_kill(connection, SIGKILL);
ALLOW_DEPRECATED_DECLARATIONS_END
}

void handleXPCExitMessage(xpc_object_t event)
{
if (xpc_get_type(event) == XPC_TYPE_DICTIONARY) {
auto* messageName = xpc_dictionary_get_string(event, messageNameKey);
if (exitProcessMessage == messageName) {
RELEASE_LOG_ERROR(IPC, "Received exit message, exiting now.");
terminateProcess(EXIT_FAILURE);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#import "AuthenticationChallengeDisposition.h"
#import "ClientCertificateAuthenticationXPCConstants.h"
#import "Connection.h"
#import "XPCUtilities.h"
#import <pal/spi/cocoa/NSXPCConnectionSPI.h>
#import <pal/spi/cocoa/SecKeyProxySPI.h>
#import <wtf/MainThread.h>
Expand All @@ -51,9 +50,6 @@
// The following xpc event handler overwrites the boostrap event handler and is only used
// to capture client certificate credential.
xpc_connection_set_event_handler(connection->xpcConnection(), ^(xpc_object_t event) {

handleXPCExitMessage(event);

callOnMainRunLoop([event = OSObjectPtr(event), weakThis = weakThis] {
RELEASE_ASSERT(isMainRunLoop());

Expand Down
3 changes: 0 additions & 3 deletions Source/WebKit/Shared/Cocoa/XPCEndpoint.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#import "config.h"
#import "XPCEndpoint.h"
#import "XPCUtilities.h"

#import <wtf/cocoa/Entitlements.h>
#import <wtf/text/ASCIILiteral.h>
Expand All @@ -47,8 +46,6 @@
xpc_connection_set_event_handler(m_connection.get(), ^(xpc_object_t message) {
xpc_type_t type = xpc_get_type(message);

handleXPCExitMessage(message);

if (type == XPC_TYPE_CONNECTION) {
OSObjectPtr<xpc_connection_t> connection = message;
#if USE(APPLE_INTERNAL_SDK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#import "Logging.h"
#import "WKCrashReporter.h"
#import "XPCServiceEntryPoint.h"
#import "XPCUtilities.h"
#import <CoreFoundation/CoreFoundation.h>
#import <mach/mach.h>
#import <pal/spi/cf/CFUtilitiesSPI.h>
Expand Down Expand Up @@ -139,8 +138,6 @@ void XPCServiceEventHandler(xpc_connection_t peer)
return;
}

handleXPCExitMessage(event);

auto* messageName = xpc_dictionary_get_string(event, "message-name");
if (!messageName) {
RELEASE_LOG_ERROR(IPC, "XPCServiceEventHandler: 'message-name' is not present in the XPC dictionary");
Expand Down

0 comments on commit a5376aa

Please sign in to comment.