Run a virtual iPhone on an Apple Silicon Mac.
Swift
Restart the vphoned worker every second and log why it exits
Lakr2e2ed0a89075
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.mdindex ba199283..4c389680 100644--- a/Research/vphoned_http_api.md+++ b/Research/vphoned_http_api.md@@ -330,9 +330,17 @@ A dropped HTTP or WebSocket connection closes only that request channel. Theguest launchd plist starts a small vphoned proxy. It uses `posix_spawn` tostart the same signed executable with `--io`, then waits for and reaps thatworker. The worker owns VSOCK 1338 and 1339 and all API state. The proxy-restarts an unexpectedly exited worker with bounded backoff, and forwards-shutdown to it. A pipe makes the worker exit if launchd kills the proxy, so-the old worker cannot retain the ports after launchd starts a replacement.+restarts an unexpectedly exited worker after a fixed one-second pause, for+as long as it runs, and forwards shutdown to it. The previous exponential+backoff kept a 26.4 guest's API down until about 24 s after launchd started+the proxy: early-boot workers exited, and the proxy waited 1, 2, 4 and 8 s+between them. The proxy logs each worker exit with its status or signal to+`/var/log/vphoned.log`, which the plist names as stdout and stderr. The plist+also sets `ThrottleInterval` to 1 so launchd restarts the proxy itself one+second after it exits, not the default ten, and `ProcessType` to+`Interactive` so boot-time CPU and I/O throttling does not apply. A pipe+makes the worker exit if launchd kills the proxy, so the old worker cannot+retain the ports after launchd starts a replacement.The proxy never initializes NIO, IcliKit, or the camera server under its6 MB per-process Jetsam limit. A successful `agent.apply_update` worker exitmakes the proxy exit so launchd can restart the updated cached binary. If adiff --git a/VPhoneDaemon/Configuration/vphoned.plist b/VPhoneDaemon/Configuration/vphoned.plistindex 29ea2653..e06f30a6 100644--- a/VPhoneDaemon/Configuration/vphoned.plist+++ b/VPhoneDaemon/Configuration/vphoned.plist@@ -12,5 +12,13 @@<true/><key>KeepAlive</key><true/>+ <key>ThrottleInterval</key>+ <integer>1</integer>+ <key>ProcessType</key>+ <string>Interactive</string>+ <key>StandardOutPath</key>+ <string>/var/log/vphoned.log</string>+ <key>StandardErrorPath</key>+ <string>/var/log/vphoned.log</string></dict></plist>diff --git a/VPhoneDaemon/Native/vphoned_proxy.c b/VPhoneDaemon/Native/vphoned_proxy.cindex cbb58a90..e3b49492 100644--- a/VPhoneDaemon/Native/vphoned_proxy.c+++ b/VPhoneDaemon/Native/vphoned_proxy.c@@ -61,8 +61,11 @@ int vp_native_watch_proxy(void) {return result == 0 ? 0 : -1;}-static void pause_before_retry(unsigned seconds) {- struct timespec remaining = {.tv_sec = seconds, .tv_nsec = 0};+static void pause_before_retry(void) {+ // A fixed delay, however often the worker fails: during boot the worker+ // can exit several times, and a growing backoff kept the API down for+ // tens of seconds after the guest was otherwise ready.+ struct timespec remaining = {.tv_sec = 1, .tv_nsec = 0};while (!stopping && nanosleep(&remaining, &remaining) < 0 && errno == EINTR) {}}@@ -89,7 +92,6 @@ int vp_native_run_proxy(void) {sigaction(SIGTERM, &action, NULL);sigaction(SIGINT, &action, NULL);- unsigned retry_delay = 1;while (!stopping) {int pipe_fds[2];if (pipe(pipe_fds) != 0) return 1;@@ -118,7 +120,7 @@ int vp_native_run_proxy(void) {if (error != 0) {fprintf(stderr, "vphoned proxy: posix_spawn failed: %s\n", strerror(error));close(pipe_fds[1]);- pause_before_retry(retry_delay);+ pause_before_retry();} else {if (stopping) {stop_worker(child, pipe_fds[1]);@@ -145,10 +147,15 @@ int vp_native_run_proxy(void) {// start falls back to the bundled binary.return 1;}- fprintf(stderr, "vphoned proxy: worker exited; retrying\n");- pause_before_retry(retry_delay);+ if (waited != child) {+ fprintf(stderr, "vphoned proxy: waitpid %d failed: %s; retrying\n", child, strerror(errno));+ } else if (WIFSIGNALED(status)) {+ fprintf(stderr, "vphoned proxy: worker %d killed by signal %d; retrying\n", child, WTERMSIG(status));+ } else {+ fprintf(stderr, "vphoned proxy: worker %d exited with status %d; retrying\n", child, WEXITSTATUS(status));+ }+ pause_before_retry();}- if (retry_delay < 10) retry_delay *= 2;}return 0;}