[iOS] LayoutTestRelay should ensure its DRT/WKTR dies when receiving kill/term signals
authordfarler@apple.com <dfarler@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Oct 2014 01:09:30 +0000 (01:09 +0000)
committerdfarler@apple.com <dfarler@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Oct 2014 01:09:30 +0000 (01:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137528

Reviewed by Simon Fraser.

Catch SIGINT and SIGTERM signals in the LayoutTestRelay
and SIGKILL the paired simulator app before exiting cleanly.

webkitpy only uses SIGKILL to kill processes which you cannot
catch. Send SIGTERM to the process and give it chance to do
its thing before sending SIGKILL. Sending a SIGKILL to an already
dead PID is safe.

* LayoutTestRelay/LayoutTestRelay/LTRelayController.h:
* LayoutTestRelay/LayoutTestRelay/LTRelayController.m:
(-[LTRelayController finish]):
* LayoutTestRelay/LayoutTestRelay/main.m:
(receivedSignal):
(main):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174628 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/LayoutTestRelay/LayoutTestRelay/LTRelayController.h
Tools/LayoutTestRelay/LayoutTestRelay/main.m
Tools/Scripts/webkitpy/common/system/executive.py

index 3c17a92..cd49307 100644 (file)
@@ -1,5 +1,27 @@
 2014-10-10  David Farler  <dfarler@apple.com>
 
+        [iOS] LayoutTestRelay should ensure its DRT/WKTR dies when receiving kill/term signals
+        https://bugs.webkit.org/show_bug.cgi?id=137528
+
+        Reviewed by Simon Fraser.
+
+        Catch SIGINT and SIGTERM signals in the LayoutTestRelay
+        and SIGKILL the paired simulator app before exiting cleanly.
+
+        webkitpy only uses SIGKILL to kill processes which you cannot
+        catch. Send SIGTERM to the process and give it chance to do
+        its thing before sending SIGKILL. Sending a SIGKILL to an already
+        dead PID is safe.
+
+        * LayoutTestRelay/LayoutTestRelay/LTRelayController.h:
+        * LayoutTestRelay/LayoutTestRelay/LTRelayController.m:
+        (-[LTRelayController finish]):
+        * LayoutTestRelay/LayoutTestRelay/main.m:
+        (receivedSignal):
+        (main):
+
+2014-10-10  David Farler  <dfarler@apple.com>
+
         [iOS] LayoutTestRelay should detect EOF and properly signal underlying DRT/WKTR
         https://bugs.webkit.org/show_bug.cgi?id=137527
 
index f93e945..cb890eb 100644 (file)
@@ -34,6 +34,7 @@
 @interface LTRelayController : NSObject <LTRelayDelegate>
 - (id)initWithDevice:(SimDevice *)device productDir:(NSString *)productDir appPath:(NSString *)appPath identifierSuffix:(NSString *)suffix dumpToolArguments:(NSArray *)arguments;
 - (void)start;
+- (void)finish;
 @end
 
 #endif
index a142f0d..4cf0b07 100644 (file)
@@ -28,6 +28,8 @@
 #import <CoreSimulator/CoreSimulator.h>
 #import <Foundation/Foundation.h>
 
+static LTRelayController *relayController;
+
 void usage()
 {
     NSString *helpText = @"LayoutTestRelay: run a dump tool in the simulator. Not for direct consumption.\n"
@@ -96,6 +98,16 @@ NSArray *getDumpToolArguments()
     return dumpToolArguments;
 }
 
+void finish()
+{
+    [relayController finish];
+}
+
+void receivedSignal(int signal)
+{
+    exit(EXIT_SUCCESS);
+}
+
 int main(int argc, const char * argv[])
 {
     @autoreleasepool {
@@ -127,8 +139,13 @@ int main(int argc, const char * argv[])
 
         SimDevice *device = getTestingSimDevice(deviceType, runtime);
 
-        LTRelayController *relayController = [[LTRelayController alloc] initWithDevice:device productDir:productDir appPath:appPath identifierSuffix:suffix dumpToolArguments:dumpToolArguments];
+        relayController = [[LTRelayController alloc] initWithDevice:device productDir:productDir appPath:appPath identifierSuffix:suffix dumpToolArguments:dumpToolArguments];
         [relayController start];
+
+        atexit(finish);
+        signal(SIGINT, receivedSignal);
+        signal(SIGTERM, receivedSignal);
+
         [[NSRunLoop mainRunLoop] run];
     }
     return 0;
index 692b364..6be07e0 100644 (file)
@@ -199,6 +199,10 @@ class Executive(object):
         while retries_left > 0:
             try:
                 retries_left -= 1
+                # Give processes one change to clean up quickly before exiting.
+                # Following up with a kill should have no effect if the process
+                # already exited, and forcefully kill it if SIGTERM wasn't enough.
+                os.kill(pid, signal.SIGTERM)
                 os.kill(pid, signal.SIGKILL)
                 _ = os.waitpid(pid, os.WNOHANG)
             except OSError, e: