Deleted Added
full compact
pty.c (154170) pty.c (154833)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
30 */
31
32#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tty_pty.c 8.4 (Berkeley) 2/20/95
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/kern/tty_pty.c 154170 2006-01-10 09:19:10Z phk $");
33__FBSDID("$FreeBSD: head/sys/kern/tty_pty.c 154833 2006-01-26 01:30:34Z cognet $");
34
35/*
36 * Pseudo-teletype Driver
37 * (Actually two drivers, requiring two entries in 'cdevsw')
38 */
39#include "opt_compat.h"
40#include "opt_tty.h"
41#include <sys/param.h>

--- 60 unchanged lines hidden (view full) ---

102
103struct ptsc {
104 int pt_flags;
105 struct selinfo pt_selr, pt_selw;
106 u_char pt_send;
107 u_char pt_ucntl;
108 struct tty *pt_tty;
109 struct cdev *devs, *devc;
34
35/*
36 * Pseudo-teletype Driver
37 * (Actually two drivers, requiring two entries in 'cdevsw')
38 */
39#include "opt_compat.h"
40#include "opt_tty.h"
41#include <sys/param.h>

--- 60 unchanged lines hidden (view full) ---

102
103struct ptsc {
104 int pt_flags;
105 struct selinfo pt_selr, pt_selw;
106 u_char pt_send;
107 u_char pt_ucntl;
108 struct tty *pt_tty;
109 struct cdev *devs, *devc;
110 int pt_devs_open, pt_devc_open;
110 struct prison *pt_prison;
111};
112
113#define PF_PKT 0x08 /* packet mode */
114#define PF_STOPPED 0x10 /* user told stopped */
115#define PF_NOSTOP 0x40
116#define PF_UCNTL 0x80 /* user control mode */
117

--- 9 unchanged lines hidden (view full) ---

127 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
128 *
129 * XXX: define and add mapping of upper minor bits to allow more
130 * than 256 ptys.
131 */
132static struct cdev *
133ptyinit(struct cdev *devc, struct thread *td)
134{
111 struct prison *pt_prison;
112};
113
114#define PF_PKT 0x08 /* packet mode */
115#define PF_STOPPED 0x10 /* user told stopped */
116#define PF_NOSTOP 0x40
117#define PF_UCNTL 0x80 /* user control mode */
118

--- 9 unchanged lines hidden (view full) ---

128 * ptc == /dev/pty[pqrsPQRS][0123456789abcdefghijklmnopqrstuv]
129 *
130 * XXX: define and add mapping of upper minor bits to allow more
131 * than 256 ptys.
132 */
133static struct cdev *
134ptyinit(struct cdev *devc, struct thread *td)
135{
135 struct cdev *devs;
136 struct ptsc *pt;
137 int n;
138
139 n = minor(devc);
140 /* For now we only map the lower 8 bits of the minor */
141 if (n & ~0xff)
142 return (NULL);
143
144 devc->si_flags &= ~SI_CHEAPCLONE;
145
136 struct ptsc *pt;
137 int n;
138
139 n = minor(devc);
140 /* For now we only map the lower 8 bits of the minor */
141 if (n & ~0xff)
142 return (NULL);
143
144 devc->si_flags &= ~SI_CHEAPCLONE;
145
146 /*
147 * Initially do not create a slave endpoint.
148 */
146 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK | M_ZERO);
149 pt = malloc(sizeof(*pt), M_PTY, M_WAITOK | M_ZERO);
147 pt->devs = devs = make_dev_cred(&pts_cdevsw, n, td->td_ucred,
148 UID_ROOT, GID_WHEEL, 0666, "tty%c%r", names[n / 32], n % 32);
149 pt->devc = devc;
150
151 pt->pt_tty = ttyalloc();
152 pt->pt_tty->t_sc = pt;
150 pt->devc = devc;
151
152 pt->pt_tty = ttyalloc();
153 pt->pt_tty->t_sc = pt;
153 devs->si_drv1 = devc->si_drv1 = pt;
154 devs->si_tty = devc->si_tty = pt->pt_tty;
155 pt->pt_tty->t_dev = devs;
154 devc->si_drv1 = pt;
155 devc->si_tty = pt->pt_tty;
156 return (devc);
157}
158
156 return (devc);
157}
158
159static void
160pty_create_slave(struct ucred *cred, struct ptsc *pt, int n)
161{
162
163 pt->devs = make_dev_cred(&pts_cdevsw, n, cred, UID_ROOT, GID_WHEEL,
164 0666, "tty%c%r", names[n / 32], n % 32);
165 pt->devs->si_drv1 = pt;
166 pt->devs->si_tty = pt->pt_tty;
167 pt->pt_tty->t_dev = pt->devs;
168}
169
170static void
171pty_destroy_slave(struct ptsc *pt)
172{
173
174 pt->pt_tty->t_dev = NULL;
175 destroy_dev(pt->devs);
176 pt->devs = NULL;
177}
178
179static void
180pty_maybe_destroy_slave(struct ptsc *pt)
181{
182
183 if (pt->pt_devc_open == 0 && pt->pt_devs_open == 0)
184 pty_destroy_slave(pt);
185}
186
159/*ARGSUSED*/
160static int
161ptsopen(struct cdev *dev, int flag, int devtype, struct thread *td)
162{
163 struct tty *tp;
164 int error;
165 struct ptsc *pt;
166

--- 13 unchanged lines hidden (view full) ---

180 if (flag&FNONBLOCK)
181 break;
182 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
183 "ptsopn", 0);
184 if (error)
185 return (error);
186 }
187 error = ttyld_open(tp, dev);
187/*ARGSUSED*/
188static int
189ptsopen(struct cdev *dev, int flag, int devtype, struct thread *td)
190{
191 struct tty *tp;
192 int error;
193 struct ptsc *pt;
194

--- 13 unchanged lines hidden (view full) ---

208 if (flag&FNONBLOCK)
209 break;
210 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
211 "ptsopn", 0);
212 if (error)
213 return (error);
214 }
215 error = ttyld_open(tp, dev);
188 if (error == 0)
216 if (error == 0) {
189 ptcwakeup(tp, FREAD|FWRITE);
217 ptcwakeup(tp, FREAD|FWRITE);
218 pt->pt_devs_open = 1;
219 } else
220 pty_maybe_destroy_slave(pt);
190 return (error);
191}
192
193static int
194ptsclose(struct cdev *dev, int flag, int mode, struct thread *td)
195{
221 return (error);
222}
223
224static int
225ptsclose(struct cdev *dev, int flag, int mode, struct thread *td)
226{
227 struct ptsc *pti;
196 struct tty *tp;
197 int err;
198
199 tp = dev->si_tty;
228 struct tty *tp;
229 int err;
230
231 tp = dev->si_tty;
232 pti = dev->si_drv1;
233
234 KASSERT(dev == pti->devs, ("ptsclose: dev != pti->devs"));
235
200 err = ttyld_close(tp, flag);
201 (void) tty_close(tp);
236 err = ttyld_close(tp, flag);
237 (void) tty_close(tp);
238
239 pti->pt_devs_open = 0;
240 pty_maybe_destroy_slave(pti);
241
202 return (err);
203}
204
205static int
206ptsread(struct cdev *dev, struct uio *uio, int flag)
207{
208 struct tty *tp = dev->si_tty;
209 int error = 0;

--- 71 unchanged lines hidden (view full) ---

281 tp->t_stop = ptsstop;
282 (void)ttyld_modem(tp, 1);
283 tp->t_lflag &= ~EXTPROC;
284 pt = dev->si_drv1;
285 pt->pt_prison = td->td_ucred->cr_prison;
286 pt->pt_flags = 0;
287 pt->pt_send = 0;
288 pt->pt_ucntl = 0;
242 return (err);
243}
244
245static int
246ptsread(struct cdev *dev, struct uio *uio, int flag)
247{
248 struct tty *tp = dev->si_tty;
249 int error = 0;

--- 71 unchanged lines hidden (view full) ---

321 tp->t_stop = ptsstop;
322 (void)ttyld_modem(tp, 1);
323 tp->t_lflag &= ~EXTPROC;
324 pt = dev->si_drv1;
325 pt->pt_prison = td->td_ucred->cr_prison;
326 pt->pt_flags = 0;
327 pt->pt_send = 0;
328 pt->pt_ucntl = 0;
329
330 pty_create_slave(td->td_ucred, pt, minor(dev));
331 pt->pt_devc_open = 1;
332
289 return (0);
290}
291
292static int
293ptcclose(struct cdev *dev, int flags, int fmt, struct thread *td)
294{
333 return (0);
334}
335
336static int
337ptcclose(struct cdev *dev, int flags, int fmt, struct thread *td)
338{
339 struct ptsc *pti = dev->si_drv1;
295 struct tty *tp;
296
297 tp = dev->si_tty;
298 (void)ttyld_modem(tp, 0);
299
300 /*
301 * XXX MDMBUF makes no sense for ptys but would inhibit the above
302 * l_modem(). CLOCAL makes sense but isn't supported. Special

--- 4 unchanged lines hidden (view full) ---

307 */
308 if (tp->t_state & TS_ISOPEN) {
309 tp->t_state &= ~(TS_CARR_ON | TS_CONNECTED);
310 tp->t_state |= TS_ZOMBIE;
311 ttyflush(tp, FREAD | FWRITE);
312 }
313
314 tp->t_oproc = 0; /* mark closed */
340 struct tty *tp;
341
342 tp = dev->si_tty;
343 (void)ttyld_modem(tp, 0);
344
345 /*
346 * XXX MDMBUF makes no sense for ptys but would inhibit the above
347 * l_modem(). CLOCAL makes sense but isn't supported. Special

--- 4 unchanged lines hidden (view full) ---

352 */
353 if (tp->t_state & TS_ISOPEN) {
354 tp->t_state &= ~(TS_CARR_ON | TS_CONNECTED);
355 tp->t_state |= TS_ZOMBIE;
356 ttyflush(tp, FREAD | FWRITE);
357 }
358
359 tp->t_oproc = 0; /* mark closed */
360 pti->pt_devc_open = 0;
361 pty_maybe_destroy_slave(pti);
315 return (0);
316}
317
318static int
319ptcread(struct cdev *dev, struct uio *uio, int flag)
320{
321 struct tty *tp = dev->si_tty;
322 struct ptsc *pt = dev->si_drv1;

--- 398 unchanged lines hidden ---
362 return (0);
363}
364
365static int
366ptcread(struct cdev *dev, struct uio *uio, int flag)
367{
368 struct tty *tp = dev->si_tty;
369 struct ptsc *pt = dev->si_drv1;

--- 398 unchanged lines hidden ---