From nobody@FreeBSD.org  Tue May 28 12:25:05 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id A43C3331
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 28 May 2013 12:25:05 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.FreeBSD.org (oldred.freebsd.org [8.8.178.121])
	by mx1.freebsd.org (Postfix) with ESMTP id 96ABA616
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 28 May 2013 12:25:05 +0000 (UTC)
Received: from oldred.FreeBSD.org ([127.0.1.6])
	by oldred.FreeBSD.org (8.14.5/8.14.5) with ESMTP id r4SCP4eU029977
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 28 May 2013 12:25:04 GMT
	(envelope-from nobody@oldred.FreeBSD.org)
Received: (from nobody@localhost)
	by oldred.FreeBSD.org (8.14.5/8.14.5/Submit) id r4SCP4j8029976;
	Tue, 28 May 2013 12:25:04 GMT
	(envelope-from nobody)
Message-Id: <201305281225.r4SCP4j8029976@oldred.FreeBSD.org>
Date: Tue, 28 May 2013 12:25:04 GMT
From: Serhii Kharchenko <harry@advancedhosters.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: watch(8) doesn't stop listening TTY when user releases it
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         179048
>Category:       bin
>Synopsis:       watch(8) doesn't stop listening TTY when user releases it
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 28 12:30:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Tue May 28 13:42:46 UTC 2013
>Originator:     Serhii Kharchenko
>Release:        9.1-RELEASE-p1
>Organization:
AdvancedHosters
>Environment:
FreeBSD test-advancedhosters.com 9.1-RELEASE-p1 FreeBSD 9.1-RELEASE-p1 #1: Fri May 24 13:37:29 UTC 2013     root@test-advancedhosters.com:/usr/obj/usr/src/sys/Z-AMD64  amd64

>Description:
When watch(8) is listening TTY and user stops using this TTY (e.g. closes SSH connection) - watch proceeds listening it. It does not exit and does not write that the session is ended. 

The same problem is observed when security/termlog is used. termlog also uses snp(4) device and it also does not stop listening released TTY.

Looks that this problem appeared in FreeBSD-8 after pty(4) was replaced with pts(4) and snp(4) was completely rewritten.
>How-To-Repeat:
Just open 2 SSH sessions to the server:
Session #1:
root@test-advancedhosters:/root # tty
/dev/pts/0

Session #2:
root@test-advancedhosters:/root # watch /dev/pts/0
(and we see all the I/O of terminal /dev/pts/0)

After logout of session #1 we see just "logout" word and watch proceeds listening. TTY device is present and it is disappear only after watch is killed:
root@test-advancedhosters:/root # ps aux | grep watch | grep -v grep
root    45903   0.0  0.0 12288 1940  1  I+   12:11PM    0:00.00 watch /dev/pts/0
root@test-advancedhosters:/root # ls -la /dev/pts/0
crw-rw-rw-  1 root  wheel    0,  67 May 28 12:13 /dev/pts/0
root@test-advancedhosters:/root # kill 45903
root@test-advancedhosters:/root # ls -la /dev/pts/0
ls: /dev/pts/0: No such file or directory

>Fix:


>Release-Note:
>Audit-Trail:
>Unformatted:
