View | Details | Raw Unified | Return to bug 65372
Collapse All | Expand All

(-)a/drivers/char/tty_io.c (-10 / +29 lines)
Lines 918-926 Link Here
918
918
919
	lock_kernel();
919
	lock_kernel();
920
920
921
	down(&tty_sem);
921
	tty = current->signal->tty;
922
	tty = current->signal->tty;
922
	if (tty) {
923
	if (tty) {
923
		tty_pgrp = tty->pgrp;
924
		tty_pgrp = tty->pgrp;
925
		up(&tty_sem);
924
		if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
926
		if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
925
			tty_vhangup(tty);
927
			tty_vhangup(tty);
926
	} else {
928
	} else {
Lines 928-933 Link Here
928
			kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit);
930
			kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit);
929
			kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit);
931
			kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit);
930
		}
932
		}
933
		up(&tty_sem);
931
		unlock_kernel();	
934
		unlock_kernel();	
932
		return;
935
		return;
933
	}
936
	}
Lines 937-951 Link Here
937
			kill_pg(tty_pgrp, SIGCONT, on_exit);
940
			kill_pg(tty_pgrp, SIGCONT, on_exit);
938
	}
941
	}
939
942
943
	/* Must lock changes to tty_old_pgrp */
944
	down(&tty_sem);
940
	current->signal->tty_old_pgrp = 0;
945
	current->signal->tty_old_pgrp = 0;
941
	tty->session = 0;
946
	tty->session = 0;
942
	tty->pgrp = -1;
947
	tty->pgrp = -1;
943
948
949
	/* Now clear signal->tty under the lock */
944
	read_lock(&tasklist_lock);
950
	read_lock(&tasklist_lock);
945
	do_each_task_pid(current->signal->session, PIDTYPE_SID, p) {
951
	do_each_task_pid(current->signal->session, PIDTYPE_SID, p) {
946
		p->signal->tty = NULL;
952
		p->signal->tty = NULL;
947
	} while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
953
	} while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
948
	read_unlock(&tasklist_lock);
954
	read_unlock(&tasklist_lock);
955
	up(&tty_sem);
949
	unlock_kernel();
956
	unlock_kernel();
950
}
957
}
951
958
Lines 1172-1183 Link Here
1172
	struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
1179
	struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
1173
	int retval=0;
1180
	int retval=0;
1174
1181
1175
	/* 
1176
	 * Check whether we need to acquire the tty semaphore to avoid
1177
	 * race conditions.  For now, play it safe.
1178
	 */
1179
	down(&tty_sem);
1180
1181
	/* check whether we're reopening an existing tty */
1182
	/* check whether we're reopening an existing tty */
1182
	if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
1183
	if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
1183
		tty = devpts_get_tty(idx);
1184
		tty = devpts_get_tty(idx);
Lines 1366-1372 Link Here
1366
	
1367
	
1367
	/* All paths come through here to release the semaphore */
1368
	/* All paths come through here to release the semaphore */
1368
end_init:
1369
end_init:
1369
	up(&tty_sem);
1370
	return retval;
1370
	return retval;
1371
1371
1372
	/* Release locally allocated memory ... nothing placed in slots */
1372
	/* Release locally allocated memory ... nothing placed in slots */
Lines 1562-1570 Link Here
1562
	 * each iteration we avoid any problems.
1562
	 * each iteration we avoid any problems.
1563
	 */
1563
	 */
1564
	while (1) {
1564
	while (1) {
1565
		/* Guard against races with tty->count changes elsewhere and
1566
		   opens on /dev/tty */
1567
		   
1568
		down(&tty_sem);
1565
		tty_closing = tty->count <= 1;
1569
		tty_closing = tty->count <= 1;
1566
		o_tty_closing = o_tty &&
1570
		o_tty_closing = o_tty &&
1567
			(o_tty->count <= (pty_master ? 1 : 0));
1571
			(o_tty->count <= (pty_master ? 1 : 0));
1572
		up(&tty_sem);
1568
		do_sleep = 0;
1573
		do_sleep = 0;
1569
1574
1570
		if (tty_closing) {
1575
		if (tty_closing) {
Lines 1600-1605 Link Here
1600
	 * both sides, and we've completed the last operation that could 
1605
	 * both sides, and we've completed the last operation that could 
1601
	 * block, so it's safe to proceed with closing.
1606
	 * block, so it's safe to proceed with closing.
1602
	 */
1607
	 */
1608
	 
1609
	down(&tty_sem);
1603
	if (pty_master) {
1610
	if (pty_master) {
1604
		if (--o_tty->count < 0) {
1611
		if (--o_tty->count < 0) {
1605
			printk(KERN_WARNING "release_dev: bad pty slave count "
1612
			printk(KERN_WARNING "release_dev: bad pty slave count "
Lines 1613-1619 Link Here
1613
		       tty->count, tty_name(tty, buf));
1620
		       tty->count, tty_name(tty, buf));
1614
		tty->count = 0;
1621
		tty->count = 0;
1615
	}
1622
	}
1616
1623
	up(&tty_sem);
1624
	
1617
	/*
1625
	/*
1618
	 * We've decremented tty->count, so we need to remove this file
1626
	 * We've decremented tty->count, so we need to remove this file
1619
	 * descriptor off the tty->tty_files list; this serves two
1627
	 * descriptor off the tty->tty_files list; this serves two
Lines 1760-1769 Link Here
1760
	noctty = filp->f_flags & O_NOCTTY;
1768
	noctty = filp->f_flags & O_NOCTTY;
1761
	index  = -1;
1769
	index  = -1;
1762
	retval = 0;
1770
	retval = 0;
1771
	
1772
	down(&tty_sem);
1763
1773
1764
	if (device == MKDEV(TTYAUX_MAJOR,0)) {
1774
	if (device == MKDEV(TTYAUX_MAJOR,0)) {
1765
		if (!current->signal->tty)
1775
		if (!current->signal->tty) {
1776
			up(&tty_sem);
1766
			return -ENXIO;
1777
			return -ENXIO;
1778
		}
1767
		driver = current->signal->tty->driver;
1779
		driver = current->signal->tty->driver;
1768
		index = current->signal->tty->index;
1780
		index = current->signal->tty->index;
1769
		filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
1781
		filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
Lines 1788-1801 Link Here
1788
			noctty = 1;
1800
			noctty = 1;
1789
			goto got_driver;
1801
			goto got_driver;
1790
		}
1802
		}
1803
		up(&tty_sem);
1791
		return -ENODEV;
1804
		return -ENODEV;
1792
	}
1805
	}
1793
1806
1794
	driver = get_tty_driver(device, &index);
1807
	driver = get_tty_driver(device, &index);
1795
	if (!driver)
1808
	if (!driver) {
1809
		up(&tty_sem);
1796
		return -ENODEV;
1810
		return -ENODEV;
1811
	}
1797
got_driver:
1812
got_driver:
1798
	retval = init_dev(driver, index, &tty);
1813
	retval = init_dev(driver, index, &tty);
1814
	up(&tty_sem);
1799
	if (retval)
1815
	if (retval)
1800
		return retval;
1816
		return retval;
1801
1817
Lines 1881-1887 Link Here
1881
	}
1897
	}
1882
	up(&allocated_ptys_lock);
1898
	up(&allocated_ptys_lock);
1883
1899
1900
	down(&tty_sem);
1884
	retval = init_dev(ptm_driver, index, &tty);
1901
	retval = init_dev(ptm_driver, index, &tty);
1902
	up(&tty_sem);
1903
	
1885
	if (retval)
1904
	if (retval)
1886
		goto out;
1905
		goto out;
1887
1906
(-)a/kernel/exit.c (+2 lines)
Lines 332-338 Link Here
332
	exit_mm(current);
332
	exit_mm(current);
333
333
334
	set_special_pids(1, 1);
334
	set_special_pids(1, 1);
335
	down(&tty_sem);
335
	current->signal->tty = NULL;
336
	current->signal->tty = NULL;
337
	up(&tty_sem);
336
338
337
	/* Block and flush all signals */
339
	/* Block and flush all signals */
338
	sigfillset(&blocked);
340
	sigfillset(&blocked);
(-)a/kernel/sys.c (+2 lines)
Lines 1075-1080 Link Here
1075
	if (!thread_group_leader(current))
1075
	if (!thread_group_leader(current))
1076
		return -EINVAL;
1076
		return -EINVAL;
1077
1077
1078
	down(&tty_sem);
1078
	write_lock_irq(&tasklist_lock);
1079
	write_lock_irq(&tasklist_lock);
1079
1080
1080
	pid = find_pid(PIDTYPE_PGID, current->pid);
1081
	pid = find_pid(PIDTYPE_PGID, current->pid);
Lines 1088-1093 Link Here
1088
	err = process_group(current);
1089
	err = process_group(current);
1089
out:
1090
out:
1090
	write_unlock_irq(&tasklist_lock);
1091
	write_unlock_irq(&tasklist_lock);
1092
	up(&tty_sem);
1091
	return err;
1093
	return err;
1092
}
1094
}
1093
1095

Return to bug 65372