--- rxvt-unicode/src/proxy.C 2006/01/25 22:09:33 1.3 +++ rxvt-unicode/src/proxy.C 2007/02/12 17:34:58 1.7 @@ -27,16 +27,17 @@ #include "ptytty.h" -// helper/proxy support - -#if PTYTTY_HELPER - #include #include #include #include #include +#include + +// helper/proxy support + +#if PTYTTY_HELPER static int sock_fd = -1, lock_fd = -1; static int helper_pid, owner_pid; @@ -125,6 +126,11 @@ { if (id) { + close_tty (); + + if (pty >= 0) + close (pty); + NEED_TOKEN; command cmd; @@ -292,8 +298,27 @@ } void +ptytty::sanitise_stdfd () +{ + // sanitise stdin/stdout/stderr to point to *something*. + for (int fd = 0; fd <= 2; ++fd) + if (fcntl (fd, F_GETFL) < 0 && errno == EBADF) + { + int fd2 = open ("/dev/tty", fd ? O_WRONLY : O_RDONLY); + + if (fd2 < 0) + fd2 = open ("/dev/null", fd ? O_WRONLY : O_RDONLY); + + if (fd2 != fd) + abort (); + } +} + +void ptytty::init () { + sanitise_stdfd (); + uid_t uid = getuid (); gid_t gid = getgid ();