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.158 by root, Tue Jan 3 23:40:58 2006 UTC vs.
Revision 1.173 by root, Wed Jan 11 19:55:34 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.
46 46
47#ifdef HAVE_TERMIOS_H 47#ifdef HAVE_TERMIOS_H
48# include <termios.h> 48# include <termios.h>
49#endif 49#endif
50 50
51#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
52static uid_t saved_euid;
53static gid_t saved_egid;
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}
65
51vector<rxvt_term *> rxvt_term::termlist; 66vector<rxvt_term *> rxvt_term::termlist;
52 67
53static char curlocale[128], savelocale[128]; 68static char curlocale[128], savelocale[128];
54 69
55bool 70bool
61 strncpy (curlocale, locale, 128); 76 strncpy (curlocale, locale, 128);
62 setlocale (LC_CTYPE, curlocale); 77 setlocale (LC_CTYPE, curlocale);
63 return true; 78 return true;
64} 79}
65 80
66bool 81void
67rxvt_push_locale (const char *locale) 82rxvt_push_locale (const char *locale)
68{ 83{
69 strcpy (savelocale, curlocale); 84 strcpy (savelocale, curlocale);
70 rxvt_set_locale (locale); 85 rxvt_set_locale (locale);
71} 86}
206 pty.put (); 221 pty.put ();
207} 222}
208 223
209rxvt_term::~rxvt_term () 224rxvt_term::~rxvt_term ()
210{ 225{
211 PERL_INVOKE ((this, HOOK_DESTROY, DT_END)); 226 HOOK_INVOKE ((this, HOOK_DESTROY, DT_END));
212 227
213 termlist.erase (find (termlist.begin (), termlist.end(), this)); 228 termlist.erase (find (termlist.begin (), termlist.end(), this));
214 229
215 emergency_cleanup (); 230 emergency_cleanup ();
216 231
269 if (parent[0]) 284 if (parent[0])
270 XDestroyWindow (disp, parent[0]); 285 XDestroyWindow (disp, parent[0]);
271 } 286 }
272 287
273 // TODO: free pixcolours, colours should become part of rxvt_display 288 // TODO: free pixcolours, colours should become part of rxvt_display
274
275 delete pix_colors_focused; 289 delete pix_colors_focused;
276#if OFF_FOCUS_FADING 290#if OFF_FOCUS_FADING
277 delete pix_colors_unfocused; 291 delete pix_colors_unfocused;
278#endif 292#endif
279 293
464/*----------------------------------------------------------------------*/ 478/*----------------------------------------------------------------------*/
465bool 479bool
466rxvt_term::init (int argc, const char *const *argv) 480rxvt_term::init (int argc, const char *const *argv)
467{ 481{
468 SET_R (this); 482 SET_R (this);
483 TEMP_ENV; // few things in X do not call setlocale :(
469 484
470 set_locale (""); 485 set_locale ("");
471 486
472 if (!init_vars ()) 487 if (!init_vars ())
473 return false; 488 return false;
487 if (OPTION (Opt_scrollBar)) 502 if (OPTION (Opt_scrollBar))
488 scrollBar.setIdle (); /* set existence for size calculations */ 503 scrollBar.setIdle (); /* set existence for size calculations */
489#endif 504#endif
490 505
491#if ENABLE_PERL 506#if ENABLE_PERL
507 if (!rs[Rs_perl_ext_1])
508 rs[Rs_perl_ext_1] = "default";
509
492 if (rs[Rs_perl_ext] && *rs[Rs_perl_ext]) 510 if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1])
511 || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2])
512 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
493 { 513 {
514#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
515 // ignore some perl-related arguments if some bozo installed us set[ug]id
516 if (rxvt_tainted ())
517 {
518 if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib])
519 || (rs[Rs_perl_eval] && *rs[Rs_perl_eval]))
520 {
521 rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n");
522 rs[Rs_perl_lib] = 0;
523 rs[Rs_perl_eval] = 0;
524 }
525 }
526#endif
494 rxvt_perl.init (); 527 rxvt_perl.init ();
495 PERL_INVOKE ((this, HOOK_INIT, DT_END)); 528 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
496 } 529 }
497#endif 530#endif
498 531
499 create_windows (argc, argv); 532 create_windows (argc, argv);
500 533
501 dDisp; 534 dDisp;
502 535
503 init_xlocale (); 536 init_xlocale ();
504 537
505 scr_reset (); /* initialize screen */ 538 scr_reset (); // initialize screen
506 539
507#if 0 540#if 0
508 XSynchronize (disp, True); 541 XSynchronize (disp, True);
509#endif 542#endif
510 543
532 565
533 init_command (cmd_argv); 566 init_command (cmd_argv);
534 567
535 free (cmd_argv); 568 free (cmd_argv);
536 569
570 if (pty.pty >= 0)
537 pty_ev.start (pty.pty, EVENT_READ); 571 pty_ev.start (pty.pty, EVENT_READ);
538 572
539 check_ev.start (); 573 check_ev.start ();
540 574
541 PERL_INVOKE ((this, HOOK_START, DT_END)); 575 HOOK_INVOKE ((this, HOOK_START, DT_END));
542 576
543 return true; 577 return true;
544} 578}
545 579
546static struct sig_handlers 580static struct sig_handlers
607 /* signal (SIGURG, SIG_DFL); */ 641 /* signal (SIGURG, SIG_DFL); */
608 642
609 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 643 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
610 // TODO: handle this with exceptions and tolerate the memory loss 644 // TODO: handle this with exceptions and tolerate the memory loss
611 XSetIOErrorHandler (rxvt_xioerror_handler); 645 XSetIOErrorHandler (rxvt_xioerror_handler);
646
647 XrmInitialize ();
612} 648}
613 649
614/* ------------------------------------------------------------------------- * 650/* ------------------------------------------------------------------------- *
615 * MEMORY ALLOCATION WRAPPERS * 651 * MEMORY ALLOCATION WRAPPERS *
616 * ------------------------------------------------------------------------- */ 652 * ------------------------------------------------------------------------- */
652 * ------------------------------------------------------------------------- */ 688 * ------------------------------------------------------------------------- */
653/* take care of suid/sgid super-user (root) privileges */ 689/* take care of suid/sgid super-user (root) privileges */
654void 690void
655rxvt_privileges (rxvt_privaction action) 691rxvt_privileges (rxvt_privaction action)
656{ 692{
657#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
658 static uid_t euid;
659 static gid_t egid;
660#endif
661
662#if ! defined(__CYGWIN32__) 693#if ! defined(__CYGWIN32__)
663# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 694# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
664 /* setreuid () is the poor man's setuid (), seteuid () */ 695 /* setreuid () is the poor man's setuid (), seteuid () */
665# define seteuid(a) setreuid(-1, (a)) 696# define seteuid(a) setreuid(-1, (a))
666# define setegid(a) setregid(-1, (a)) 697# define setegid(a) setregid(-1, (a))
672 case IGNORE: 703 case IGNORE:
673 /* 704 /*
674 * change effective uid/gid - not real uid/gid - so we can switch 705 * change effective uid/gid - not real uid/gid - so we can switch
675 * back to root later, as required 706 * back to root later, as required
676 */ 707 */
708 setegid (getgid ());
677 seteuid (getuid ()); 709 seteuid (getuid ());
678 setegid (getgid ());
679 break; 710 break;
680 case SAVE: 711 case SAVE:
681 euid = geteuid ();
682 egid = getegid (); 712 saved_egid = getegid ();
713 saved_euid = geteuid ();
683 break; 714 break;
684 case RESTORE: 715 case RESTORE:
685 seteuid (euid);
686 setegid (egid); 716 setegid (saved_egid);
717 seteuid (saved_euid);
687 break; 718 break;
688 } 719 }
689# else 720# else
690 switch (action) 721 switch (action)
691 { 722 {
692 case IGNORE: 723 case IGNORE:
724 setgid (getgid ());
693 setuid (getuid ()); 725 setuid (getuid ());
694 setgid (getgid ());
695 /* FALLTHROUGH */ 726 /* FALLTHROUGH */
696 case SAVE: 727 case SAVE:
697 /* FALLTHROUGH */ 728 /* FALLTHROUGH */
698 case RESTORE: 729 case RESTORE:
699 break; 730 break;
1024 i = atoi (color); 1055 i = atoi (color);
1025 1056
1026 if (i >= 8 && i <= 15) 1057 if (i >= 8 && i <= 15)
1027 { /* bright colors */ 1058 { /* bright colors */
1028 i -= 8; 1059 i -= 8;
1029# ifndef NO_BRIGHTCOLOR
1030 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 1060 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1031 SET_PIXCOLOR (idx); 1061 SET_PIXCOLOR (idx);
1032 goto done; 1062 goto done;
1033# endif
1034 } 1063 }
1035 1064
1036 if (i >= 0 && i <= 7) 1065 if (i >= 0 && i <= 7)
1037 { /* normal colors */ 1066 { /* normal colors */
1038 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1067 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1222 } 1251 }
1223 1252
1224 if (menubar_visible ()) 1253 if (menubar_visible ())
1225 XMoveResizeWindow (disp, menuBar.win, 1254 XMoveResizeWindow (disp, menuBar.win,
1226 window_vt_x, 0, 1255 window_vt_x, 0,
1227 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1256 width, menuBar_TotalHeight ());
1228 1257
1229 XMoveResizeWindow (disp, vt, 1258 XMoveResizeWindow (disp, vt,
1230 window_vt_x, window_vt_y, 1259 window_vt_x, window_vt_y,
1231 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1260 width, height);
1232 1261
1233 scr_clear (); 1262 scr_clear ();
1234#ifdef XPM_BACKGROUND 1263#ifdef XPM_BACKGROUND
1235 resize_pixmap (); 1264 resize_pixmap ();
1236#endif 1265#endif
1416 XRectangle rect, status_rect, needed_rect; 1445 XRectangle rect, status_rect, needed_rect;
1417 unsigned long fg, bg; 1446 unsigned long fg, bg;
1418 const char *p; 1447 const char *p;
1419 char **s; 1448 char **s;
1420 XIMStyles *xim_styles; 1449 XIMStyles *xim_styles;
1450
1451 TEMP_ENV;
1421 1452
1422 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1453 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1423 return false; 1454 return false;
1424 1455
1425 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1456 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines