From 8a5545c5808d2173ba65ff2fbc9cd0a870bd1df9 Mon Sep 17 00:00:00 2001 From: Thatchapon Unprasert Date: Fri, 7 Jul 2017 22:00:50 +0700 Subject: [PATCH] Increase multiprogramming. --- respring_simulator/respring_simulator.mm | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/respring_simulator/respring_simulator.mm b/respring_simulator/respring_simulator.mm index 39ea801..172bbab 100644 --- a/respring_simulator/respring_simulator.mm +++ b/respring_simulator/respring_simulator.mm @@ -18,7 +18,7 @@ void printUsage() { printf("\t(Will respring iPhone 5 simulator running iOS 8.1)\n"); printf("\nRespring the booted device with matching UDID:\n\n"); printf("\trespring_simulator -i 5AA1C45D-DB69-4C52-A75B-E9BE9C7E7770\n"); - printf("\t(Will respring simulator with UDID 5AA1C45D-DB69-4C52-A75B-E9BE9C7E7770)\n\n"); + printf("\t(Will respring simulator with UDID 5AA1C45D-DB69-4C52-A75B-E9BE9C7E7770)\n"); printf("\nRespring any booted simulator:\n\n"); printf("\trespring_simulator all\n"); printf("\n"); @@ -43,15 +43,22 @@ void injectHeader() { } void inject(const char *udid, const char *device, BOOL _exit) { - system([[NSString stringWithFormat:@"xcrun simctl spawn %s launchctl setenv DYLD_INSERT_LIBRARIES /opt/simject/simject.dylib", udid] UTF8String]); - if (device) { - printf("Respringing %s (%s) ...\n", udid, device); - } else { - printf("Respringing %s ...\n", strcmp(udid, "booted") == 0 ? "a booted device" : udid); - } - system([[NSString stringWithFormat:@"xcrun simctl spawn %s launchctl stop com.apple.backboardd", udid] UTF8String]); - if (_exit) + pid_t pid = fork(); + if (pid == 0) { + system([[NSString stringWithFormat:@"xcrun simctl spawn %s launchctl setenv DYLD_INSERT_LIBRARIES /opt/simject/simject.dylib", udid] UTF8String]); + if (device) { + printf("Respringing %s (%s) ...\n", udid, device); + } else { + printf("Respringing %s ...\n", !strcmp(udid, "booted") ? "a booted device" : udid); + } + system([[NSString stringWithFormat:@"xcrun simctl spawn %s launchctl stop com.apple.backboardd", udid] UTF8String]); exit(EXIT_SUCCESS); + } else { + waitpid(pid, NULL, 0); + if (_exit) + exit(EXIT_SUCCESS); + + } } void injectUDIDs(const char *udid, BOOL all) {