--- rxvt-unicode/src/main.C 2005/12/18 00:59:42 1.149 +++ rxvt-unicode/src/main.C 2006/01/11 00:59:58 1.170 @@ -13,7 +13,7 @@ * Copyright (c) 1997,1998 Oezguer Kesim * Copyright (c) 1998-2001 Geoff Wing * - extensive modifications - * Copyright (c) 2003-2004 Marc Lehmann + * Copyright (c) 2003-2006 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,10 @@ #include "../config.h" /* NECESSARY */ #include "rxvt.h" /* NECESSARY */ +#include "keyboard.h" +#include "rxvtperl.h" + +#include #include #include @@ -44,13 +48,24 @@ # include #endif -#ifdef KEYSYM_RESOURCE -# include "keyboard.h" +#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) +static uid_t saved_euid; +static gid_t saved_egid; +#endif + +bool +rxvt_tainted () +{ +#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) + return getuid () != saved_euid || getgid () != saved_egid; +#else + return false; #endif +} vector rxvt_term::termlist; -static char curlocale[128]; +static char curlocale[128], savelocale[128]; bool rxvt_set_locale (const char *locale) @@ -63,6 +78,19 @@ return true; } +void +rxvt_push_locale (const char *locale) +{ + strcpy (savelocale, curlocale); + rxvt_set_locale (locale); +} + +void +rxvt_pop_locale () +{ + rxvt_set_locale (savelocale); +} + #if ENABLE_COMBINING class rxvt_composite_vec rxvt_composite; @@ -195,6 +223,8 @@ rxvt_term::~rxvt_term () { + HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); + termlist.erase (find (termlist.begin (), termlist.end(), this)); emergency_cleanup (); @@ -289,6 +319,15 @@ } void +rxvt_term::child_exit () +{ + cmd_pid = 0; + + if (!OPTION (Opt_hold)) + destroy (); +} + +void rxvt_term::destroy () { if (destroy_ev.active) @@ -460,10 +499,36 @@ menubar_read (rs[Rs_menu]); #endif #ifdef HAVE_SCROLLBARS - if (options & Opt_scrollBar) + if (OPTION (Opt_scrollBar)) scrollBar.setIdle (); /* set existence for size calculations */ #endif +#if ENABLE_PERL + if (!rs[Rs_perl_ext_1]) + rs[Rs_perl_ext_1] = "default"; + + if ((rs[Rs_perl_ext_1] && *rs[Rs_perl_ext_1]) + || (rs[Rs_perl_ext_2] && *rs[Rs_perl_ext_2]) + || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) + { +#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) + // ignore some perl-related arguments if some bozo installed us set[ug]id + if (rxvt_tainted ()) + { + if ((rs[Rs_perl_lib] && *rs[Rs_perl_lib]) + || (rs[Rs_perl_eval] && *rs[Rs_perl_eval])) + { + rxvt_warn ("running with elevated privileges: ignoring perl-lib and perl-eval.\n"); + rs[Rs_perl_lib] = 0; + rs[Rs_perl_eval] = 0; + } + } +#endif + rxvt_perl.init (); + HOOK_INVOKE ((this, HOOK_INIT, DT_END)); + } +#endif + create_windows (argc, argv); dDisp; @@ -477,7 +542,7 @@ #endif #ifdef HAVE_SCROLLBARS - if (options & Opt_scrollBar) + if (OPTION (Opt_scrollBar)) resize_scrollbar (); /* create and map scrollbar */ #endif #if (MENUBAR_MAX) @@ -485,7 +550,7 @@ XMapWindow (disp, menuBar.win); #endif #ifdef TRANSPARENT - if (options & Opt_transparent) + if (OPTION (Opt_transparent)) { XSelectInput (disp, display->root, PropertyChangeMask); check_our_parents (); @@ -502,10 +567,13 @@ free (cmd_argv); - pty_ev.start (pty.pty, EVENT_READ); + if (pty.pty >= 0) + pty_ev.start (pty.pty, EVENT_READ); check_ev.start (); + HOOK_INVOKE ((this, HOOK_START, DT_END)); + return true; } @@ -522,7 +590,7 @@ for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) if (pid == (*t)->cmd_pid) { - (*t)->destroy (); + (*t)->child_exit (); break; } } @@ -575,6 +643,8 @@ old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); // TODO: handle this with exceptions and tolerate the memory loss XSetIOErrorHandler (rxvt_xioerror_handler); + + XrmInitialize (); } /* ------------------------------------------------------------------------- * @@ -620,11 +690,6 @@ void rxvt_privileges (rxvt_privaction action) { -#if (defined(HAVE_SETEUID) || defined(HAVE_SETREUID)) && !defined(__CYGWIN32__) - static uid_t euid; - static gid_t egid; -#endif - #if ! defined(__CYGWIN32__) # if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) /* setreuid () is the poor man's setuid (), seteuid () */ @@ -644,12 +709,12 @@ setegid (getgid ()); break; case SAVE: - euid = geteuid (); - egid = getegid (); + saved_euid = geteuid (); + saved_egid = getegid (); break; case RESTORE: - seteuid (euid); - setegid (egid); + seteuid (saved_euid); + setegid (saved_egid); break; } # else @@ -672,7 +737,7 @@ void rxvt_term::privileged_utmp (rxvt_privaction action) { - if ((options & Opt_utmpInhibit) + if (OPTION (Opt_utmpInhibit) || !pty.name || !*pty.name) return; @@ -720,13 +785,13 @@ if (flags & WidthValue) { - ncol = BOUND_POSITIVE_INT16 (w); + ncol = clamp (w, 0, std::numeric_limits::max ()); szHint.flags |= USSize; } if (flags & HeightValue) { - nrow = BOUND_POSITIVE_INT16 (h); + nrow = clamp (h, 0, std::numeric_limits::max ()); szHint.flags |= USSize; } @@ -774,7 +839,7 @@ { sb_w = scrollbar_TotalWidth (); szHint.base_width += sb_w; - if (!(options & Opt_scrollBar_right)) + if (!OPTION (Opt_scrollBar_right)) window_vt_x += sb_w; } @@ -797,7 +862,7 @@ } else { - MIN_IT (width, max_width); + min_it (width, max_width); szHint.width = szHint.base_width + width; } @@ -808,11 +873,11 @@ } else { - MIN_IT (height, max_height); + min_it (height, max_height); szHint.height = szHint.base_height + height; } - if (scrollbar_visible () && (options & Opt_scrollBar_right)) + if (scrollbar_visible () && OPTION (Opt_scrollBar_right)) window_sb_x = szHint.width - sb_w; if (recalc_x) @@ -891,9 +956,7 @@ fwidth = prop.width; fheight = prop.height; - fweight = prop.weight; - fslant = prop.slant; - fbase = (*fs)[1]->ascent; + fbase = prop.ascent; for (int style = 1; style < 4; style++) { @@ -937,7 +1000,6 @@ void rxvt_term::set_string_property (Atom prop, const char *str, int len) { - // TODO: SMART_WINDOW_TITLE XChangeProperty (display->display, parent[0], prop, XA_STRING, 8, PropModeReplace, (const unsigned char *)str, len >= 0 ? len : strlen (str)); @@ -945,7 +1007,6 @@ void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) { - // TODO: SMART_WINDOW_TITLE wchar_t *ws = rxvt_mbstowcs (str, len); char *s = rxvt_wcstoutf8 (ws); @@ -996,11 +1057,9 @@ if (i >= 8 && i <= 15) { /* bright colors */ i -= 8; -# ifndef NO_BRIGHTCOLOR pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; SET_PIXCOLOR (idx); goto done; -# endif } if (i >= 0 && i <= 7) @@ -1194,11 +1253,11 @@ if (menubar_visible ()) XMoveResizeWindow (disp, menuBar.win, window_vt_x, 0, - TermWin_TotalWidth (), menuBar_TotalHeight ()); + width, menuBar_TotalHeight ()); XMoveResizeWindow (disp, vt, window_vt_x, window_vt_y, - TermWin_TotalWidth (), TermWin_TotalHeight ()); + width, height); scr_clear (); #ifdef XPM_BACKGROUND