1 /* $OpenBSD: tty.c,v 1.17 2018/03/15 16:51:29 anton Exp $ */
11 int tty_fd
= -1; /* dup'd tty file descriptor */
12 int tty_devtty
; /* true if tty_fd is from /dev/tty */
13 struct termios tty_state
; /* saved tty state */
24 /* Initialize tty_fd. Used for saving/resetting tty modes upon
25 * foreground job completion and for setting up tty process group.
28 tty_init(int init_ttystate
)
36 tfd
= open("/dev/tty", O_RDWR
, 0);
39 warningf(false, "No controlling tty (open /dev/tty: %s)",
48 warningf(false, "Can't find tty file descriptor");
52 if ((tty_fd
= fcntl(tfd
, F_DUPFD_CLOEXEC
, FDBASE
)) < 0) {
53 warningf(false, "%s: dup of tty fd failed: %s",
54 __func__
, strerror(errno
));
55 } else if (init_ttystate
)
56 tcgetattr(tty_fd
, &tty_state
);