From 0061d91c7b5520682dafbed5fd12d107a9579e53 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 21 Mar 2024 17:22:05 -0700 Subject: [PATCH] Close nicely --- src/devices/console.c | 7 +++---- src/uxn11.c | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/devices/console.c b/src/devices/console.c index 75021c2..21804db 100644 --- a/src/devices/console.c +++ b/src/devices/console.c @@ -127,6 +127,7 @@ start_fork_pty(Uint8 *d) static void start_fork_pipe(Uint8 *d) { + pid_t pid; if(child_mode & 0x01) { /* parent writes to child's stdin */ if(pipe(to_child_fd) == -1) { @@ -135,7 +136,6 @@ start_fork_pipe(Uint8 *d) return; } } - if(child_mode & 0x06) { /* parent reads from child's stdout and/or stderr */ if(pipe(from_child_fd) == -1) { @@ -144,8 +144,7 @@ start_fork_pipe(Uint8 *d) return; } } - - pid_t pid = fork(); + pid = fork(); if(pid < 0) { /* failure */ d[0x6] = 0xff; fprintf(stderr, "fork failure\n"); @@ -180,9 +179,9 @@ start_fork_pipe(Uint8 *d) static void kill_child(Uint8 *d, int options) { + int wstatus; if(child_pid) { kill(child_pid, 9); - int wstatus; if(waitpid(child_pid, &wstatus, options)) { d[0x6] = 1; d[0x7] = WEXITSTATUS(wstatus); diff --git a/src/uxn11.c b/src/uxn11.c index a5ec9f8..4ccb8b7 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -102,6 +102,7 @@ emu_end(Uxn *u) XDestroyImage(ximage); XDestroyWindow(display, window); XCloseDisplay(display); + exit(0); return u->dev[0x0f] & 0x7f; } @@ -143,8 +144,7 @@ emu_event(Uxn *u) XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, w, h); } break; case ClientMessage: - emu_end(u); - exit(0); + u->dev[0x0f] = 0x80; break; case KeyPress: { KeySym sym; @@ -225,7 +225,7 @@ display_init(void) } static int -emu_run(Uxn *u, char *rom) +emu_run(Uxn *u) { int i = 1, n; char expirations[8]; @@ -287,7 +287,7 @@ main(int argc, char **argv) u.dev[0x17] = argc - i; if(uxn_eval(&u, PAGE_PROGRAM)) { console_listen(&u, i, argc, argv); - emu_run(&u, boot_rom); + emu_run(&u); } return emu_end(&u); }