1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: main.c |
2 | * File: main.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: main.C,v 1.7 2003/11/26 10:42:34 pcg Exp $ |
4 | * $Id: main.C,v 1.8 2003/11/27 10:12:10 pcg Exp $ |
5 | * |
5 | * |
6 | * All portions of code are copyright by their respective author/s. |
6 | * All portions of code are copyright by their respective author/s. |
7 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
7 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
8 | * - original version |
8 | * - original version |
9 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
9 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
… | |
… | |
65 | blink_ev (this, &rxvt_term::blink_cb), |
65 | blink_ev (this, &rxvt_term::blink_cb), |
66 | #endif |
66 | #endif |
67 | #ifdef POINTER_BLANK |
67 | #ifdef POINTER_BLANK |
68 | pointer_ev (this, &rxvt_term::pointer_cb), |
68 | pointer_ev (this, &rxvt_term::pointer_cb), |
69 | #endif |
69 | #endif |
70 | x_ev (this, &rxvt_term::x_cb) |
70 | x_ev (this, &rxvt_term::x_cb), |
|
|
71 | destroy_ev (this, &rxvt_term::destroy_cb) |
71 | { |
72 | { |
72 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
73 | cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; |
73 | } |
74 | } |
74 | |
75 | |
75 | rxvt_term::~rxvt_term () |
76 | rxvt_term::~rxvt_term () |
76 | { |
77 | { |
|
|
78 | rxvt_scr_release (this); |
|
|
79 | |
|
|
80 | #ifndef NO_SETOWNER_TTYDEV |
|
|
81 | rxvt_privileged_ttydev (this, RESTORE); |
|
|
82 | #endif |
|
|
83 | #ifdef UTMP_SUPPORT |
|
|
84 | rxvt_privileged_utmp (this, RESTORE); |
|
|
85 | #endif |
|
|
86 | #ifdef USE_XIM |
|
|
87 | if (Input_Context != NULL) |
|
|
88 | { |
|
|
89 | XDestroyIC (Input_Context); |
|
|
90 | Input_Context = NULL; |
|
|
91 | } |
|
|
92 | #endif |
|
|
93 | |
|
|
94 | if (cmd_fd >= 0) |
|
|
95 | close (cmd_fd); |
|
|
96 | |
|
|
97 | if (Xfd >= 0) |
|
|
98 | XCloseDisplay (Xdisplay); |
|
|
99 | |
77 | delete PixColors; |
100 | delete PixColors; |
|
|
101 | } |
|
|
102 | |
|
|
103 | void |
|
|
104 | rxvt_term::destroy () |
|
|
105 | { |
|
|
106 | pty_ev.stop (); |
|
|
107 | x_ev.stop (); |
|
|
108 | #ifdef CURSOR_BLINK |
|
|
109 | blink_ev.stop (); |
|
|
110 | #endif |
|
|
111 | #ifdef POINTER_BLANK |
|
|
112 | pointer_ev.stop (); |
|
|
113 | #endif |
|
|
114 | |
|
|
115 | destroy_ev.start (0); |
|
|
116 | } |
|
|
117 | |
|
|
118 | void |
|
|
119 | rxvt_term::destroy_cb (time_watcher &w) |
|
|
120 | { |
|
|
121 | SET_R (this); |
|
|
122 | |
|
|
123 | delete this; |
78 | } |
124 | } |
79 | |
125 | |
80 | /*----------------------------------------------------------------------*/ |
126 | /*----------------------------------------------------------------------*/ |
81 | /* rxvt_init() */ |
127 | /* rxvt_init() */ |
82 | /* LIBPROTO */ |
128 | /* LIBPROTO */ |
… | |
… | |
91 | delete R; |
137 | delete R; |
92 | return NULL; |
138 | return NULL; |
93 | } |
139 | } |
94 | |
140 | |
95 | return R; |
141 | return R; |
|
|
142 | } |
|
|
143 | |
|
|
144 | /* EXTPROTO */ |
|
|
145 | void |
|
|
146 | rxvt_init_signals () |
|
|
147 | { |
|
|
148 | /* install exit handler for cleanup */ |
|
|
149 | #if 0 |
|
|
150 | #ifdef HAVE_ATEXIT |
|
|
151 | atexit(rxvt_clean_exit); |
|
|
152 | #else |
|
|
153 | # ifdef HAVE_ON_EXIT |
|
|
154 | on_exit(rxvt_clean_exit, NULL); /* non-ANSI exit handler */ |
|
|
155 | # endif |
|
|
156 | #endif |
|
|
157 | #endif |
|
|
158 | |
|
|
159 | struct sigaction sa; |
|
|
160 | |
|
|
161 | sigfillset (&sa.sa_mask); |
|
|
162 | sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; |
|
|
163 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGHUP , &sa, 0); //TODO, also: SIGPIPE |
|
|
164 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); |
|
|
165 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); |
|
|
166 | sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); |
|
|
167 | sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); |
|
|
168 | |
|
|
169 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
|
|
170 | /* signal (SIGURG, SIG_DFL); */ |
|
|
171 | |
|
|
172 | XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
|
|
173 | //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); |
96 | } |
174 | } |
97 | |
175 | |
98 | bool |
176 | bool |
99 | rxvt_term::init (int argc, const char *const *argv) |
177 | rxvt_term::init (int argc, const char *const *argv) |
100 | { |
178 | { |
… | |
… | |
132 | #endif |
210 | #endif |
133 | |
211 | |
134 | #if 0 |
212 | #if 0 |
135 | #ifdef DEBUG_X |
213 | #ifdef DEBUG_X |
136 | XSynchronize(Xdisplay, True); |
214 | XSynchronize(Xdisplay, True); |
137 | XSetErrorHandler((XErrorHandler) abort); |
|
|
138 | #else |
|
|
139 | XSetErrorHandler((XErrorHandler) rxvt_xerror_handler); |
|
|
140 | #endif |
215 | #endif |
141 | #endif |
216 | #endif |
142 | |
217 | |
143 | #ifdef HAVE_SCROLLBARS |
218 | #ifdef HAVE_SCROLLBARS |
144 | if (Options & Opt_scrollBar) |
219 | if (Options & Opt_scrollBar) |
… | |
… | |
178 | /* ARGSUSED */ |
253 | /* ARGSUSED */ |
179 | /* EXTPROTO */ |
254 | /* EXTPROTO */ |
180 | RETSIGTYPE |
255 | RETSIGTYPE |
181 | rxvt_Child_signal(int sig __attribute__ ((unused))) |
256 | rxvt_Child_signal(int sig __attribute__ ((unused))) |
182 | { |
257 | { |
183 | dR; |
|
|
184 | int pid, save_errno = errno; |
258 | int pid, save_errno = errno; |
185 | |
|
|
186 | do { |
|
|
187 | errno = 0; |
|
|
188 | } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); |
259 | while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) |
|
|
260 | ; |
|
|
261 | errno = save_errno; |
189 | |
262 | |
|
|
263 | #if 0 |
190 | if (pid == R->cmd_pid) |
264 | if (pid == R->cmd_pid) |
191 | exit(EXIT_SUCCESS); |
265 | exit (EXIT_SUCCESS); |
192 | |
266 | #endif |
193 | errno = save_errno; |
|
|
194 | signal(SIGCHLD, rxvt_Child_signal); |
|
|
195 | } |
267 | } |
196 | |
268 | |
197 | /* |
269 | /* |
198 | * Catch a fatal signal and tidy up before quitting |
270 | * Catch a fatal signal and tidy up before quitting |
199 | */ |
271 | */ |
… | |
… | |
213 | /* INTPROTO */ |
285 | /* INTPROTO */ |
214 | int |
286 | int |
215 | rxvt_xerror_handler(const Display * display |
287 | rxvt_xerror_handler(const Display * display |
216 | __attribute__ ((unused)), const XErrorEvent * event) |
288 | __attribute__ ((unused)), const XErrorEvent * event) |
217 | { |
289 | { |
218 | dR; |
290 | dR; |
219 | |
291 | |
220 | if (R->allowedxerror == -1) { |
292 | if (R->allowedxerror == -1) |
221 | R->allowedxerror = event->error_code; |
293 | R->allowedxerror = event->error_code; |
222 | return 0; /* ignored anyway */ |
294 | else |
223 | } |
295 | { |
224 | rxvt_print_error("XError: Request: %d . %d, Error: %d", |
296 | rxvt_print_error("XError: Request: %d . %d, Error: %d", |
225 | event->request_code, event->minor_code, |
297 | event->request_code, event->minor_code, |
226 | event->error_code); |
298 | event->error_code); |
227 | /* XXX: probably should call rxvt_clean_exit() bypassing X routines */ |
299 | |
228 | exit(EXIT_FAILURE); |
300 | R->destroy (); |
229 | /* NOTREACHED */ |
301 | } |
|
|
302 | |
|
|
303 | return 0; |
230 | } |
304 | } |
231 | |
305 | |
232 | /*----------------------------------------------------------------------*/ |
306 | /*----------------------------------------------------------------------*/ |
233 | /* |
307 | /* |
234 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
308 | * Exit gracefully, clearing the utmp entry and restoring tty attributes |
235 | * TODO: if debugging, this should free up any known resources if we can |
309 | * TODO: if debugging, this should free up any known resources if we can |
236 | */ |
310 | */ |
237 | /* EXTPROTO */ |
311 | /* EXTPROTO */ |
238 | void |
312 | void |
239 | rxvt_clean_exit(void) |
313 | rxvt_clean_exit () |
240 | { |
314 | { |
241 | dR; |
315 | dR; |
242 | |
316 | |
243 | #ifdef DEBUG_SCREEN |
317 | R->destroy (); |
244 | rxvt_scr_release(aR); |
|
|
245 | #endif |
|
|
246 | #ifndef NO_SETOWNER_TTYDEV |
|
|
247 | rxvt_privileged_ttydev(aR_ RESTORE); |
|
|
248 | #endif |
|
|
249 | #ifdef UTMP_SUPPORT |
|
|
250 | rxvt_privileged_utmp(aR_ RESTORE); |
|
|
251 | #endif |
|
|
252 | #ifdef USE_XIM |
|
|
253 | if (R->Input_Context != NULL) { |
|
|
254 | XDestroyIC(R->Input_Context); |
|
|
255 | R->Input_Context = NULL; |
|
|
256 | } |
|
|
257 | #endif |
|
|
258 | } |
318 | } |
259 | |
319 | |
260 | /* ------------------------------------------------------------------------- * |
320 | /* ------------------------------------------------------------------------- * |
261 | * MEMORY ALLOCATION WRAPPERS * |
321 | * MEMORY ALLOCATION WRAPPERS * |
262 | * ------------------------------------------------------------------------- */ |
322 | * ------------------------------------------------------------------------- */ |