Commit 2a39b907 authored by Niels Möller's avatar Niels Möller

* src/unix_interact.c (install_suspend_handler): New function.

(stop_handler): New signal handler for TSTP, that sets and resets
the tty modes.

Rev: src/unix_interact.c:1.6
parent b38b5afd
......@@ -57,6 +57,48 @@ static void winch_handler(int signum)
window_changed = 1;
}
static struct termios original_mode;
static int tty_fd = -1;
static void
stop_handler(int signum)
{
struct termios mine;
int need_reset;
assert(signum == SIGTSTP);
need_reset = tty_getattr(tty_fd, &mine);
tty_setattr(tty_fd, &original_mode);
kill(getpid(), SIGSTOP);
if (need_reset)
tty_setattr(tty_fd, &mine);
}
static void
install_suspend_handler(int fd)
{
struct sigaction stop;
memset(&stop, 0, sizeof(stop));
stop.sa_handler = stop_handler;
sigemptyset(&stop.sa_mask);
stop.sa_flags = 0;
tty_fd = fd;
if (!tty_getattr(fd, &original_mode))
werror("install_suspend_handler: tty_getattr failed (errno = %i): %z\n",
errno, STRERROR(errno));
else if (sigaction(SIGTSTP, &stop, NULL) < 0)
werror("Failed to install SIGTSTP handler (errno = %i): %z\n",
errno, STRERROR(errno));
}
/* Depends on the tty being line buffered */
static int
read_line(int fd, UINT32 size, UINT8 *buffer)
......@@ -291,9 +333,7 @@ unix_window_size(struct interact *s,
CAST(unix_interact, self, s);
return IS_TTY(self)
&& tty_getwinsize(self->tty_fd,
&d->char_width, &d->char_height,
&d->pixel_width, &d->pixel_height);
&& tty_getwinsize(self->tty_fd, d);
}
static struct resource *
......@@ -395,6 +435,8 @@ make_unix_interact(struct io_backend *backend)
io_signal_handler(backend, &window_changed,
make_winch_handler(self));
install_suspend_handler(self->tty_fd);
}
return &self->super;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment