commit 359d262
chld
·
2026-10-27 12:47:38 +0000 UTC
parent 192cc07
remove subprocess, tune flags to work
M
uxn.c
+13,
-153
1@@ -3,6 +3,9 @@ gcc -s -O2 -Wno-unused-result -fwrapv main.c `sdl-config --cflags --libs`
2 exit
3 #endif
4
5+/*
6+ stdout and stderr are ignored
7+*/
8 // This file is public domain.
9
10 #include "SDL/SDL.h"
11@@ -279,21 +282,21 @@ static FILE*inf;
12 static FILE*outf;
13
14 static const char*rom_name;
15-static Uint8 use_console=1;
16+static Uint8 use_console=0;
17 static Uint8 use_screen=1;
18-static Uint8 use_mouse=1;
19+static Uint8 use_mouse=0;
20 static Uint8 use_debug=0;
21 static Uint8 use_utc=0;
22-static Uint8 use_extension=0;
23+static Uint8 use_extension=1;
24 static Uint8 use_thread=0;
25 static Uint8 hide_cursor=0;
26 static Uint8 allow_write=0;
27 static Uint8 joypad_repeat=0;
28 static Uint16 scroll_size=1;
29 static Uint8 zoom=1;
30-static Uint8 disallow_size_change=0;
31-static Sint16 default_width=512;
32-static Sint16 default_height=320;
33+static Uint8 disallow_size_change=1; /* fixed 320x240 res */
34+static Sint16 default_width=320;
35+static Sint16 default_height=240;
36 static Uint32 scrflags=SDL_SWSURFACE;
37 static Uint16 timer_rate=16;
38 static Uint8 paused=0;
39@@ -301,12 +304,12 @@ static Uint8 picture_changed=0;
40 static Uint8 size_changed=0;
41 static volatile Uint8 timer_expired=0;
42 static SDL_Surface*screen;
43-static Uint8 layers;
44+static Uint8 layers=0;
45 static Uint8 palet=7;
46 static Uint8 touch_mode=0;
47 static SDL_cond*stdin_cond;
48 static Uint8 screencompat=0x03;
49-static int randomfd=-1;
50+// static int randomfd=-1;
51
52 static Uint16 scriptc;
53 static Script*scriptv;
54@@ -501,155 +504,12 @@ static void system_out(Device*dev,Uint8 id) {
55 }
56
57 // Subprocess support
58-
59-static char enable_subprocess=0;
60-static char *fork_args[4] = {"/bin/sh", "-c", "", NULL};
61-static int child_mode;
62-static int to_child_fd[2];
63-static int from_child_fd[2];
64-static int saved_in;
65-static int saved_out;
66-static pid_t child_pid;
67-
68-/* call after we're sure the process has exited */
69-static void console_clean_after_child(void) {
70- child_pid = 0;
71- if(child_mode & 0x01) {
72- close(to_child_fd[1]);
73- dup2(saved_out, 1);
74- }
75- if(child_mode & (0x04 | 0x02)) {
76- close(from_child_fd[0]);
77- dup2(saved_in, 0);
78- }
79- child_mode = 0;
80- saved_in = -1;
81- saved_out = -1;
82-}
83-
84-static void console_start_fork_pipe(Device*dev) {
85- pid_t pid;
86- pid_t parent_pid = getpid();
87- int addr = GET16(dev->d+12);
88- fflush(stdout);
89- if(child_mode & 0x08) {
90- dev->d[6] = dev->d[5] = 0;
91- return;
92- }
93- if(child_mode & 0x01) {
94- /* parent writes to child's stdin */
95- if(pipe(to_child_fd) == -1) {
96- dev->d[6] = dev->d[5] = 255;
97- fprintf(stderr, "pipe error: to child\n");
98- return;
99- }
100- }
101- if(child_mode & (0x04 | 0x02)) {
102- /* parent reads from child's stdout and/or stderr */
103- if(pipe(from_child_fd) == -1) {
104- dev->d[6] = dev->d[5] = 255;
105- fprintf(stderr, "pipe error: from child\n");
106- return;
107- }
108- }
109-
110- fork_args[2] = (char *)(mem + GET16(dev->d+12));
111- pid = fork();
112- if(pid < 0) { /* failure */
113- dev->d[6] = dev->d[5] = 255;
114- fprintf(stderr, "fork failure\n");
115- } else if(pid == 0) { /* child */
116-
117-#ifdef __linux__
118- int r = prctl(PR_SET_PDEATHSIG, SIGTERM);
119- if(r == -1) {
120- perror(0);
121- exit(6);
122- }
123- if(getppid() != parent_pid) exit(13);
124-#endif
125-
126- if(child_mode & 0x01) {
127- dup2(to_child_fd[0], 0);
128- close(to_child_fd[1]);
129- }
130- if(child_mode & (0x04 | 0x02)) {
131- if(child_mode & 0x02) dup2(from_child_fd[1], 1);
132- if(child_mode & 0x04) dup2(from_child_fd[1], 2);
133- close(from_child_fd[0]);
134- }
135- fflush(stdout);
136- execvp(fork_args[0], fork_args);
137- exit(1);
138- } else { /*parent*/
139- child_pid = pid;
140- dev->d[5] = 1;
141- dev->d[6] = 0;
142- if(child_mode & 0x01) {
143- saved_out = dup(1);
144- dup2(to_child_fd[1], 1);
145- close(to_child_fd[0]);
146- }
147- if(child_mode & (0x04 | 0x02)) {
148- saved_in = dup(0);
149- dup2(from_child_fd[0], 0);
150- close(from_child_fd[1]);
151- }
152- }
153-}
154-
155-static void console_check_child(Device*dev) {
156- int wstatus;
157- if(child_pid) {
158- if(waitpid(child_pid, &wstatus, WNOHANG)) {
159- dev->d[5] = 255;
160- dev->d[6] = WEXITSTATUS(wstatus);
161- console_clean_after_child();
162- } else {
163- dev->d[5] = 1;
164- dev->d[6] = 0;
165- }
166- }
167-}
168-
169-static void console_kill_child(Device*dev) {
170- int wstatus;
171- if(child_pid) {
172- kill(child_pid, 9);
173- if(waitpid(child_pid, &wstatus, WNOHANG)) {
174- dev->d[5] = 255;
175- dev->d[6] = WEXITSTATUS(wstatus);
176- console_clean_after_child();
177- }
178- }
179-}
180-
181-static void console_start_fork(Device*dev) {
182- fflush(stderr);
183- console_kill_child(dev);
184- child_mode = dev->d[14];
185- console_start_fork_pipe(dev);
186-}
187-
188-static void close_console(Device*dev) {
189- console_kill_child(dev);
190-}
191-
192-static Uint8 subprocess_console_in(Device*dev,Uint8 id) {
193- switch(id) {
194- case 5: case 6: console_check_child(dev); break;
195- }
196- return dev->d[id];
197-}
198-
199 // End of subprocess support
200
201 static void console_out(Device*dev,Uint8 id) {
202 switch(id) {
203- case 8: fputc(dev->d[8],outf); break;
204- case 9: fputc(dev->d[9],stderr); break;
205- // Subprocess
206- case 15: if(enable_subprocess) console_start_fork(dev); break;
207+ case 8: break;
208+ case 9: break;
209 }
210 }
211
A
uxn.o
+0,
-0