*** empty log message ***
authorroot <root>
Thu, 17 Feb 2005 15:07:48 +0000 (15:07 +0000)
committerroot <root>
Thu, 17 Feb 2005 15:07:48 +0000 (15:07 +0000)
15 files changed:
Changes
MANIFEST
doc/embed [new file with mode: 0755]
doc/pty-fd [new file with mode: 0755]
doc/rxvt.1.html
doc/rxvt.1.man.in
doc/rxvt.1.pod
doc/rxvt.1.txt
src/command.C
src/init.C
src/logging.C
src/main.C
src/ptytty.C
src/rxvt.h
src/xdefaults.C

diff --git a/Changes b/Changes
index d1805074335c19a1281b2ac3f67959a316bc3e59..0d26953146170ed93a601ad409ba497a2978bf8d 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,4 +1,3 @@
-TODO: switch default keypad mode to cope for broken apps.
 TODO: manpage 900mb update
 TODO: safer command: keymap processing.
 TODO: "slow" rendering mode for bidi and scripts
@@ -13,6 +12,9 @@ WISH: tabbed windows (hey, just use screen...)
 WISH: just for fun, do shade and tint with XRender.
 
 5.2
+       - new option -pty-fd that makes the terminal a slave
+          that uses an existing pty for I/O instead of starting
+          a command.
         - SYNCCVS. backported bugfixes done to rxvt
           (sourceforge bugs #1028739, #1028732), except for
           pts/%s fix as it seems to collide with freebsd,
index 30d294299cdbd7f016bce503c0fd9c808a9d0604..17cd0d136fb24f4a4f11b2d54d55f5e35d24f4c9 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -10,6 +10,8 @@ configure
 reconf
 genac
 
+doc/embed
+doc/pty-fd
 doc/etc/rxvt-unicode.terminfo
 doc/etc/rxvt-unicode.termcap
 doc/menu/example.menu
diff --git a/doc/embed b/doc/embed
new file mode 100755 (executable)
index 0000000..f535f8d
--- /dev/null
+++ b/doc/embed
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+# embed a rxvt inside another X app
+# see also pty-fd
+
+# doesn't handle sigchld
+
+use Gtk2;
+
+init Gtk2;
+
+my $window = new Gtk2::Window 'toplevel';
+
+my $frame = new Gtk2::Frame "embedded rxvt-unicode terminal";
+
+$window->add ($frame);
+
+my $rxvt = new Gtk2::DrawingArea;
+$frame->add ($rxvt);
+$frame->set_size_request (700, 400);
+$window->show_all;
+my $xid = $rxvt->window->get_xid;
+
+system "rxvt -embed $xid &";
+
+$window->show_all;
+
+main Gtk2;
diff --git a/doc/pty-fd b/doc/pty-fd
new file mode 100755 (executable)
index 0000000..4d0812c
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use IO::Pty;
+use Fcntl;
+
+my $pty = new IO::Pty;
+fcntl $pty, F_SETFD, 0; # clear close-on-exec
+
+system "rxvt -pty-fd " . (fileno $pty) . "&";
+
+# now communicate with rxvt
+my $slave = $pty->slave;
+
+print $slave "hi! please enter something and press return (ctrl-d to exit):\n";
+
+while (<$slave>) {
+   print $slave "you entered: $_";
+}
+
index c2daeda9f449877b35469af1f781189163e2daa2..e551da5f265776d569835afe872d93ce1c0de403 100644 (file)
@@ -513,13 +513,13 @@ Turn on/off secondary screen scroll (default enabled); resource
 <strong>secondaryScroll</strong>.
 </dd>
 <p></p>
-<dt><strong><a name="item__2dkeysym_2esym_3a_string"><strong>-keysym.</strong><em>sym</em>: <em>string</em></a></strong><br />
+<dt><strong><a name="item__2dkeysym_2esym_string"><strong>-keysym.</strong><em>sym</em> <em>string</em></a></strong><br />
 </dt>
 <dd>
 Remap a key symbol. See resource <strong>keysym</strong>.
 </dd>
 <p></p>
-<dt><strong><a name="item__2dembed_3a_windowid"><strong>-embed</strong>: <em>windowid</em></a></strong><br />
+<dt><strong><a name="item__2dembed_windowid"><strong>-embed</strong> <em>windowid</em></a></strong><br />
 </dt>
 <dd>
 Tells rxvt to embed it's windows into an already-existing window,
@@ -541,6 +541,59 @@ can use file descriptors to communicate with the programs within the
 terminal. This works regardless of wether the <code>-embed</code> option was used or
 not.</p>
 </dd>
+<dd>
+<p>Here is a short Gtk2-perl snippet that illustrates how this option can be
+used (a longer example is in <em>doc/embed</em>):</p>
+</dd>
+<dd>
+<pre>
+   my $rxvt = new Gtk2::DrawingArea;
+   $...-&gt;add ($rxvt); # important to add it somewhere first
+   $rxvt-&gt;realize; # now it can be realized
+   my $xid = $rxvt-&gt;window-&gt;get_xid;</pre>
+</dd>
+<dd>
+<pre>
+   system &quot;rxvt -embed $xid &amp;&quot;;</pre>
+</dd>
+<p></p>
+<dt><strong><a name="item__2dpty_2dfd_fileno"><strong>-pty-fd</strong> <em>fileno</em></a></strong><br />
+</dt>
+<dd>
+Tells rxvt NOT to execute any commands or create a new pty/tty
+pair but instead use the given filehandle as the tty master. This is
+useful if you want to drive rxvt as a generic terminal emulator
+without having to run a program within it.
+</dd>
+<dd>
+<p>If this switch is given, rxvt will not create any utmp/wtmp
+entries and will not tinker with pty/tty permissions - you have to do that
+yourself if you want that.</p>
+</dd>
+<dd>
+<p>Here is a example in perl that illustrates how this option can be used (a
+longer example is in <em>doc/pty-fd</em>):</p>
+</dd>
+<dd>
+<pre>
+   use IO::Pty;
+   use Fcntl;</pre>
+</dd>
+<dd>
+<pre>
+   my $pty = new IO::Pty;
+   fcntl $pty, F_SETFD, 0; # clear close-on-exec</pre>
+</dd>
+<dd>
+<pre>
+   system &quot;rxvt -pty-fd &quot; . (fileno $pty) . &quot;&amp;&quot;;</pre>
+</dd>
+<dd>
+<pre>
+   # now communicate with rxvt
+   my $slave = $pty-&gt;slave;
+   while (&lt;$slave&gt;) { print $slave &quot;got &lt;$_&gt;\n&quot; }</pre>
+</dd>
 <p></p></dl>
 <p>
 </p>
index 865988fbf84853d6d86d60bedb207d6322b95824..1c6549227b5c064339847662c9446bde76360b36 100644 (file)
 .\" ========================================================================
 .\"
 .IX Title "rxvt 1"
-.TH rxvt 1 "2005-02-16" "5.2" "RXVT-UNICODE"
+.TH rxvt 1 "2005-02-17" "5.2" "RXVT-UNICODE"
 .SH "NAME"
 rxvt\-unicode (ouR XVT, unicode) \- (a VT102 emulator for the X window system)
 .SH "SYNOPSIS"
@@ -443,11 +443,11 @@ Turn on/off secondary screen (default enabled); resource
 .IX Item "-ssr|+ssr"
 Turn on/off secondary screen scroll (default enabled); resource
 \&\fBsecondaryScroll\fR.
-.IP "\fB\-keysym.\fR\fIsym\fR: \fIstring\fR" 4
-.IX Item "-keysym.sym: string"
+.IP "\fB\-keysym.\fR\fIsym\fR \fIstring\fR" 4
+.IX Item "-keysym.sym string"
 Remap a key symbol. See resource \fBkeysym\fR.
-.IP "\fB\-embed\fR: \fIwindowid\fR" 4
-.IX Item "-embed: windowid"
+.IP "\fB\-embed\fR \fIwindowid\fR" 4
+.IX Item "-embed windowid"
 Tells @@RXVT_NAME@@ to embed it's windows into an already-existing window,
 which enables applications to easily embed a terminal.
 .Sp
@@ -463,6 +463,53 @@ descriptors passed to it (except for stdin/out/err, of course), so you
 can use file descriptors to communicate with the programs within the
 terminal. This works regardless of wether the \f(CW\*(C`\-embed\*(C'\fR option was used or
 not.
+.Sp
+Here is a short Gtk2\-perl snippet that illustrates how this option can be
+used (a longer example is in \fIdoc/embed\fR):
+.Sp
+.Vb 4
+\&   my $rxvt = new Gtk2::DrawingArea;
+\&   $...->add ($rxvt); # important to add it somewhere first
+\&   $rxvt->realize; # now it can be realized
+\&   my $xid = $rxvt->window->get_xid;
+.Ve
+.Sp
+.Vb 1
+\&   system "@@RXVT_NAME@@ -embed $xid &";
+.Ve
+.IP "\fB\-pty\-fd\fR \fIfileno\fR" 4
+.IX Item "-pty-fd fileno"
+Tells @@RXVT_NAME@@ \s-1NOT\s0 to execute any commands or create a new pty/tty
+pair but instead use the given filehandle as the tty master. This is
+useful if you want to drive @@RXVT_NAME@@ as a generic terminal emulator
+without having to run a program within it.
+.Sp
+If this switch is given, @@RXVT_NAME@@ will not create any utmp/wtmp
+entries and will not tinker with pty/tty permissions \- you have to do that
+yourself if you want that.
+.Sp
+Here is a example in perl that illustrates how this option can be used (a
+longer example is in \fIdoc/pty\-fd\fR):
+.Sp
+.Vb 2
+\&   use IO::Pty;
+\&   use Fcntl;
+.Ve
+.Sp
+.Vb 2
+\&   my $pty = new IO::Pty;
+\&   fcntl $pty, F_SETFD, 0; # clear close-on-exec
+.Ve
+.Sp
+.Vb 1
+\&   system "@@RXVT_NAME@@ -pty-fd " . (fileno $pty) . "&";
+.Ve
+.Sp
+.Vb 3
+\&   # now communicate with rxvt
+\&   my $slave = $pty->slave;
+\&   while (<$slave>) { print $slave "got <$_>\en" }
+.Ve
 .SH "RESOURCES (available also as long\-options)"
 .IX Header "RESOURCES (available also as long-options)"
 Note: `@@RXVT_NAME@@ \-\-help' gives a list of all resources (long
index 0b116ac8e963efd08685da6e63e4c9880f2d0193..1035bc539027922bc37a8a544fcd2c3f3dcc6f17 100644 (file)
@@ -370,11 +370,11 @@ B<secondaryScreen>.
 Turn on/off secondary screen scroll (default enabled); resource
 B<secondaryScroll>.
 
-=item B<-keysym.>I<sym>: I<string>
+=item B<-keysym.>I<sym> I<string>
 
 Remap a key symbol. See resource B<keysym>.
 
-=item B<-embed>: I<windowid>
+=item B<-embed> I<windowid>
 
 Tells @@RXVT_NAME@@ to embed it's windows into an already-existing window,
 which enables applications to easily embed a terminal.
@@ -392,6 +392,42 @@ can use file descriptors to communicate with the programs within the
 terminal. This works regardless of wether the C<-embed> option was used or
 not.
 
+Here is a short Gtk2-perl snippet that illustrates how this option can be
+used (a longer example is in F<doc/embed>):
+
+   my $rxvt = new Gtk2::DrawingArea;
+   $...->add ($rxvt); # important to add it somewhere first
+   $rxvt->realize; # now it can be realized
+   my $xid = $rxvt->window->get_xid;
+
+   system "@@RXVT_NAME@@ -embed $xid &";
+
+=item B<-pty-fd> I<fileno>
+
+Tells @@RXVT_NAME@@ NOT to execute any commands or create a new pty/tty
+pair but instead use the given filehandle as the tty master. This is
+useful if you want to drive @@RXVT_NAME@@ as a generic terminal emulator
+without having to run a program within it.
+
+If this switch is given, @@RXVT_NAME@@ will not create any utmp/wtmp
+entries and will not tinker with pty/tty permissions - you have to do that
+yourself if you want that.
+
+Here is a example in perl that illustrates how this option can be used (a
+longer example is in F<doc/pty-fd>):
+
+   use IO::Pty;
+   use Fcntl;
+
+   my $pty = new IO::Pty;
+   fcntl $pty, F_SETFD, 0; # clear close-on-exec
+
+   system "@@RXVT_NAME@@ -pty-fd " . (fileno $pty) . "&";
+
+   # now communicate with rxvt
+   my $slave = $pty->slave;
+   while (<$slave>) { print $slave "got <$_>\n" }
+
 =back
 
 =head1 RESOURCES (available also as long-options)
index 95ce1b5e64548a9f950bc4399af444f5648e3360..bfd8a7d757ab881badc194fee58f3bfd06480af6 100644 (file)
@@ -313,10 +313,10 @@ OPTIONS
         Turn on/off secondary screen scroll (default enabled); resource
         secondaryScroll.
 
-    -keysym.*sym*: *string*
+    -keysym.*sym* *string*
         Remap a key symbol. See resource keysym.
 
-    -embed: *windowid*
+    -embed *windowid*
         Tells rxvt to embed it's windows into an already-existing window,
         which enables applications to easily embed a terminal.
 
@@ -333,6 +333,41 @@ OPTIONS
         terminal. This works regardless of wether the "-embed" option was
         used or not.
 
+        Here is a short Gtk2-perl snippet that illustrates how this option
+        can be used (a longer example is in doc/embed):
+
+           my $rxvt = new Gtk2::DrawingArea;
+           $...->add ($rxvt); # important to add it somewhere first
+           $rxvt->realize; # now it can be realized
+           my $xid = $rxvt->window->get_xid;
+
+           system "rxvt -embed $xid &";
+
+    -pty-fd *fileno*
+        Tells rxvt NOT to execute any commands or create a new pty/tty pair
+        but instead use the given filehandle as the tty master. This is
+        useful if you want to drive rxvt as a generic terminal emulator
+        without having to run a program within it.
+
+        If this switch is given, rxvt will not create any utmp/wtmp entries
+        and will not tinker with pty/tty permissions - you have to do that
+        yourself if you want that.
+
+        Here is a example in perl that illustrates how this option can be
+        used (a longer example is in doc/pty-fd):
+
+           use IO::Pty;
+           use Fcntl;
+
+           my $pty = new IO::Pty;
+           fcntl $pty, F_SETFD, 0; # clear close-on-exec
+
+           system "rxvt -pty-fd " . (fileno $pty) . "&";
+
+           # now communicate with rxvt
+           my $slave = $pty->slave;
+           while (<$slave>) { print $slave "got <$_>\n" }
+
 RESOURCES (available also as long-options)
     Note: `rxvt --help' gives a list of all resources (long options)
     compiled into your version.
index 67d2415cfec9ee8064a40bd054d454d6e827f9ce..2b71770ca444ff13a1cb54fb3df9b313aaaaecdc 100644 (file)
@@ -2604,7 +2604,7 @@ rxvt_term::cmd_parse ()
               // unfortunately other programs are even more buggy and dislike
               // being sent SIGWINCH, so only do it when we were in fact being
               // resized.
-              if (seen_resize)
+              if (seen_resize && cmd_pid)
                 kill (-cmd_pid, SIGWINCH);
             }
 
index 739b075f01baff2d455c696e195f8c0e9563dcbf..749b339e181b09417ca62c361684252e3d52b36d 100644 (file)
@@ -227,8 +227,6 @@ rxvt_term::init_vars ()
   MEvent.button = AnyButton;
   options = DEFAULT_OPTIONS;
   want_refresh = 1;
-  cmd_pid = -1;
-  pty.pty = pty.tty = -1;
   priv_modes = SavedModes = PrivMode_Default;
   TermWin.focus = 0;
   TermWin.ncol = 80;
@@ -675,6 +673,7 @@ rxvt_term::init_command (const char *const *argv)
       priv_modes |= PrivMode_scrollBar;
       SavedModes |= PrivMode_scrollBar;
     }
+
   if (menubar_visible ())
     {
       priv_modes |= PrivMode_menuBar;
@@ -1419,8 +1418,16 @@ rxvt_get_ttymode (ttymode_t *tio, int erase)
 void
 rxvt_term::run_command (const char *const *argv)
 {
-  if (!pty.get ())
-    rxvt_fatal ("can't initialize pseudo-tty, aborting.\n");
+#if ENABLE_FRILLS
+  if (rs[Rs_pty_fd])
+    {
+      pty.pty = atoi (rs[Rs_pty_fd]);
+      fcntl (pty.pty, F_SETFL, O_NONBLOCK);
+    }
+  else
+#endif
+    if (!pty.get ())
+      rxvt_fatal ("can't initialize pseudo-tty, aborting.\n");
 
   pty.set_utf8_mode (enc_utf8);
 
@@ -1440,6 +1447,11 @@ rxvt_term::run_command (const char *const *argv)
 
   rxvt_get_ttymode (&tio, er);
 
+#if ENABLE_FRILLS
+  if (rs[Rs_pty_fd])
+    return;
+#endif
+
   sw_chld.start (SIGCHLD);
 
 #ifndef __QNX__
@@ -1447,7 +1459,10 @@ rxvt_term::run_command (const char *const *argv)
   switch (cmd_pid = fork ())
     {
       case -1:
-        rxvt_fatal ("can't fork, aborting.\n");
+        {
+          cmd_pid = 0;
+          rxvt_fatal ("can't fork, aborting.\n");
+        }
       case 0:
         init_env ();
 
index e8606954b00750c04a4900ee164f46d2542dccab..215dc668af361ccc70e7d8ef4f559668bdd7cd69 100644 (file)
@@ -75,7 +75,7 @@ rxvt_term::makeutent (const char *pty, const char *hostname)
 #ifdef HAVE_UTMP_PID
   int i;
 #endif
-  struct passwd  *pwent = getpwuid (getuid ());
+  struct passwd *pwent = getpwuid (getuid ());
 
   if (!strncmp (pty, "/dev/", 5))
     pty += 5;          /* skip /dev/ prefix */
index 1e54a03efc5b3a2a13804e5066adb2c78789c9dd..eebe70b382fe4d17552f6ec0eab6bf13e41cba77 100644 (file)
@@ -847,7 +847,7 @@ rxvt_term::tt_winch ()
 #if 0
   // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
   if (cmd_pid)               /* force through to the command */
-    kill (cmd_pid, SIGWINCH);
+    kill (-cmd_pid, SIGWINCH);
 #endif
 }
 
index 93a57388bfb1491caab8fdc654387abdd190dbb1..3cf50424f51651c2770e112e5b0eefdb91e8c6f7 100644 (file)
@@ -336,6 +336,9 @@ static struct ttyconf {
 void
 rxvt_ptytty::privileges (rxvt_privaction action)
 {
+  if (tty < 0)
+    return;
+
   rxvt_privileges (RESTORE);
 
   if (action == SAVE)
@@ -347,14 +350,12 @@ rxvt_ptytty::privileges (rxvt_privaction action)
         ;//next_tty_action = IGNORE;
       else
 # endif
-
         {
           chown (name, getuid (), ttyconf.gid);      /* fail silently */
           chmod (name, ttyconf.mode);
 # ifdef HAVE_REVOKE
           revoke (name);
 # endif
-
         }
     }
   else
index b93ed3427c444595c0996a972f714136fe6bcc0f..f68138dc06c329cabbc33131f45d5563480b2053 100644 (file)
@@ -611,6 +611,7 @@ enum {
   Rs_borderLess,
   Rs_lineSpace,
   Rs_embed,
+  Rs_pty_fd,
 #endif
   Rs_cutchars,
   Rs_modifier,
index d6c16abaf49b8d74cfa1a7a9c5d1f4b2c65f8d61..8c7d2b992c96a519faf1e2f7b6222a67a0278208 100644 (file)
@@ -220,6 +220,7 @@ optList[] = {
               STRG (Rs_saveLines, "saveLines", "sl", "number", "number of scrolled lines to save"),
 #if ENABLE_FRILLS
               STRG (Rs_embed, NULL, "embed", "windowid", "window id to embed terminal in"),
+              STRG (Rs_pty_fd, NULL, "pty-fd", "fileno", "file descriptor of pty to use"),
               STRG (Rs_ext_bwidth, "externalBorder", "w", "number", "external border in pixels"),
               STRG (Rs_ext_bwidth, NULL, "bw", NULL, NULL),
               STRG (Rs_ext_bwidth, NULL, "borderwidth", NULL, NULL),