helper: send SIGKILL if process is unresponsive
QEMU can refuse to react to SIGTERM due to a deadlock bug or for any other reason. If it does not gracefully quit in 1 second, then we send SIGKILL. Fixes #5769
This commit is contained in:
parent
2ea42d82e3
commit
d9159539b1
|
@ -17,6 +17,9 @@
|
|||
#import "QEMUHelper.h"
|
||||
#import "QEMUHelperDelegate.h"
|
||||
#import <stdio.h>
|
||||
#import <signal.h>
|
||||
|
||||
static const int64_t kProcessTerminateTimeoutSeconds = 1;
|
||||
|
||||
@interface QEMUHelper ()
|
||||
|
||||
|
@ -150,8 +153,21 @@
|
|||
}
|
||||
|
||||
- (void)terminate {
|
||||
[self.childTask terminate];
|
||||
NSTask *childTask = self.childTask;
|
||||
self.childTask = nil;
|
||||
if (childTask) {
|
||||
void (^terminationHandler)(NSTask *) = childTask.terminationHandler;
|
||||
dispatch_semaphore_t terminatedEvent = dispatch_semaphore_create(0);
|
||||
childTask.terminationHandler = ^(NSTask *task) {
|
||||
terminationHandler(task);
|
||||
dispatch_semaphore_signal(terminatedEvent);
|
||||
};
|
||||
[childTask terminate];
|
||||
if (childTask.isRunning && dispatch_semaphore_wait(terminatedEvent, dispatch_time(DISPATCH_TIME_NOW, kProcessTerminateTimeoutSeconds*NSEC_PER_SEC)) != 0) {
|
||||
NSLog(@"Process %d failed to respond to SIGTERM, sending SIGKILL...", childTask.processIdentifier);
|
||||
kill(childTask.processIdentifier, SIGKILL);
|
||||
}
|
||||
}
|
||||
[self invalidateToken];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue