Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Mar 2012 15:00:36 GMT
From:      Ed Schouten <ed@80386.nl>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/143017: watch(8): fatal: cannot attach to tty
Message-ID:  <201203101500.q2AF0aKC045266@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/143017; it has been noted by GNATS.

From: Ed Schouten <ed@80386.nl>
To: Mark <markjdb@gmail.com>
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 <markjdb@gmail.com>, 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 <ed@80386.nl>
  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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203101500.q2AF0aKC045266>