1 /* $OpenBSD: tty.c,v 1.9 2006/03/14 22:08:01 deraadt Exp $ */
9 /* Initialize tty_fd. Used for saving/reseting tty modes upon
10 * foreground job completion and for setting up tty process group.
13 tty_init(int init_ttystate
)
24 if ((tfd
= open("/dev/tty", O_RDWR
, 0)) < 0) {
26 warningf(false, "No controlling tty (open /dev/tty: %s)",
37 warningf(false, "Can't find tty file descriptor");
41 if ((tty_fd
= fcntl(tfd
, F_DUPFD
, FDBASE
)) < 0) {
42 warningf(false, "j_ttyinit: dup of tty fd failed: %s",
44 } else if (fcntl(tty_fd
, F_SETFD
, FD_CLOEXEC
) < 0) {
45 warningf(false, "j_ttyinit: can't set close-on-exec flag: %s",
49 } else if (init_ttystate
)
50 tcgetattr(tty_fd
, &tty_state
);