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.145 by root, Thu Aug 11 02:05:07 2005 UTC vs.
Revision 1.148 by root, Wed Nov 30 21:05:39 2005 UTC

157 pointer_ev (this, &rxvt_term::pointer_cb), 157 pointer_ev (this, &rxvt_term::pointer_cb),
158#endif 158#endif
159#ifdef USE_XIM 159#ifdef USE_XIM
160 im_ev (this, &rxvt_term::im_cb), 160 im_ev (this, &rxvt_term::im_cb),
161#endif 161#endif
162 sw_term (this, &rxvt_term::sig_term),
163 sw_int (this, &rxvt_term::sig_term),
164 sw_chld (this, &rxvt_term::sig_chld),
165 termwin_ev (this, &rxvt_term::x_cb), 162 termwin_ev (this, &rxvt_term::x_cb),
166 vt_ev (this, &rxvt_term::x_cb), 163 vt_ev (this, &rxvt_term::x_cb),
167 check_ev (this, &rxvt_term::check_cb), 164 check_ev (this, &rxvt_term::check_cb),
168 flush_ev (this, &rxvt_term::flush_cb), 165 flush_ev (this, &rxvt_term::flush_cb),
169 destroy_ev (this, &rxvt_term::destroy_cb), 166 destroy_ev (this, &rxvt_term::destroy_cb),
417{ 414{
418 if (GET_R->allowedxerror == -1) 415 if (GET_R->allowedxerror == -1)
419 GET_R->allowedxerror = event->error_code; 416 GET_R->allowedxerror = event->error_code;
420 else 417 else
421 { 418 {
422 //TODO: GET_R is most likely not the terminal which caused the error 419 // GET_R is most likely not the terminal which caused the error,
423 //TODO: maybe just output the error and continue? 420 // so just output the error and continue
424#if ENABLE_FRILLS 421#if ENABLE_FRILLS
425 print_x_error (display, event); 422 print_x_error (display, event);
426#else 423#else
427 old_xerror_handler (display, event); 424 old_xerror_handler (display, event);
428#endif 425#endif
438 DisplayString (display)); 435 DisplayString (display));
439 rxvt_emergency_cleanup (); 436 rxvt_emergency_cleanup ();
440 _exit (EXIT_FAILURE); 437 _exit (EXIT_FAILURE);
441} 438}
442 439
443/*
444 * Catch a fatal signal and tidy up before quitting
445 */
446void
447rxvt_term::sig_term (sig_watcher &w)
448{
449#ifdef DEBUG_CMD
450 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
451#endif
452 rxvt_emergency_cleanup ();
453 signal (w.signum, SIG_DFL);
454 kill (getpid (), w.signum);
455}
456
457/*----------------------------------------------------------------------*/ 440/*----------------------------------------------------------------------*/
458/* rxvt_init () */
459bool 441bool
460rxvt_term::init (int argc, const char *const *argv) 442rxvt_term::init (int argc, const char *const *argv)
461{ 443{
462 SET_R (this); 444 SET_R (this);
463 445
524 506
525 check_ev.start (); 507 check_ev.start ();
526 508
527 return true; 509 return true;
528} 510}
511
512static struct sig_handlers
513{
514 sig_watcher sw_chld, sw_term, sw_int;
515
516 void sig_chld (sig_watcher &w)
517 {
518 // we are being called for every SIGCHLD, find the corresponding term
519 int pid;
520
521 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
522 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
523 if (pid == (*t)->cmd_pid)
524 {
525 (*t)->destroy ();
526 break;
527 }
528 }
529
530 /*
531 * Catch a fatal signal and tidy up before quitting
532 */
533 void
534 sig_term (sig_watcher &w)
535 {
536#ifdef DEBUG_CMD
537 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
538#endif
539 rxvt_emergency_cleanup ();
540 signal (w.signum, SIG_DFL);
541 kill (getpid (), w.signum);
542 }
543
544 sig_handlers ()
545 : sw_chld (this, &sig_handlers::sig_chld),
546 sw_term (this, &sig_handlers::sig_term),
547 sw_int (this, &sig_handlers::sig_term)
548 {
549 }
550} sig_handlers;
529 551
530void 552void
531rxvt_init () 553rxvt_init ()
532{ 554{
533 /* 555 /*
541 rxvt_privileges (IGNORE); 563 rxvt_privileges (IGNORE);
542 564
543 signal (SIGHUP, SIG_IGN); 565 signal (SIGHUP, SIG_IGN);
544 signal (SIGPIPE, SIG_IGN); 566 signal (SIGPIPE, SIG_IGN);
545 567
568 sig_handlers.sw_chld.start (SIGCHLD);
569 sig_handlers.sw_term.start (SIGTERM);
570 sig_handlers.sw_int.start (SIGINT);
571
546 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 572 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
547 /* signal (SIGURG, SIG_DFL); */ 573 /* signal (SIGURG, SIG_DFL); */
548 574
549 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 575 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
550 // TODO: handle this with exceptions and tolerate the memory loss 576 // TODO: handle this with exceptions and tolerate the memory loss
551 XSetIOErrorHandler (rxvt_xioerror_handler); 577 XSetIOErrorHandler (rxvt_xioerror_handler);
552}
553
554/* ------------------------------------------------------------------------- *
555 * SIGNAL HANDLING & EXIT HANDLER *
556 * ------------------------------------------------------------------------- */
557/*
558 * Catch a SIGCHLD signal and exit if the direct child has died
559 */
560
561void
562rxvt_term::sig_chld (sig_watcher &w)
563{
564 // we are being called for every SIGCHLD, not just ours
565 int pid;
566
567 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
568 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
569 if (pid == (*t)->cmd_pid)
570 {
571 (*t)->destroy ();
572 break;
573 }
574} 578}
575 579
576/* ------------------------------------------------------------------------- * 580/* ------------------------------------------------------------------------- *
577 * MEMORY ALLOCATION WRAPPERS * 581 * MEMORY ALLOCATION WRAPPERS *
578 * ------------------------------------------------------------------------- */ 582 * ------------------------------------------------------------------------- */
585 rxvt_fatal ("memory allocation failure. aborting.\n"); 589 rxvt_fatal ("memory allocation failure. aborting.\n");
586 590
587 return p; 591 return p;
588} 592}
589 593
590void * 594void *
591rxvt_calloc (size_t number, size_t size) 595rxvt_calloc (size_t number, size_t size)
592{ 596{
593 void *p = calloc (number, size); 597 void *p = calloc (number, size);
594 598
595 if (!p) 599 if (!p)
847#endif 851#endif
848} 852}
849 853
850/*----------------------------------------------------------------------*/ 854/*----------------------------------------------------------------------*/
851/* set_fonts () - load and set the various fonts 855/* set_fonts () - load and set the various fonts
852/* 856 *
853 * init = 1 - initialize 857 * init = 1 - initialize
854 * 858 *
855 * fontname == FONT_UP - switch to bigger font 859 * fontname == FONT_UP - switch to bigger font
856 * fontname == FONT_DN - switch to smaller font 860 * fontname == FONT_DN - switch to smaller font
857 */ 861 */
1551} 1555}
1552 1556
1553void 1557void
1554rxvt_term::im_cb () 1558rxvt_term::im_cb ()
1555{ 1559{
1556 int i, found, had_im; 1560 int i;
1557 const char *p; 1561 const char *p;
1558 char **s; 1562 char **s;
1559 char buf[IMBUFSIZ]; 1563 char buf[IMBUFSIZ];
1560 1564
1561 SET_R (this); 1565 SET_R (this);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines