ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.4 by pcg, Tue Nov 25 15:25:17 2003 UTC vs.
Revision 1.8 by pcg, Thu Nov 27 10:12:10 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: main.c 2 * File: main.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: main.C,v 1.4 2003/11/25 15:25:17 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>
58{ 58{
59 free (p); 59 free (p);
60} 60}
61 61
62rxvt_term::rxvt_term () 62rxvt_term::rxvt_term ()
63: pty_ev(this, &rxvt_term::pty_cb), 63: pty_ev (this, &rxvt_term::pty_cb),
64#ifdef CURSOR_BLINK
65 blink_ev (this, &rxvt_term::blink_cb),
66#endif
67#ifdef POINTER_BLANK
68 pointer_ev (this, &rxvt_term::pointer_cb),
69#endif
64 x_ev (this, &rxvt_term::x_cb) 70 x_ev (this, &rxvt_term::x_cb),
71 destroy_ev (this, &rxvt_term::destroy_cb)
65{ 72{
66 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; 73 cmdbuf_ptr = cmdbuf_endp = cmdbuf_base;
67} 74}
68 75
69rxvt_term::~rxvt_term () 76rxvt_term::~rxvt_term ()
70{ 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
71 delete PixColors; 100 delete PixColors;
101}
102
103void
104rxvt_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
118void
119rxvt_term::destroy_cb (time_watcher &w)
120{
121 SET_R (this);
122
123 delete this;
72} 124}
73 125
74/*----------------------------------------------------------------------*/ 126/*----------------------------------------------------------------------*/
75/* rxvt_init() */ 127/* rxvt_init() */
76/* LIBPROTO */ 128/* LIBPROTO */
85 delete R; 137 delete R;
86 return NULL; 138 return NULL;
87 } 139 }
88 140
89 return R; 141 return R;
142}
143
144/* EXTPROTO */
145void
146rxvt_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);
90} 174}
91 175
92bool 176bool
93rxvt_term::init (int argc, const char *const *argv) 177rxvt_term::init (int argc, const char *const *argv)
94{ 178{
126#endif 210#endif
127 211
128#if 0 212#if 0
129#ifdef DEBUG_X 213#ifdef DEBUG_X
130 XSynchronize(Xdisplay, True); 214 XSynchronize(Xdisplay, True);
131 XSetErrorHandler((XErrorHandler) abort);
132#else
133 XSetErrorHandler((XErrorHandler) rxvt_xerror_handler);
134#endif 215#endif
135#endif 216#endif
136 217
137#ifdef HAVE_SCROLLBARS 218#ifdef HAVE_SCROLLBARS
138 if (Options & Opt_scrollBar) 219 if (Options & Opt_scrollBar)
155 rxvt_init_env (this); 236 rxvt_init_env (this);
156 rxvt_init_command (this, cmd_argv); 237 rxvt_init_command (this, cmd_argv);
157 238
158 x_ev.start (Xfd, EVENT_READ); 239 x_ev.start (Xfd, EVENT_READ);
159 pty_ev.start (cmd_fd, EVENT_READ); 240 pty_ev.start (cmd_fd, EVENT_READ);
241
242 flush ();
160 243
161 return true; 244 return true;
162} 245}
163 246
164/* ------------------------------------------------------------------------- * 247/* ------------------------------------------------------------------------- *
170/* ARGSUSED */ 253/* ARGSUSED */
171/* EXTPROTO */ 254/* EXTPROTO */
172RETSIGTYPE 255RETSIGTYPE
173rxvt_Child_signal(int sig __attribute__ ((unused))) 256rxvt_Child_signal(int sig __attribute__ ((unused)))
174{ 257{
175 dR;
176 int pid, save_errno = errno; 258 int pid, save_errno = errno;
177
178 do {
179 errno = 0;
180 } while ((pid = waitpid(-1, NULL, WNOHANG)) == -1 && errno == EINTR); 259 while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR)
260 ;
261 errno = save_errno;
181 262
263#if 0
182 if (pid == R->cmd_pid) 264 if (pid == R->cmd_pid)
183 exit(EXIT_SUCCESS); 265 exit (EXIT_SUCCESS);
184 266#endif
185 errno = save_errno;
186 signal(SIGCHLD, rxvt_Child_signal);
187} 267}
188 268
189/* 269/*
190 * Catch a fatal signal and tidy up before quitting 270 * Catch a fatal signal and tidy up before quitting
191 */ 271 */
205/* INTPROTO */ 285/* INTPROTO */
206int 286int
207rxvt_xerror_handler(const Display * display 287rxvt_xerror_handler(const Display * display
208 __attribute__ ((unused)), const XErrorEvent * event) 288 __attribute__ ((unused)), const XErrorEvent * event)
209{ 289{
210 dR; 290 dR;
211 291
212 if (R->allowedxerror == -1) { 292 if (R->allowedxerror == -1)
213 R->allowedxerror = event->error_code; 293 R->allowedxerror = event->error_code;
214 return 0; /* ignored anyway */ 294 else
215 } 295 {
216 rxvt_print_error("XError: Request: %d . %d, Error: %d", 296 rxvt_print_error("XError: Request: %d . %d, Error: %d",
217 event->request_code, event->minor_code, 297 event->request_code, event->minor_code,
218 event->error_code); 298 event->error_code);
219/* XXX: probably should call rxvt_clean_exit() bypassing X routines */ 299
220 exit(EXIT_FAILURE); 300 R->destroy ();
221/* NOTREACHED */ 301 }
302
303 return 0;
222} 304}
223 305
224/*----------------------------------------------------------------------*/ 306/*----------------------------------------------------------------------*/
225/* 307/*
226 * Exit gracefully, clearing the utmp entry and restoring tty attributes 308 * Exit gracefully, clearing the utmp entry and restoring tty attributes
227 * 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
228 */ 310 */
229/* EXTPROTO */ 311/* EXTPROTO */
230void 312void
231rxvt_clean_exit(void) 313rxvt_clean_exit ()
232{ 314{
233 dR; 315 dR;
234 316
235#ifdef DEBUG_SCREEN 317 R->destroy ();
236 rxvt_scr_release(aR);
237#endif
238#ifndef NO_SETOWNER_TTYDEV
239 rxvt_privileged_ttydev(aR_ RESTORE);
240#endif
241#ifdef UTMP_SUPPORT
242 rxvt_privileged_utmp(aR_ RESTORE);
243#endif
244#ifdef USE_XIM
245 if (R->Input_Context != NULL) {
246 XDestroyIC(R->Input_Context);
247 R->Input_Context = NULL;
248 }
249#endif
250} 318}
251 319
252/* ------------------------------------------------------------------------- * 320/* ------------------------------------------------------------------------- *
253 * MEMORY ALLOCATION WRAPPERS * 321 * MEMORY ALLOCATION WRAPPERS *
254 * ------------------------------------------------------------------------- */ 322 * ------------------------------------------------------------------------- */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines