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.156 by root, Mon Jan 2 18:20:23 2006 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.
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
363} 377}
364 378
365void 379void
366rxvt_term::destroy_cb (time_watcher &w) 380rxvt_term::destroy_cb (time_watcher &w)
367{ 381{
368 SET_R (this); 382 make_current ();
369 383
370 delete this; 384 delete this;
371} 385}
372 386
373/*----------------------------------------------------------------------*/ 387/*----------------------------------------------------------------------*/
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);
469
470 set_locale (""); 483 set_locale ("");
484 set_environ (envv); // few things in X do not call setlocale :(
471 485
472 if (!init_vars ()) 486 if (!init_vars ())
473 return false; 487 return false;
474 488
475 init_secondary (); 489 init_secondary ();
487 if (OPTION (Opt_scrollBar)) 501 if (OPTION (Opt_scrollBar))
488 scrollBar.setIdle (); /* set existence for size calculations */ 502 scrollBar.setIdle (); /* set existence for size calculations */
489#endif 503#endif
490 504
491#if ENABLE_PERL 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
492 rxvt_perl.init (); 526 rxvt_perl.init (this);
493#endif
494
495 PERL_INVOKE ((this, HOOK_INIT, DT_END)); 527 HOOK_INVOKE ((this, HOOK_INIT, DT_END));
528 }
529#endif
496 530
497 create_windows (argc, argv); 531 create_windows (argc, argv);
498 532
499 dDisp; 533 dDisp;
500 534
501 init_xlocale (); 535 init_xlocale ();
502 536
503 scr_reset (); /* initialize screen */ 537 scr_reset (); // initialize screen
504 538
505#if 0 539#if 0
506 XSynchronize (disp, True); 540 XSynchronize (disp, True);
507#endif 541#endif
508 542
530 564
531 init_command (cmd_argv); 565 init_command (cmd_argv);
532 566
533 free (cmd_argv); 567 free (cmd_argv);
534 568
569 if (pty.pty >= 0)
535 pty_ev.start (pty.pty, EVENT_READ); 570 pty_ev.start (pty.pty, EVENT_READ);
536 571
537 check_ev.start (); 572 check_ev.start ();
538 573
539 PERL_INVOKE ((this, HOOK_START, DT_END)); 574 HOOK_INVOKE ((this, HOOK_START, DT_END));
540 575
541 return true; 576 return true;
542} 577}
543 578
544static struct sig_handlers 579static struct sig_handlers
579 sw_int (this, &sig_handlers::sig_term) 614 sw_int (this, &sig_handlers::sig_term)
580 { 615 {
581 } 616 }
582} sig_handlers; 617} sig_handlers;
583 618
619char **rxvt_environ; // startup environment
620
584void 621void
585rxvt_init () 622rxvt_init ()
586{ 623{
624 rxvt_environ = environ;
625
587 /* 626 /*
588 * Save and then give up any super-user privileges 627 * Save and then give up any super-user privileges
589 * 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.
590 * We should only need to be root in these cases: 629 * We should only need to be root in these cases:
591 * 1. write utmp entries on some systems 630 * 1. write utmp entries on some systems
605 /* signal (SIGURG, SIG_DFL); */ 644 /* signal (SIGURG, SIG_DFL); */
606 645
607 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 646 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
608 // TODO: handle this with exceptions and tolerate the memory loss 647 // TODO: handle this with exceptions and tolerate the memory loss
609 XSetIOErrorHandler (rxvt_xioerror_handler); 648 XSetIOErrorHandler (rxvt_xioerror_handler);
649
650 XrmInitialize ();
610} 651}
611 652
612/* ------------------------------------------------------------------------- * 653/* ------------------------------------------------------------------------- *
613 * MEMORY ALLOCATION WRAPPERS * 654 * MEMORY ALLOCATION WRAPPERS *
614 * ------------------------------------------------------------------------- */ 655 * ------------------------------------------------------------------------- */
650 * ------------------------------------------------------------------------- */ 691 * ------------------------------------------------------------------------- */
651/* take care of suid/sgid super-user (root) privileges */ 692/* take care of suid/sgid super-user (root) privileges */
652void 693void
653rxvt_privileges (rxvt_privaction action) 694rxvt_privileges (rxvt_privaction action)
654{ 695{
655#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__)
656 static uid_t euid;
657 static gid_t egid;
658#endif
659
660#if ! defined(__CYGWIN32__) 696#if ! defined(__CYGWIN32__)
661# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 697# if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
662 /* setreuid () is the poor man's setuid (), seteuid () */ 698 /* setreuid () is the poor man's setuid (), seteuid () */
663# define seteuid(a) setreuid(-1, (a)) 699# define seteuid(a) setreuid(-1, (a))
664# define setegid(a) setregid(-1, (a)) 700# define setegid(a) setregid(-1, (a))
670 case IGNORE: 706 case IGNORE:
671 /* 707 /*
672 * 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
673 * back to root later, as required 709 * back to root later, as required
674 */ 710 */
711 setegid (getgid ());
675 seteuid (getuid ()); 712 seteuid (getuid ());
676 setegid (getgid ());
677 break; 713 break;
678 case SAVE: 714 case SAVE:
679 euid = geteuid ();
680 egid = getegid (); 715 saved_egid = getegid ();
716 saved_euid = geteuid ();
681 break; 717 break;
682 case RESTORE: 718 case RESTORE:
683 seteuid (euid);
684 setegid (egid); 719 setegid (saved_egid);
720 seteuid (saved_euid);
685 break; 721 break;
686 } 722 }
687# else 723# else
688 switch (action) 724 switch (action)
689 { 725 {
690 case IGNORE: 726 case IGNORE:
727 setgid (getgid ());
691 setuid (getuid ()); 728 setuid (getuid ());
692 setgid (getgid ());
693 /* FALLTHROUGH */ 729 /* FALLTHROUGH */
694 case SAVE: 730 case SAVE:
695 /* FALLTHROUGH */ 731 /* FALLTHROUGH */
696 case RESTORE: 732 case RESTORE:
697 break; 733 break;
921 prop.height += lineSpace; 957 prop.height += lineSpace;
922 fs->set_prop (prop); 958 fs->set_prop (prop);
923 959
924 fwidth = prop.width; 960 fwidth = prop.width;
925 fheight = prop.height; 961 fheight = prop.height;
926 fbase = (*fs)[1]->ascent; 962 fbase = prop.ascent;
927 963
928 for (int style = 1; style < 4; style++) 964 for (int style = 1; style < 4; style++)
929 { 965 {
930#if ENABLE_STYLES 966#if ENABLE_STYLES
931 const char *res = rs[Rs_font + style]; 967 const char *res = rs[Rs_font + style];
1022 i = atoi (color); 1058 i = atoi (color);
1023 1059
1024 if (i >= 8 && i <= 15) 1060 if (i >= 8 && i <= 15)
1025 { /* bright colors */ 1061 { /* bright colors */
1026 i -= 8; 1062 i -= 8;
1027# ifndef NO_BRIGHTCOLOR
1028 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 1063 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
1029 SET_PIXCOLOR (idx); 1064 SET_PIXCOLOR (idx);
1030 goto done; 1065 goto done;
1031# endif
1032 } 1066 }
1033 1067
1034 if (i >= 0 && i <= 7) 1068 if (i >= 0 && i <= 7)
1035 { /* normal colors */ 1069 { /* normal colors */
1036 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1070 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1220 } 1254 }
1221 1255
1222 if (menubar_visible ()) 1256 if (menubar_visible ())
1223 XMoveResizeWindow (disp, menuBar.win, 1257 XMoveResizeWindow (disp, menuBar.win,
1224 window_vt_x, 0, 1258 window_vt_x, 0,
1225 TermWin_TotalWidth (), menuBar_TotalHeight ()); 1259 width, menuBar_TotalHeight ());
1226 1260
1227 XMoveResizeWindow (disp, vt, 1261 XMoveResizeWindow (disp, vt,
1228 window_vt_x, window_vt_y, 1262 window_vt_x, window_vt_y,
1229 TermWin_TotalWidth (), TermWin_TotalHeight ()); 1263 width, height);
1230 1264
1231 scr_clear (); 1265 scr_clear ();
1232#ifdef XPM_BACKGROUND 1266#ifdef XPM_BACKGROUND
1233 resize_pixmap (); 1267 resize_pixmap ();
1234#endif 1268#endif
1414 XRectangle rect, status_rect, needed_rect; 1448 XRectangle rect, status_rect, needed_rect;
1415 unsigned long fg, bg; 1449 unsigned long fg, bg;
1416 const char *p; 1450 const char *p;
1417 char **s; 1451 char **s;
1418 XIMStyles *xim_styles; 1452 XIMStyles *xim_styles;
1453
1454 set_environ (envv);
1419 1455
1420 if (! ((p = XSetLocaleModifiers (modifiers)) && *p)) 1456 if (! ((p = XSetLocaleModifiers (modifiers)) && *p))
1421 return false; 1457 return false;
1422 1458
1423 D_MAIN ((stderr, "rxvt_IM_get_IC ()")); 1459 D_MAIN ((stderr, "rxvt_IM_get_IC ()"));
1589 int i; 1625 int i;
1590 const char *p; 1626 const char *p;
1591 char **s; 1627 char **s;
1592 char buf[IMBUFSIZ]; 1628 char buf[IMBUFSIZ];
1593 1629
1594 SET_R (this); 1630 make_current ();
1595 1631
1596 im_destroy (); 1632 im_destroy ();
1597 1633
1598 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1634 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1599 if (Input_Context) 1635 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines