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.151 by root, Wed Dec 21 19:50:16 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
286 delete argv; 307 delete argv;
287 308
288#ifdef KEYSYM_RESOURCE 309#ifdef KEYSYM_RESOURCE
289 delete keyboard; 310 delete keyboard;
290#endif 311#endif
312}
313
314void
315rxvt_term::child_exit ()
316{
317 cmd_pid = 0;
318
319 if (!OPTION (Opt_hold))
320 destroy ();
291} 321}
292 322
293void 323void
294rxvt_term::destroy () 324rxvt_term::destroy ()
295{ 325{
460 490
461#if MENUBAR_MAX 491#if MENUBAR_MAX
462 menubar_read (rs[Rs_menu]); 492 menubar_read (rs[Rs_menu]);
463#endif 493#endif
464#ifdef HAVE_SCROLLBARS 494#ifdef HAVE_SCROLLBARS
465 if (options & Opt_scrollBar) 495 if (OPTION (Opt_scrollBar))
466 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 }
467#endif 527#endif
468 528
469 create_windows (argc, argv); 529 create_windows (argc, argv);
470 530
471 dDisp; 531 dDisp;
477#if 0 537#if 0
478 XSynchronize (disp, True); 538 XSynchronize (disp, True);
479#endif 539#endif
480 540
481#ifdef HAVE_SCROLLBARS 541#ifdef HAVE_SCROLLBARS
482 if (options & Opt_scrollBar) 542 if (OPTION (Opt_scrollBar))
483 resize_scrollbar (); /* create and map scrollbar */ 543 resize_scrollbar (); /* create and map scrollbar */
484#endif 544#endif
485#if (MENUBAR_MAX) 545#if (MENUBAR_MAX)
486 if (menubar_visible ()) 546 if (menubar_visible ())
487 XMapWindow (disp, menuBar.win); 547 XMapWindow (disp, menuBar.win);
488#endif 548#endif
489#ifdef TRANSPARENT 549#ifdef TRANSPARENT
490 if (options & Opt_transparent) 550 if (OPTION (Opt_transparent))
491 { 551 {
492 XSelectInput (disp, display->root, PropertyChangeMask); 552 XSelectInput (disp, display->root, PropertyChangeMask);
493 check_our_parents (); 553 check_our_parents ();
494 rootwin_ev.start (display, display->root); 554 rootwin_ev.start (display, display->root);
495 } 555 }
502 562
503 init_command (cmd_argv); 563 init_command (cmd_argv);
504 564
505 free (cmd_argv); 565 free (cmd_argv);
506 566
567 if (pty.pty >= 0)
507 pty_ev.start (pty.pty, EVENT_READ); 568 pty_ev.start (pty.pty, EVENT_READ);
508 569
509 check_ev.start (); 570 check_ev.start ();
571
572 HOOK_INVOKE ((this, HOOK_START, DT_END));
510 573
511 return true; 574 return true;
512} 575}
513 576
514static struct sig_handlers 577static struct sig_handlers
522 585
523 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) 586 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
524 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 587 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
525 if (pid == (*t)->cmd_pid) 588 if (pid == (*t)->cmd_pid)
526 { 589 {
527 (*t)->destroy (); 590 (*t)->child_exit ();
528 break; 591 break;
529 } 592 }
530 } 593 }
531 594
532 /* 595 /*
575 /* signal (SIGURG, SIG_DFL); */ 638 /* signal (SIGURG, SIG_DFL); */
576 639
577 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 640 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
578 // TODO: handle this with exceptions and tolerate the memory loss 641 // TODO: handle this with exceptions and tolerate the memory loss
579 XSetIOErrorHandler (rxvt_xioerror_handler); 642 XSetIOErrorHandler (rxvt_xioerror_handler);
643
644#ifdef USE_XGETDEFAULT
645 XrmInitialize ();
646#endif
580} 647}
581 648
582/* ------------------------------------------------------------------------- * 649/* ------------------------------------------------------------------------- *
583 * MEMORY ALLOCATION WRAPPERS * 650 * MEMORY ALLOCATION WRAPPERS *
584 * ------------------------------------------------------------------------- */ 651 * ------------------------------------------------------------------------- */
620 * ------------------------------------------------------------------------- */ 687 * ------------------------------------------------------------------------- */
621/* take care of suid/sgid super-user (root) privileges */ 688/* take care of suid/sgid super-user (root) privileges */
622void 689void
623rxvt_privileges (rxvt_privaction action) 690rxvt_privileges (rxvt_privaction action)
624{ 691{
625#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
626 static uid_t euid;
627 static gid_t egid;
628#endif
629
630#if ! defined(__CYGWIN32__) 692#if ! defined(__CYGWIN32__)
631# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 693# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
632 /* setreuid () is the poor man's setuid (), seteuid () */ 694 /* setreuid () is the poor man's setuid (), seteuid () */
633# define seteuid(a) setreuid(-1, (a)) 695# define seteuid(a) setreuid(-1, (a))
634# define setegid(a) setregid(-1, (a)) 696# define setegid(a) setregid(-1, (a))
644 */ 706 */
645 seteuid (getuid ()); 707 seteuid (getuid ());
646 setegid (getgid ()); 708 setegid (getgid ());
647 break; 709 break;
648 case SAVE: 710 case SAVE:
649 euid = geteuid (); 711 saved_euid = geteuid ();
650 egid = getegid (); 712 saved_egid = getegid ();
651 break; 713 break;
652 case RESTORE: 714 case RESTORE:
653 seteuid (euid); 715 seteuid (saved_euid);
654 setegid (egid); 716 setegid (saved_egid);
655 break; 717 break;
656 } 718 }
657# else 719# else
658 switch (action) 720 switch (action)
659 { 721 {
672 734
673#ifdef UTMP_SUPPORT 735#ifdef UTMP_SUPPORT
674void 736void
675rxvt_term::privileged_utmp (rxvt_privaction action) 737rxvt_term::privileged_utmp (rxvt_privaction action)
676{ 738{
677 if ((options & Opt_utmpInhibit) 739 if (OPTION (Opt_utmpInhibit)
678 || !pty.name || !*pty.name) 740 || !pty.name || !*pty.name)
679 return; 741 return;
680 742
681 rxvt_privileges (RESTORE); 743 rxvt_privileges (RESTORE);
682 744
774 836
775 if (scrollbar_visible ()) 837 if (scrollbar_visible ())
776 { 838 {
777 sb_w = scrollbar_TotalWidth (); 839 sb_w = scrollbar_TotalWidth ();
778 szHint.base_width += sb_w; 840 szHint.base_width += sb_w;
779 if (!(options & Opt_scrollBar_right)) 841 if (!OPTION (Opt_scrollBar_right))
780 window_vt_x += sb_w; 842 window_vt_x += sb_w;
781 } 843 }
782 844
783 if (menubar_visible ()) 845 if (menubar_visible ())
784 { 846 {
812 { 874 {
813 min_it (height, max_height); 875 min_it (height, max_height);
814 szHint.height = szHint.base_height + height; 876 szHint.height = szHint.base_height + height;
815 } 877 }
816 878
817 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 879 if (scrollbar_visible () && OPTION (Opt_scrollBar_right))
818 window_sb_x = szHint.width - sb_w; 880 window_sb_x = szHint.width - sb_w;
819 881
820 if (recalc_x) 882 if (recalc_x)
821 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 883 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth;
822 if (recalc_y) 884 if (recalc_y)
891 prop.height += lineSpace; 953 prop.height += lineSpace;
892 fs->set_prop (prop); 954 fs->set_prop (prop);
893 955
894 fwidth = prop.width; 956 fwidth = prop.width;
895 fheight = prop.height; 957 fheight = prop.height;
896 fbase = (*fs)[1]->ascent; 958 fbase = prop.ascent;
897 959
898 for (int style = 1; style < 4; style++) 960 for (int style = 1; style < 4; style++)
899 { 961 {
900#if ENABLE_STYLES 962#if ENABLE_STYLES
901 const char *res = rs[Rs_font + style]; 963 const char *res = rs[Rs_font + style];
935 return true; 997 return true;
936} 998}
937 999
938void rxvt_term::set_string_property (Atom prop, const char *str, int len) 1000void rxvt_term::set_string_property (Atom prop, const char *str, int len)
939{ 1001{
940 // TODO: SMART_WINDOW_TITLE
941 XChangeProperty (display->display, parent[0], 1002 XChangeProperty (display->display, parent[0],
942 prop, XA_STRING, 8, PropModeReplace, 1003 prop, XA_STRING, 8, PropModeReplace,
943 (const unsigned char *)str, len >= 0 ? len : strlen (str)); 1004 (const unsigned char *)str, len >= 0 ? len : strlen (str));
944} 1005}
945 1006
946void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) 1007void rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
947{ 1008{
948 // TODO: SMART_WINDOW_TITLE
949 wchar_t *ws = rxvt_mbstowcs (str, len); 1009 wchar_t *ws = rxvt_mbstowcs (str, len);
950 char *s = rxvt_wcstoutf8 (ws); 1010 char *s = rxvt_wcstoutf8 (ws);
951 1011
952 XChangeProperty (display->display, parent[0], 1012 XChangeProperty (display->display, parent[0],
953 prop, xa[XA_UTF8_STRING], 8, PropModeReplace, 1013 prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
994 i = atoi (color); 1054 i = atoi (color);
995 1055
996 if (i >= 8 && i <= 15) 1056 if (i >= 8 && i <= 15)
997 { /* bright colors */ 1057 { /* bright colors */
998 i -= 8; 1058 i -= 8;
999# ifndef NO_BRIGHTCOLOR
1000 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 1059 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1001 SET_PIXCOLOR (idx); 1060 SET_PIXCOLOR (idx);
1002 goto done; 1061 goto done;
1003# endif
1004 } 1062 }
1005 1063
1006 if (i >= 0 && i <= 7) 1064 if (i >= 0 && i <= 7)
1007 { /* normal colors */ 1065 { /* normal colors */
1008 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1066 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1192 } 1250 }
1193 1251
1194 if (menubar_visible ()) 1252 if (menubar_visible ())
1195 XMoveResizeWindow (disp, menuBar.win, 1253 XMoveResizeWindow (disp, menuBar.win,
1196 window_vt_x, 0, 1254 window_vt_x, 0,
1197 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1255 width, menuBar_TotalHeight ());
1198 1256
1199 XMoveResizeWindow (disp, vt, 1257 XMoveResizeWindow (disp, vt,
1200 window_vt_x, window_vt_y, 1258 window_vt_x, window_vt_y,
1201 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1259 width, height);
1202 1260
1203 scr_clear (); 1261 scr_clear ();
1204#ifdef XPM_BACKGROUND 1262#ifdef XPM_BACKGROUND
1205 resize_pixmap (); 1263 resize_pixmap ();
1206#endif 1264#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines