summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-07-10 09:10:05 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-07-10 09:10:05 +0000
commite5377fb3d709abd2d04ba8990e49dc31dc97302a (patch)
tree47264f35d4f4691f8431ee150d33b0841f336895
parent8e2071059fc32b1a9e399868f122d810deebe2b3 (diff)
Implement ~C.
-rw-r--r--usr.bin/cu/command.c55
-rw-r--r--usr.bin/cu/cu.112
2 files changed, 65 insertions, 2 deletions
diff --git a/usr.bin/cu/command.c b/usr.bin/cu/command.c
index a6d9b80b95d..7898d79c193 100644
--- a/usr.bin/cu/command.c
+++ b/usr.bin/cu/command.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: command.c,v 1.3 2012/07/10 08:42:43 nicm Exp $ */
+/* $OpenBSD: command.c,v 1.4 2012/07/10 09:10:04 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
@@ -33,6 +33,7 @@
#include "cu.h"
void pipe_command(void);
+void connect_command(void);
void send_file(void);
void
@@ -81,6 +82,54 @@ pipe_command(void)
}
void
+connect_command(void)
+{
+ const char *cmd;
+ pid_t pid;
+
+ /*
+ * Fork a program with:
+ * 0 <-> remote tty in
+ * 1 <-> remote tty out
+ * 2 <-> local tty stderr
+ */
+
+ cmd = get_input("Local command?");
+ if (cmd == NULL || *cmd == '\0')
+ return;
+
+ restore_termios();
+
+ switch (pid = fork()) {
+ case -1:
+ err(1, "fork");
+ case 0:
+ if (signal(SIGINT, SIG_DFL) == SIG_ERR)
+ _exit(1);
+ if (signal(SIGQUIT, SIG_DFL) == SIG_ERR)
+ _exit(1);
+
+ /* attach stdout and stdin to line */
+ if (dup2(line_fd, STDOUT_FILENO) == -1)
+ _exit(1);
+ if (dup2(line_fd, STDIN_FILENO) == -1)
+ _exit(1);
+
+ if (closefrom(STDOUT_FILENO + 1) != 0)
+ _exit(1);
+
+ execl(_PATH_BSHELL, "sh", "-c", cmd, (void*)NULL);
+ _exit(1);
+ default:
+ while (waitpid(pid, NULL, 0) == -1 && errno == EINTR)
+ /* nothing */;
+ break;
+ }
+
+ set_termios();
+}
+
+void
send_file(void)
{
const char *file;
@@ -141,6 +190,9 @@ do_command(char c)
kill(getpid(), SIGTSTP);
set_termios();
break;
+ case 'C':
+ connect_command();
+ break;
case 'S':
set_speed();
break;
@@ -160,6 +212,7 @@ do_command(char c)
"~# send break\r\n"
"~$ pipe local command to remote host\r\n"
"~> send file to remote host\r\n"
+ "~C connect program to remote host\r\n"
"~S set speed\r\n"
"~? get this summary\r\n"
);
diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1
index 80b9fd29f22..edf1bb4e549 100644
--- a/usr.bin/cu/cu.1
+++ b/usr.bin/cu/cu.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cu.1,v 1.2 2012/07/10 08:16:27 nicm Exp $
+.\" $OpenBSD: cu.1,v 1.3 2012/07/10 09:10:04 nicm Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -113,6 +113,16 @@ to the remote system.
Stop
.Nm
(only available with job control).
+.It Ic ~C
+Fork a child process on the local system to perform special protocols
+such as XMODEM.
+The child program will be run with the following arrangement of
+file descriptors:
+.Bd -literal -offset indent
+0 \*(Lt-\*(Gt remote tty in
+1 \*(Lt-\*(Gt remote tty out
+2 \*(Lt-\*(Gt local tty stderr
+.Ed
.It Ic ~S
Change the speed of the connection.
.It Ic ~?