summaryrefslogtreecommitdiff
path: root/usr.bin/cu/cu.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-10-05 23:15:32 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-10-05 23:15:32 +0000
commit2d92ba262b738383c5c5e36b29be9ddc4825e301 (patch)
treebca91fc3e82cff7d92b9a26d5188146337576edc /usr.bin/cu/cu.c
parentefcc57aee02bbe160b6270134845accf59a00550 (diff)
Set the line file descriptor nonblocking and make it blocking again for
xmodem and child processes, makes xmodem work with -d. Reported by Kim Zeitler via guenther@, tested by Jiri B. ok (and a small change) guenther
Diffstat (limited to 'usr.bin/cu/cu.c')
-rw-r--r--usr.bin/cu/cu.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c
index ac8ddae2d7a..8bb812a169a 100644
--- a/usr.bin/cu/cu.c
+++ b/usr.bin/cu/cu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cu.c,v 1.22 2015/05/18 09:35:05 nicm Exp $ */
+/* $OpenBSD: cu.c,v 1.23 2015/10/05 23:15:31 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
@@ -186,6 +186,7 @@ main(int argc, char **argv)
NULL);
bufferevent_enable(output_ev, EV_WRITE);
+ set_blocking(line_fd, 0);
line_ev = bufferevent_new(line_fd, line_read, NULL, line_error,
NULL);
bufferevent_enable(line_ev, EV_READ|EV_WRITE);
@@ -209,6 +210,21 @@ signal_event(int fd, short events, void *data)
}
void
+set_blocking(int fd, int state)
+{
+ int mode;
+
+ state = state ? 0 : O_NONBLOCK;
+ if ((mode = fcntl(fd, F_GETFL)) == -1)
+ cu_err(1, "fcntl");
+ if ((mode & O_NONBLOCK) != state) {
+ mode = (mode & ~O_NONBLOCK) | state;
+ if (fcntl(fd, F_SETFL, mode) == -1)
+ cu_err(1, "fcntl");
+ }
+}
+
+void
set_termios(void)
{
struct termios tio;
@@ -342,7 +358,7 @@ try_remote(const char *host, const char *path, const char *entry)
if (entry != NULL && cgetset(entry) != 0)
cu_errx(1, "cgetset failed");
- error = cgetent(&cp, (char**)paths, (char*)host);
+ error = cgetent(&cp, (char **)paths, (char *)host);
if (error < 0) {
switch (error) {
case -1: