diff options
Diffstat (limited to 'src/util/pty/initialize_slave.c')
-rw-r--r-- | src/util/pty/initialize_slave.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/util/pty/initialize_slave.c b/src/util/pty/initialize_slave.c new file mode 100644 index 000000000..1f7327880 --- /dev/null +++ b/src/util/pty/initialize_slave.c @@ -0,0 +1,89 @@ +/* + * pty_open_slave: open slave side of terminal, clearing for use. + * and utmp entries. + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * + *Permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + */ + +#include "mit-copyright.h" +#include <com_err.h> +#include "libpty.h" +#include "pty-int.h" + +long pty_initialize_slave (fd) + int fd; +{ +#if defined(POSIX_TERMIOS) && !defined(ultrix) + struct termios new_termio; +#else + struct sgttyb b; +#endif /* POSIX_TERMIOS */ + int pid; +#ifdef POSIX_SIGNALS + struct sigaction sa; + /* Initialize "sa" structure. */ + (void) sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + +#endif + +#ifdef HAVE_STREAMS + while (ioctl (fd, I_POP, 0) == 0); /*Clear out any old lined's*/ +#ifdef HAVE_LINE_PUSH + if (line_push(fd) < 0) + { + (void) close(fd); fd = -1; + return PTY_OPEN_SLAVE_LINE_PUSHFAIL; + } +#else /*No line_push */ +#ifdef sun + if (ioctl(fd, I_PUSH, "ptem") < 0) + return PTY_OPEN_SLAVE_PUSH_FAIL; + if (ioctl(fd, I_PUSH, "ldterm") < 0) + return PTY_OPEN_SLAVE_PUSH_FAIL; + if (ioctl(fd, I_PUSH, "ttcompat") < 0) + return PTY_OPEN_SLAVE_PUSH_FAIL; + +#endif /*SUN*/ +#endif /*LINE_PUSH*/ +#endif /*HAVE_STREAMS*/ + + /* + * Under Ultrix 3.0, the pgrp of the slave pty terminal + * needs to be set explicitly. Why rlogind works at all + * without this on 4.3BSD is a mystery. + */ +#ifdef GETPGRP_ONEARG + pid = getpgrp(getpid()); +#else + pid = getpgrp(); +#endif + +#ifdef TIOCSPGRP + ioctl(fd, TIOCSPGRP, &pid); +#endif + + +#if defined(POSIX_TERMIOS) && !defined(ultrix) + tcsetpgrp(fd, pid); + tcgetattr(fd,&new_termio); + new_termio.c_cc[VMIN] = 1; + new_termio.c_cc[VTIME] = 0; + tcsetattr(fd,TCSANOW,&new_termio); +#endif /* POSIX_TERMIOS */ + + return 0; +} |