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.180 by root, Mon Jan 16 15:00:20 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
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
529 create_windows (argc, argv); 514 create_windows (argc, argv);
530 515
531 dDisp; 516 dDisp;
532 517
533 init_xlocale (); 518 init_xlocale ();
534 519
535 scr_reset (); /* initialize screen */ 520 scr_reset (); // initialize screen
536 521
537#if 0 522#if 0
538 XSynchronize (disp, True); 523 XSynchronize (disp, True);
539#endif 524#endif
540 525
541#ifdef HAVE_SCROLLBARS 526#ifdef HAVE_SCROLLBARS
542 if (OPTION (Opt_scrollBar)) 527 if (OPTION (Opt_scrollBar))
543 resize_scrollbar (); /* create and map scrollbar */ 528 resize_scrollbar (); /* create and map scrollbar */
544#endif
545#if (MENUBAR_MAX)
546 if (menubar_visible ())
547 XMapWindow (disp, menuBar.win);
548#endif 529#endif
549#ifdef TRANSPARENT 530#ifdef TRANSPARENT
550 if (OPTION (Opt_transparent)) 531 if (OPTION (Opt_transparent))
551 { 532 {
552 XSelectInput (disp, display->root, PropertyChangeMask); 533 XSelectInput (disp, display->root, PropertyChangeMask);
612 sw_int (this, &sig_handlers::sig_term) 593 sw_int (this, &sig_handlers::sig_term)
613 { 594 {
614 } 595 }
615} sig_handlers; 596} sig_handlers;
616 597
598char **rxvt_environ; // startup environment
599
617void 600void
618rxvt_init () 601rxvt_init ()
619{ 602{
603 rxvt_environ = environ;
604
620 /* 605 /*
621 * Save and then give up any super-user privileges 606 * Save and then give up any super-user privileges
622 * If we need privileges in any area then we must specifically request it. 607 * If we need privileges in any area then we must specifically request it.
623 * We should only need to be root in these cases: 608 * We should only need to be root in these cases:
624 * 1. write utmp entries on some systems 609 * 1. write utmp entries on some systems
639 624
640 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 625 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
641 // TODO: handle this with exceptions and tolerate the memory loss 626 // TODO: handle this with exceptions and tolerate the memory loss
642 XSetIOErrorHandler (rxvt_xioerror_handler); 627 XSetIOErrorHandler (rxvt_xioerror_handler);
643 628
644#ifdef USE_XGETDEFAULT
645 XrmInitialize (); 629 XrmInitialize ();
646#endif
647} 630}
648 631
649/* ------------------------------------------------------------------------- * 632/* ------------------------------------------------------------------------- *
650 * MEMORY ALLOCATION WRAPPERS * 633 * MEMORY ALLOCATION WRAPPERS *
651 * ------------------------------------------------------------------------- */ 634 * ------------------------------------------------------------------------- */
702 case IGNORE: 685 case IGNORE:
703 /* 686 /*
704 * change effective uid/gid - not real uid/gid - so we can switch 687 * change effective uid/gid - not real uid/gid - so we can switch
705 * back to root later, as required 688 * back to root later, as required
706 */ 689 */
690 setegid (getgid ());
707 seteuid (getuid ()); 691 seteuid (getuid ());
708 setegid (getgid ());
709 break; 692 break;
710 case SAVE: 693 case SAVE:
694 saved_egid = getegid ();
711 saved_euid = geteuid (); 695 saved_euid = geteuid ();
712 saved_egid = getegid ();
713 break; 696 break;
714 case RESTORE: 697 case RESTORE:
698 setegid (saved_egid);
715 seteuid (saved_euid); 699 seteuid (saved_euid);
716 setegid (saved_egid);
717 break; 700 break;
718 } 701 }
719# else 702# else
720 switch (action) 703 switch (action)
721 { 704 {
722 case IGNORE: 705 case IGNORE:
706 setgid (getgid ());
723 setuid (getuid ()); 707 setuid (getuid ());
724 setgid (getgid ());
725 /* FALLTHROUGH */ 708 /* FALLTHROUGH */
726 case SAVE: 709 case SAVE:
727 /* FALLTHROUGH */ 710 /* FALLTHROUGH */
728 case RESTORE: 711 case RESTORE:
729 break; 712 break;
758 */ 741 */
759void 742void
760rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight) 743rxvt_term::window_calc (unsigned int newwidth, unsigned int newheight)
761{ 744{
762 short recalc_x, recalc_y; 745 short recalc_x, recalc_y;
763 int x, y, sb_w, mb_h, flags; 746 int x, y, sb_w, flags;
764 unsigned int w, h; 747 unsigned int w, h;
765 unsigned int max_width, max_height; 748 unsigned int max_width, max_height;
766 dDisp; 749 dDisp;
767 750
768 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d", 751 D_SIZE ((stderr, "< Cols/Rows: %3d x %3d ; Width/Height: %4d x %4d",
829 max_width = MAX_COLS * fwidth; 812 max_width = MAX_COLS * fwidth;
830 max_height = MAX_ROWS * fheight; 813 max_height = MAX_ROWS * fheight;
831 814
832 szHint.base_width = szHint.base_height = 2 * int_bwidth; 815 szHint.base_width = szHint.base_height = 2 * int_bwidth;
833 816
834 sb_w = mb_h = 0; 817 sb_w = 0;
835 window_vt_x = window_vt_y = int_bwidth; 818 window_vt_x = window_vt_y = int_bwidth;
836 819
837 if (scrollbar_visible ()) 820 if (scrollBar.state)
838 { 821 {
839 sb_w = scrollbar_TotalWidth (); 822 sb_w = scrollbar_TotalWidth ();
840 szHint.base_width += sb_w; 823 szHint.base_width += sb_w;
841 if (!OPTION (Opt_scrollBar_right)) 824 if (!OPTION (Opt_scrollBar_right))
842 window_vt_x += sb_w; 825 window_vt_x += sb_w;
843 } 826 }
844 827
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; 828 szHint.width_inc = fwidth;
853 szHint.height_inc = fheight; 829 szHint.height_inc = fheight;
854 szHint.min_width = szHint.base_width + szHint.width_inc; 830 szHint.min_width = szHint.base_width + szHint.width_inc;
855 szHint.min_height = szHint.base_height + szHint.height_inc; 831 szHint.min_height = szHint.base_height + szHint.height_inc;
856 832
874 { 850 {
875 min_it (height, max_height); 851 min_it (height, max_height);
876 szHint.height = szHint.base_height + height; 852 szHint.height = szHint.base_height + height;
877 } 853 }
878 854
879 if (scrollbar_visible () && OPTION (Opt_scrollBar_right)) 855 if (scrollBar.state && OPTION (Opt_scrollBar_right))
880 window_sb_x = szHint.width - sb_w; 856 window_sb_x = szHint.width - sb_w;
881 857
882 if (recalc_x) 858 if (recalc_x)
883 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 859 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth;
884 if (recalc_y) 860 if (recalc_y)
1239 1215
1240 fix_screen = ncol != prev_ncol || nrow != prev_nrow; 1216 fix_screen = ncol != prev_ncol || nrow != prev_nrow;
1241 1217
1242 if (fix_screen || newwidth != old_width || newheight != old_height) 1218 if (fix_screen || newwidth != old_width || newheight != old_height)
1243 { 1219 {
1244 if (scrollbar_visible ()) 1220 if (scrollBar.state)
1245 { 1221 {
1246 XMoveResizeWindow (disp, scrollBar.win, 1222 XMoveResizeWindow (disp, scrollBar.win,
1247 window_sb_x, 0, 1223 window_sb_x, 0,
1248 scrollbar_TotalWidth (), szHint.height); 1224 scrollbar_TotalWidth (), szHint.height);
1249 resize_scrollbar (); 1225 resize_scrollbar ();
1250 } 1226 }
1251
1252 if (menubar_visible ())
1253 XMoveResizeWindow (disp, menuBar.win,
1254 window_vt_x, 0,
1255 width, menuBar_TotalHeight ());
1256 1227
1257 XMoveResizeWindow (disp, vt, 1228 XMoveResizeWindow (disp, vt,
1258 window_vt_x, window_vt_y, 1229 window_vt_x, window_vt_y,
1259 width, height); 1230 width, height);
1260 1231
1444 XRectangle rect, status_rect, needed_rect; 1415 XRectangle rect, status_rect, needed_rect;
1445 unsigned long fg, bg; 1416 unsigned long fg, bg;
1446 const char *p; 1417 const char *p;
1447 char **s; 1418 char **s;
1448 XIMStyles *xim_styles; 1419 XIMStyles *xim_styles;
1420
1421 set_environ (envv);
1449 1422
1450 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1423 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1451 return false; 1424 return false;
1452 1425
1453 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1426 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1619 int i; 1592 int i;
1620 const char *p; 1593 const char *p;
1621 char **s; 1594 char **s;
1622 char buf[IMBUFSIZ]; 1595 char buf[IMBUFSIZ];
1623 1596
1624 SET_R (this); 1597 make_current ();
1625 1598
1626 im_destroy (); 1599 im_destroy ();
1627 1600
1628 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1601 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1629 if (Input_Context) 1602 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines