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:
src/command.h
src/encoding.C
src/encoding.h
+src/fdpass.h
+src/fdpass.C
src/feature.h
src/init.C
src/init.h
/* 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
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>
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
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
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
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;
}
--- /dev/null
+/*--------------------------------*-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
+
--- /dev/null
+/*--------------------------------*-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
+
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
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, ...);
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
#include "../config.h"
#include "rxvtdaemon.h"
+#include "fdpass.h"
#include "rxvt.h"
c.send ("END");
auto_str tok;
+ int cint;
for (;;)
if (!c.recv (tok))
}
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;
}
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;
}
#include "../config.h"
#include "rxvt.h"
#include "rxvtdaemon.h"
+#include "fdpass.h"
#include "iom.h"
#include <cstdio>
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);
}
}
+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);
rxvt_term *term = new rxvt_term;
term->log_hook = &log_cb;
+ term->getfd_hook = &getfd_cb;
term->argv = argv;
term->envv = envv;