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.154 by root, Sat Dec 31 17:16:17 2005 UTC vs.
Revision 1.177 by root, Mon Jan 16 06:37:52 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);
92}
93
94void
95rxvt_term::make_current () const
96{
97 SET_R (this);
98 rxvt_set_locale (locale);
99 set_environ (envv);
66} 100}
67 101
68#if ENABLE_COMBINING 102#if ENABLE_COMBINING
69class rxvt_composite_vec rxvt_composite; 103class rxvt_composite_vec rxvt_composite;
70 104
195 pty.put (); 229 pty.put ();
196} 230}
197 231
198rxvt_term::~rxvt_term () 232rxvt_term::~rxvt_term ()
199{ 233{
234 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
235
200 termlist.erase (find (termlist.begin (), termlist.end(), this)); 236 termlist.erase (find (termlist.begin (), termlist.end(), this));
201 237
202 emergency_cleanup (); 238 emergency_cleanup ();
203 239
204#if ENABLE_STYLES 240#if ENABLE_STYLES
256 if (parent[0]) 292 if (parent[0])
257 XDestroyWindow (disp, parent[0]); 293 XDestroyWindow (disp, parent[0]);
258 } 294 }
259 295
260 // TODO: free pixcolours, colours should become part of rxvt_display 296 // TODO: free pixcolours, colours should become part of rxvt_display
261
262 delete pix_colors_focused; 297 delete pix_colors_focused;
263#if OFF_FOCUS_FADING 298#if OFF_FOCUS_FADING
264 delete pix_colors_unfocused; 299 delete pix_colors_unfocused;
265#endif 300#endif
266 301
350} 385}
351 386
352void 387void
353rxvt_term::destroy_cb (time_watcher &w) 388rxvt_term::destroy_cb (time_watcher &w)
354{ 389{
355 SET_R (this); 390 make_current ();
356 391
357 delete this; 392 delete this;
358} 393}
359 394
360/*----------------------------------------------------------------------*/ 395/*----------------------------------------------------------------------*/
451/*----------------------------------------------------------------------*/ 486/*----------------------------------------------------------------------*/
452bool 487bool
453rxvt_term::init (int argc, const char *const *argv) 488rxvt_term::init (int argc, const char *const *argv)
454{ 489{
455 SET_R (this); 490 SET_R (this);
456
457 set_locale (""); 491 set_locale ("");
492 set_environ (envv); // few things in X do not call setlocale :(
458 493
459 if (!init_vars ()) 494 if (!init_vars ())
460 return false; 495 return false;
461 496
462 init_secondary (); 497 init_secondary ();
473#ifdef HAVE_SCROLLBARS 508#ifdef HAVE_SCROLLBARS
474 if (OPTION (Opt_scrollBar)) 509 if (OPTION (Opt_scrollBar))
475 scrollBar.setIdle (); /* set existence for size calculations */ 510 scrollBar.setIdle (); /* set existence for size calculations */
476#endif 511#endif
477 512
513#if ENABLE_PERL
514 if (!rs[Rs_perl_ext_1])
515 rs[Rs_perl_ext_1] = "default";
516
517 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
518 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
519 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
520 {
521#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
522 // ignore some perl-related arguments if some bozo installed us set[ug]id
523 if (rxvt_tainted ())
524 {
525 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
526 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
527 {
528 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
529 rs[Rs_perl_lib] = 0;
530 rs[Rs_perl_eval] = 0;
531 }
532 }
533#endif
534 rxvt_perl.init ();
535 setlocale (LC_CTYPE, curlocale); // perl init destroys current locale
536 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
537 }
538#endif
539
478 create_windows (argc, argv); 540 create_windows (argc, argv);
479 541
480 dDisp; 542 dDisp;
481 543
482 init_xlocale (); 544 init_xlocale ();
483 545
484 scr_reset (); /* initialize screen */ 546 scr_reset (); // initialize screen
485 547
486#if 0 548#if 0
487 XSynchronize (disp, True); 549 XSynchronize (disp, True);
488#endif 550#endif
489 551
511 573
512 init_command (cmd_argv); 574 init_command (cmd_argv);
513 575
514 free (cmd_argv); 576 free (cmd_argv);
515 577
578 if (pty.pty >= 0)
516 pty_ev.start (pty.pty, EVENT_READ); 579 pty_ev.start (pty.pty, EVENT_READ);
517 580
518 check_ev.start (); 581 check_ev.start ();
582
583 HOOK_INVOKE ((this, HOOK_START, DT_END));
519 584
520 return true; 585 return true;
521} 586}
522 587
523static struct sig_handlers 588static struct sig_handlers
558 sw_int (this, &sig_handlers::sig_term) 623 sw_int (this, &sig_handlers::sig_term)
559 { 624 {
560 } 625 }
561} sig_handlers; 626} sig_handlers;
562 627
628char **rxvt_environ; // startup environment
629
563void 630void
564rxvt_init () 631rxvt_init ()
565{ 632{
633 rxvt_environ = environ;
634
566 /* 635 /*
567 * Save and then give up any super-user privileges 636 * Save and then give up any super-user privileges
568 * If we need privileges in any area then we must specifically request it. 637 * If we need privileges in any area then we must specifically request it.
569 * We should only need to be root in these cases: 638 * We should only need to be root in these cases:
570 * 1. write utmp entries on some systems 639 * 1. write utmp entries on some systems
584 /* signal (SIGURG, SIG_DFL); */ 653 /* signal (SIGURG, SIG_DFL); */
585 654
586 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 655 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
587 // TODO: handle this with exceptions and tolerate the memory loss 656 // TODO: handle this with exceptions and tolerate the memory loss
588 XSetIOErrorHandler (rxvt_xioerror_handler); 657 XSetIOErrorHandler (rxvt_xioerror_handler);
658
659 XrmInitialize ();
589} 660}
590 661
591/* ------------------------------------------------------------------------- * 662/* ------------------------------------------------------------------------- *
592 * MEMORY ALLOCATION WRAPPERS * 663 * MEMORY ALLOCATION WRAPPERS *
593 * ------------------------------------------------------------------------- */ 664 * ------------------------------------------------------------------------- */
629 * ------------------------------------------------------------------------- */ 700 * ------------------------------------------------------------------------- */
630/* take care of suid/sgid super-user (root) privileges */ 701/* take care of suid/sgid super-user (root) privileges */
631void 702void
632rxvt_privileges (rxvt_privaction action) 703rxvt_privileges (rxvt_privaction action)
633{ 704{
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__) 705#if ! defined(__CYGWIN32__)
640# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 706# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
641 /* setreuid () is the poor man's setuid (), seteuid () */ 707 /* setreuid () is the poor man's setuid (), seteuid () */
642# define seteuid(a) setreuid(-1, (a)) 708# define seteuid(a) setreuid(-1, (a))
643# define setegid(a) setregid(-1, (a)) 709# define setegid(a) setregid(-1, (a))
649 case IGNORE: 715 case IGNORE:
650 /* 716 /*
651 * change effective uid/gid - not real uid/gid - so we can switch 717 * change effective uid/gid - not real uid/gid - so we can switch
652 * back to root later, as required 718 * back to root later, as required
653 */ 719 */
720 setegid (getgid ());
654 seteuid (getuid ()); 721 seteuid (getuid ());
655 setegid (getgid ());
656 break; 722 break;
657 case SAVE: 723 case SAVE:
658 euid = geteuid ();
659 egid = getegid (); 724 saved_egid = getegid ();
725 saved_euid = geteuid ();
660 break; 726 break;
661 case RESTORE: 727 case RESTORE:
662 seteuid (euid);
663 setegid (egid); 728 setegid (saved_egid);
729 seteuid (saved_euid);
664 break; 730 break;
665 } 731 }
666# else 732# else
667 switch (action) 733 switch (action)
668 { 734 {
669 case IGNORE: 735 case IGNORE:
736 setgid (getgid ());
670 setuid (getuid ()); 737 setuid (getuid ());
671 setgid (getgid ());
672 /* FALLTHROUGH */ 738 /* FALLTHROUGH */
673 case SAVE: 739 case SAVE:
674 /* FALLTHROUGH */ 740 /* FALLTHROUGH */
675 case RESTORE: 741 case RESTORE:
676 break; 742 break;
900 prop.height += lineSpace; 966 prop.height += lineSpace;
901 fs->set_prop (prop); 967 fs->set_prop (prop);
902 968
903 fwidth = prop.width; 969 fwidth = prop.width;
904 fheight = prop.height; 970 fheight = prop.height;
905 fbase = (*fs)[1]->ascent; 971 fbase = prop.ascent;
906 972
907 for (int style = 1; style < 4; style++) 973 for (int style = 1; style < 4; style++)
908 { 974 {
909#if ENABLE_STYLES 975#if ENABLE_STYLES
910 const char *res = rs[Rs_font + style]; 976 const char *res = rs[Rs_font + style];
1001 i = atoi (color); 1067 i = atoi (color);
1002 1068
1003 if (i >= 8 && i <= 15) 1069 if (i >= 8 && i <= 15)
1004 { /* bright colors */ 1070 { /* bright colors */
1005 i -= 8; 1071 i -= 8;
1006# ifndef NO_BRIGHTCOLOR
1007 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 1072 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1008 SET_PIXCOLOR (idx); 1073 SET_PIXCOLOR (idx);
1009 goto done; 1074 goto done;
1010# endif
1011 } 1075 }
1012 1076
1013 if (i >= 0 && i <= 7) 1077 if (i >= 0 && i <= 7)
1014 { /* normal colors */ 1078 { /* normal colors */
1015 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1079 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1199 } 1263 }
1200 1264
1201 if (menubar_visible ()) 1265 if (menubar_visible ())
1202 XMoveResizeWindow (disp, menuBar.win, 1266 XMoveResizeWindow (disp, menuBar.win,
1203 window_vt_x, 0, 1267 window_vt_x, 0,
1204 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1268 width, menuBar_TotalHeight ());
1205 1269
1206 XMoveResizeWindow (disp, vt, 1270 XMoveResizeWindow (disp, vt,
1207 window_vt_x, window_vt_y, 1271 window_vt_x, window_vt_y,
1208 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1272 width, height);
1209 1273
1210 scr_clear (); 1274 scr_clear ();
1211#ifdef XPM_BACKGROUND 1275#ifdef XPM_BACKGROUND
1212 resize_pixmap (); 1276 resize_pixmap ();
1213#endif 1277#endif
1393 XRectangle rect, status_rect, needed_rect; 1457 XRectangle rect, status_rect, needed_rect;
1394 unsigned long fg, bg; 1458 unsigned long fg, bg;
1395 const char *p; 1459 const char *p;
1396 char **s; 1460 char **s;
1397 XIMStyles *xim_styles; 1461 XIMStyles *xim_styles;
1462
1463 set_environ (envv);
1398 1464
1399 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1465 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1400 return false; 1466 return false;
1401 1467
1402 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1468 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1568 int i; 1634 int i;
1569 const char *p; 1635 const char *p;
1570 char **s; 1636 char **s;
1571 char buf[IMBUFSIZ]; 1637 char buf[IMBUFSIZ];
1572 1638
1573 SET_R (this); 1639 make_current ();
1574 1640
1575 im_destroy (); 1641 im_destroy ();
1576 1642
1577 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1643 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1578 if (Input_Context) 1644 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines