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.153 by root, Tue Dec 27 12:23:37 2005 UTC vs.
Revision 1.167 by root, Sun Jan 8 08:43:11 2006 UTC

11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA> 11 * Copyright (c) 1997 mj olesen <olesen@me.QueensU.CA>
12 * - extensive modifications 12 * - extensive modifications
13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 13 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 14 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
15 * - extensive modifications 15 * - extensive modifications
16 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 16 * Copyright (c) 2003-2006 Marc Lehmann <pcg@goof.com>
17 * 17 *
18 * This program is free software; you can redistribute it and/or modify 18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by 19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or 20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version. 21 * (at your option) any later version.
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *---------------------------------------------------------------------*/ 31 *---------------------------------------------------------------------*/
32 32
33#include "../config.h" /* NECESSARY */ 33#include "../config.h" /* NECESSARY */
34#include "rxvt.h" /* NECESSARY */ 34#include "rxvt.h" /* NECESSARY */
35#include "keyboard.h"
36#include "rxvtperl.h"
35 37
36#include <limits> 38#include <limits>
37 39
38#include <csignal> 40#include <csignal>
39#include <cstring> 41#include <cstring>
44 46
45#ifdef HAVE_TERMIOS_H 47#ifdef HAVE_TERMIOS_H
46# include <termios.h> 48# include <termios.h>
47#endif 49#endif
48 50
49#ifdef KEYSYM_RESOURCE 51#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
50# include "keyboard.h" 52static uid_t saved_euid;
53static gid_t saved_egid;
51#endif 54#endif
52 55
53vector<rxvt_term *> rxvt_term::termlist; 56vector<rxvt_term *> rxvt_term::termlist;
54 57
55static char curlocale[128]; 58static char curlocale[128], savelocale[128];
56 59
57bool 60bool
58rxvt_set_locale (const char *locale) 61rxvt_set_locale (const char *locale)
59{ 62{
60 if (!locale || !strncmp (locale, curlocale, 128)) 63 if (!locale || !strncmp (locale, curlocale, 128))
61 return false; 64 return false;
62 65
63 strncpy (curlocale, locale, 128); 66 strncpy (curlocale, locale, 128);
64 setlocale (LC_CTYPE, curlocale); 67 setlocale (LC_CTYPE, curlocale);
65 return true; 68 return true;
69}
70
71bool
72rxvt_push_locale (const char *locale)
73{
74 strcpy (savelocale, curlocale);
75 rxvt_set_locale (locale);
76}
77
78void
79rxvt_pop_locale ()
80{
81 rxvt_set_locale (savelocale);
66} 82}
67 83
68#if ENABLE_COMBINING 84#if ENABLE_COMBINING
69class rxvt_composite_vec rxvt_composite; 85class rxvt_composite_vec rxvt_composite;
70 86
195 pty.put (); 211 pty.put ();
196} 212}
197 213
198rxvt_term::~rxvt_term () 214rxvt_term::~rxvt_term ()
199{ 215{
216 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
217
200 termlist.erase (find (termlist.begin (), termlist.end(), this)); 218 termlist.erase (find (termlist.begin (), termlist.end(), this));
201 219
202 emergency_cleanup (); 220 emergency_cleanup ();
203 221
204#if ENABLE_STYLES 222#if ENABLE_STYLES
261 279
262 delete pix_colors_focused; 280 delete pix_colors_focused;
263#if OFF_FOCUS_FADING 281#if OFF_FOCUS_FADING
264 delete pix_colors_unfocused; 282 delete pix_colors_unfocused;
265#endif 283#endif
284#if USE_XGETDEFAULT
285 XrmDestroyDatabase (xrmdatabase);
286#endif
266 287
267 displays.put (display); 288 displays.put (display);
268 289
269 scr_release (); 290 scr_release ();
270 291
293void 314void
294rxvt_term::child_exit () 315rxvt_term::child_exit ()
295{ 316{
296 cmd_pid = 0; 317 cmd_pid = 0;
297 318
298 if (!(options & Opt_hold)) 319 if (!OPTION (Opt_hold))
299 destroy (); 320 destroy ();
300} 321}
301 322
302void 323void
303rxvt_term::destroy () 324rxvt_term::destroy ()
469 490
470#if MENUBAR_MAX 491#if MENUBAR_MAX
471 menubar_read (rs[Rs_menu]); 492 menubar_read (rs[Rs_menu]);
472#endif 493#endif
473#ifdef HAVE_SCROLLBARS 494#ifdef HAVE_SCROLLBARS
474 if (options & Opt_scrollBar) 495 if (OPTION (Opt_scrollBar))
475 scrollBar.setIdle (); /* set existence for size calculations */ 496 scrollBar.setIdle (); /* set existence for size calculations */
497#endif
498
499#if ENABLE_PERL
500 if (!rs[Rs_perl_ext_1])
501 rs[Rs_perl_ext_1] = "default";
502
503 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
504 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
505 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
506 {
507 bool tainted = false;
508
509#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
510 // ignore some perl-related arguments if some bozo installed us set[ug]id
511 if (getuid () != saved_euid || getgid () != saved_egid)
512 {
513 tainted = true;
514
515 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
516 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
517 {
518 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
519 rs[Rs_perl_lib] = 0;
520 rs[Rs_perl_eval] = "our $tainted = 1";
521 }
522 }
523#endif
524 rxvt_perl.init (tainted);
525 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
526 }
476#endif 527#endif
477 528
478 create_windows (argc, argv); 529 create_windows (argc, argv);
479 530
480 dDisp; 531 dDisp;
486#if 0 537#if 0
487 XSynchronize (disp, True); 538 XSynchronize (disp, True);
488#endif 539#endif
489 540
490#ifdef HAVE_SCROLLBARS 541#ifdef HAVE_SCROLLBARS
491 if (options & Opt_scrollBar) 542 if (OPTION (Opt_scrollBar))
492 resize_scrollbar (); /* create and map scrollbar */ 543 resize_scrollbar (); /* create and map scrollbar */
493#endif 544#endif
494#if (MENUBAR_MAX) 545#if (MENUBAR_MAX)
495 if (menubar_visible ()) 546 if (menubar_visible ())
496 XMapWindow (disp, menuBar.win); 547 XMapWindow (disp, menuBar.win);
497#endif 548#endif
498#ifdef TRANSPARENT 549#ifdef TRANSPARENT
499 if (options & Opt_transparent) 550 if (OPTION (Opt_transparent))
500 { 551 {
501 XSelectInput (disp, display->root, PropertyChangeMask); 552 XSelectInput (disp, display->root, PropertyChangeMask);
502 check_our_parents (); 553 check_our_parents ();
503 rootwin_ev.start (display, display->root); 554 rootwin_ev.start (display, display->root);
504 } 555 }
511 562
512 init_command (cmd_argv); 563 init_command (cmd_argv);
513 564
514 free (cmd_argv); 565 free (cmd_argv);
515 566
567 if (pty.pty >= 0)
516 pty_ev.start (pty.pty, EVENT_READ); 568 pty_ev.start (pty.pty, EVENT_READ);
517 569
518 check_ev.start (); 570 check_ev.start ();
571
572 HOOK_INVOKE ((this, HOOK_START, DT_END));
519 573
520 return true; 574 return true;
521} 575}
522 576
523static struct sig_handlers 577static struct sig_handlers
584 /* signal (SIGURG, SIG_DFL); */ 638 /* signal (SIGURG, SIG_DFL); */
585 639
586 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 640 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
587 // TODO: handle this with exceptions and tolerate the memory loss 641 // TODO: handle this with exceptions and tolerate the memory loss
588 XSetIOErrorHandler (rxvt_xioerror_handler); 642 XSetIOErrorHandler (rxvt_xioerror_handler);
643
644#ifdef USE_XGETDEFAULT
645 XrmInitialize ();
646#endif
589} 647}
590 648
591/* ------------------------------------------------------------------------- * 649/* ------------------------------------------------------------------------- *
592 * MEMORY ALLOCATION WRAPPERS * 650 * MEMORY ALLOCATION WRAPPERS *
593 * ------------------------------------------------------------------------- */ 651 * ------------------------------------------------------------------------- */
629 * ------------------------------------------------------------------------- */ 687 * ------------------------------------------------------------------------- */
630/* take care of suid/sgid super-user (root) privileges */ 688/* take care of suid/sgid super-user (root) privileges */
631void 689void
632rxvt_privileges (rxvt_privaction action) 690rxvt_privileges (rxvt_privaction action)
633{ 691{
634#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
635 static uid_t euid;
636 static gid_t egid;
637#endif
638
639#if ! defined(__CYGWIN32__) 692#if ! defined(__CYGWIN32__)
640# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 693# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
641 /* setreuid () is the poor man's setuid (), seteuid () */ 694 /* setreuid () is the poor man's setuid (), seteuid () */
642# define seteuid(a) setreuid(-1, (a)) 695# define seteuid(a) setreuid(-1, (a))
643# define setegid(a) setregid(-1, (a)) 696# define setegid(a) setregid(-1, (a))
653 */ 706 */
654 seteuid (getuid ()); 707 seteuid (getuid ());
655 setegid (getgid ()); 708 setegid (getgid ());
656 break; 709 break;
657 case SAVE: 710 case SAVE:
658 euid = geteuid (); 711 saved_euid = geteuid ();
659 egid = getegid (); 712 saved_egid = getegid ();
660 break; 713 break;
661 case RESTORE: 714 case RESTORE:
662 seteuid (euid); 715 seteuid (saved_euid);
663 setegid (egid); 716 setegid (saved_egid);
664 break; 717 break;
665 } 718 }
666# else 719# else
667 switch (action) 720 switch (action)
668 { 721 {
681 734
682#ifdef UTMP_SUPPORT 735#ifdef UTMP_SUPPORT
683void 736void
684rxvt_term::privileged_utmp (rxvt_privaction action) 737rxvt_term::privileged_utmp (rxvt_privaction action)
685{ 738{
686 if ((options & Opt_utmpInhibit) 739 if (OPTION (Opt_utmpInhibit)
687 || !pty.name || !*pty.name) 740 || !pty.name || !*pty.name)
688 return; 741 return;
689 742
690 rxvt_privileges (RESTORE); 743 rxvt_privileges (RESTORE);
691 744
783 836
784 if (scrollbar_visible ()) 837 if (scrollbar_visible ())
785 { 838 {
786 sb_w = scrollbar_TotalWidth (); 839 sb_w = scrollbar_TotalWidth ();
787 szHint.base_width += sb_w; 840 szHint.base_width += sb_w;
788 if (!(options & Opt_scrollBar_right)) 841 if (!OPTION (Opt_scrollBar_right))
789 window_vt_x += sb_w; 842 window_vt_x += sb_w;
790 } 843 }
791 844
792 if (menubar_visible ()) 845 if (menubar_visible ())
793 { 846 {
821 { 874 {
822 min_it (height, max_height); 875 min_it (height, max_height);
823 szHint.height = szHint.base_height + height; 876 szHint.height = szHint.base_height + height;
824 } 877 }
825 878
826 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 879 if (scrollbar_visible () && OPTION (Opt_scrollBar_right))
827 window_sb_x = szHint.width - sb_w; 880 window_sb_x = szHint.width - sb_w;
828 881
829 if (recalc_x) 882 if (recalc_x)
830 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 883 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth;
831 if (recalc_y) 884 if (recalc_y)
900 prop.height += lineSpace; 953 prop.height += lineSpace;
901 fs->set_prop (prop); 954 fs->set_prop (prop);
902 955
903 fwidth = prop.width; 956 fwidth = prop.width;
904 fheight = prop.height; 957 fheight = prop.height;
905 fbase = (*fs)[1]->ascent; 958 fbase = prop.ascent;
906 959
907 for (int style = 1; style < 4; style++) 960 for (int style = 1; style < 4; style++)
908 { 961 {
909#if ENABLE_STYLES 962#if ENABLE_STYLES
910 const char *res = rs[Rs_font + style]; 963 const char *res = rs[Rs_font + style];
1001 i = atoi (color); 1054 i = atoi (color);
1002 1055
1003 if (i >= 8 && i <= 15) 1056 if (i >= 8 && i <= 15)
1004 { /* bright colors */ 1057 { /* bright colors */
1005 i -= 8; 1058 i -= 8;
1006# ifndef NO_BRIGHTCOLOR
1007 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 1059 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1008 SET_PIXCOLOR (idx); 1060 SET_PIXCOLOR (idx);
1009 goto done; 1061 goto done;
1010# endif
1011 } 1062 }
1012 1063
1013 if (i >= 0 && i <= 7) 1064 if (i >= 0 && i <= 7)
1014 { /* normal colors */ 1065 { /* normal colors */
1015 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1066 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1199 } 1250 }
1200 1251
1201 if (menubar_visible ()) 1252 if (menubar_visible ())
1202 XMoveResizeWindow (disp, menuBar.win, 1253 XMoveResizeWindow (disp, menuBar.win,
1203 window_vt_x, 0, 1254 window_vt_x, 0,
1204 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1255 width, menuBar_TotalHeight ());
1205 1256
1206 XMoveResizeWindow (disp, vt, 1257 XMoveResizeWindow (disp, vt,
1207 window_vt_x, window_vt_y, 1258 window_vt_x, window_vt_y,
1208 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1259 width, height);
1209 1260
1210 scr_clear (); 1261 scr_clear ();
1211#ifdef XPM_BACKGROUND 1262#ifdef XPM_BACKGROUND
1212 resize_pixmap (); 1263 resize_pixmap ();
1213#endif 1264#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines