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.187 by root, Tue Jan 17 16:22:41 2006 UTC vs.
Revision 1.191 by root, Fri Jan 20 10:27:08 2006 UTC

48# include <termios.h> 48# include <termios.h>
49#endif 49#endif
50 50
51vector<rxvt_term *> rxvt_term::termlist; 51vector<rxvt_term *> rxvt_term::termlist;
52 52
53// used to tell global functions which terminal instance is "active"
54rxvt_t rxvt_current_term;
55
53static char curlocale[128], savelocale[128]; 56static char curlocale[128], savelocale[128];
54 57
55bool 58bool
56rxvt_set_locale (const char *locale) 59rxvt_set_locale (const char *locale) NOTHROW
57{ 60{
58 if (!locale || !strncmp (locale, curlocale, 128)) 61 if (!locale || !strncmp (locale, curlocale, 128))
59 return false; 62 return false;
60 63
61 strncpy (curlocale, locale, 128); 64 strncpy (curlocale, locale, 128);
62 setlocale (LC_CTYPE, curlocale); 65 setlocale (LC_CTYPE, curlocale);
63 return true; 66 return true;
64} 67}
65 68
66void 69void
67rxvt_push_locale (const char *locale) 70rxvt_push_locale (const char *locale) NOTHROW
68{ 71{
69 strcpy (savelocale, curlocale); 72 strcpy (savelocale, curlocale);
70 rxvt_set_locale (locale); 73 rxvt_set_locale (locale);
71} 74}
72 75
73void 76void
74rxvt_pop_locale () 77rxvt_pop_locale () NOTHROW
75{ 78{
76 rxvt_set_locale (savelocale); 79 rxvt_set_locale (savelocale);
77} 80}
78 81
79#if ENABLE_COMBINING 82#if ENABLE_COMBINING
169#ifdef USE_XIM 172#ifdef USE_XIM
170 im_ev (this, &rxvt_term::im_cb), 173 im_ev (this, &rxvt_term::im_cb),
171#endif 174#endif
172 termwin_ev (this, &rxvt_term::x_cb), 175 termwin_ev (this, &rxvt_term::x_cb),
173 vt_ev (this, &rxvt_term::x_cb), 176 vt_ev (this, &rxvt_term::x_cb),
177 child_ev (this, &rxvt_term::child_cb),
174 check_ev (this, &rxvt_term::check_cb), 178 check_ev (this, &rxvt_term::check_cb),
175 flush_ev (this, &rxvt_term::flush_cb), 179 flush_ev (this, &rxvt_term::flush_cb),
176 destroy_ev (this, &rxvt_term::destroy_cb), 180 destroy_ev (this, &rxvt_term::destroy_cb),
177 pty_ev (this, &rxvt_term::pty_cb), 181 pty_ev (this, &rxvt_term::pty_cb),
178 incr_ev (this, &rxvt_term::incr_cb) 182 incr_ev (this, &rxvt_term::incr_cb)
181 185
182 termlist.push_back (this); 186 termlist.push_back (this);
183 187
184#ifdef KEYSYM_RESOURCE 188#ifdef KEYSYM_RESOURCE
185 keyboard = new keyboard_manager; 189 keyboard = new keyboard_manager;
186
187 if (!keyboard)
188 rxvt_fatal ("out of memory, aborting.\n");
189#endif 190#endif
190} 191}
191 192
192// clean up the most important stuff, do *not* call x or free mem etc. 193// clean up the most important stuff, do *not* call x or free mem etc.
193// for use before an emergency exit 194// for use before an emergency exit
199 delete pty; pty = 0; 200 delete pty; pty = 0;
200} 201}
201 202
202rxvt_term::~rxvt_term () 203rxvt_term::~rxvt_term ()
203{ 204{
204 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
205
206 termlist.erase (find (termlist.begin (), termlist.end(), this)); 205 termlist.erase (find (termlist.begin (), termlist.end(), this));
207 206
208 emergency_cleanup (); 207 emergency_cleanup ();
209 208
210#if ENABLE_STYLES 209#if ENABLE_STYLES
285#ifdef KEYSYM_RESOURCE 284#ifdef KEYSYM_RESOURCE
286 delete keyboard; 285 delete keyboard;
287#endif 286#endif
288} 287}
289 288
289// child has exited, usually destroys
290void 290void
291rxvt_term::child_exit () 291rxvt_term::child_cb (child_watcher &w, int status)
292{ 292{
293 HOOK_INVOKE ((this, HOOK_CHILD_EXIT, DT_INT, status, DT_END));
294
293 cmd_pid = 0; 295 cmd_pid = 0;
294 296
295 if (!OPTION (Opt_hold)) 297 if (!OPTION (Opt_hold))
296 destroy (); 298 destroy ();
297} 299}
298 300
299void 301void
300rxvt_term::destroy () 302rxvt_term::destroy ()
301{ 303{
302 if (destroy_ev.active) 304 if (destroy_ev.active)
305 return;
306
307 if (HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)))
303 return; 308 return;
304 309
305#if ENABLE_OVERLAY 310#if ENABLE_OVERLAY
306 scr_overlay_off (); 311 scr_overlay_off ();
307#endif 312#endif
459 464
460#ifdef KEYSYM_RESOURCE 465#ifdef KEYSYM_RESOURCE
461 keyboard->register_done (); 466 keyboard->register_done ();
462#endif 467#endif
463 468
469#if ENABLE_PERL
470 if (!rs[Rs_perl_ext_1])
471 rs[Rs_perl_ext_1] = "default";
472
473 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
474 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
475 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
476 {
477 rxvt_perl.init (this);
478 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
479 }
480#endif
481
464#ifdef HAVE_SCROLLBARS 482#ifdef HAVE_SCROLLBARS
465 if (OPTION (Opt_scrollBar)) 483 if (OPTION (Opt_scrollBar))
466 scrollBar.setIdle (); /* set existence for size calculations */ 484 scrollBar.setIdle (); /* set existence for size calculations */
467#endif 485#endif
468 486
469#if ENABLE_PERL
470 if (!rs[Rs_perl_ext_1])
471 rs[Rs_perl_ext_1] = "default";
472
473 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
474 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
475 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
476 {
477 rxvt_perl.init (this);
478 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
479 }
480#endif
481
482 pty = rxvt_new_ptytty (); 487 pty = rxvt_new_ptytty ();
483 488
484 create_windows (argc, argv); 489 create_windows (argc, argv);
485 490
486 dDisp; 491 dDisp;
504 check_our_parents (); 509 check_our_parents ();
505 rootwin_ev.start (display, display->root); 510 rootwin_ev.start (display, display->root);
506 } 511 }
507#endif 512#endif
508 513
514 set_colorfgbg ();
515
516 init_command (cmd_argv);
517
518 free (cmd_argv);
519
520 if (pty->pty >= 0)
521 pty_ev.start (pty->pty, EVENT_READ);
522
523 check_ev.start ();
524
525 HOOK_INVOKE ((this, HOOK_START, DT_END));
526
509 XMapWindow (disp, vt); 527 XMapWindow (disp, vt);
510 XMapWindow (disp, parent[0]); 528 XMapWindow (disp, parent[0]);
511 529
512 set_colorfgbg ();
513
514 init_command (cmd_argv);
515
516 free (cmd_argv);
517
518 if (pty->pty >= 0)
519 pty_ev.start (pty->pty, EVENT_READ);
520
521 check_ev.start ();
522
523 HOOK_INVOKE ((this, HOOK_START, DT_END));
524
525 return true; 530 return true;
526} 531}
527 532
528static struct sig_handlers 533static struct sig_handlers
529{ 534{
530 sig_watcher sw_chld, sw_term, sw_int; 535 sig_watcher sw_term, sw_int;
531 536
532 void sig_chld (sig_watcher &w)
533 {
534 // we are being called for every SIGCHLD, find the corresponding term
535 int pid;
536
537 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
538 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
539 if (pid == (*t)->cmd_pid)
540 {
541 (*t)->child_exit ();
542 break;
543 }
544 }
545
546 /* 537 /*
547 * Catch a fatal signal and tidy up before quitting 538 * Catch a fatal signal and tidy up before quitting
548 */ 539 */
549 void 540 void
550 sig_term (sig_watcher &w) 541 sig_term (sig_watcher &w)
556 signal (w.signum, SIG_DFL); 547 signal (w.signum, SIG_DFL);
557 kill (getpid (), w.signum); 548 kill (getpid (), w.signum);
558 } 549 }
559 550
560 sig_handlers () 551 sig_handlers ()
561 : sw_chld (this, &sig_handlers::sig_chld),
562 sw_term (this, &sig_handlers::sig_term), 552 : sw_term (this, &sig_handlers::sig_term),
563 sw_int (this, &sig_handlers::sig_term) 553 sw_int (this, &sig_handlers::sig_term)
564 { 554 {
565 } 555 }
566} sig_handlers; 556} sig_handlers;
567 557
574 gid_t gid = getgid (); 564 gid_t gid = getgid ();
575 565
576 // before doing anything else, check for setuid/setgid operation, 566 // before doing anything else, check for setuid/setgid operation,
577 // start the helper process and drop privileges 567 // start the helper process and drop privileges
578 if (uid != geteuid () 568 if (uid != geteuid ()
579 || 1 //D
580 || gid != getegid ()) 569 || gid != getegid ())
581 { 570 {
582#if PTYTTY_HELPER 571#if PTYTTY_HELPER
583 rxvt_ptytty_server (); 572 rxvt_ptytty_server ();
584#else 573#else
605 rxvt_environ = environ; 594 rxvt_environ = environ;
606 595
607 signal (SIGHUP, SIG_IGN); 596 signal (SIGHUP, SIG_IGN);
608 signal (SIGPIPE, SIG_IGN); 597 signal (SIGPIPE, SIG_IGN);
609 598
610 sig_handlers.sw_chld.start (SIGCHLD);
611 sig_handlers.sw_term.start (SIGTERM); 599 sig_handlers.sw_term.start (SIGTERM);
612 sig_handlers.sw_int.start (SIGINT); 600 sig_handlers.sw_int.start (SIGINT);
613 601
614 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 602 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
615 /* signal (SIGURG, SIG_DFL); */ 603 /* signal (SIGURG, SIG_DFL); */
644 rxvt_fatal ("memory allocation failure. aborting.\n"); 632 rxvt_fatal ("memory allocation failure. aborting.\n");
645 633
646 return p; 634 return p;
647} 635}
648 636
649void * 637void *
650rxvt_realloc (void *ptr, size_t size) 638rxvt_realloc (void *ptr, size_t size)
651{ 639{
652 void *p = realloc (ptr, size); 640 void *p = realloc (ptr, size);
653 641
654 if (!p) 642 if (!p)
1602 XFree (preedit_attr); 1590 XFree (preedit_attr);
1603 XFree (status_attr); 1591 XFree (status_attr);
1604} 1592}
1605#endif /* USE_XIM */ 1593#endif /* USE_XIM */
1606 1594
1607/*----------------------------------------------------------------------*/
1608rxvt_t rxvt_current_term;
1609
1610/*----------------------- end-of-file (C source) -----------------------*/ 1595/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines