xref: /original-bsd/sys/kern/tty_tty.c (revision 87febec0)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)tty_tty.c	7.4 (Berkeley) 05/05/89
7  */
8 
9 /*
10  * Indirect driver for controlling tty.
11  *
12  * THIS IS GARBAGE: MUST SOON BE DONE WITH struct inode * IN PROC TABLE.
13  */
14 #include "param.h"
15 #include "systm.h"
16 #include "conf.h"
17 #include "user.h"
18 #include "ioctl.h"
19 #include "tty.h"
20 #include "proc.h"
21 #include "uio.h"
22 
23 /*ARGSUSED*/
24 syopen(dev, flag)
25 	dev_t dev;
26 	int flag;
27 {
28 
29 	if (u.u_ttyp == NULL)
30 		return (ENXIO);
31 	return ((*cdevsw[major(u.u_ttyd)].d_open)(u.u_ttyd, flag));
32 }
33 
34 /*ARGSUSED*/
35 syread(dev, uio, flag)
36 	dev_t dev;
37 	struct uio *uio;
38 {
39 
40 	if (u.u_ttyp == NULL)
41 		return (ENXIO);
42 	return ((*cdevsw[major(u.u_ttyd)].d_read)(u.u_ttyd, uio, flag));
43 }
44 
45 /*ARGSUSED*/
46 sywrite(dev, uio, flag)
47 	dev_t dev;
48 	struct uio *uio;
49 {
50 
51 	if (u.u_ttyp == NULL)
52 		return (ENXIO);
53 	return ((*cdevsw[major(u.u_ttyd)].d_write)(u.u_ttyd, uio, flag));
54 }
55 
56 /*ARGSUSED*/
57 syioctl(dev, cmd, addr, flag)
58 	dev_t dev;
59 	int cmd;
60 	caddr_t addr;
61 	int flag;
62 {
63 
64 	if (cmd == TIOCNOTTY) {
65 		if (SESS_LEADER(u.u_procp)) {
66 			/*
67 			 * XXX - check posix draft
68 			 */
69 			u.u_ttyp->t_session = 0;
70 			u.u_ttyp->t_pgid = 0;
71 		}
72 		u.u_ttyp = 0;
73 		u.u_ttyd = 0;
74 		return (0);
75 	}
76 	if (u.u_ttyp == NULL)
77 		return (ENXIO);
78 	return ((*cdevsw[major(u.u_ttyd)].d_ioctl)(u.u_ttyd, cmd, addr, flag));
79 }
80 
81 /*ARGSUSED*/
82 syselect(dev, flag)
83 	dev_t dev;
84 	int flag;
85 {
86 
87 	if (u.u_ttyp == NULL) {
88 		u.u_error = ENXIO;
89 		return (0);
90 	}
91 	return ((*cdevsw[major(u.u_ttyd)].d_select)(u.u_ttyd, flag));
92 }
93