Close nicely

This commit is contained in:
Devine Lu Linvega 2024-03-21 17:22:05 -07:00
parent b7660a1920
commit 0061d91c7b
2 changed files with 7 additions and 8 deletions

View File

@ -127,6 +127,7 @@ start_fork_pty(Uint8 *d)
static void static void
start_fork_pipe(Uint8 *d) start_fork_pipe(Uint8 *d)
{ {
pid_t pid;
if(child_mode & 0x01) { if(child_mode & 0x01) {
/* parent writes to child's stdin */ /* parent writes to child's stdin */
if(pipe(to_child_fd) == -1) { if(pipe(to_child_fd) == -1) {
@ -135,7 +136,6 @@ start_fork_pipe(Uint8 *d)
return; return;
} }
} }
if(child_mode & 0x06) { if(child_mode & 0x06) {
/* parent reads from child's stdout and/or stderr */ /* parent reads from child's stdout and/or stderr */
if(pipe(from_child_fd) == -1) { if(pipe(from_child_fd) == -1) {
@ -144,8 +144,7 @@ start_fork_pipe(Uint8 *d)
return; return;
} }
} }
pid = fork();
pid_t pid = fork();
if(pid < 0) { /* failure */ if(pid < 0) { /* failure */
d[0x6] = 0xff; d[0x6] = 0xff;
fprintf(stderr, "fork failure\n"); fprintf(stderr, "fork failure\n");
@ -180,9 +179,9 @@ start_fork_pipe(Uint8 *d)
static void static void
kill_child(Uint8 *d, int options) kill_child(Uint8 *d, int options)
{ {
int wstatus;
if(child_pid) { if(child_pid) {
kill(child_pid, 9); kill(child_pid, 9);
int wstatus;
if(waitpid(child_pid, &wstatus, options)) { if(waitpid(child_pid, &wstatus, options)) {
d[0x6] = 1; d[0x6] = 1;
d[0x7] = WEXITSTATUS(wstatus); d[0x7] = WEXITSTATUS(wstatus);

View File

@ -102,6 +102,7 @@ emu_end(Uxn *u)
XDestroyImage(ximage); XDestroyImage(ximage);
XDestroyWindow(display, window); XDestroyWindow(display, window);
XCloseDisplay(display); XCloseDisplay(display);
exit(0);
return u->dev[0x0f] & 0x7f; 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); XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, w, h);
} break; } break;
case ClientMessage: case ClientMessage:
emu_end(u); u->dev[0x0f] = 0x80;
exit(0);
break; break;
case KeyPress: { case KeyPress: {
KeySym sym; KeySym sym;
@ -225,7 +225,7 @@ display_init(void)
} }
static int static int
emu_run(Uxn *u, char *rom) emu_run(Uxn *u)
{ {
int i = 1, n; int i = 1, n;
char expirations[8]; char expirations[8];
@ -287,7 +287,7 @@ main(int argc, char **argv)
u.dev[0x17] = argc - i; u.dev[0x17] = argc - i;
if(uxn_eval(&u, PAGE_PROGRAM)) { if(uxn_eval(&u, PAGE_PROGRAM)) {
console_listen(&u, i, argc, argv); console_listen(&u, i, argc, argv);
emu_run(&u, boot_rom); emu_run(&u);
} }
return emu_end(&u); return emu_end(&u);
} }