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.167 by root, Sun Jan 8 08:43:11 2006 UTC vs.
Revision 1.185 by root, Tue Jan 17 15:17:39 2006 UTC

51#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) 51#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
52static uid_t saved_euid; 52static uid_t saved_euid;
53static gid_t saved_egid; 53static gid_t saved_egid;
54#endif 54#endif
55 55
56bool
57rxvt_tainted ()
58{
59#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
60 return getuid () != saved_euid || getgid () != saved_egid;
61#else
62 return false;
63#endif
64}
65
56vector<rxvt_term *> rxvt_term::termlist; 66vector<rxvt_term *> rxvt_term::termlist;
57 67
58static char curlocale[128], savelocale[128]; 68static char curlocale[128], savelocale[128];
59 69
60bool 70bool
66 strncpy (curlocale, locale, 128); 76 strncpy (curlocale, locale, 128);
67 setlocale (LC_CTYPE, curlocale); 77 setlocale (LC_CTYPE, curlocale);
68 return true; 78 return true;
69} 79}
70 80
71bool 81void
72rxvt_push_locale (const char *locale) 82rxvt_push_locale (const char *locale)
73{ 83{
74 strcpy (savelocale, curlocale); 84 strcpy (savelocale, curlocale);
75 rxvt_set_locale (locale); 85 rxvt_set_locale (locale);
76} 86}
150#if TRANSPARENT 160#if TRANSPARENT
151 rootwin_ev (this, &rxvt_term::rootwin_cb), 161 rootwin_ev (this, &rxvt_term::rootwin_cb),
152#endif 162#endif
153#ifdef HAVE_SCROLLBARS 163#ifdef HAVE_SCROLLBARS
154 scrollbar_ev (this, &rxvt_term::x_cb), 164 scrollbar_ev (this, &rxvt_term::x_cb),
155#endif
156#ifdef MENUBAR
157 menubar_ev (this, &rxvt_term::x_cb),
158#endif 165#endif
159#ifdef CURSOR_BLINK 166#ifdef CURSOR_BLINK
160 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), 167 cursor_blink_ev (this, &rxvt_term::cursor_blink_cb),
161#endif 168#endif
162#ifdef TEXT_BLINK 169#ifdef TEXT_BLINK
206 213
207#ifdef UTMP_SUPPORT 214#ifdef UTMP_SUPPORT
208 privileged_utmp (RESTORE); 215 privileged_utmp (RESTORE);
209#endif 216#endif
210 217
211 pty.put (); 218 delete pty; pty = 0;
212} 219}
213 220
214rxvt_term::~rxvt_term () 221rxvt_term::~rxvt_term ()
215{ 222{
216 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); 223 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
232 239
233 selection_clear (); 240 selection_clear ();
234 241
235#ifdef USE_XIM 242#ifdef USE_XIM
236 im_destroy (); 243 im_destroy ();
237#endif
238#ifdef MENUBAR
239 if (menubarGC) XFreeGC (disp, menubarGC);
240#endif 244#endif
241#ifdef XTERM_SCROLLBAR 245#ifdef XTERM_SCROLLBAR
242 if (xscrollbarGC) XFreeGC (disp, xscrollbarGC); 246 if (xscrollbarGC) XFreeGC (disp, xscrollbarGC);
243 if (ShadowGC) XFreeGC (disp, ShadowGC); 247 if (ShadowGC) XFreeGC (disp, ShadowGC);
244#endif 248#endif
255 if (upArrow) XFreePixmap (disp, upArrow); 259 if (upArrow) XFreePixmap (disp, upArrow);
256 if (downArrow) XFreePixmap (disp, downArrow); 260 if (downArrow) XFreePixmap (disp, downArrow);
257 if (upArrowHi) XFreePixmap (disp, upArrowHi); 261 if (upArrowHi) XFreePixmap (disp, upArrowHi);
258 if (downArrowHi) XFreePixmap (disp, downArrowHi); 262 if (downArrowHi) XFreePixmap (disp, downArrowHi);
259#endif 263#endif
260#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) 264#ifdef RXVT_SCROLLBAR
261 if (topShadowGC) XFreeGC (disp, topShadowGC); 265 if (topShadowGC) XFreeGC (disp, topShadowGC);
262 if (botShadowGC) XFreeGC (disp, botShadowGC); 266 if (botShadowGC) XFreeGC (disp, botShadowGC);
263 if (scrollbarGC) XFreeGC (disp, scrollbarGC); 267 if (scrollbarGC) XFreeGC (disp, scrollbarGC);
264#endif 268#endif
265 if (gc) XFreeGC (disp, gc); 269 if (gc) XFreeGC (disp, gc);
266 270
267#if defined(MENUBAR) && (MENUBAR_MAX > 1)
268 delete menuBar.drawable;
269 //if (menuBar.win)
270 // XDestroyWindow (disp, menuBar.win);
271#endif
272 delete drawable; 271 delete drawable;
273 // destroy all windows 272 // destroy all windows
274 if (parent[0]) 273 if (parent[0])
275 XDestroyWindow (disp, parent[0]); 274 XDestroyWindow (disp, parent[0]);
276 } 275 }
277 276
278 // TODO: free pixcolours, colours should become part of rxvt_display 277 // TODO: free pixcolours, colours should become part of rxvt_display
279
280 delete pix_colors_focused; 278 delete pix_colors_focused;
281#if OFF_FOCUS_FADING 279#if OFF_FOCUS_FADING
282 delete pix_colors_unfocused; 280 delete pix_colors_unfocused;
283#endif
284#if USE_XGETDEFAULT
285 XrmDestroyDatabase (xrmdatabase);
286#endif 281#endif
287 282
288 displays.put (display); 283 displays.put (display);
289 284
290 scr_release (); 285 scr_release ();
336 im_ev.stop (display); 331 im_ev.stop (display);
337#endif 332#endif
338#if HAVE_SCROLLBARS 333#if HAVE_SCROLLBARS
339 scrollbar_ev.stop (display); 334 scrollbar_ev.stop (display);
340#endif 335#endif
341#if MENUBAR
342 menubar_ev.stop (display);
343#endif
344#if TRANSPARENT 336#if TRANSPARENT
345 rootwin_ev.stop (display); 337 rootwin_ev.stop (display);
346#endif 338#endif
347 incr_ev.stop (); 339 incr_ev.stop ();
348 termwin_ev.stop (display); 340 termwin_ev.stop (display);
371} 363}
372 364
373void 365void
374rxvt_term::destroy_cb (time_watcher &w) 366rxvt_term::destroy_cb (time_watcher &w)
375{ 367{
376 SET_R (this); 368 make_current ();
377 369
378 delete this; 370 delete this;
379} 371}
380 372
381/*----------------------------------------------------------------------*/ 373/*----------------------------------------------------------------------*/
472/*----------------------------------------------------------------------*/ 464/*----------------------------------------------------------------------*/
473bool 465bool
474rxvt_term::init (int argc, const char *const *argv) 466rxvt_term::init (int argc, const char *const *argv)
475{ 467{
476 SET_R (this); 468 SET_R (this);
477
478 set_locale (""); 469 set_locale ("");
470 set_environ (envv); // few things in X do not call setlocale :(
479 471
480 if (!init_vars ()) 472 if (!init_vars ())
481 return false; 473 return false;
482 474
483 init_secondary (); 475 init_secondary ();
486 478
487#ifdef KEYSYM_RESOURCE 479#ifdef KEYSYM_RESOURCE
488 keyboard->register_done (); 480 keyboard->register_done ();
489#endif 481#endif
490 482
491#if MENUBAR_MAX
492 menubar_read (rs[Rs_menu]);
493#endif
494#ifdef HAVE_SCROLLBARS 483#ifdef HAVE_SCROLLBARS
495 if (OPTION (Opt_scrollBar)) 484 if (OPTION (Opt_scrollBar))
496 scrollBar.setIdle (); /* set existence for size calculations */ 485 scrollBar.setIdle (); /* set existence for size calculations */
497#endif 486#endif
498 487
502 491
503 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) 492 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
504 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) 493 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
505 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 494 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
506 { 495 {
507 bool tainted = false;
508
509#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) 496#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
510 // ignore some perl-related arguments if some bozo installed us set[ug]id 497 // ignore some perl-related arguments if some bozo installed us set[ug]id
511 if (getuid () != saved_euid || getgid () != saved_egid) 498 if (rxvt_tainted ())
512 { 499 {
513 tainted = true;
514
515 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) 500 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
516 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) 501 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
517 { 502 {
518 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); 503 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
519 rs[Rs_perl_lib] = 0; 504 rs[Rs_perl_lib] = 0;
520 rs[Rs_perl_eval] = "our $tainted = 1"; 505 rs[Rs_perl_eval] = 0;
521 } 506 }
522 } 507 }
523#endif 508#endif
524 rxvt_perl.init (tainted); 509 rxvt_perl.init (this);
525 HOOK_INVOKE ((this, HOOK_INIT, DT_END)); 510 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
526 } 511 }
527#endif 512#endif
528 513
514 pty = rxvt_new_ptytty ();
515
529 create_windows (argc, argv); 516 create_windows (argc, argv);
530 517
531 dDisp; 518 dDisp;
532 519
533 init_xlocale (); 520 init_xlocale ();
534 521
535 scr_reset (); /* initialize screen */ 522 scr_reset (); // initialize screen
536 523
537#if 0 524#if 0
538 XSynchronize (disp, True); 525 XSynchronize (disp, True);
539#endif 526#endif
540 527
541#ifdef HAVE_SCROLLBARS 528#ifdef HAVE_SCROLLBARS
542 if (OPTION (Opt_scrollBar)) 529 if (OPTION (Opt_scrollBar))
543 resize_scrollbar (); /* create and map scrollbar */ 530 resize_scrollbar (); /* create and map scrollbar */
544#endif 531#endif
545#if (MENUBAR_MAX)
546 if (menubar_visible ())
547 XMapWindow (disp, menuBar.win);
548#endif
549#ifdef TRANSPARENT 532#ifdef TRANSPARENT
550 if (OPTION (Opt_transparent)) 533 if (OPTION (Opt_transparent))
551 { 534 {
552 XSelectInput (disp, display->root, PropertyChangeMask); 535 XSelectInput (disp, display->root, PropertyChangeMask);
553 check_our_parents (); 536 check_our_parents ();
562 545
563 init_command (cmd_argv); 546 init_command (cmd_argv);
564 547
565 free (cmd_argv); 548 free (cmd_argv);
566 549
567 if (pty.pty >= 0) 550 if (pty->pty >= 0)
568 pty_ev.start (pty.pty, EVENT_READ); 551 pty_ev.start (pty->pty, EVENT_READ);
569 552
570 check_ev.start (); 553 check_ev.start ();
571 554
572 HOOK_INVOKE ((this, HOOK_START, DT_END)); 555 HOOK_INVOKE ((this, HOOK_START, DT_END));
573 556
612 sw_int (this, &sig_handlers::sig_term) 595 sw_int (this, &sig_handlers::sig_term)
613 { 596 {
614 } 597 }
615} sig_handlers; 598} sig_handlers;
616 599
600char **rxvt_environ; // startup environment
601
617void 602void
618rxvt_init () 603rxvt_init ()
619{ 604{
605 rxvt_environ = environ;
606
620 /* 607 /*
621 * Save and then give up any super-user privileges 608 * Save and then give up any super-user privileges
622 * If we need privileges in any area then we must specifically request it. 609 * If we need privileges in any area then we must specifically request it.
623 * We should only need to be root in these cases: 610 * We should only need to be root in these cases:
624 * 1. write utmp entries on some systems 611 * 1. write utmp entries on some systems
639 626
640 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 627 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
641 // TODO: handle this with exceptions and tolerate the memory loss 628 // TODO: handle this with exceptions and tolerate the memory loss
642 XSetIOErrorHandler (rxvt_xioerror_handler); 629 XSetIOErrorHandler (rxvt_xioerror_handler);
643 630
644#ifdef USE_XGETDEFAULT
645 XrmInitialize (); 631 XrmInitialize ();
646#endif
647} 632}
648 633
649/* ------------------------------------------------------------------------- * 634/* ------------------------------------------------------------------------- *
650 * MEMORY ALLOCATION WRAPPERS * 635 * MEMORY ALLOCATION WRAPPERS *
651 * ------------------------------------------------------------------------- */ 636 * ------------------------------------------------------------------------- */
702 case IGNORE: 687 case IGNORE:
703 /* 688 /*
704 * change effective uid/gid - not real uid/gid - so we can switch 689 * change effective uid/gid - not real uid/gid - so we can switch
705 * back to root later, as required 690 * back to root later, as required
706 */ 691 */
692 setegid (getgid ());
707 seteuid (getuid ()); 693 seteuid (getuid ());
708 setegid (getgid ());
709 break; 694 break;
710 case SAVE: 695 case SAVE:
696 saved_egid = getegid ();
711 saved_euid = geteuid (); 697 saved_euid = geteuid ();
712 saved_egid = getegid ();
713 break; 698 break;
714 case RESTORE: 699 case RESTORE:
700 setegid (saved_egid);
715 seteuid (saved_euid); 701 seteuid (saved_euid);
716 setegid (saved_egid);
717 break; 702 break;
718 } 703 }
719# else 704# else
720 switch (action) 705 switch (action)
721 { 706 {
722 case IGNORE: 707 case IGNORE:
708 setgid (getgid ());
723 setuid (getuid ()); 709 setuid (getuid ());
724 setgid (getgid ());
725 /* FALLTHROUGH */ 710 /* FALLTHROUGH */
726 case SAVE: 711 case SAVE:
727 /* FALLTHROUGH */ 712 /* FALLTHROUGH */
728 case RESTORE: 713 case RESTORE:
729 break; 714 break;
730 } 715 }
731# endif 716# endif
732#endif 717#endif
733} 718}
734 719
735#ifdef UTMP_SUPPORT
736void
737rxvt_term::privileged_utmp (rxvt_privaction action)
738{
739 if (OPTION (Opt_utmpInhibit)
740 || !pty.name || !*pty.name)
741 return;
742
743 rxvt_privileges (RESTORE);
744
745 if (action == SAVE)
746 makeutent (pty.name, rs[Rs_display_name]);
747 else
748 cleanutent ();
749
750 rxvt_privileges (IGNORE);
751}
752#endif
753
754/*----------------------------------------------------------------------*/ 720/*----------------------------------------------------------------------*/
755/* 721/*
756 * window size/position calculcations for XSizeHint and other storage. 722 * window size/position calculcations for XSizeHint and other storage.
757 * if width/height are non-zero then override calculated width/height 723 * if width/height are non-zero then override calculated width/height
758 */ 724 */
759void 725void
760rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) 726rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight)
761{ 727{
762 short recalc_x, recalc_y; 728 short recalc_x, recalc_y;
763 int x, y, sb_w, mb_h, flags; 729 int x, y, sb_w, flags;
764 unsigned int w, h; 730 unsigned int w, h;
765 unsigned int max_width, max_height; 731 unsigned int max_width, max_height;
766 dDisp; 732 dDisp;
767 733
768 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 734 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
829 max_width = MAX_COLS * fwidth; 795 max_width = MAX_COLS * fwidth;
830 max_height = MAX_ROWS * fheight; 796 max_height = MAX_ROWS * fheight;
831 797
832 szHint.base_width = szHint.base_height = 2 * int_bwidth; 798 szHint.base_width = szHint.base_height = 2 * int_bwidth;
833 799
834 sb_w = mb_h = 0; 800 sb_w = 0;
835 window_vt_x = window_vt_y = int_bwidth; 801 window_vt_x = window_vt_y = int_bwidth;
836 802
837 if (scrollbar_visible ()) 803 if (scrollBar.state)
838 { 804 {
839 sb_w = scrollbar_TotalWidth (); 805 sb_w = scrollbar_TotalWidth ();
840 szHint.base_width += sb_w; 806 szHint.base_width += sb_w;
841 if (!OPTION (Opt_scrollBar_right)) 807 if (!OPTION (Opt_scrollBar_right))
842 window_vt_x += sb_w; 808 window_vt_x += sb_w;
843 } 809 }
844 810
845 if (menubar_visible ())
846 {
847 mb_h = menuBar_TotalHeight ();
848 szHint.base_height += mb_h;
849 window_vt_y += mb_h;
850 }
851
852 szHint.width_inc = fwidth; 811 szHint.width_inc = fwidth;
853 szHint.height_inc = fheight; 812 szHint.height_inc = fheight;
854 szHint.min_width = szHint.base_width + szHint.width_inc; 813 szHint.min_width = szHint.base_width + szHint.width_inc;
855 szHint.min_height = szHint.base_height + szHint.height_inc; 814 szHint.min_height = szHint.base_height + szHint.height_inc;
856 815
874 { 833 {
875 min_it (height, max_height); 834 min_it (height, max_height);
876 szHint.height = szHint.base_height + height; 835 szHint.height = szHint.base_height + height;
877 } 836 }
878 837
879 if (scrollbar_visible () && OPTION (Opt_scrollBar_right)) 838 if (scrollBar.state && OPTION (Opt_scrollBar_right))
880 window_sb_x = szHint.width - sb_w; 839 window_sb_x = szHint.width - sb_w;
881 840
882 if (recalc_x) 841 if (recalc_x)
883 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 842 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth;
884 if (recalc_y) 843 if (recalc_y)
898 * Called after a window size change. 857 * Called after a window size change.
899 */ 858 */
900void 859void
901rxvt_term::tt_winch () 860rxvt_term::tt_winch ()
902{ 861{
903 if (pty.pty < 0) 862 if (pty->pty < 0)
904 return; 863 return;
905 864
906 struct winsize ws; 865 struct winsize ws;
907 866
908 ws.ws_col = ncol; 867 ws.ws_col = ncol;
909 ws.ws_row = nrow; 868 ws.ws_row = nrow;
910 ws.ws_xpixel = width; 869 ws.ws_xpixel = width;
911 ws.ws_ypixel = height; 870 ws.ws_ypixel = height;
912 (void)ioctl (pty.pty, TIOCSWINSZ, &ws); 871 (void)ioctl (pty->pty, TIOCSWINSZ, &ws);
913 872
914#if 0 873#if 0
915 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly 874 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
916 if (cmd_pid) /* force through to the command */ 875 if (cmd_pid) /* force through to the command */
917 kill (-cmd_pid, SIGWINCH); 876 kill (-cmd_pid, SIGWINCH);
1239 1198
1240 fix_screen = ncol != prev_ncol || nrow != prev_nrow; 1199 fix_screen = ncol != prev_ncol || nrow != prev_nrow;
1241 1200
1242 if (fix_screen || newwidth != old_width || newheight != old_height) 1201 if (fix_screen || newwidth != old_width || newheight != old_height)
1243 { 1202 {
1244 if (scrollbar_visible ()) 1203 if (scrollBar.state)
1245 { 1204 {
1246 XMoveResizeWindow (disp, scrollBar.win, 1205 XMoveResizeWindow (disp, scrollBar.win,
1247 window_sb_x, 0, 1206 window_sb_x, 0,
1248 scrollbar_TotalWidth (), szHint.height); 1207 scrollbar_TotalWidth (), szHint.height);
1249 resize_scrollbar (); 1208 resize_scrollbar ();
1250 } 1209 }
1251
1252 if (menubar_visible ())
1253 XMoveResizeWindow (disp, menuBar.win,
1254 window_vt_x, 0,
1255 width, menuBar_TotalHeight ());
1256 1210
1257 XMoveResizeWindow (disp, vt, 1211 XMoveResizeWindow (disp, vt,
1258 window_vt_x, window_vt_y, 1212 window_vt_x, window_vt_y,
1259 width, height); 1213 width, height);
1260 1214
1444 XRectangle rect, status_rect, needed_rect; 1398 XRectangle rect, status_rect, needed_rect;
1445 unsigned long fg, bg; 1399 unsigned long fg, bg;
1446 const char *p; 1400 const char *p;
1447 char **s; 1401 char **s;
1448 XIMStyles *xim_styles; 1402 XIMStyles *xim_styles;
1403
1404 set_environ (envv);
1449 1405
1450 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1406 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1451 return false; 1407 return false;
1452 1408
1453 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1409 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1619 int i; 1575 int i;
1620 const char *p; 1576 const char *p;
1621 char **s; 1577 char **s;
1622 char buf[IMBUFSIZ]; 1578 char buf[IMBUFSIZ];
1623 1579
1624 SET_R (this); 1580 make_current ();
1625 1581
1626 im_destroy (); 1582 im_destroy ();
1627 1583
1628 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1584 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1629 if (Input_Context) 1585 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines