From: root Date: Fri, 23 Dec 2005 14:46:34 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=f00f622575e7ce7baab40cdfb38d1aebdd3ac43b;p=dana%2Furxvt.git *** empty log message *** --- diff --git a/Changes b/Changes index cb217ba4..2f9265a0 100644 --- a/Changes +++ b/Changes @@ -20,6 +20,7 @@ WISH: just for fun, do shade and tint with XRender. partial patch). - bump max columns/rows to 10000 each. - bump max savelines to 10000000. + - -pty-fd now passes the urxvtc fd to the urxvtd process. - major code cleanup (still not complete, though). - implement -hold option. - _major_ rewrite of internal buffer handling: diff --git a/MANIFEST b/MANIFEST index 01dfe5a5..477042f6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -68,6 +68,8 @@ src/command.C src/command.h src/encoding.C src/encoding.h +src/fdpass.h +src/fdpass.C src/feature.h src/init.C src/init.h diff --git a/autoconf/config.h.in b/autoconf/config.h.in index d442d1aa..b90b4900 100644 --- a/autoconf/config.h.in +++ b/autoconf/config.h.in @@ -316,6 +316,9 @@ /* Define if nl_langinfo(CODESET) works */ #undef HAVE_NL_LANGINFO +/* Define if sys/socket.h defines the necessary macros/functions for file handle passing */ +#undef HAVE_UNIX_FDPASS + /* Define if your XIMCallback specifies XIC as first type. */ #undef XIMCB_PROTO_BROKEN diff --git a/autoconf/configure.in b/autoconf/configure.in index 53b6121d..a2e96ea9 100644 --- a/autoconf/configure.in +++ b/autoconf/configure.in @@ -1118,6 +1118,39 @@ if test x$rxvt_cv_func_nl_langinfo = xyes; then AC_DEFINE(HAVE_NL_LANGINFO, 1, Define if nl_langinfo(CODESET) works) fi +AC_CACHE_CHECK(for unix-compliant filehandle passing ability, rxvt_can_pass_fds, +[AC_TRY_LINK([ +#include +#include +],[ +{ + msghdr msg; + iovec iov; + char buf [100]; + char data = 0; + + iov.iov_base = &data; + iov.iov_len = 1; + + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = buf; + msg.msg_controllen = sizeof buf; + + cmsghdr *cmsg = CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = 100; + + *(int *)CMSG_DATA (cmsg) = 5; + + return sendmsg (3, &msg, 0); +} +],[rxvt_can_pass_fds=yes],[rxvt_can_pass_fds=no])]) +if test x$rxvt_can_pass_fds = xyes; then + AC_DEFINE(HAVE_UNIX_FDPASS, 1, Define if sys/socket.h defines the necessary macros/functions for file handle passing) +fi + AC_CACHE_CHECK(for broken XIM callback, rxvt_broken_ximcb, [AC_COMPILE_IFELSE([ #include diff --git a/configure b/configure index 3018338f..c09fccd1 100755 --- a/configure +++ b/configure @@ -11340,6 +11340,94 @@ _ACEOF fi +echo "$as_me:$LINENO: checking for unix-compliant filehandle passing ability" >&5 +echo $ECHO_N "checking for unix-compliant filehandle passing ability... $ECHO_C" >&6 +if test "${rxvt_can_pass_fds+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include +#include + +int +main () +{ + +{ + msghdr msg; + iovec iov; + char buf [100]; + char data = 0; + + iov.iov_base = &data; + iov.iov_len = 1; + + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = buf; + msg.msg_controllen = sizeof buf; + + cmsghdr *cmsg = CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = 100; + + *(int *)CMSG_DATA (cmsg) = 5; + + return sendmsg (3, &msg, 0); +} + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_cxx_werror_flag" || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + rxvt_can_pass_fds=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +rxvt_can_pass_fds=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $rxvt_can_pass_fds" >&5 +echo "${ECHO_T}$rxvt_can_pass_fds" >&6 +if test x$rxvt_can_pass_fds = xyes; then + +cat >>confdefs.h <<\_ACEOF +#define HAVE_UNIX_FDPASS 1 +_ACEOF + +fi + echo "$as_me:$LINENO: checking for broken XIM callback" >&5 echo $ECHO_N "checking for broken XIM callback... $ECHO_C" >&6 if test "${rxvt_broken_ximcb+set}" = set; then diff --git a/src/Makefile.in b/src/Makefile.in index 04bb1b4c..6a6de2d0 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -156,12 +156,12 @@ ptytty.o: salloc.h menubar.h rxvt.o: ../config.h rxvt.h rxvtlib.h ptytty.h feature.h encoding.h rxvtfont.h rxvt.o: rxvtutil.h rxvttoolkit.h iom.h iom_conf.h callback.h salloc.h rxvt.o: menubar.h -rxvtc.o: ../config.h rxvtdaemon.h rxvtutil.h rxvt.h rxvtlib.h ptytty.h -rxvtc.o: feature.h encoding.h rxvtfont.h rxvttoolkit.h iom.h iom_conf.h -rxvtc.o: callback.h salloc.h menubar.h +rxvtc.o: ../config.h rxvtdaemon.h rxvtutil.h fdpass.h rxvt.h rxvtlib.h +rxvtc.o: ptytty.h feature.h encoding.h rxvtfont.h rxvttoolkit.h iom.h +rxvtc.o: iom_conf.h callback.h salloc.h menubar.h rxvtd.o: ../config.h rxvt.h rxvtlib.h ptytty.h feature.h encoding.h rxvtd.o: rxvtfont.h rxvtutil.h rxvttoolkit.h iom.h iom_conf.h callback.h -rxvtd.o: salloc.h menubar.h rxvtdaemon.h +rxvtd.o: salloc.h menubar.h rxvtdaemon.h fdpass.h rxvtdaemon.o: rxvtdaemon.h rxvtutil.h rxvtfont.o: ../config.h rxvt.h rxvtlib.h ptytty.h feature.h encoding.h rxvtfont.o: rxvtfont.h rxvtutil.h rxvttoolkit.h iom.h iom_conf.h callback.h @@ -246,12 +246,12 @@ ptytty.lo: salloc.h menubar.h rxvt.lo: ../config.h rxvt.h rxvtlib.h ptytty.h feature.h encoding.h rxvt.lo: rxvtfont.h rxvtutil.h rxvttoolkit.h iom.h iom_conf.h callback.h rxvt.lo: salloc.h menubar.h -rxvtc.lo: ../config.h rxvtdaemon.h rxvtutil.h rxvt.h rxvtlib.h ptytty.h -rxvtc.lo: feature.h encoding.h rxvtfont.h rxvttoolkit.h iom.h iom_conf.h -rxvtc.lo: callback.h salloc.h menubar.h +rxvtc.lo: ../config.h rxvtdaemon.h rxvtutil.h fdpass.h rxvt.h rxvtlib.h +rxvtc.lo: ptytty.h feature.h encoding.h rxvtfont.h rxvttoolkit.h iom.h +rxvtc.lo: iom_conf.h callback.h salloc.h menubar.h rxvtd.lo: ../config.h rxvt.h rxvtlib.h ptytty.h feature.h encoding.h rxvtd.lo: rxvtfont.h rxvtutil.h rxvttoolkit.h iom.h iom_conf.h callback.h -rxvtd.lo: salloc.h menubar.h rxvtdaemon.h +rxvtd.lo: salloc.h menubar.h rxvtdaemon.h fdpass.h rxvtdaemon.lo: rxvtdaemon.h rxvtutil.h rxvtfont.lo: ../config.h rxvt.h rxvtlib.h ptytty.h feature.h encoding.h rxvtfont.lo: rxvtfont.h rxvtutil.h rxvttoolkit.h iom.h iom_conf.h callback.h diff --git a/src/command.C b/src/command.C index 489e5a73..76eb690c 100644 --- a/src/command.C +++ b/src/command.C @@ -1069,8 +1069,13 @@ rxvt_term::pty_fill () cmdbuf_endp += n; return true; } - else if (n < 0 && errno != EAGAIN && errno != EINTR) - pty_ev.stop (); + else if ((n < 0 && errno != EAGAIN && errno != EINTR) || n == 0) + { + pty_ev.stop (); + + if (!(options & Opt_hold)) + destroy (); + } return false; } diff --git a/src/fdpass.C b/src/fdpass.C new file mode 100644 index 00000000..d57282bc --- /dev/null +++ b/src/fdpass.C @@ -0,0 +1,105 @@ +/*--------------------------------*-C-*---------------------------------* + * File: fdpass.C + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2005 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#include "../config.h" /* NECESSARY */ + +#if ENABLE_FRILLS && HAVE_UNIX_FDPASS + +#include +#include + +#include "fdpass.h" + +#include //d + +#ifndef CMSG_LEN // CMSG_SPACe && CMSG_LEN are rfc2292 extensions to unix +# define CMSG_LEN(len) (sizeof (cmsghdr) + len) +#endif + +int +rxvt_send_fd (int socket, int fd) +{ + msghdr msg; + iovec iov; + char buf [CMSG_LEN (sizeof (int))]; + char data = 0; + + iov.iov_base = &data; + iov.iov_len = 1; + + msg.msg_name = 0; + msg.msg_namelen = 0; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = (void *)buf; + msg.msg_controllen = sizeof buf; + + cmsghdr *cmsg = CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN (sizeof (int)); + + *(int *)CMSG_DATA (cmsg) = fd; + + msg.msg_controllen = cmsg->cmsg_len; + + return sendmsg (socket, &msg, 0); +} + +int +rxvt_recv_fd (int socket) +{ + msghdr msg; + iovec iov; + char buf [CMSG_LEN (sizeof (int))]; /* ancillary data buffer */ + char data = 1; + + iov.iov_base = &data; + iov.iov_len = 1; + + msg.msg_name = 0; + msg.msg_namelen = 0; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = buf; + msg.msg_controllen = sizeof buf; + + cmsghdr *cmsg = CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN (sizeof (int)); + + msg.msg_controllen = cmsg->cmsg_len; + + if (recvmsg (socket, &msg, 0) <= 0 + || data != 0 + || msg.msg_controllen < CMSG_LEN (sizeof (int)) + || cmsg->cmsg_level != SOL_SOCKET + || cmsg->cmsg_type != SCM_RIGHTS + || cmsg->cmsg_len < CMSG_LEN (sizeof (int))) + return -1; + + return *(int *)CMSG_DATA (cmsg); +} + +#endif + diff --git a/src/fdpass.h b/src/fdpass.h new file mode 100644 index 00000000..6b02c570 --- /dev/null +++ b/src/fdpass.h @@ -0,0 +1,31 @@ +/*--------------------------------*-C-*---------------------------------* + * File: fdpass.h + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2005 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *----------------------------------------------------------------------*/ + +#include "../config.h" /* NECESSARY */ + +#if ENABLE_FRILLS && HAVE_UNIX_FDPASS + +int rxvt_send_fd (int socket, int fd); +int rxvt_recv_fd (int socket); + +#endif + diff --git a/src/init.C b/src/init.C index 90d6a3ea..70e1b905 100644 --- a/src/init.C +++ b/src/init.C @@ -1412,7 +1412,12 @@ rxvt_term::run_command (const char *const *argv) if (rs[Rs_pty_fd]) { pty.pty = atoi (rs[Rs_pty_fd]); - fcntl (pty.pty, F_SETFL, O_NONBLOCK); + + if (getfd_hook) + pty.pty = (*getfd_hook) (pty.pty); + + if (pty.pty < 0 || fcntl (pty.pty, F_SETFL, O_NONBLOCK)) + rxvt_fatal ("unusable pty-fd filehandle, aborting.\n"); } else #endif diff --git a/src/rxvt.h b/src/rxvt.h index 15a5bd6a..89c2a1b4 100644 --- a/src/rxvt.h +++ b/src/rxvt.h @@ -961,6 +961,7 @@ enum { extern class rxvt_failure_exception { } rxvt_failure_exception; typedef callback1 log_callback; +typedef callback1 getfd_callback; extern void rxvt_vlog (const char *fmt, va_list arg_ptr); extern void rxvt_log (const char *fmt, ...); @@ -1047,6 +1048,7 @@ extern class rxvt_composite_vec rxvt_composite; struct rxvt_term : zero_initialized, rxvt_vars { log_callback *log_hook; // log error messages through this hook, if != 0 + getfd_callback *getfd_hook; // convert remote to local fd, if != 0 struct mbstate mbstate; // current input multibyte state diff --git a/src/rxvtc.C b/src/rxvtc.C index ff9dbd0e..e4d5db0e 100644 --- a/src/rxvtc.C +++ b/src/rxvtc.C @@ -22,6 +22,7 @@ #include "../config.h" #include "rxvtdaemon.h" +#include "fdpass.h" #include "rxvt.h" @@ -99,6 +100,7 @@ main (int argc, const char *const *argv) c.send ("END"); auto_str tok; + int cint; for (;;) if (!c.recv (tok)) @@ -108,6 +110,14 @@ main (int argc, const char *const *argv) } else if (!strcmp (tok, "MSG") && c.recv (tok)) fprintf (stderr, "%s", (const char *)tok); + else if (!strcmp (tok, "GETFD") && c.recv (cint)) + { + if (rxvt_send_fd (c.fd, cint) < 0) + { + fprintf (stderr, "unable to send fd %d: ", cint); perror (0); + exit (EXIT_FAILURE); + } + } else if (!strcmp (tok, "END")) { int success; @@ -116,7 +126,7 @@ main (int argc, const char *const *argv) } else { - fprintf (stderr, "protocol error: received illegal token '%s'.\n", (const char *)tok); + fprintf (stderr, "protocol error: received unsupported token '%s'.\n", (const char *)tok); break; } diff --git a/src/rxvtd.C b/src/rxvtd.C index 7bd89af5..4a714e1b 100644 --- a/src/rxvtd.C +++ b/src/rxvtd.C @@ -23,6 +23,7 @@ #include "../config.h" #include "rxvt.h" #include "rxvtdaemon.h" +#include "fdpass.h" #include "iom.h" #include @@ -43,13 +44,16 @@ extern char **environ; struct server : rxvt_connection { log_callback log_cb; + getfd_callback getfd_cb; void read_cb (io_watcher &w, short revents); io_watcher read_ev; void log_msg (const char *msg); + int getfd (int remote_fd); server (int fd) : read_ev (this, &server::read_cb), - log_cb (this, &server::log_msg) + log_cb (this, &server::log_msg), + getfd_cb (this, &server::getfd) { this->fd = fd; read_ev.start (fd, EVENT_READ); @@ -114,6 +118,17 @@ void unix_listener::accept_cb (io_watcher &w, short revents) } } +int server::getfd (int remote_fd) +{ +#if ENABLE_FRILLS && HAVE_UNIX_FDPASS + send ("GETFD"); + send (remote_fd); + return rxvt_recv_fd (fd); +#else + return -1; +#endif +} + void server::log_msg (const char *msg) { send ("MSG"), send (msg); @@ -179,6 +194,7 @@ void server::read_cb (io_watcher &w, short revents) rxvt_term *term = new rxvt_term; term->log_hook = &log_cb; + term->getfd_hook = &getfd_cb; term->argv = argv; term->envv = envv;