Deleted Added
full compact
pty.c (130054) pty.c (130077)
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 130054 2004-06-04 06:50:35Z phk $");
33__FBSDID("$FreeBSD: head/sys/kern/tty_pty.c 130077 2004-06-04 16:02:56Z phk $");
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>

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

177 tp->t_lflag = TTYDEF_LFLAG;
178 tp->t_cflag = TTYDEF_CFLAG;
179 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
180 } else if (tp->t_state & TS_XCLUDE && suser(td))
181 return (EBUSY);
182 else if (pti->pt_prison != td->td_ucred->cr_prison)
183 return (EBUSY);
184 if (tp->t_oproc) /* Ctrlr still around. */
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>

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

177 tp->t_lflag = TTYDEF_LFLAG;
178 tp->t_cflag = TTYDEF_CFLAG;
179 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
180 } else if (tp->t_state & TS_XCLUDE && suser(td))
181 return (EBUSY);
182 else if (pti->pt_prison != td->td_ucred->cr_prison)
183 return (EBUSY);
184 if (tp->t_oproc) /* Ctrlr still around. */
185 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
185 (void)ttyld_modem(tp, 1);
186 while ((tp->t_state & TS_CARR_ON) == 0) {
187 if (flag&FNONBLOCK)
188 break;
189 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
190 "ptsopn", 0);
191 if (error)
192 return (error);
193 }
186 while ((tp->t_state & TS_CARR_ON) == 0) {
187 if (flag&FNONBLOCK)
188 break;
189 error = ttysleep(tp, TSA_CARR_ON(tp), TTIPRI | PCATCH,
190 "ptsopn", 0);
191 if (error)
192 return (error);
193 }
194 error = (*linesw[tp->t_line].l_open)(dev, tp);
194 error = ttyld_open(tp, dev);
195 if (error == 0)
196 ptcwakeup(tp, FREAD|FWRITE);
197 return (error);
198}
199
200static int
201ptsclose(dev, flag, mode, td)
202 dev_t dev;
203 int flag, mode;
204 struct thread *td;
205{
206 struct tty *tp;
207 int err;
208
209 tp = dev->si_tty;
195 if (error == 0)
196 ptcwakeup(tp, FREAD|FWRITE);
197 return (error);
198}
199
200static int
201ptsclose(dev, flag, mode, td)
202 dev_t dev;
203 int flag, mode;
204 struct thread *td;
205{
206 struct tty *tp;
207 int err;
208
209 tp = dev->si_tty;
210 err = (*linesw[tp->t_line].l_close)(tp, flag);
210 err = ttyld_close(tp, flag);
211 (void) ttyclose(tp);
212 return (err);
213}
214
215static int
216ptsread(dev, uio, flag)
217 dev_t dev;
218 struct uio *uio;

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

263 break;
264 }
265 if (tp->t_canq.c_cc == 1)
266 (void) getc(&tp->t_canq);
267 if (tp->t_canq.c_cc)
268 return (error);
269 } else
270 if (tp->t_oproc)
211 (void) ttyclose(tp);
212 return (err);
213}
214
215static int
216ptsread(dev, uio, flag)
217 dev_t dev;
218 struct uio *uio;

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

263 break;
264 }
265 if (tp->t_canq.c_cc == 1)
266 (void) getc(&tp->t_canq);
267 if (tp->t_canq.c_cc)
268 return (error);
269 } else
270 if (tp->t_oproc)
271 error = (*linesw[tp->t_line].l_read)(tp, uio, flag);
271 error = ttyld_read(tp, uio, flag);
272 ptcwakeup(tp, FWRITE);
273 return (error);
274}
275
276/*
277 * Write to pseudo-tty.
278 * Wakeups of controlling tty will happen
279 * indirectly, when tty driver calls ptsstart.

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

284 struct uio *uio;
285 int flag;
286{
287 struct tty *tp;
288
289 tp = dev->si_tty;
290 if (tp->t_oproc == 0)
291 return (EIO);
272 ptcwakeup(tp, FWRITE);
273 return (error);
274}
275
276/*
277 * Write to pseudo-tty.
278 * Wakeups of controlling tty will happen
279 * indirectly, when tty driver calls ptsstart.

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

284 struct uio *uio;
285 int flag;
286{
287 struct tty *tp;
288
289 tp = dev->si_tty;
290 if (tp->t_oproc == 0)
291 return (EIO);
292 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
292 return (ttyld_write(tp, uio, flag));
293}
294
295/*
296 * Start output on pseudo-tty.
297 * Wake up process selecting or sleeping for input from controlling tty.
298 */
299static void
300ptsstart(tp)

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

