aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rtty.159
-rw-r--r--rtty.c35
2 files changed, 51 insertions, 43 deletions
diff --git a/rtty.1 b/rtty.1
index d8a01eb..926e977 100644
--- a/rtty.1
+++ b/rtty.1
@@ -6,38 +6,40 @@
.Nd limited but responsive remote shell
.Sh SYNOPSIS
.Nm
-.Op Sy +dp
+.Op Sy +dpx
.Op Ar ...
.Sh DESCRIPTION
.Pp
.Nm
is a wrapper around
-.Xr ssh 1
-that provides a remote shell as responsive as
-.Xr mosh 1
-and as limited as a hard-copy teletypewriter.
+.Xr ssh 1 ,
+providing a line-based remote shell.
It is a very useful tool on slow connections.
-As
+.Pp
.Nm
-uses the default line-editing capabilities of the terminal,
-user input is only sent to the remote server
+uses the default line-editing capabilities of the terminal.
+User input is only sent to the remote server
once a full line has been input.
+As such, input is as responsive as on the local machine.
+The session can be killed by sending a QUIT signal (C-/).
.Pp
Flags specific to
.Nm
-are prefixed with a plus sign.
-If the
-.Sy +d
-flag is provided,
-.Nm
-disables all heuristics to detect password prompts
+are prefixed with a plus sign:
+.Bl -tag -width xx -offset indent
+.It Sy +d
+Disables all heuristics to detect password prompts
from the remote server and hide the user's input,
which are enabled by default.
-If the
-.Sy +p
-flag is provided,
+.It Sy +h
+Makes
.Nm
-manually asks the user for a password
+identify as a hard-copy terminal,
+preventing visual programs such as
+.Xr vi 1
+from running.
+.It Sy +p
+Manually asks the user for a password
before connecting to the server.
This requires
.Xr sshpass 1
@@ -47,19 +49,24 @@ Without the
flag,
.Xr ssh 1
is launched in batch mode.
+.It Sy +x
+Enables escaped commands beginning with
+.Ql \&! ,
+like
+.Ql "!vi mbox" .
+An escaped command runs on the local system,
+but operates on a remote file,
+which is downloaded and re-uploaded with
+.Xr scp 1 .
+.El
.Pp
-All other arguments
+All remaining arguments
are passed to
.Xr ssh 1 .
+.Sh SEE ALSO
+.Xr dtach 1
.Sh AUTHORS
.Pp
.Nm
is written by John Ankarström
.Aq Mt "john (at) ankarstrom.se" .
-.Sh CAVEATS
-.Pp
-.Nm
-exits immediately on SIGINT;
-it is best used in conjunction with
-.Xr dtach 1
-on the remote server.
diff --git a/rtty.c b/rtty.c
index 12a9350..a555e2c 100644
--- a/rtty.c
+++ b/rtty.c
@@ -11,15 +11,16 @@
#include <termios.h>
#include <unistd.h>
-#define INIT "export TERM=tty43 EDITOR=ed PAGER='pr -ptl22'\n"
+#define INIT "export EDITOR=ed PAGER=ul\n"
+#define HINIT "export TERM=tty43 EDITOR=ed PAGER=cat\n"
#define MAXBUF 2048
#define MAXEARG 32
#define MAXWD 255
char *getpw(char *);
-void noop(int);
-void killall(int);
+void killall();
+void noop();
int
main(int argc, char *argv[])
@@ -28,10 +29,12 @@ main(int argc, char *argv[])
*eargv[MAXEARG], in[30], **nargv, out[30], *p, pw[255], *q,
wd[MAXWD];
fd_set rfds0, rfds1;
- int child, dumb, escape, fdin, fdout, i, n, offset, s, sshpass;
+ int child, dumb, escape, fdin, fdout, hardcopy, i, n, offset, s,
+ sshpass;
struct timeval tv;
- signal(SIGINT, killall);
+ signal(SIGINT, noop);
+ signal(SIGQUIT, killall);
signal(SIGCHLD, killall);
/* Create named pipes. */
@@ -42,9 +45,10 @@ main(int argc, char *argv[])
err(1, "mkfifo");
/* Process rtty-specific flags. */
- escape = dumb = sshpass = 0;
+ escape = dumb = hardcopy = sshpass = 0;
for(;argv[1][0] == '+';){
if(strchr(argv[1], 'd')) dumb = 1;
+ if(strchr(argv[1], 'h')) hardcopy = 1;
if(strchr(argv[1], 'x')) escape = 1;
if(strchr(argv[1], 'p')) sshpass = 1;
@@ -111,7 +115,10 @@ main(int argc, char *argv[])
err(1, "open");
/* Print initialization command. */
- dprintf(fdin, INIT);
+ if(hardcopy)
+ dprintf(fdin, HINIT);
+ else
+ dprintf(fdin, INIT);
FD_ZERO(&rfds0);
FD_ZERO(&rfds1);
@@ -198,17 +205,16 @@ found:
err(1, "malloc");
if(eargv[i][0] == '/'){
sprintf(p, "%s:%s", address, eargv[i]);
- eargv[i]++;
}else
sprintf(p, "%s:%s/%s", address, wd, eargv[i]);
+ q = strrchr(eargv[i], '/');
+ if(q) eargv[i] = q+1;
/*
* During the execution of the external commands,
- * the SIGCHLD handler is temporarily disabled
- * and the SIGINT handler is set to do nothing.
+ * the SIGCHLD handler is temporarily disabled.
*/
signal(SIGCHLD, NULL);
- signal(SIGINT, noop);
/* Download file. */
if((child = fork()) == 0){
@@ -254,7 +260,6 @@ found:
/* Clean up. */
done:
- signal(SIGINT, killall);
signal(SIGCHLD, killall);
free(p);
@@ -354,12 +359,8 @@ getpw(char *pw)
}
void
-noop(int s)
+noop()
{
- /*
- * This handler is active in the parent when an escaped command
- * is running. SIGINTs should not affect the parent in any way.
- */
}
void