commit 0061d91
Devine Lu Linvega
·
2024-03-22 00:22:05 +0000 UTC
parent b7660a1
Close nicely
2 files changed,
+7,
-8
+3,
-4
1@@ -127,6 +127,7 @@ start_fork_pty(Uint8 *d)
2 static void
3 start_fork_pipe(Uint8 *d)
4 {
5+ pid_t pid;
6 if(child_mode & 0x01) {
7 /* parent writes to child's stdin */
8 if(pipe(to_child_fd) == -1) {
9@@ -135,7 +136,6 @@ start_fork_pipe(Uint8 *d)
10 return;
11 }
12 }
13-
14 if(child_mode & 0x06) {
15 /* parent reads from child's stdout and/or stderr */
16 if(pipe(from_child_fd) == -1) {
17@@ -144,8 +144,7 @@ start_fork_pipe(Uint8 *d)
18 return;
19 }
20 }
21-
22- pid_t pid = fork();
23+ pid = fork();
24 if(pid < 0) { /* failure */
25 d[0x6] = 0xff;
26 fprintf(stderr, "fork failure\n");
27@@ -180,9 +179,9 @@ start_fork_pipe(Uint8 *d)
28 static void
29 kill_child(Uint8 *d, int options)
30 {
31+ int wstatus;
32 if(child_pid) {
33 kill(child_pid, 9);
34- int wstatus;
35 if(waitpid(child_pid, &wstatus, options)) {
36 d[0x6] = 1;
37 d[0x7] = WEXITSTATUS(wstatus);
+4,
-4
1@@ -102,6 +102,7 @@ emu_end(Uxn *u)
2 XDestroyImage(ximage);
3 XDestroyWindow(display, window);
4 XCloseDisplay(display);
5+ exit(0);
6 return u->dev[0x0f] & 0x7f;
7 }
8
9@@ -143,8 +144,7 @@ emu_event(Uxn *u)
10 XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, w, h);
11 } break;
12 case ClientMessage:
13- emu_end(u);
14- exit(0);
15+ u->dev[0x0f] = 0x80;
16 break;
17 case KeyPress: {
18 KeySym sym;
19@@ -225,7 +225,7 @@ display_init(void)
20 }
21
22 static int
23-emu_run(Uxn *u, char *rom)
24+emu_run(Uxn *u)
25 {
26 int i = 1, n;
27 char expirations[8];
28@@ -287,7 +287,7 @@ main(int argc, char **argv)
29 u.dev[0x17] = argc - i;
30 if(uxn_eval(&u, PAGE_PROGRAM)) {
31 console_listen(&u, i, argc, argv);
32- emu_run(&u, boot_rom);
33+ emu_run(&u);
34 }
35 return emu_end(&u);
36 }