342 if (!dev->si_drv1)
343 return(ENXIO);
344 tp = dev->si_tty;
345 if (tp->t_oproc)
346 return (EIO);
347 tp->t_timeout = -1;
348 tp->t_oproc = ptsstart;
349 tp->t_stop = ptsstop;
293}
294
295/*
296 * Start output on pseudo-tty.
297 * Wake up process selecting or sleeping for input from controlling tty.
298 */
299static void
300ptsstart(tp)

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

342 if (!dev->si_drv1)
343 return(ENXIO);
344 tp = dev->si_tty;
345 if (tp->t_oproc)
346 return (EIO);
347 tp->t_timeout = -1;
348 tp->t_oproc = ptsstart;
349 tp->t_stop = ptsstop;
350 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
350 (void)ttyld_modem(tp, 1);
351 tp->t_lflag &= ~EXTPROC;
352 pti = dev->si_drv1;
353 pti->pt_prison = td->td_ucred->cr_prison;
354 pti->pt_flags = 0;
355 pti->pt_send = 0;
356 pti->pt_ucntl = 0;
357 return (0);
358}
359
360static int
361ptcclose(dev, flags, fmt, td)
362 dev_t dev;
363 int flags;
364 int fmt;
365 struct thread *td;
366{
367 struct tty *tp;
368
369 tp = dev->si_tty;
351 tp->t_lflag &= ~EXTPROC;
352 pti = dev->si_drv1;
353 pti->pt_prison = td->td_ucred->cr_prison;
354 pti->pt_flags = 0;
355 pti->pt_send = 0;
356 pti->pt_ucntl = 0;
357 return (0);
358}
359
360static int
361ptcclose(dev, flags, fmt, td)
362 dev_t dev;
363 int flags;
364 int fmt;
365 struct thread *td;
366{
367 struct tty *tp;
368
369 tp = dev->si_tty;
370 (void)(*linesw[tp->t_line].l_modem)(tp, 0);
370 (void)ttyld_modem(tp, 0);
371
372 /*
373 * XXX MDMBUF makes no sense for ptys but would inhibit the above
374 * l_modem(). CLOCAL makes sense but isn't supported. Special
375 * l_modem()s that ignore carrier drop make no sense for ptys but
376 * may be in use because other parts of the line discipline make
377 * sense for ptys. Recover by doing everything that a normal
378 * ttymodem() would have done except for sending a SIGHUP.

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

595 }
596 }
597 while (cc > 0) {
598 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
599 (tp->t_canq.c_cc > 0 || !(tp->t_lflag&ICANON))) {
600 wakeup(TSA_HUP_OR_INPUT(tp));
601 goto block;
602 }
371
372 /*
373 * XXX MDMBUF makes no sense for ptys but would inhibit the above
374 * l_modem(). CLOCAL makes sense but isn't supported. Special
375 * l_modem()s that ignore carrier drop make no sense for ptys but
376 * may be in use because other parts of the line discipline make
377 * sense for ptys. Recover by doing everything that a normal
378 * ttymodem() would have done except for sending a SIGHUP.

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

595 }
596 }
597 while (cc > 0) {
598 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
599 (tp->t_canq.c_cc > 0 || !(tp->t_lflag&ICANON))) {
600 wakeup(TSA_HUP_OR_INPUT(tp));
601 goto block;
602 }
603 (*linesw[tp->t_line].l_rint)(*cp++, tp);
603 ttyld_rint(tp, *cp++);
604 cnt++;
605 cc--;
606 }
607 cc = 0;
608 }
609 return (0);
610block:
611 /*

--- 249 unchanged lines hidden ---
604 cnt++;
605 cc--;
606 }
607 cc = 0;
608 }
609 return (0);
610block:
611 /*

--- 249 unchanged lines hidden ---