*** empty log message ***
authorroot <root>
Fri, 23 Dec 2005 14:46:34 +0000 (14:46 +0000)
committerroot <root>
Fri, 23 Dec 2005 14:46:34 +0000 (14:46 +0000)
13 files changed:
Changes
MANIFEST
autoconf/config.h.in
autoconf/configure.in
configure
src/Makefile.in
src/command.C
src/fdpass.C [new file with mode: 0644]
src/fdpass.h [new file with mode: 0644]
src/init.C
src/rxvt.h
src/rxvtc.C
src/rxvtd.C

diff --git a/Changes b/Changes
index cb217ba459ffcf796fa33ae91d573036623570ab..2f9265a0b887d28da39e0d65f8a5d342b33b79fb 100644 (file)
--- 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:
index 01dfe5a548a3c32b05c96c9bc052e1937c073972..477042f692276bd1cf4b23c576ea2df4b17845c9 100644 (file)
--- 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
index d442d1aad442a317915bab320d2c3f8f732a4592..b90b4900687f628d8c045577d2d81207b49355f6 100644 (file)
 /* 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
 
index 53b6121d1df2e961a4e75c4be64448e950db0283..a2e96ea99973445c9277232b44655a3a612feca3 100644 (file)
@@ -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 <sys/types.h>
+#include <sys/socket.h>
+],[
+{
+  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 <X11/Xlib.h>
index 3018338f2937992af0922a52c4f9f4a16bf08533..c09fccd189dc4e93cf11bc2a04e05d0d8b6d281d 100755 (executable)
--- 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 <sys/types.h>
+#include <sys/socket.h>
+
+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
index 04bb1b4c12670823923e36c50273cf18e8519068..6a6de2d0b38ce2b6f143ec3af67bd843a4cfb5f1 100644 (file)
@@ -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
index 489e5a7387b430e717ca9d33ceb3289ddab4a2c1..76eb690c6641b5bb9ac480a3c18cc5a3234dd743 100644 (file)
@@ -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 (file)
index 0000000..d57282b
--- /dev/null
@@ -0,0 +1,105 @@
+/*--------------------------------*-C-*---------------------------------*
+ * File:       fdpass.C
+ *----------------------------------------------------------------------*
+ *
+ * All portions of code are copyright by their respective author/s.
+ * Copyright (c) 2005      Marc Lehmann <pcg@goof.com>
+ *
+ * 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 <sys/types.h>
+#include <sys/socket.h>
+
+#include "fdpass.h"
+
+#include <cstdio> //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 (file)
index 0000000..6b02c57
--- /dev/null
@@ -0,0 +1,31 @@
+/*--------------------------------*-C-*---------------------------------*
+ * File:       fdpass.h
+ *----------------------------------------------------------------------*
+ *
+ * All portions of code are copyright by their respective author/s.
+ * Copyright (c) 2005      Marc Lehmann <pcg@goof.com>
+ *
+ * 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
+
index 90d6a3eac65c708701c0b4d88584a149ddf2c847..70e1b905e95680892ef9d945e53fc784d168ead6 100644 (file)
@@ -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
index 15a5bd6a43546b393e5161ce66d8adb1fddab157..89c2a1b46481b7b07e39cd41e039cb917292ea8b 100644 (file)
@@ -961,6 +961,7 @@ enum {
 extern class rxvt_failure_exception { } rxvt_failure_exception;
 
 typedef callback1<void, const char *> log_callback;
+typedef callback1<int, int> 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
 
index ff9dbd0ed15ef0a52faf2e7cb8d0f46c709d98e2..e4d5db0e78af27e1af1476616ad137dc4772b510 100644 (file)
@@ -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;
       }
 
index 7bd89af580cd69d45f6228ef0cdf9b9e1a0bafd3..4a714e1b66c72a1725298cf204e4de4adf43af90 100644 (file)
@@ -23,6 +23,7 @@
 #include "../config.h"
 #include "rxvt.h"
 #include "rxvtdaemon.h"
+#include "fdpass.h"
 #include "iom.h"
 
 #include <cstdio>
@@ -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;