pty.c (10902) | pty.c (11789) |
---|---|
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 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93 | 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 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)tty_pty.c 8.2 (Berkeley) 9/23/93 |
34 * $Id: tty_pty.c,v 1.20 1995/09/08 11:08:38 bde Exp $ | 34 * $Id: tty_pty.c,v 1.21 1995/09/19 12:26:47 bde Exp $ |
35 */ 36 37/* 38 * Pseudo-teletype Driver 39 * (Actually two drivers, requiring two entries in 'cdevsw') 40 */ 41#include "pty.h" /* XXX */ 42 --- 4 unchanged lines hidden (view full) --- 47#include <sys/tty.h> 48#include <sys/conf.h> 49#include <sys/file.h> 50#include <sys/uio.h> 51#include <sys/kernel.h> 52#include <sys/vnode.h> 53#include <sys/signalvar.h> 54 | 35 */ 36 37/* 38 * Pseudo-teletype Driver 39 * (Actually two drivers, requiring two entries in 'cdevsw') 40 */ 41#include "pty.h" /* XXX */ 42 --- 4 unchanged lines hidden (view full) --- 47#include <sys/tty.h> 48#include <sys/conf.h> 49#include <sys/file.h> 50#include <sys/uio.h> 51#include <sys/kernel.h> 52#include <sys/vnode.h> 53#include <sys/signalvar.h> 54 |
55void ptyattach __P((int n)); 56void ptsstart __P((struct tty *tp)); 57void ptcwakeup __P((struct tty *tp, int flag)); 58 |
|
55#if NPTY == 1 56#undef NPTY 57#define NPTY 32 /* crude XXX */ 58#endif 59 60#define BUFSIZ 100 /* Chunk size iomoved to/from user */ 61 62/* --- 418 unchanged lines hidden (view full) --- 481 int error = 0; 482 483again: 484 if ((tp->t_state&TS_ISOPEN) == 0) 485 goto block; 486 if (pti->pt_flags & PF_REMOTE) { 487 if (tp->t_canq.c_cc) 488 goto block; | 59#if NPTY == 1 60#undef NPTY 61#define NPTY 32 /* crude XXX */ 62#endif 63 64#define BUFSIZ 100 /* Chunk size iomoved to/from user */ 65 66/* --- 418 unchanged lines hidden (view full) --- 485 int error = 0; 486 487again: 488 if ((tp->t_state&TS_ISOPEN) == 0) 489 goto block; 490 if (pti->pt_flags & PF_REMOTE) { 491 if (tp->t_canq.c_cc) 492 goto block; |
489 while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG - 1) { | 493 while ((uio->uio_resid > 0 || cc > 0) && 494 tp->t_canq.c_cc < TTYHOG - 1) { |
490 if (cc == 0) { 491 cc = min(uio->uio_resid, BUFSIZ); 492 cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc); 493 cp = locbuf; 494 error = uiomove((caddr_t)cp, cc, uio); 495 if (error) 496 return (error); 497 /* check again for safety */ | 495 if (cc == 0) { 496 cc = min(uio->uio_resid, BUFSIZ); 497 cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc); 498 cp = locbuf; 499 error = uiomove((caddr_t)cp, cc, uio); 500 if (error) 501 return (error); 502 /* check again for safety */ |
498 if ((tp->t_state&TS_ISOPEN) == 0) | 503 if ((tp->t_state & TS_ISOPEN) == 0) { 504 /* adjust as usual */ 505 uio->uio_resid += cc; |
499 return (EIO); | 506 return (EIO); |
507 } |
|
500 } 501 if (cc) | 508 } 509 if (cc) |
502 (void) b_to_q((char *)cp, cc, &tp->t_canq); 503 cc = 0; | 510 cc -= b_to_q((char *)cp, cc, &tp->t_canq); |
504 } | 511 } |
512 /* adjust for data copied in but not written */ 513 uio->uio_resid += cc; |
|
505 (void) putc(0, &tp->t_canq); 506 ttwakeup(tp); 507 wakeup(TSA_PTS_READ(tp)); 508 return (0); 509 } | 514 (void) putc(0, &tp->t_canq); 515 ttwakeup(tp); 516 wakeup(TSA_PTS_READ(tp)); 517 return (0); 518 } |
510 while (uio->uio_resid > 0) { | 519 while (uio->uio_resid > 0 || cc > 0) { |
511 if (cc == 0) { 512 cc = min(uio->uio_resid, BUFSIZ); 513 cp = locbuf; 514 error = uiomove((caddr_t)cp, cc, uio); 515 if (error) 516 return (error); 517 /* check again for safety */ | 520 if (cc == 0) { 521 cc = min(uio->uio_resid, BUFSIZ); 522 cp = locbuf; 523 error = uiomove((caddr_t)cp, cc, uio); 524 if (error) 525 return (error); 526 /* check again for safety */ |
518 if ((tp->t_state&TS_ISOPEN) == 0) | 527 if ((tp->t_state & TS_ISOPEN) == 0) { 528 /* adjust for data copied in but not written */ 529 uio->uio_resid += cc; |
519 return (EIO); | 530 return (EIO); |
531 } |
|
520 } 521 while (cc > 0) { 522 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && 523 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) { 524 wakeup(TSA_HUP_OR_INPUT(tp)); 525 goto block; 526 } 527 (*linesw[tp->t_line].l_rint)(*cp++, tp); 528 cnt++; 529 cc--; 530 } 531 cc = 0; 532 } 533 return (0); 534block: 535 /* 536 * Come here to wait for slave to open, for space 537 * in outq, or space in rawq. 538 */ | 532 } 533 while (cc > 0) { 534 if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 && 535 (tp->t_canq.c_cc > 0 || !(tp->t_iflag&ICANON))) { 536 wakeup(TSA_HUP_OR_INPUT(tp)); 537 goto block; 538 } 539 (*linesw[tp->t_line].l_rint)(*cp++, tp); 540 cnt++; 541 cc--; 542 } 543 cc = 0; 544 } 545 return (0); 546block: 547 /* 548 * Come here to wait for slave to open, for space 549 * in outq, or space in rawq. 550 */ |
539 if ((tp->t_state & TS_CONNECTED) == 0) | 551 if ((tp->t_state & TS_CONNECTED) == 0) { 552 /* adjust for data copied in but not written */ 553 uio->uio_resid += cc; |
540 return (EIO); | 554 return (EIO); |
555 } |
|
541 if (flag & IO_NDELAY) { 542 /* adjust for data copied in but not written */ 543 uio->uio_resid += cc; 544 if (cnt == 0) 545 return (EWOULDBLOCK); 546 return (0); 547 } 548 error = tsleep(TSA_PTC_WRITE(tp), TTOPRI | PCATCH, "ptcout", 0); --- 175 unchanged lines hidden --- | 556 if (flag & IO_NDELAY) { 557 /* adjust for data copied in but not written */ 558 uio->uio_resid += cc; 559 if (cnt == 0) 560 return (EWOULDBLOCK); 561 return (0); 562 } 563 error = tsleep(TSA_PTC_WRITE(tp), TTOPRI | PCATCH, "ptcout", 0); --- 175 unchanged lines hidden --- |