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.147 by root, Mon Nov 28 19:35:04 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),
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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines