-/* $OpenBSD: command.c,v 1.14 2015/10/05 17:53:56 nicm Exp $ */
+/* $OpenBSD: command.c,v 1.15 2015/10/05 23:15:31 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
return;
restore_termios();
+ set_blocking(line_fd, 1);
switch (pid = fork()) {
case -1:
break;
}
+ set_blocking(line_fd, 0);
set_termios();
}
return;
restore_termios();
+ set_blocking(line_fd, 1);
switch (pid = fork()) {
case -1:
break;
}
+ set_blocking(line_fd, 0);
set_termios();
}
-/* $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>
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);
exit(0);
}
+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)
{
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:
-/* $OpenBSD: cu.h,v 1.6 2012/07/10 12:47:23 nicm Exp $ */
+/* $OpenBSD: cu.h,v 1.7 2015/10/05 23:15:31 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
extern struct termios saved_tio;
extern int line_fd;
extern struct bufferevent *line_ev;
+void set_blocking(int, int);
int set_line(int);
void set_termios(void);
void restore_termios(void);
-/* $OpenBSD: xmodem.c,v 1.7 2014/09/21 05:29:47 daniel Exp $ */
+/* $OpenBSD: xmodem.c,v 1.8 2015/10/05 23:15:31 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio) != 0)
cu_err(1, "tcsetattr");
}
-
+ set_blocking(line_fd, 1);
tcflush(line_fd, TCIFLUSH);
+
if (xmodem_read(&c) != 0)
goto fail;
if (c == XMODEM_C)
cu_warn("%s", file);
out:
+ set_blocking(line_fd, 0);
set_termios();
sigaction(SIGINT, &oact, NULL);