From nobody@FreeBSD.org  Sun Dec 12 18:52:33 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 3143B1065673
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 12 Dec 2010 18:52:33 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 207A48FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 12 Dec 2010 18:52:33 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id oBCIqWDA069391
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 12 Dec 2010 18:52:32 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id oBCIqWSj069390;
	Sun, 12 Dec 2010 18:52:32 GMT
	(envelope-from nobody)
Message-Id: <201012121852.oBCIqWSj069390@red.freebsd.org>
Date: Sun, 12 Dec 2010 18:52:32 GMT
From: David Demelier <demelier.david@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: watch(8) breaks tty on error
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         153052
>Category:       bin
>Synopsis:       [patch] watch(8) breaks tty on error
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 12 19:00:19 UTC 2010
>Closed-Date:    
>Last-Modified:  Fri Sep 13 21:00:00 UTC 2013
>Originator:     David Demelier
>Release:        8.2-PRERELEASE
>Organization:
>Environment:
FreeBSD Melon.malikania.fr 8.2-PRERELEASE FreeBSD 8.2-PRERELEASE #7: Wed Dec  8 14:03:55 CET 2010     root@Melon.malikania.fr:/usr/obj/usr/src/sys/Melon  amd64

>Description:
When you run watch and snp module is not loaded (or probably any other error) watch breaks the terminal

I have removed unset_tty() and seems to work in my case, but I can't test for the others fatal() calls.

markand@Melon /usr/src/usr.sbin/watch $ watch
watch: snp module not available: Operation not permitted
watch: fatal: cannot open snoop device
                                      %                                                                                                                                                           markand@Melon /usr/src/usr.sbin/watch $ ls
Makefile     watch.8      watch.c      watch.c.orig
                                                   % 

markand@Melon /usr/src/usr.sbin/watch $ ls -l
total 26
        -rw-r--r--  1 root  wheel   187  3 Aug  2009 Makefile
                                                             -rw-r--r--  1 root  wheel  2645  3 Aug  2009 watch.8
                                                                                                                 -rw-r--r--  1 root  wheel  9042 12 Dec 19:46 watch.c
                                                                                                                                                                     -rw-r--r--  1 root  wheel  9042 12 Dec 19:38 watch.c.orig
                            % 
>How-To-Repeat:

>Fix:
-- watch.c.diff begins here --
--- watch.c.orig	2010-12-12 19:38:27.000000000 +0100
+++ watch.c	2010-12-12 19:44:21.000000000 +0100
@@ -142,7 +142,6 @@
 static void
 fatal(int error, const char *buf)
 {
-	unset_tty();
 	if (buf)
 		errx(error, "fatal: %s", buf);
 	else
-- watch.d.diff ends here --

>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, demelier.david@gmail.com
Cc:  
Subject: Re: bin/153052: [patch] watch(8) breaks tty on error
Date: Sun, 1 Sep 2013 17:56:56 +0200

 In PR bin/153052, you wrote:
 > When you run watch and snp module is not loaded (or probably any other
 > error) watch breaks the terminal
 
 > I have removed unset_tty() and seems to work in my case, but I can't
 > test for the others fatal() calls.
 
 Your patch prevents restoring the terminal state if watch(8) is exited
 using Ctrl+G while watching.
 
 I think it is better to record the initial state earlier, so it is
 always safe to restore it, like this:
 
 Index: usr.sbin/watch/watch.c
 ===================================================================
 --- usr.sbin/watch/watch.c	(revision 255093)
 +++ usr.sbin/watch/watch.c	(working copy)
 @@ -110,7 +110,6 @@ set_tty(void)
  {
  	struct termios	ntty;
  
 -	tcgetattr(std_in, &otty);
  	ntty = otty;
  	ntty.c_lflag &= ~ICANON;	/* disable canonical operation */
  	ntty.c_lflag &= ~ECHO;
 @@ -324,6 +323,8 @@ main(int ac, char *av[])
  			usage();
  		}
  
 +	tcgetattr(std_in, &otty);
 +
  	if (modfind("snp") == -1)
  		if (kldload("snp") == -1 || modfind("snp") == -1)
  			warn("snp module not available");
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Thu Sep 5 19:08:31 UTC 2013 
State-Changed-Why:  
Fixed in head. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Thu Sep 5 19:08:31 UTC 2013 
Responsible-Changed-Why:  
I did the commit. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153052 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/153052: commit references a PR
Date: Thu,  5 Sep 2013 19:02:11 +0000 (UTC)

 Author: jilles
 Date: Thu Sep  5 19:02:03 2013
 New Revision: 255261
 URL: http://svnweb.freebsd.org/changeset/base/255261
 
 Log:
   watch: Do not mess up the tty modes on early error.
   
   Record the initial state earlier, so it is always safe to restore it.
   
   One way this happens is if watch(8) is started by a user that does not have
   access to /dev/snp. The result is "staircase effect" during later commands.
   
   PR:		bin/153052
   MFC after:	1 week
 
 Modified:
   head/usr.sbin/watch/watch.c
 
 Modified: head/usr.sbin/watch/watch.c
 ==============================================================================
 --- head/usr.sbin/watch/watch.c	Thu Sep  5 18:45:23 2013	(r255260)
 +++ head/usr.sbin/watch/watch.c	Thu Sep  5 19:02:03 2013	(r255261)
 @@ -110,7 +110,6 @@ set_tty(void)
  {
  	struct termios	ntty;
  
 -	tcgetattr(std_in, &otty);
  	ntty = otty;
  	ntty.c_lflag &= ~ICANON;	/* disable canonical operation */
  	ntty.c_lflag &= ~ECHO;
 @@ -324,6 +323,8 @@ main(int ac, char *av[])
  			usage();
  		}
  
 +	tcgetattr(std_in, &otty);
 +
  	if (modfind("snp") == -1)
  		if (kldload("snp") == -1 || modfind("snp") == -1)
  			warn("snp module not available");
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/153052: commit references a PR
Date: Fri, 13 Sep 2013 20:56:49 +0000 (UTC)

 Author: jilles
 Date: Fri Sep 13 20:56:42 2013
 New Revision: 255529
 URL: http://svnweb.freebsd.org/changeset/base/255529
 
 Log:
   MFC r255261: watch: Do not mess up the tty modes on early error.
   
   Record the initial state earlier, so it is always safe to restore it.
   
   One way this happens is if watch(8) is started by a user that does not have
   access to /dev/snp. The result is "staircase effect" during later commands.
   
   PR:		bin/153052
 
 Modified:
   stable/9/usr.sbin/watch/watch.c
 Directory Properties:
   stable/9/usr.sbin/watch/   (props changed)
 
 Modified: stable/9/usr.sbin/watch/watch.c
 ==============================================================================
 --- stable/9/usr.sbin/watch/watch.c	Fri Sep 13 19:55:40 2013	(r255528)
 +++ stable/9/usr.sbin/watch/watch.c	Fri Sep 13 20:56:42 2013	(r255529)
 @@ -110,7 +110,6 @@ set_tty(void)
  {
  	struct termios	ntty;
  
 -	tcgetattr(std_in, &otty);
  	ntty = otty;
  	ntty.c_lflag &= ~ICANON;	/* disable canonical operation */
  	ntty.c_lflag &= ~ECHO;
 @@ -324,6 +323,8 @@ main(int ac, char *av[])
  			usage();
  		}
  
 +	tcgetattr(std_in, &otty);
 +
  	if (modfind("snp") == -1)
  		if (kldload("snp") == -1 || modfind("snp") == -1)
  			warn("snp module not available");
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
