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.179 by root, Mon Jan 16 08:48:09 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
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}
52 65
53vector<rxvt_term *> rxvt_term::termlist; 66vector<rxvt_term *> rxvt_term::termlist;
54 67
55static char curlocale[128]; 68static char curlocale[128], savelocale[128];
56 69
57bool 70bool
58rxvt_set_locale (const char *locale) 71rxvt_set_locale (const char *locale)
59{ 72{
60 if (!locale || !strncmp (locale, curlocale, 128)) 73 if (!locale || !strncmp (locale, curlocale, 128))
61 return false; 74 return false;
62 75
63 strncpy (curlocale, locale, 128); 76 strncpy (curlocale, locale, 128);
64 setlocale (LC_CTYPE, curlocale); 77 setlocale (LC_CTYPE, curlocale);
65 return true; 78 return true;
79}
80
81void
82rxvt_push_locale (const char *locale)
83{
84 strcpy (savelocale, curlocale);
85 rxvt_set_locale (locale);
86}
87
88void
89rxvt_pop_locale ()
90{
91 rxvt_set_locale (savelocale);
66} 92}
67 93
68#if ENABLE_COMBINING 94#if ENABLE_COMBINING
69class rxvt_composite_vec rxvt_composite; 95class rxvt_composite_vec rxvt_composite;
70 96
195 pty.put (); 221 pty.put ();
196} 222}
197 223
198rxvt_term::~rxvt_term () 224rxvt_term::~rxvt_term ()
199{ 225{
226 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
227
200 termlist.erase (find (termlist.begin (), termlist.end(), this)); 228 termlist.erase (find (termlist.begin (), termlist.end(), this));
201 229
202 emergency_cleanup (); 230 emergency_cleanup ();
203 231
204#if ENABLE_STYLES 232#if ENABLE_STYLES
256 if (parent[0]) 284 if (parent[0])
257 XDestroyWindow (disp, parent[0]); 285 XDestroyWindow (disp, parent[0]);
258 } 286 }
259 287
260 // TODO: free pixcolours, colours should become part of rxvt_display 288 // TODO: free pixcolours, colours should become part of rxvt_display
261
262 delete pix_colors_focused; 289 delete pix_colors_focused;
263#if OFF_FOCUS_FADING 290#if OFF_FOCUS_FADING
264 delete pix_colors_unfocused; 291 delete pix_colors_unfocused;
265#endif 292#endif
266 293
293void 320void
294rxvt_term::child_exit () 321rxvt_term::child_exit ()
295{ 322{
296 cmd_pid = 0; 323 cmd_pid = 0;
297 324
298 if (!(options & Opt_hold)) 325 if (!OPTION (Opt_hold))
299 destroy (); 326 destroy ();
300} 327}
301 328
302void 329void
303rxvt_term::destroy () 330rxvt_term::destroy ()
350} 377}
351 378
352void 379void
353rxvt_term::destroy_cb (time_watcher &w) 380rxvt_term::destroy_cb (time_watcher &w)
354{ 381{
355 SET_R (this); 382 make_current ();
356 383
357 delete this; 384 delete this;
358} 385}
359 386
360/*----------------------------------------------------------------------*/ 387/*----------------------------------------------------------------------*/
451/*----------------------------------------------------------------------*/ 478/*----------------------------------------------------------------------*/
452bool 479bool
453rxvt_term::init (int argc, const char *const *argv) 480rxvt_term::init (int argc, const char *const *argv)
454{ 481{
455 SET_R (this); 482 SET_R (this);
456
457 set_locale (""); 483 set_locale ("");
484 set_environ (envv); // few things in X do not call setlocale :(
458 485
459 if (!init_vars ()) 486 if (!init_vars ())
460 return false; 487 return false;
461 488
462 init_secondary (); 489 init_secondary ();
469 496
470#if MENUBAR_MAX 497#if MENUBAR_MAX
471 menubar_read (rs[Rs_menu]); 498 menubar_read (rs[Rs_menu]);
472#endif 499#endif
473#ifdef HAVE_SCROLLBARS 500#ifdef HAVE_SCROLLBARS
474 if (options & Opt_scrollBar) 501 if (OPTION (Opt_scrollBar))
475 scrollBar.setIdle (); /* set existence for size calculations */ 502 scrollBar.setIdle (); /* set existence for size calculations */
476#endif 503#endif
477 504
505#if ENABLE_PERL
506 if (!rs[Rs_perl_ext_1])
507 rs[Rs_perl_ext_1] = "default";
508
509 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
510 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
511 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
512 {
513#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
514 // ignore some perl-related arguments if some bozo installed us set[ug]id
515 if (rxvt_tainted ())
516 {
517 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
518 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
519 {
520 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
521 rs[Rs_perl_lib] = 0;
522 rs[Rs_perl_eval] = 0;
523 }
524 }
525#endif
526 rxvt_perl.init (this);
527 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
528 }
529#endif
530
478 create_windows (argc, argv); 531 create_windows (argc, argv);
479 532
480 dDisp; 533 dDisp;
481 534
482 init_xlocale (); 535 init_xlocale ();
483 536
484 scr_reset (); /* initialize screen */ 537 scr_reset (); // initialize screen
485 538
486#if 0 539#if 0
487 XSynchronize (disp, True); 540 XSynchronize (disp, True);
488#endif 541#endif
489 542
490#ifdef HAVE_SCROLLBARS 543#ifdef HAVE_SCROLLBARS
491 if (options & Opt_scrollBar) 544 if (OPTION (Opt_scrollBar))
492 resize_scrollbar (); /* create and map scrollbar */ 545 resize_scrollbar (); /* create and map scrollbar */
493#endif 546#endif
494#if (MENUBAR_MAX) 547#if (MENUBAR_MAX)
495 if (menubar_visible ()) 548 if (menubar_visible ())
496 XMapWindow (disp, menuBar.win); 549 XMapWindow (disp, menuBar.win);
497#endif 550#endif
498#ifdef TRANSPARENT 551#ifdef TRANSPARENT
499 if (options & Opt_transparent) 552 if (OPTION (Opt_transparent))
500 { 553 {
501 XSelectInput (disp, display->root, PropertyChangeMask); 554 XSelectInput (disp, display->root, PropertyChangeMask);
502 check_our_parents (); 555 check_our_parents ();
503 rootwin_ev.start (display, display->root); 556 rootwin_ev.start (display, display->root);
504 } 557 }
511 564
512 init_command (cmd_argv); 565 init_command (cmd_argv);
513 566
514 free (cmd_argv); 567 free (cmd_argv);
515 568
569 if (pty.pty >= 0)
516 pty_ev.start (pty.pty, EVENT_READ); 570 pty_ev.start (pty.pty, EVENT_READ);
517 571
518 check_ev.start (); 572 check_ev.start ();
573
574 HOOK_INVOKE ((this, HOOK_START, DT_END));
519 575
520 return true; 576 return true;
521} 577}
522 578
523static struct sig_handlers 579static struct sig_handlers
558 sw_int (this, &sig_handlers::sig_term) 614 sw_int (this, &sig_handlers::sig_term)
559 { 615 {
560 } 616 }
561} sig_handlers; 617} sig_handlers;
562 618
619char **rxvt_environ; // startup environment
620
563void 621void
564rxvt_init () 622rxvt_init ()
565{ 623{
624 rxvt_environ = environ;
625
566 /* 626 /*
567 * Save and then give up any super-user privileges 627 * Save and then give up any super-user privileges
568 * If we need privileges in any area then we must specifically request it. 628 * If we need privileges in any area then we must specifically request it.
569 * We should only need to be root in these cases: 629 * We should only need to be root in these cases:
570 * 1. write utmp entries on some systems 630 * 1. write utmp entries on some systems
584 /* signal (SIGURG, SIG_DFL); */ 644 /* signal (SIGURG, SIG_DFL); */
585 645
586 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 646 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
587 // TODO: handle this with exceptions and tolerate the memory loss 647 // TODO: handle this with exceptions and tolerate the memory loss
588 XSetIOErrorHandler (rxvt_xioerror_handler); 648 XSetIOErrorHandler (rxvt_xioerror_handler);
649
650 XrmInitialize ();
589} 651}
590 652
591/* ------------------------------------------------------------------------- * 653/* ------------------------------------------------------------------------- *
592 * MEMORY ALLOCATION WRAPPERS * 654 * MEMORY ALLOCATION WRAPPERS *
593 * ------------------------------------------------------------------------- */ 655 * ------------------------------------------------------------------------- */
629 * ------------------------------------------------------------------------- */ 691 * ------------------------------------------------------------------------- */
630/* take care of suid/sgid super-user (root) privileges */ 692/* take care of suid/sgid super-user (root) privileges */
631void 693void
632rxvt_privileges (rxvt_privaction action) 694rxvt_privileges (rxvt_privaction action)
633{ 695{
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__) 696#if ! defined(__CYGWIN32__)
640# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 697# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
641 /* setreuid () is the poor man's setuid (), seteuid () */ 698 /* setreuid () is the poor man's setuid (), seteuid () */
642# define seteuid(a) setreuid(-1, (a)) 699# define seteuid(a) setreuid(-1, (a))
643# define setegid(a) setregid(-1, (a)) 700# define setegid(a) setregid(-1, (a))
649 case IGNORE: 706 case IGNORE:
650 /* 707 /*
651 * change effective uid/gid - not real uid/gid - so we can switch 708 * change effective uid/gid - not real uid/gid - so we can switch
652 * back to root later, as required 709 * back to root later, as required
653 */ 710 */
711 setegid (getgid ());
654 seteuid (getuid ()); 712 seteuid (getuid ());
655 setegid (getgid ());
656 break; 713 break;
657 case SAVE: 714 case SAVE:
658 euid = geteuid ();
659 egid = getegid (); 715 saved_egid = getegid ();
716 saved_euid = geteuid ();
660 break; 717 break;
661 case RESTORE: 718 case RESTORE:
662 seteuid (euid);
663 setegid (egid); 719 setegid (saved_egid);
720 seteuid (saved_euid);
664 break; 721 break;
665 } 722 }
666# else 723# else
667 switch (action) 724 switch (action)
668 { 725 {
669 case IGNORE: 726 case IGNORE:
727 setgid (getgid ());
670 setuid (getuid ()); 728 setuid (getuid ());
671 setgid (getgid ());
672 /* FALLTHROUGH */ 729 /* FALLTHROUGH */
673 case SAVE: 730 case SAVE:
674 /* FALLTHROUGH */ 731 /* FALLTHROUGH */
675 case RESTORE: 732 case RESTORE:
676 break; 733 break;
681 738
682#ifdef UTMP_SUPPORT 739#ifdef UTMP_SUPPORT
683void 740void
684rxvt_term::privileged_utmp (rxvt_privaction action) 741rxvt_term::privileged_utmp (rxvt_privaction action)
685{ 742{
686 if ((options & Opt_utmpInhibit) 743 if (OPTION (Opt_utmpInhibit)
687 || !pty.name || !*pty.name) 744 || !pty.name || !*pty.name)
688 return; 745 return;
689 746
690 rxvt_privileges (RESTORE); 747 rxvt_privileges (RESTORE);
691 748
783 840
784 if (scrollbar_visible ()) 841 if (scrollbar_visible ())
785 { 842 {
786 sb_w = scrollbar_TotalWidth (); 843 sb_w = scrollbar_TotalWidth ();
787 szHint.base_width += sb_w; 844 szHint.base_width += sb_w;
788 if (!(options & Opt_scrollBar_right)) 845 if (!OPTION (Opt_scrollBar_right))
789 window_vt_x += sb_w; 846 window_vt_x += sb_w;
790 } 847 }
791 848
792 if (menubar_visible ()) 849 if (menubar_visible ())
793 { 850 {
821 { 878 {
822 min_it (height, max_height); 879 min_it (height, max_height);
823 szHint.height = szHint.base_height + height; 880 szHint.height = szHint.base_height + height;
824 } 881 }
825 882
826 if (scrollbar_visible () && (options & Opt_scrollBar_right)) 883 if (scrollbar_visible () && OPTION (Opt_scrollBar_right))
827 window_sb_x = szHint.width - sb_w; 884 window_sb_x = szHint.width - sb_w;
828 885
829 if (recalc_x) 886 if (recalc_x)
830 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth; 887 szHint.x += DisplayWidth (disp, display->screen) - szHint.width - 2 * ext_bwidth;
831 if (recalc_y) 888 if (recalc_y)
900 prop.height += lineSpace; 957 prop.height += lineSpace;
901 fs->set_prop (prop); 958 fs->set_prop (prop);
902 959
903 fwidth = prop.width; 960 fwidth = prop.width;
904 fheight = prop.height; 961 fheight = prop.height;
905 fbase = (*fs)[1]->ascent; 962 fbase = prop.ascent;
906 963
907 for (int style = 1; style < 4; style++) 964 for (int style = 1; style < 4; style++)
908 { 965 {
909#if ENABLE_STYLES 966#if ENABLE_STYLES
910 const char *res = rs[Rs_font + style]; 967 const char *res = rs[Rs_font + style];
1001 i = atoi (color); 1058 i = atoi (color);
1002 1059
1003 if (i >= 8 && i <= 15) 1060 if (i >= 8 && i <= 15)
1004 { /* bright colors */ 1061 { /* bright colors */
1005 i -= 8; 1062 i -= 8;
1006# ifndef NO_BRIGHTCOLOR
1007 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 1063 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1008 SET_PIXCOLOR (idx); 1064 SET_PIXCOLOR (idx);
1009 goto done; 1065 goto done;
1010# endif
1011 } 1066 }
1012 1067
1013 if (i >= 0 && i <= 7) 1068 if (i >= 0 && i <= 7)
1014 { /* normal colors */ 1069 { /* normal colors */
1015 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1070 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1199 } 1254 }
1200 1255
1201 if (menubar_visible ()) 1256 if (menubar_visible ())
1202 XMoveResizeWindow (disp, menuBar.win, 1257 XMoveResizeWindow (disp, menuBar.win,
1203 window_vt_x, 0, 1258 window_vt_x, 0,
1204 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1259 width, menuBar_TotalHeight ());
1205 1260
1206 XMoveResizeWindow (disp, vt, 1261 XMoveResizeWindow (disp, vt,
1207 window_vt_x, window_vt_y, 1262 window_vt_x, window_vt_y,
1208 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1263 width, height);
1209 1264
1210 scr_clear (); 1265 scr_clear ();
1211#ifdef XPM_BACKGROUND 1266#ifdef XPM_BACKGROUND
1212 resize_pixmap (); 1267 resize_pixmap ();
1213#endif 1268#endif
1393 XRectangle rect, status_rect, needed_rect; 1448 XRectangle rect, status_rect, needed_rect;
1394 unsigned long fg, bg; 1449 unsigned long fg, bg;
1395 const char *p; 1450 const char *p;
1396 char **s; 1451 char **s;
1397 XIMStyles *xim_styles; 1452 XIMStyles *xim_styles;
1453
1454 set_environ (envv);
1398 1455
1399 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1456 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1400 return false; 1457 return false;
1401 1458
1402 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1459 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1568 int i; 1625 int i;
1569 const char *p; 1626 const char *p;
1570 char **s; 1627 char **s;
1571 char buf[IMBUFSIZ]; 1628 char buf[IMBUFSIZ];
1572 1629
1573 SET_R (this); 1630 make_current ();
1574 1631
1575 im_destroy (); 1632 im_destroy ();
1576 1633
1577 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1634 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1578 if (Input_Context) 1635 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines