bin/153052: [patch] watch(8) breaks tty on error

Jilles Tjoelker jilles at
Sun Sep 1 16:00:02 UTC 2013

The following reply was made to PR bin/153052; it has been noted by GNATS.

From: Jilles Tjoelker <jilles at>
To: bug-followup at, demelier.david at
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[])
 +	tcgetattr(std_in, &otty);
  	if (modfind("snp") == -1)
  		if (kldload("snp") == -1 || modfind("snp") == -1)
  			warn("snp module not available");

More information about the freebsd-bugs mailing list