From owner-freebsd-bugs@FreeBSD.ORG Sat Mar 10 15:00:36 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7F21E1065676 for ; Sat, 10 Mar 2012 15:00:36 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 5EAE38FC08 for ; Sat, 10 Mar 2012 15:00:36 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q2AF0ach045271 for ; Sat, 10 Mar 2012 15:00:36 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q2AF0aKC045266; Sat, 10 Mar 2012 15:00:36 GMT (envelope-from gnats) Date: Sat, 10 Mar 2012 15:00:36 GMT Message-Id: <201203101500.q2AF0aKC045266@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Ed Schouten Cc: Subject: Re: bin/143017: watch(8): fatal: cannot attach to tty X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Ed Schouten List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Mar 2012 15:00:36 -0000 The following reply was made to PR bin/143017; it has been noted by GNATS. From: Ed Schouten To: Mark Cc: bug-followup@FreeBSD.org, dummy@smtp.ru Subject: Re: bin/143017: watch(8): fatal: cannot attach to tty Date: Sat, 10 Mar 2012 15:59:56 +0100 --z0eOaCaDLjvTGF2l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello Mark, * Mark , 20120310 09:50: > How about something like the attached change to snp(4)? It has snp > detach from the tty when the input to SNPSTTY is -1, which is what the > man page says is supposed to happen. This isn't the right approach. It would break when a snoop descriptor is used by two or more threads. Imagine what would happen if one thread would call read(), while the other would call SNPSTTY. The only way you could implement this safely, is by locking down all the system calls using for example an sx lock. I think the easiest way to fix this would be by simply patching watch(8) to not reuse snoop descriptors to switch between TTYs. The following (ugly) patch should make watch(8) work properly: Index: usr.sbin/watch/watch.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- usr.sbin/watch/watch.c (Revision 232781) +++ usr.sbin/watch/watch.c (Arbeitskopie) @@ -206,10 +206,9 @@ static void detach_snp(void) { - int fd; =20 - fd =3D -1; - ioctl(snp_io, SNPSTTY, &fd); + close(snp_io); + snp_io =3D open_snp(); } =20 static void @@ -217,6 +216,7 @@ { int snp_tty; =20 + detach_snp(); snp_tty =3D open(dev_name, O_RDONLY | O_NONBLOCK); if (snp_tty < 0) fatal(EX_DATAERR, "can't open device"); If someone would write a nice set of patches to clean up the watch(8) source code (and fix this bug), I'd be more than happy to commit them to SVN. In fact, I think we should simplify the watch(8) utility. In my opinion the `interactive mode' is pretty useless. --=20 Ed Schouten WWW: http://80386.nl/ --z0eOaCaDLjvTGF2l Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iQIcBAEBAgAGBQJPW2xrAAoJEG5e2P40kaK7FB4P/ievaLjSLqfiHFisDP4tzcJc VG6yf/4h6PVckcOkSP9H84XCWl8s5UygY31LF07n8DKmZUqSlH8CwnNYEyhdo7U5 uFjTxkO5JtWaQFJJLZtm+teOryGTKeCZInFkr3zDbuxmmhkeZC5Eetmn9K5a3KNX L1/yrxvY2ibWe3xCQ6PyGKbT7CLC11VMQYoLdk0cwWpiX/DTIagnoS/ZbsNc369A qKtWRqFmaeFnx+Tcp3w0kLHq49sDfMkGaVAtGdh+Dr87ymDokKNlfIc3frgiWjL7 o0M3W3CxrcZcxjERGdru8SFTNiSh6vjsAKmb1yTYg6jABHmfhqKH29fEU/YpXTAe 2X2HKNvGCPJ2R65/aqQ3ALc/8Wz7R17z1nKLXPSOG7gv3HXDTSro7rxvBWbA4Qyj 8amwVBdKFoLK+VWQLn/7V8Uo2lwP3U5zDXlMYZnnswmozz/Dk5JjcLa4T5dI2BAx VsFwBcijp+fVzP9dmVFjVnRdI/pGP1LXGntCDkU/NaiyIPpgodnxRjq9gnz+hY/3 72vrEZVL6nV5Jurbceu2kHP+SQXADl9+j9P5Zo33bdqkF89tEYMHSvCLYgnYrAJm WkDl5kBZ8kYlj7w8m3T88Xi3DhB7qAzml0MVhobZ8UG8MWd3b/xwHuD7Yhc5XrJa mVGMYdyLAQwZfWWNWnbL =K2kY -----END PGP SIGNATURE----- --z0eOaCaDLjvTGF2l--