From: nicm Date: Mon, 18 May 2015 09:35:05 +0000 (+0000) Subject: Add -d flag and dc capability to open devices non-blocking, used for the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=50866e703a3338d2d43118daf6189dc6a50ce6b4;p=openbsd Add -d flag and dc capability to open devices non-blocking, used for the few drivers that do not support cua* so tty* must be used. ok miod millert --- diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1 index 0535ed81ace..2f1a3c836c6 100644 --- a/usr.bin/cu/cu.1 +++ b/usr.bin/cu/cu.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cu.1,v 1.14 2015/04/24 18:06:31 deraadt Exp $ +.\" $OpenBSD: cu.1,v 1.15 2015/05/18 09:35:05 nicm Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: April 24 2015 $ +.Dd $Mdocdate: May 18 2015 $ .Dt CU 1 .Os .Sh NAME @@ -35,6 +35,7 @@ .Nd serial terminal emulator .Sh SYNOPSIS .Nm +.Op Fl d .Op Fl l Ar line .Op Fl s Ar speed | Fl Ar speed .Nm @@ -50,6 +51,10 @@ debugging purposes. .Pp The options are as follows: .Bl -tag -width 4n +.It Fl d +Specify that the line is directly connected and +.Nm +should not allow the driver to block waiting for a carrier to be detected. .It Fl l Ar line Specify the line to use. Either of the forms like @@ -79,6 +84,7 @@ is given, uses the .Xr remote 5 database to retrieve the +.Sy dc Pq directly connected , .Sy dv Pq device and .Sy br Pq baud rate diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c index 52e2f94f357..ac8ddae2d7a 100644 --- a/usr.bin/cu/cu.c +++ b/usr.bin/cu/cu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cu.c,v 1.21 2015/02/08 17:33:35 nicm Exp $ */ +/* $OpenBSD: cu.c,v 1.22 2015/05/18 09:35:05 nicm Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott @@ -41,6 +41,7 @@ FILE *record_file; struct termios saved_tio; struct bufferevent *input_ev; struct bufferevent *output_ev; +int is_direct = -1; const char *line_path = NULL; int line_speed = -1; int line_fd; @@ -65,7 +66,7 @@ void try_remote(const char *, const char *, const char *); __dead void usage(void) { - fprintf(stderr, "usage: %s [-l line] [-s speed | -speed]\n", + fprintf(stderr, "usage: %s [-d] [-l line] [-s speed | -speed]\n", __progname); fprintf(stderr, " %s [host]\n", __progname); exit(1); @@ -76,7 +77,7 @@ main(int argc, char **argv) { const char *errstr; char *tmp, *s, *host; - int opt, i; + int opt, i, flags; if (isatty(STDIN_FILENO) && tcgetattr(STDIN_FILENO, &saved_tio) != 0) err(1, "tcgetattr"); @@ -95,8 +96,11 @@ main(int argc, char **argv) errx(1, "speed asprintf"); } - while ((opt = getopt(argc, argv, "l:s:")) != -1) { + while ((opt = getopt(argc, argv, "dl:s:")) != -1) { switch (opt) { + case 'd': + is_direct = 1; + break; case 'l': line_path = optarg; break; @@ -114,7 +118,7 @@ main(int argc, char **argv) if (argc != 0 && argc != 1) usage(); - if (line_path != NULL || line_speed != -1) { + if (line_path != NULL || line_speed != -1 || is_direct != -1) { if (argc != 0) usage(); } else { @@ -139,6 +143,8 @@ main(int argc, char **argv) line_path = "/dev/cua00"; if (line_speed == -1) line_speed = 9600; + if (is_direct == -1) + is_direct = 0; if (strchr(line_path, '/') == NULL) { if (asprintf(&tmp, "%s%s", _PATH_DEV, line_path) == -1) @@ -146,7 +152,10 @@ main(int argc, char **argv) line_path = tmp; } - line_fd = open(line_path, O_RDWR); + flags = O_RDWR; + if (is_direct) + flags |= O_NONBLOCK; + line_fd = open(line_path, flags); if (line_fd < 0) err(1, "open(\"%s\")", line_path); if (ioctl(line_fd, TIOCEXCL) != 0) @@ -347,6 +356,9 @@ try_remote(const char *host, const char *path, const char *entry) } } + if (is_direct == -1 && cgetcap(cp, "dc", ':') != NULL) + is_direct = 1; + if (line_path == NULL && cgetstr(cp, "dv", &s) >= 0) line_path = s;