1264573Sdelphij/* $FreeBSD$ */ 2264573Sdelphij/* $OpenBSD: tty.c,v 1.2 2013/11/12 13:54:51 deraadt Exp $ */ 3264573Sdelphij 4264573Sdelphij/* 5264573Sdelphij * Copyright (c) 2013, Otto Moerbeek <otto@drijf.net> 6264573Sdelphij * 7264573Sdelphij * Permission to use, copy, modify, and distribute this software for any 8264573Sdelphij * purpose with or without fee is hereby granted, provided that the above 9264573Sdelphij * copyright notice and this permission notice appear in all copies. 10264573Sdelphij * 11264573Sdelphij * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12264573Sdelphij * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13264573Sdelphij * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14264573Sdelphij * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15264573Sdelphij * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16264573Sdelphij * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17264573Sdelphij * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18264573Sdelphij */ 19264573Sdelphij 20264573Sdelphij#include <errno.h> 21264573Sdelphij#include <signal.h> 22264573Sdelphij#include <histedit.h> 23264573Sdelphij#include <termios.h> 24264573Sdelphij#include "extern.h" 25264573Sdelphij 26264573Sdelphijstruct termios ttysaved, ttyedit; 27264573Sdelphij 28264573Sdelphijstatic int 29264573Sdelphijsettty(struct termios *t) 30264573Sdelphij{ 31264573Sdelphij int ret; 32264573Sdelphij 33264573Sdelphij while ((ret = tcsetattr(0, TCSADRAIN, t) == -1) && errno == EINTR) 34264573Sdelphij continue; 35264573Sdelphij return ret; 36264573Sdelphij} 37264573Sdelphij 38264573Sdelphijint 39264573Sdelphijgettty(struct termios *t) 40264573Sdelphij{ 41264573Sdelphij int ret; 42264573Sdelphij 43264573Sdelphij while ((ret = tcgetattr(0, t) == -1) && errno == EINTR) 44264573Sdelphij continue; 45264573Sdelphij return ret; 46264573Sdelphij} 47264573Sdelphij 48264573Sdelphij/* ARGSUSED */ 49264573Sdelphijvoid 50264573Sdelphijtstpcont(int sig) 51264573Sdelphij{ 52264573Sdelphij int save_errno = errno; 53264573Sdelphij 54264573Sdelphij if (sig == SIGTSTP) { 55264573Sdelphij signal(SIGCONT, tstpcont); 56264573Sdelphij gettty(&ttyedit); 57264573Sdelphij settty(&ttysaved); 58264573Sdelphij } else { 59264573Sdelphij signal(SIGTSTP, tstpcont); 60264573Sdelphij settty(&ttyedit); 61264573Sdelphij } 62264573Sdelphij signal(sig, SIG_DFL); 63264573Sdelphij kill(0, sig); 64264573Sdelphij errno = save_errno; 65264573Sdelphij} 66