|
Lines 579-587
Link Here
|
| 579 |
|
579 |
|
| 580 |
lock_kernel(); |
580 |
lock_kernel(); |
| 581 |
|
581 |
|
|
|
582 |
down(&tty_sem); |
| 582 |
tty = current->signal->tty; |
583 |
tty = current->signal->tty; |
| 583 |
if (tty) { |
584 |
if (tty) { |
| 584 |
tty_pgrp = tty->pgrp; |
585 |
tty_pgrp = tty->pgrp; |
|
|
586 |
up(&tty_sem); |
| 585 |
if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) |
587 |
if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) |
| 586 |
tty_vhangup(tty); |
588 |
tty_vhangup(tty); |
| 587 |
} else { |
589 |
} else { |
|
Lines 589-594
Link Here
|
| 589 |
kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); |
591 |
kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); |
| 590 |
kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); |
592 |
kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); |
| 591 |
} |
593 |
} |
|
|
594 |
up(&tty_sem); |
| 592 |
unlock_kernel(); |
595 |
unlock_kernel(); |
| 593 |
return; |
596 |
return; |
| 594 |
} |
597 |
} |
|
Lines 598-612
Link Here
|
| 598 |
kill_pg(tty_pgrp, SIGCONT, on_exit); |
601 |
kill_pg(tty_pgrp, SIGCONT, on_exit); |
| 599 |
} |
602 |
} |
| 600 |
|
603 |
|
|
|
604 |
/* Must lock changes to tty_old_pgrp */ |
| 605 |
down(&tty_sem); |
| 601 |
current->signal->tty_old_pgrp = 0; |
606 |
current->signal->tty_old_pgrp = 0; |
| 602 |
tty->session = 0; |
607 |
tty->session = 0; |
| 603 |
tty->pgrp = -1; |
608 |
tty->pgrp = -1; |
| 604 |
|
609 |
|
|
|
610 |
/* Now clear signal->tty under the lock */ |
| 605 |
read_lock(&tasklist_lock); |
611 |
read_lock(&tasklist_lock); |
| 606 |
do_each_task_pid(current->signal->session, PIDTYPE_SID, p) { |
612 |
do_each_task_pid(current->signal->session, PIDTYPE_SID, p) { |
| 607 |
p->signal->tty = NULL; |
613 |
p->signal->tty = NULL; |
| 608 |
} while_each_task_pid(current->signal->session, PIDTYPE_SID, p); |
614 |
} while_each_task_pid(current->signal->session, PIDTYPE_SID, p); |
| 609 |
read_unlock(&tasklist_lock); |
615 |
read_unlock(&tasklist_lock); |
|
|
616 |
up(&tty_sem); |
| 610 |
unlock_kernel(); |
617 |
unlock_kernel(); |
| 611 |
} |
618 |
} |
| 612 |
|
619 |
|
|
Lines 790-801
Link Here
|
| 790 |
struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; |
797 |
struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; |
| 791 |
int retval=0; |
798 |
int retval=0; |
| 792 |
|
799 |
|
| 793 |
/* |
|
|
| 794 |
* Check whether we need to acquire the tty semaphore to avoid |
| 795 |
* race conditions. For now, play it safe. |
| 796 |
*/ |
| 797 |
down(&tty_sem); |
| 798 |
|
| 799 |
/* check whether we're reopening an existing tty */ |
800 |
/* check whether we're reopening an existing tty */ |
| 800 |
if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { |
801 |
if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { |
| 801 |
tty = devpts_get_tty(idx); |
802 |
tty = devpts_get_tty(idx); |
|
Lines 978-984
Link Here
|
| 978 |
|
979 |
|
| 979 |
/* All paths come through here to release the semaphore */ |
980 |
/* All paths come through here to release the semaphore */ |
| 980 |
end_init: |
981 |
end_init: |
| 981 |
up(&tty_sem); |
|
|
| 982 |
return retval; |
982 |
return retval; |
| 983 |
|
983 |
|
| 984 |
/* Release locally allocated memory ... nothing placed in slots */ |
984 |
/* Release locally allocated memory ... nothing placed in slots */ |
|
Lines 1174-1182
Link Here
|
| 1174 |
* each iteration we avoid any problems. |
1174 |
* each iteration we avoid any problems. |
| 1175 |
*/ |
1175 |
*/ |
| 1176 |
while (1) { |
1176 |
while (1) { |
|
|
1177 |
/* Guard against races with tty->count changes elsewhere and |
| 1178 |
opens on /dev/tty */ |
| 1179 |
|
| 1180 |
down(&tty_sem); |
| 1177 |
tty_closing = tty->count <= 1; |
1181 |
tty_closing = tty->count <= 1; |
| 1178 |
o_tty_closing = o_tty && |
1182 |
o_tty_closing = o_tty && |
| 1179 |
(o_tty->count <= (pty_master ? 1 : 0)); |
1183 |
(o_tty->count <= (pty_master ? 1 : 0)); |
|
|
1184 |
up(&tty_sem); |
| 1180 |
do_sleep = 0; |
1185 |
do_sleep = 0; |
| 1181 |
|
1186 |
|
| 1182 |
if (tty_closing) { |
1187 |
if (tty_closing) { |
|
Lines 1212-1217
Link Here
|
| 1212 |
* both sides, and we've completed the last operation that could |
1217 |
* both sides, and we've completed the last operation that could |
| 1213 |
* block, so it's safe to proceed with closing. |
1218 |
* block, so it's safe to proceed with closing. |
| 1214 |
*/ |
1219 |
*/ |
|
|
1220 |
|
| 1221 |
down(&tty_sem); |
| 1215 |
if (pty_master) { |
1222 |
if (pty_master) { |
| 1216 |
if (--o_tty->count < 0) { |
1223 |
if (--o_tty->count < 0) { |
| 1217 |
printk(KERN_WARNING "release_dev: bad pty slave count " |
1224 |
printk(KERN_WARNING "release_dev: bad pty slave count " |
|
Lines 1225-1231
Link Here
|
| 1225 |
tty->count, tty_name(tty, buf)); |
1232 |
tty->count, tty_name(tty, buf)); |
| 1226 |
tty->count = 0; |
1233 |
tty->count = 0; |
| 1227 |
} |
1234 |
} |
| 1228 |
|
1235 |
up(&tty_sem); |
|
|
1236 |
|
| 1229 |
/* |
1237 |
/* |
| 1230 |
* We've decremented tty->count, so we need to remove this file |
1238 |
* We've decremented tty->count, so we need to remove this file |
| 1231 |
* descriptor off the tty->tty_files list; this serves two |
1239 |
* descriptor off the tty->tty_files list; this serves two |
|
Lines 1349-1358
Link Here
|
| 1349 |
noctty = filp->f_flags & O_NOCTTY; |
1357 |
noctty = filp->f_flags & O_NOCTTY; |
| 1350 |
index = -1; |
1358 |
index = -1; |
| 1351 |
retval = 0; |
1359 |
retval = 0; |
|
|
1360 |
|
| 1361 |
down(&tty_sem); |
| 1352 |
|
1362 |
|
| 1353 |
if (device == MKDEV(TTYAUX_MAJOR,0)) { |
1363 |
if (device == MKDEV(TTYAUX_MAJOR,0)) { |
| 1354 |
if (!current->signal->tty) |
1364 |
if (!current->signal->tty) { |
|
|
1365 |
up(&tty_sem); |
| 1355 |
return -ENXIO; |
1366 |
return -ENXIO; |
|
|
1367 |
} |
| 1356 |
driver = current->signal->tty->driver; |
1368 |
driver = current->signal->tty->driver; |
| 1357 |
index = current->signal->tty->index; |
1369 |
index = current->signal->tty->index; |
| 1358 |
filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */ |
1370 |
filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */ |
|
Lines 1377-1390
Link Here
|
| 1377 |
noctty = 1; |
1389 |
noctty = 1; |
| 1378 |
goto got_driver; |
1390 |
goto got_driver; |
| 1379 |
} |
1391 |
} |
|
|
1392 |
up(&tty_sem); |
| 1380 |
return -ENODEV; |
1393 |
return -ENODEV; |
| 1381 |
} |
1394 |
} |
| 1382 |
|
1395 |
|
| 1383 |
driver = get_tty_driver(device, &index); |
1396 |
driver = get_tty_driver(device, &index); |
| 1384 |
if (!driver) |
1397 |
if (!driver) { |
|
|
1398 |
up(&tty_sem); |
| 1385 |
return -ENODEV; |
1399 |
return -ENODEV; |
|
|
1400 |
} |
| 1386 |
got_driver: |
1401 |
got_driver: |
| 1387 |
retval = init_dev(driver, index, &tty); |
1402 |
retval = init_dev(driver, index, &tty); |
|
|
1403 |
up(&tty_sem); |
| 1388 |
if (retval) |
1404 |
if (retval) |
| 1389 |
return retval; |
1405 |
return retval; |
| 1390 |
|
1406 |
|
|
Lines 1470-1476
Link Here
|
| 1470 |
} |
1486 |
} |
| 1471 |
up(&allocated_ptys_lock); |
1487 |
up(&allocated_ptys_lock); |
| 1472 |
|
1488 |
|
|
|
1489 |
down(&tty_sem); |
| 1473 |
retval = init_dev(ptm_driver, index, &tty); |
1490 |
retval = init_dev(ptm_driver, index, &tty); |
|
|
1491 |
up(&tty_sem); |
| 1492 |
|
| 1474 |
if (retval) |
1493 |
if (retval) |
| 1475 |
goto out; |
1494 |
goto out; |
| 1476 |
|
1495 |
|