login_tty.c revision 13137
1159307Spjd/*-
2220922Spjd * Copyright (c) 1990, 1993
3159307Spjd *	The Regents of the University of California.  All rights reserved.
4159307Spjd *
5159307Spjd * Redistribution and use in source and binary forms, with or without
6159307Spjd * modification, are permitted provided that the following conditions
7159307Spjd * are met:
8159307Spjd * 1. Redistributions of source code must retain the above copyright
9159307Spjd *    notice, this list of conditions and the following disclaimer.
10159307Spjd * 2. Redistributions in binary form must reproduce the above copyright
11159307Spjd *    notice, this list of conditions and the following disclaimer in the
12159307Spjd *    documentation and/or other materials provided with the distribution.
13159307Spjd * 3. All advertising materials mentioning features or use of this software
14159307Spjd *    must display the following acknowledgement:
15159307Spjd *	This product includes software developed by the University of
16159307Spjd *	California, Berkeley and its contributors.
17159307Spjd * 4. Neither the name of the University nor the names of its contributors
18159307Spjd *    may be used to endorse or promote products derived from this software
19159307Spjd *    without specific prior written permission.
20159307Spjd *
21159307Spjd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22159307Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23159307Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24159307Spjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25159307Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26159307Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27159307Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28159307Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29159307Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30159307Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31159307Spjd * SUCH DAMAGE.
32159307Spjd */
33159307Spjd
34159307Spjd#if defined(LIBC_SCCS) && !defined(lint)
35159307Spjdstatic char sccsid[] = "@(#)login_tty.c	8.1 (Berkeley) 6/4/93";
36159307Spjd#endif /* LIBC_SCCS and not lint */
37159307Spjd
38159307Spjd#include <sys/param.h>
39159307Spjd#include <sys/ioctl.h>
40159307Spjd
41159307Spjd#include <unistd.h>
42159307Spjd#include <stdlib.h>
43159307Spjd#include <libutil.h>
44159307Spjd
45159307Spjdint
46159307Spjdlogin_tty(fd)
47159307Spjd	int fd;
48159307Spjd{
49159307Spjd	(void) setsid();
50159307Spjd	if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1)
51159307Spjd		return (-1);
52159307Spjd	(void) dup2(fd, 0);
53159307Spjd	(void) dup2(fd, 1);
54159307Spjd	(void) dup2(fd, 2);
55159307Spjd	if (fd > 2)
56214118Spjd		(void) close(fd);
57159307Spjd	return (0);
58159307Spjd}
59159307Spjd