Title: [292128] trunk/Source/WebKit
Revision
292128
Author
cdu...@apple.com
Date
2022-03-30 16:33:13 -0700 (Wed, 30 Mar 2022)

Log Message

Use dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM) in setOSTransaction()
https://bugs.webkit.org/show_bug.cgi?id=238559

Reviewed by Darin Adler.

Use dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM) in setOSTransaction() instead of a
low-level signal(SIGTERM) handler, as recommended by the XPC team.

This is better becomes it has less limitations about what you can do in the handler. It is also
possible to set several handlers this way, in different parts of the code (i.e. also not worry about
some other code overriding our handler).

* Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm:
(WebKit::setOSTransaction):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (292127 => 292128)


--- trunk/Source/WebKit/ChangeLog	2022-03-30 23:23:34 UTC (rev 292127)
+++ trunk/Source/WebKit/ChangeLog	2022-03-30 23:33:13 UTC (rev 292128)
@@ -1,3 +1,20 @@
+2022-03-30  Chris Dumez  <cdu...@apple.com>
+
+        Use dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM) in setOSTransaction()
+        https://bugs.webkit.org/show_bug.cgi?id=238559
+
+        Reviewed by Darin Adler.
+
+        Use dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM) in setOSTransaction() instead of a
+        low-level signal(SIGTERM) handler, as recommended by the XPC team.
+
+        This is better becomes it has less limitations about what you can do in the handler. It is also
+        possible to set several handlers this way, in different parts of the code (i.e. also not worry about
+        some other code overriding our handler).
+
+        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm:
+        (WebKit::setOSTransaction):
+
 2022-03-30  Sihui Liu  <sihui_...@apple.com>
 
         Remove -[WKWebsiteDataStore _indexedDBDatabaseDirectory]

Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm (292127 => 292128)


--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm	2022-03-30 23:23:34 UTC (rev 292127)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm	2022-03-30 23:33:13 UTC (rev 292128)
@@ -168,13 +168,15 @@
     // services ourselves. However, one of the side effects of leaking this transaction is that the default SIGTERM
     // handler doesn't cleanly exit our XPC services when logging out or rebooting. This led to crashes with
     // XPC_EXIT_REASON_SIGTERM_TIMEOUT as termination reason (rdar://88940229). To address the issue, we now set our
-    // own SIGTERM handler that calls _exit(0). In the future, we should likely adopt RunningBoard on macOS and
+    // own SIGTERM handler that calls exit(0). In the future, we should likely adopt RunningBoard on macOS and
     // control our lifetime via process assertions instead of leaking this OS transaction.
-    static std::once_flag onceKey;
-    std::call_once(onceKey, [] {
-        signal(SIGTERM, [](int) {
-            _exit(0);
+    static dispatch_once_t flag;
+    dispatch_once(&flag, ^{
+        auto sigTermSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
+        dispatch_source_set_event_handler(sigTermSource, ^{
+            exit(0);
         });
+        dispatch_resume(sigTermSource);
     });
 
     globalTransaction.get() = WTFMove(transaction);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to