From: root Date: Thu, 17 Feb 2005 15:07:48 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=84e1f74f68dd2f107a5739aa1e60cb4bfd476e2e;p=dana%2Furxvt.git *** empty log message *** --- diff --git a/Changes b/Changes index d1805074..0d269531 100644 --- 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, diff --git a/MANIFEST b/MANIFEST index 30d29429..17cd0d13 100644 --- 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 index 00000000..f535f8d0 --- /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 index 00000000..4d0812ce --- /dev/null +++ b/doc/pty-fd @@ -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: $_"; +} + diff --git a/doc/rxvt.1.html b/doc/rxvt.1.html index c2daeda9..e551da5f 100644 --- a/doc/rxvt.1.html +++ b/doc/rxvt.1.html @@ -513,13 +513,13 @@ 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, @@ -541,6 +541,59 @@ can use file descriptors to communicate with the programs within the 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" }
+

diff --git a/doc/rxvt.1.man.in b/doc/rxvt.1.man.in index 865988fb..1c654922 100644 --- a/doc/rxvt.1.man.in +++ b/doc/rxvt.1.man.in @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .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 diff --git a/doc/rxvt.1.pod b/doc/rxvt.1.pod index 0b116ac8..1035bc53 100644 --- a/doc/rxvt.1.pod +++ b/doc/rxvt.1.pod @@ -370,11 +370,11 @@ B. Turn on/off secondary screen scroll (default enabled); resource B. -=item B<-keysym.>I: I +=item B<-keysym.>I I Remap a key symbol. See resource B. -=item B<-embed>: I +=item B<-embed> I 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): + + 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 + +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): + + 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) diff --git a/doc/rxvt.1.txt b/doc/rxvt.1.txt index 95ce1b5e..bfd8a7d7 100644 --- a/doc/rxvt.1.txt +++ b/doc/rxvt.1.txt @@ -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. diff --git a/src/command.C b/src/command.C index 67d2415c..2b71770c 100644 --- a/src/command.C +++ b/src/command.C @@ -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); } diff --git a/src/init.C b/src/init.C index 739b075f..749b339e 100644 --- a/src/init.C +++ b/src/init.C @@ -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 (); diff --git a/src/logging.C b/src/logging.C index e8606954..215dc668 100644 --- a/src/logging.C +++ b/src/logging.C @@ -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 */ diff --git a/src/main.C b/src/main.C index 1e54a03e..eebe70b3 100644 --- a/src/main.C +++ b/src/main.C @@ -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 } diff --git a/src/ptytty.C b/src/ptytty.C index 93a57388..3cf50424 100644 --- a/src/ptytty.C +++ b/src/ptytty.C @@ -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 diff --git a/src/rxvt.h b/src/rxvt.h index b93ed342..f68138dc 100644 --- a/src/rxvt.h +++ b/src/rxvt.h @@ -611,6 +611,7 @@ enum { Rs_borderLess, Rs_lineSpace, Rs_embed, + Rs_pty_fd, #endif Rs_cutchars, Rs_modifier, diff --git a/src/xdefaults.C b/src/xdefaults.C index d6c16aba..8c7d2b99 100644 --- a/src/xdefaults.C +++ b/src/xdefaults.C @@ -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),