Print this page
12306 XPG4v2 slave pty behaviour should generally be disabled
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Change-ID: I7ccd399c22866f34dd20c6bb9d28e77ba4e24c67
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/ptm.c
+++ new/usr/src/uts/common/io/ptm.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
25 25 /* All Rights Reserved */
26 26
27 +/*
28 + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
29 + */
27 30
28 -
29 31 /*
30 32 * Pseudo Terminal Master Driver.
31 33 *
32 34 * The pseudo-tty subsystem simulates a terminal connection, where the master
33 35 * side represents the terminal and the slave represents the user process's
34 36 * special device end point. The master device is set up as a cloned device
35 37 * where its major device number is the major for the clone device and its minor
36 38 * device number is the major for the ptm driver. There are no nodes in the file
37 39 * system for master devices. The master pseudo driver is opened using the
38 40 * open(2) system call with /dev/ptmx as the device parameter. The clone open
39 41 * finds the next available minor device for the ptm major device.
40 42 *
41 43 * A master device is available only if it and its corresponding slave device
42 44 * are not already open. When the master device is opened, the corresponding
43 45 * slave device is automatically locked out. Only one open is allowed on a
44 46 * master device. Multiple opens are allowed on the slave device. After both
45 47 * the master and slave have been opened, the user has two file descriptors
46 48 * which are the end points of a full duplex connection composed of two streams
47 49 * which are automatically connected at the master and slave drivers. The user
48 50 * may then push modules onto either side of the stream pair.
49 51 *
50 52 * The master and slave drivers pass all messages to their adjacent queues.
51 53 * Only the M_FLUSH needs some processing. Because the read queue of one side
52 54 * is connected to the write queue of the other, the FLUSHR flag is changed to
53 55 * the FLUSHW flag and vice versa. When the master device is closed an M_HANGUP
54 56 * message is sent to the slave device which will render the device
55 57 * unusable. The process on the slave side gets the EIO when attempting to write
56 58 * on that stream but it will be able to read any data remaining on the stream
57 59 * head read queue. When all the data has been read, read() returns 0
58 60 * indicating that the stream can no longer be used. On the last close of the
59 61 * slave device, a 0-length message is sent to the master device. When the
60 62 * application on the master side issues a read() or getmsg() and 0 is returned,
61 63 * the user of the master device decides whether to issue a close() that
62 64 * dismantles the pseudo-terminal subsystem. If the master device is not closed,
63 65 * the pseudo-tty subsystem will be available to another user to open the slave
64 66 * device.
65 67 *
66 68 * If O_NONBLOCK or O_NDELAY is set, read on the master side returns -1 with
67 69 * errno set to EAGAIN if no data is available, and write returns -1 with errno
68 70 * set to EAGAIN if there is internal flow control.
69 71 *
70 72 * IOCTLS:
71 73 *
72 74 * ISPTM: determines whether the file descriptor is that of an open master
73 75 * device. Return code of zero indicates that the file descriptor
74 76 * represents master device.
75 77 *
76 78 * UNLKPT: unlocks the master and slave devices. It returns 0 on success. On
77 79 * failure, the errno is set to EINVAL indicating that the master
78 80 * device is not open.
79 81 *
80 82 * ZONEPT: sets the zone membership of the associated pts device.
81 83 *
82 84 * GRPPT: sets the group owner of the associated pts device.
83 85 *
84 86 * Synchronization:
85 87 *
86 88 * All global data synchronization between ptm/pts is done via global
87 89 * ptms_lock mutex which is initialized at system boot time from
88 90 * ptms_initspace (called from space.c).
89 91 *
90 92 * Individual fields of pt_ttys structure (except ptm_rdq, pts_rdq and
91 93 * pt_nullmsg) are protected by pt_ttys.pt_lock mutex.
92 94 *
93 95 * PT_ENTER_READ/PT_ENTER_WRITE are reference counter based read-write locks
94 96 * which allow reader locks to be reacquired by the same thread (usual
95 97 * reader/writer locks can't be used for that purpose since it is illegal for
96 98 * a thread to acquire a lock it already holds, even as a reader). The sole
97 99 * purpose of these macros is to guarantee that the peer queue will not
98 100 * disappear (due to closing peer) while it is used. It is safe to use
99 101 * PT_ENTER_READ/PT_EXIT_READ brackets across calls like putq/putnext (since
100 102 * they are not real locks but reference counts).
101 103 *
102 104 * PT_ENTER_WRITE/PT_EXIT_WRITE brackets are used ONLY in master/slave
103 105 * open/close paths to modify ptm_rdq and pts_rdq fields. These fields should
104 106 * be set to appropriate queues *after* qprocson() is called during open (to
105 107 * prevent peer from accessing the queue with incomplete plumbing) and set to
106 108 * NULL before qprocsoff() is called during close.
107 109 *
108 110 * The pt_nullmsg field is only used in open/close routines and it is also
109 111 * protected by PT_ENTER_WRITE/PT_EXIT_WRITE brackets to avoid extra mutex
110 112 * holds.
111 113 *
112 114 * Lock Ordering:
113 115 *
114 116 * If both ptms_lock and per-pty lock should be held, ptms_lock should always
115 117 * be entered first, followed by per-pty lock.
116 118 *
117 119 * See ptms.h, pts.c and ptms_conf.c for more information.
118 120 */
119 121
120 122 #include <sys/types.h>
121 123 #include <sys/param.h>
122 124 #include <sys/file.h>
123 125 #include <sys/sysmacros.h>
124 126 #include <sys/stream.h>
125 127 #include <sys/stropts.h>
126 128 #include <sys/proc.h>
127 129 #include <sys/errno.h>
128 130 #include <sys/debug.h>
129 131 #include <sys/cmn_err.h>
130 132 #include <sys/ptms.h>
131 133 #include <sys/stat.h>
132 134 #include <sys/strsun.h>
133 135 #include <sys/systm.h>
134 136 #include <sys/modctl.h>
135 137 #include <sys/conf.h>
136 138 #include <sys/ddi.h>
137 139 #include <sys/sunddi.h>
138 140 #include <sys/zone.h>
139 141
140 142 #ifdef DEBUG
141 143 int ptm_debug = 0;
142 144 #define DBG(a) if (ptm_debug) cmn_err(CE_NOTE, a)
143 145 #else
144 146 #define DBG(a)
145 147 #endif
146 148
147 149 static int ptmopen(queue_t *, dev_t *, int, int, cred_t *);
148 150 static int ptmclose(queue_t *, int, cred_t *);
149 151 static int ptmwput(queue_t *, mblk_t *);
150 152 static int ptmrsrv(queue_t *);
151 153 static int ptmwsrv(queue_t *);
152 154
153 155 /*
154 156 * Master Stream Pseudo Terminal Module: stream data structure definitions
155 157 */
156 158
157 159 static struct module_info ptm_info = {
158 160 0xdead,
159 161 "ptm",
160 162 0,
161 163 512,
162 164 512,
163 165 128
164 166 };
165 167
166 168 static struct qinit ptmrint = {
167 169 NULL,
168 170 ptmrsrv,
169 171 ptmopen,
170 172 ptmclose,
171 173 NULL,
172 174 &ptm_info,
173 175 NULL
174 176 };
175 177
176 178 static struct qinit ptmwint = {
177 179 ptmwput,
178 180 ptmwsrv,
179 181 NULL,
180 182 NULL,
181 183 NULL,
182 184 &ptm_info,
183 185 NULL
184 186 };
185 187
186 188 static struct streamtab ptminfo = {
187 189 &ptmrint,
188 190 &ptmwint,
189 191 NULL,
190 192 NULL
191 193 };
192 194
193 195 static int ptm_attach(dev_info_t *, ddi_attach_cmd_t);
194 196 static int ptm_detach(dev_info_t *, ddi_detach_cmd_t);
195 197 static int ptm_devinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
196 198
197 199 static dev_info_t *ptm_dip; /* private devinfo pointer */
198 200
199 201 /*
200 202 * this will define (struct cb_ops cb_ptm_ops) and (struct dev_ops ptm_ops)
201 203 */
202 204 DDI_DEFINE_STREAM_OPS(ptm_ops, nulldev, nulldev, ptm_attach, ptm_detach,
203 205 nodev, ptm_devinfo, D_MP, &ptminfo, ddi_quiesce_not_supported);
204 206
205 207 /*
206 208 * Module linkage information for the kernel.
207 209 */
208 210
209 211 static struct modldrv modldrv = {
210 212 &mod_driverops, /* Type of module. This one is a pseudo driver */
211 213 "Master streams driver 'ptm'",
212 214 &ptm_ops, /* driver ops */
213 215 };
214 216
215 217 static struct modlinkage modlinkage = {
216 218 MODREV_1,
217 219 &modldrv,
218 220 NULL
219 221 };
220 222
221 223 int
222 224 _init(void)
223 225 {
224 226 int rc;
225 227
226 228 if ((rc = mod_install(&modlinkage)) == 0)
227 229 ptms_init();
228 230 return (rc);
229 231 }
230 232
231 233 int
232 234 _fini(void)
233 235 {
234 236 return (mod_remove(&modlinkage));
235 237 }
236 238
237 239 int
238 240 _info(struct modinfo *modinfop)
239 241 {
240 242 return (mod_info(&modlinkage, modinfop));
241 243 }
242 244
243 245 static int
244 246 ptm_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
245 247 {
246 248 if (cmd != DDI_ATTACH)
247 249 return (DDI_FAILURE);
248 250
249 251 if (ddi_create_minor_node(devi, "ptmajor", S_IFCHR,
250 252 0, DDI_PSEUDO, 0) == DDI_FAILURE) {
251 253 ddi_remove_minor_node(devi, NULL);
252 254 return (DDI_FAILURE);
253 255 }
254 256 if (ddi_create_minor_node(devi, "ptmx", S_IFCHR,
255 257 0, DDI_PSEUDO, CLONE_DEV) == DDI_FAILURE) {
256 258 ddi_remove_minor_node(devi, NULL);
257 259 return (DDI_FAILURE);
258 260 }
259 261 ptm_dip = devi;
260 262
261 263 return (DDI_SUCCESS);
262 264 }
263 265
264 266 static int
265 267 ptm_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
266 268 {
267 269 if (cmd != DDI_DETACH)
268 270 return (DDI_FAILURE);
269 271
270 272 ddi_remove_minor_node(devi, NULL);
271 273 return (DDI_SUCCESS);
272 274 }
273 275
274 276 /*ARGSUSED*/
275 277 static int
276 278 ptm_devinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
277 279 void **result)
278 280 {
279 281 int error;
280 282
281 283 switch (infocmd) {
282 284 case DDI_INFO_DEVT2DEVINFO:
283 285 if (ptm_dip == NULL) {
284 286 error = DDI_FAILURE;
285 287 } else {
286 288 *result = (void *)ptm_dip;
287 289 error = DDI_SUCCESS;
288 290 }
289 291 break;
290 292 case DDI_INFO_DEVT2INSTANCE:
291 293 *result = (void *)0;
292 294 error = DDI_SUCCESS;
293 295 break;
294 296 default:
295 297 error = DDI_FAILURE;
296 298 }
297 299 return (error);
298 300 }
299 301
300 302
301 303 /* ARGSUSED */
302 304 /*
303 305 * Open a minor of the master device. Store the write queue pointer and set the
304 306 * pt_state field to (PTMOPEN | PTLOCK).
305 307 * This code will work properly with both clone opens and direct opens of the
306 308 * master device.
307 309 */
308 310 static int
309 311 ptmopen(
310 312 queue_t *rqp, /* pointer to the read side queue */
311 313 dev_t *devp, /* pointer to stream tail's dev */
312 314 int oflag, /* the user open(2) supplied flags */
313 315 int sflag, /* open state flag */
314 316 cred_t *credp) /* credentials */
315 317 {
316 318 struct pt_ttys *ptmp;
317 319 mblk_t *mop; /* ptr to a setopts message block */
318 320 struct stroptions *sop;
319 321 minor_t dminor = getminor(*devp);
320 322
321 323 /* Allow reopen */
322 324 if (rqp->q_ptr != NULL)
323 325 return (0);
324 326
325 327 if (sflag & MODOPEN)
326 328 return (ENXIO);
327 329
328 330 if (!(sflag & CLONEOPEN) && dminor != 0) {
329 331 /*
330 332 * This is a direct open to specific master device through an
331 333 * artificially created entry with specific minor in
332 334 * /dev/directory. Such behavior is not supported.
333 335 */
334 336 return (ENXIO);
335 337 }
336 338
337 339 /*
338 340 * The master open requires that the slave be attached
339 341 * before it returns so that attempts to open the slave will
340 342 * succeeed
341 343 */
342 344 if (ptms_attach_slave() != 0) {
343 345 return (ENXIO);
344 346 }
345 347
346 348 mop = allocb(sizeof (struct stroptions), BPRI_MED);
347 349 if (mop == NULL) {
348 350 DDBG("ptmopen(): mop allocation failed\n", 0);
349 351 return (ENOMEM);
350 352 }
351 353
352 354 if ((ptmp = pt_ttys_alloc()) == NULL) {
353 355 DDBG("ptmopen(): pty allocation failed\n", 0);
354 356 freemsg(mop);
355 357 return (ENOMEM);
356 358 }
357 359
358 360 dminor = ptmp->pt_minor;
359 361
360 362 DDBGP("ptmopen(): allocated ptmp %p\n", (uintptr_t)ptmp);
361 363 DDBG("ptmopen(): allocated minor %d\n", dminor);
362 364
363 365 WR(rqp)->q_ptr = rqp->q_ptr = ptmp;
364 366
365 367 qprocson(rqp);
366 368
367 369 /* Allow slave to send messages to master */
368 370 PT_ENTER_WRITE(ptmp);
369 371 ptmp->ptm_rdq = rqp;
370 372 PT_EXIT_WRITE(ptmp);
371 373
372 374 /*
373 375 * set up hi/lo water marks on stream head read queue
374 376 * and add controlling tty if not set
375 377 */
376 378 mop->b_datap->db_type = M_SETOPTS;
377 379 mop->b_wptr += sizeof (struct stroptions);
378 380 sop = (struct stroptions *)mop->b_rptr;
379 381 if (oflag & FNOCTTY)
380 382 sop->so_flags = SO_HIWAT | SO_LOWAT;
381 383 else
382 384 sop->so_flags = SO_HIWAT | SO_LOWAT | SO_ISTTY;
383 385 sop->so_hiwat = _TTY_BUFSIZ;
384 386 sop->so_lowat = 256;
385 387 putnext(rqp, mop);
386 388
387 389 /*
388 390 * The input, devp, is a major device number, the output is put
389 391 * into the same parm as a major,minor pair.
390 392 */
391 393 *devp = makedevice(getmajor(*devp), dminor);
392 394
393 395 return (0);
394 396 }
395 397
396 398
397 399 /*
398 400 * Find the address to private data identifying the slave's write queue.
399 401 * Send a hang-up message up the slave's read queue to designate the
400 402 * master/slave pair is tearing down. Uattach the master and slave by
401 403 * nulling out the write queue fields in the private data structure.
402 404 * Finally, unlock the master/slave pair and mark the master as closed.
403 405 */
404 406 /*ARGSUSED1*/
405 407 static int
406 408 ptmclose(queue_t *rqp, int flag, cred_t *credp)
407 409 {
408 410 struct pt_ttys *ptmp;
409 411 queue_t *pts_rdq;
410 412
411 413 ASSERT(rqp->q_ptr);
412 414
413 415 ptmp = (struct pt_ttys *)rqp->q_ptr;
414 416 PT_ENTER_READ(ptmp);
415 417 if (ptmp->pts_rdq) {
416 418 pts_rdq = ptmp->pts_rdq;
417 419 if (pts_rdq->q_next) {
418 420 DBG(("send hangup message to slave\n"));
419 421 (void) putnextctl(pts_rdq, M_HANGUP);
420 422 }
421 423 }
422 424 PT_EXIT_READ(ptmp);
423 425 /*
424 426 * ptm_rdq should be cleared before call to qprocsoff() to prevent pts
425 427 * write procedure to attempt using ptm_rdq after qprocsoff.
426 428 */
427 429 PT_ENTER_WRITE(ptmp);
428 430 ptmp->ptm_rdq = NULL;
429 431 freemsg(ptmp->pt_nullmsg);
430 432 ptmp->pt_nullmsg = NULL;
431 433 /*
432 434 * qenable slave side write queue so that it can flush
433 435 * its messages as master's read queue is going away
434 436 */
435 437 if (ptmp->pts_rdq)
436 438 qenable(WR(ptmp->pts_rdq));
437 439 PT_EXIT_WRITE(ptmp);
438 440
439 441 qprocsoff(rqp);
440 442
441 443 /* Finish the close */
442 444 rqp->q_ptr = NULL;
443 445 WR(rqp)->q_ptr = NULL;
444 446
445 447 ptms_close(ptmp, PTMOPEN | PTLOCK);
446 448
447 449 return (0);
448 450 }
449 451
450 452 /*
451 453 * The wput procedure will only handle ioctl and flush messages.
452 454 */
453 455 static int
454 456 ptmwput(queue_t *qp, mblk_t *mp)
455 457 {
456 458 struct pt_ttys *ptmp;
457 459 struct iocblk *iocp;
458 460
459 461 DBG(("entering ptmwput\n"));
460 462 ASSERT(qp->q_ptr);
461 463
462 464 ptmp = (struct pt_ttys *)qp->q_ptr;
463 465 PT_ENTER_READ(ptmp);
464 466
465 467 switch (mp->b_datap->db_type) {
466 468 /*
467 469 * if write queue request, flush master's write
468 470 * queue and send FLUSHR up slave side. If read
469 471 * queue request, convert to FLUSHW and putnext().
470 472 */
471 473 case M_FLUSH:
472 474 {
473 475 unsigned char flush_flg = 0;
474 476
475 477 DBG(("ptm got flush request\n"));
476 478 if (*mp->b_rptr & FLUSHW) {
477 479 DBG(("got FLUSHW, flush ptm write Q\n"));
478 480 if (*mp->b_rptr & FLUSHBAND)
479 481 /*
480 482 * if it is a FLUSHBAND, do flushband.
481 483 */
482 484 flushband(qp, *(mp->b_rptr + 1),
483 485 FLUSHDATA);
484 486 else
485 487 flushq(qp, FLUSHDATA);
486 488 flush_flg = (*mp->b_rptr & ~FLUSHW) | FLUSHR;
487 489 }
488 490 if (*mp->b_rptr & FLUSHR) {
489 491 DBG(("got FLUSHR, set FLUSHW\n"));
490 492 flush_flg |= (*mp->b_rptr & ~FLUSHR) | FLUSHW;
491 493 }
492 494 if (flush_flg != 0 && ptmp->pts_rdq &&
493 495 !(ptmp->pt_state & PTLOCK)) {
494 496 DBG(("putnext to pts\n"));
495 497 *mp->b_rptr = flush_flg;
496 498 putnext(ptmp->pts_rdq, mp);
497 499 } else
498 500 freemsg(mp);
499 501 break;
500 502 }
501 503
502 504 case M_IOCTL:
503 505 iocp = (struct iocblk *)mp->b_rptr;
504 506 switch (iocp->ioc_cmd) {
505 507 default:
506 508 if ((ptmp->pt_state & PTLOCK) ||
507 509 (ptmp->pts_rdq == NULL)) {
508 510 DBG(("got M_IOCTL but no slave\n"));
509 511 miocnak(qp, mp, 0, EINVAL);
510 512 PT_EXIT_READ(ptmp);
511 513 return (0);
512 514 }
513 515 (void) putq(qp, mp);
↓ open down ↓ |
475 lines elided |
↑ open up ↑ |
514 516 break;
515 517 case UNLKPT:
516 518 mutex_enter(&ptmp->pt_lock);
517 519 ptmp->pt_state &= ~PTLOCK;
518 520 mutex_exit(&ptmp->pt_lock);
519 521 /*FALLTHROUGH*/
520 522 case ISPTM:
521 523 DBG(("ack the UNLKPT/ISPTM\n"));
522 524 miocack(qp, mp, 0, 0);
523 525 break;
526 + case PTSSTTY:
527 + mutex_enter(&ptmp->pt_lock);
528 + ptmp->pt_state |= PTSTTY;
529 + mutex_exit(&ptmp->pt_lock);
530 + DBG(("ack PTSSTTY\n"));
531 + miocack(qp, mp, 0, 0);
532 + break;
524 533 case ZONEPT:
525 534 {
526 535 zoneid_t z;
527 536 int error;
528 537
529 538 if ((error = drv_priv(iocp->ioc_cr)) != 0) {
530 539 miocnak(qp, mp, 0, error);
531 540 break;
532 541 }
533 542 if ((error = miocpullup(mp, sizeof (zoneid_t))) != 0) {
534 543 miocnak(qp, mp, 0, error);
535 544 break;
536 545 }
537 546 z = *((zoneid_t *)mp->b_cont->b_rptr);
538 547 if (z < MIN_ZONEID || z > MAX_ZONEID) {
539 548 miocnak(qp, mp, 0, EINVAL);
540 549 break;
541 550 }
542 551
543 552 mutex_enter(&ptmp->pt_lock);
544 553 ptmp->pt_zoneid = z;
545 554 mutex_exit(&ptmp->pt_lock);
546 555 miocack(qp, mp, 0, 0);
547 556 break;
548 557 }
549 558 case OWNERPT:
550 559 {
551 560 pt_own_t *ptop;
552 561 int error;
553 562 zone_t *zone;
554 563
555 564 if ((error = miocpullup(mp, sizeof (pt_own_t))) != 0) {
556 565 miocnak(qp, mp, 0, error);
557 566 break;
558 567 }
559 568
560 569 zone = zone_find_by_id(ptmp->pt_zoneid);
561 570 ptop = (pt_own_t *)mp->b_cont->b_rptr;
562 571
563 572 if (!VALID_UID(ptop->pto_ruid, zone) ||
564 573 !VALID_GID(ptop->pto_rgid, zone)) {
565 574 zone_rele(zone);
566 575 miocnak(qp, mp, 0, EINVAL);
567 576 break;
568 577 }
569 578 zone_rele(zone);
570 579 mutex_enter(&ptmp->pt_lock);
571 580 ptmp->pt_ruid = ptop->pto_ruid;
572 581 ptmp->pt_rgid = ptop->pto_rgid;
573 582 mutex_exit(&ptmp->pt_lock);
574 583 miocack(qp, mp, 0, 0);
575 584 break;
576 585 }
577 586 }
578 587 break;
579 588
580 589 case M_READ:
581 590 /* Caused by ldterm - can not pass to slave */
582 591 freemsg(mp);
583 592 break;
584 593
585 594 /*
586 595 * send other messages to slave
587 596 */
588 597 default:
589 598 if ((ptmp->pt_state & PTLOCK) || (ptmp->pts_rdq == NULL)) {
590 599 DBG(("got msg. but no slave\n"));
591 600 mp = mexchange(NULL, mp, 2, M_ERROR, -1);
592 601 if (mp != NULL) {
593 602 mp->b_rptr[0] = NOERROR;
594 603 mp->b_rptr[1] = EINVAL;
595 604 qreply(qp, mp);
596 605 }
597 606 PT_EXIT_READ(ptmp);
598 607 return (0);
599 608 }
600 609 DBG(("put msg on master's write queue\n"));
601 610 (void) putq(qp, mp);
602 611 break;
603 612 }
604 613 DBG(("return from ptmwput()\n"));
605 614 PT_EXIT_READ(ptmp);
606 615 return (0);
607 616 }
608 617
609 618
610 619 /*
611 620 * enable the write side of the slave. This triggers the
612 621 * slave to send any messages queued on its write side to
613 622 * the read side of this master.
614 623 */
615 624 static int
616 625 ptmrsrv(queue_t *qp)
617 626 {
618 627 struct pt_ttys *ptmp;
619 628
620 629 DBG(("entering ptmrsrv\n"));
621 630 ASSERT(qp->q_ptr);
622 631
623 632 ptmp = (struct pt_ttys *)qp->q_ptr;
624 633 PT_ENTER_READ(ptmp);
625 634 if (ptmp->pts_rdq) {
626 635 qenable(WR(ptmp->pts_rdq));
627 636 }
628 637 PT_EXIT_READ(ptmp);
629 638 DBG(("leaving ptmrsrv\n"));
630 639 return (0);
631 640 }
632 641
633 642
634 643 /*
635 644 * If there are messages on this queue that can be sent to
636 645 * slave, send them via putnext(). Else, if queued messages
637 646 * cannot be sent, leave them on this queue. If priority
638 647 * messages on this queue, send them to slave no matter what.
639 648 */
640 649 static int
641 650 ptmwsrv(queue_t *qp)
642 651 {
643 652 struct pt_ttys *ptmp;
644 653 mblk_t *mp;
645 654
646 655 DBG(("entering ptmwsrv\n"));
647 656 ASSERT(qp->q_ptr);
648 657
649 658 ptmp = (struct pt_ttys *)qp->q_ptr;
650 659
651 660 if ((mp = getq(qp)) == NULL) {
652 661 /* If there are no messages there's nothing to do. */
653 662 DBG(("leaving ptmwsrv (no messages)\n"));
654 663 return (0);
655 664 }
656 665
657 666 PT_ENTER_READ(ptmp);
658 667 if ((ptmp->pt_state & PTLOCK) || (ptmp->pts_rdq == NULL)) {
659 668 DBG(("in master write srv proc but no slave\n"));
660 669 /*
661 670 * Free messages on the write queue and send
662 671 * NAK for any M_IOCTL type messages to wakeup
663 672 * the user process waiting for ACK/NAK from
664 673 * the ioctl invocation
665 674 */
666 675 do {
667 676 if (mp->b_datap->db_type == M_IOCTL)
668 677 miocnak(qp, mp, 0, EINVAL);
669 678 else
670 679 freemsg(mp);
671 680 } while ((mp = getq(qp)) != NULL);
672 681 flushq(qp, FLUSHALL);
673 682
674 683 mp = mexchange(NULL, NULL, 2, M_ERROR, -1);
675 684 if (mp != NULL) {
676 685 mp->b_rptr[0] = NOERROR;
677 686 mp->b_rptr[1] = EINVAL;
678 687 qreply(qp, mp);
679 688 }
680 689 PT_EXIT_READ(ptmp);
681 690 return (0);
682 691 }
683 692 /*
684 693 * while there are messages on this write queue...
685 694 */
686 695 do {
687 696 /*
688 697 * if don't have control message and cannot put
689 698 * msg. on slave's read queue, put it back on
690 699 * this queue.
691 700 */
692 701 if (mp->b_datap->db_type <= QPCTL &&
693 702 !bcanputnext(ptmp->pts_rdq, mp->b_band)) {
694 703 DBG(("put msg. back on queue\n"));
695 704 (void) putbq(qp, mp);
696 705 break;
697 706 }
698 707 /*
699 708 * else send the message up slave's stream
700 709 */
701 710 DBG(("send message to slave\n"));
702 711 putnext(ptmp->pts_rdq, mp);
703 712 } while ((mp = getq(qp)) != NULL);
704 713 DBG(("leaving ptmwsrv\n"));
705 714 PT_EXIT_READ(ptmp);
706 715 return (0);
707 716 }
↓ open down ↓ |
174 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX