Skip to content

Commit ef578aa

Browse files
committed
Refactor restart_frontboard_kill to use spawn_and_wait for process termination
1 parent b89ec89 commit ef578aa

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

lara/kexploit/restart_frontboard.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
#include "restart_frontboard.h"
22

3-
#include <stdlib.h>
3+
44
#include <string.h>
55
#include <unistd.h>
66
#include <signal.h>
77
#include <stdio.h>
8+
#include <spawn.h>
9+
#include <sys/wait.h>
10+
#include <errno.h>
811

912
// Simpler implementation for CI/iOS SDK: avoid using libproc APIs
1013
// which may not be available in the iOS SDK on the build host.
1114
// Use a best-effort `killall` invocation instead.
1215

16+
static int spawn_and_wait(char *const argv[]) {
17+
pid_t pid = 0;
18+
int spawn_err = posix_spawnp(&pid, "killall", NULL, NULL, argv, NULL);
19+
if (spawn_err != 0) return -1;
20+
21+
int status = 0;
22+
if (waitpid(pid, &status, 0) == -1) return -1;
23+
24+
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) return 0;
25+
return -1;
26+
}
27+
1328
int restart_frontboard_kill(void) {
14-
// Try a graceful terminate first
15-
int r = system("killall -s TERM frontboardd 2>/dev/null");
16-
if (r == 0) return 0;
29+
// Attempt graceful shutdown, then force, then plain invocation.
30+
char *const args_term[] = {"killall", "-s", "TERM", "frontboardd", NULL};
31+
if (spawn_and_wait(args_term) == 0) return 0;
32+
33+
char *const args_kill[] = {"killall", "-s", "KILL", "frontboardd", NULL};
34+
if (spawn_and_wait(args_kill) == 0) return 0;
1735

18-
// If graceful termination failed, try force kill
19-
r = system("killall -s KILL frontboardd 2>/dev/null");
20-
if (r == 0) return 0;
36+
char *const args_plain[] = {"killall", "frontboardd", NULL};
37+
if (spawn_and_wait(args_plain) == 0) return 0;
2138

22-
// As a last resort, try plain killall (older busybox-like syntax)
23-
r = system("killall frontboardd 2>/dev/null");
24-
return (r == 0) ? 0 : -1;
39+
return -1;
2540
}

0 commit comments

Comments
 (0)