From owner-freebsd-current@FreeBSD.ORG Wed Jul 6 04:22:23 2005 Return-Path: X-Original-To: current@FreeBSD.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7C6DA16A41C; Wed, 6 Jul 2005 04:22:23 +0000 (GMT) (envelope-from marcus@FreeBSD.org) Received: from creme-brulee.marcuscom.com (creme-brulee.marcuscom.com [24.172.16.118]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2743043D48; Wed, 6 Jul 2005 04:22:23 +0000 (GMT) (envelope-from marcus@FreeBSD.org) Received: from shumai.marcuscom.com (shumai.marcuscom.com [192.168.1.4]) by creme-brulee.marcuscom.com (8.13.3/8.13.3) with ESMTP id j664McBm079533; Wed, 6 Jul 2005 00:22:38 -0400 (EDT) (envelope-from marcus@FreeBSD.org) From: Joe Marcus Clarke To: current@FreeBSD.org In-Reply-To: <1120539465.3587.19.camel@shumai.marcuscom.com> References: <1120539465.3587.19.camel@shumai.marcuscom.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-Vgsh+LAnOQdJswh284Au" Organization: FreeBSD, Inc. Date: Wed, 06 Jul 2005 00:22:09 -0400 Message-Id: <1120623729.99631.21.camel@shumai.marcuscom.com> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 FreeBSD GNOME Team Port Cc: phk@FreeBSD.org Subject: Re: (problem found) grantpt broken on -CURRENT X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jul 2005 04:22:23 -0000 --=-Vgsh+LAnOQdJswh284Au Content-Type: multipart/mixed; boundary="=-njWBEab4C1fYZfkZoYjg" --=-njWBEab4C1fYZfkZoYjg Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Tue, 2005-07-05 at 00:57 -0400, Joe Marcus Clarke wrote: > I recently discovered the gnome-vfs sftp method which uses > posix_openpt/ptsname/grantpt to set up a pty for communicating with the > sftp subprocess fails to work. I found that grantpt() fails due to > EACCES. The underlying reason looks to be that the pty name returned by > ptsname() is not unhidden in devfs. Basically, the following code will > fail: >=20 > #include > #include > #include > #include >=20 > main(void) { > int fd; > char *p; >=20 > fd =3D posix_openpt (O_RDWR | O_NOCTTY); >=20 > if (fd < 0) { > printf("Failed to open PTY: %s\n", strerror(errno)); > return -1; > } > else { > if ((p =3D ptsname(fd)) !=3D NULL) { > printf("ptsname =3D %s\n", p); > } > else { > printf("Failed to get ptsname: %s\n", strerror(er= rno)); > close (fd); > if (grantpt(fd) < 0) { > printf("Failed to run grantpt: %s\n", strerror(errno)); > close (fd); > return -1; > } >=20 > close (fd); >=20 > return 0; > } >=20 > Basically, everything works until the grantpt() call which returns > EACCES. The same code works just fine under 5-STABLE. I even tried > manually applying devfs rules to unhide the missing tty device > (/dev/ttys5 in my tests), but that didn't work. The program also fails > in the same way when run as root. >=20 > This has been failing since I upgraded from 5-STABLE to -CURRENT about > three weeks ago. I'm now running -CURRENT from yesterday. I did some more research, and found that the problem was not in devfs hiding the devices, but rather in the way ptsname() determined the tty name for the open file descriptor. The kernel gets the minor number for a tty from the si_drv0 member of the device cdev structure. However, ptsname() relies on the minor number of the st_rdev member of the stat structure to get the tty name. Devfs sets the st_rdev value to the device's inode xor a random number. Therefore, ptsname() returns garbage, and grantpt() subsequently fails. I created this patch that corrects the problem, but I'm not sure if it's the right way to go. Poul-Henning (or anyone) could you have a look and let me know if this is okay? I'd really like to see this working again in -CURRENT so 6.0 GNOME users will be able to use their sftp shares. Thanks. Oh, and it might be a good idea to make sys/types.h aware of MAXMINOR as it still hardcodes the constant. Joe --=20 Joe Marcus Clarke FreeBSD GNOME Team :: gnome@FreeBSD.org FreeNode / #freebsd-gnome http://www.FreeBSD.org/gnome --=-njWBEab4C1fYZfkZoYjg Content-Disposition: attachment; filename=devfs_vnops.c.diff Content-Transfer-Encoding: base64 Content-Type: text/x-patch; name=devfs_vnops.c.diff; charset=ISO-8859-1 LS0tIHNyYy9zeXMvZnMvZGV2ZnMvZGV2ZnNfdm5vcHMuYy5vcmlnCVdlZCBKdWwgIDYgMDA6MTQ6 NTYgMjAwNQ0KKysrIHNyYy9zeXMvZnMvZGV2ZnMvZGV2ZnNfdm5vcHMuYwlXZWQgSnVsICA2IDAw OjE0OjQ4IDIwMDUNCkBAIC01MjAsNyArNTIwLDcgQEAgZGV2ZnNfZ2V0YXR0cihhcCkNCiAJCWZp eChkZXYtPnNpX2N0aW1lKTsNCiAJCXZhcC0+dmFfY3RpbWUgPSBkZXYtPnNpX2N0aW1lOw0KIA0K LQkJdmFwLT52YV9yZGV2ID0gZGV2LT5zaV9pbm9kZSBeIGRldmZzX3JhbmRvbSgpOw0KKwkJdmFw LT52YV9yZGV2ID0gZGV2LT5zaV9kcnYwOw0KIAl9DQogCXZhcC0+dmFfZ2VuID0gMDsNCiAJdmFw LT52YV9mbGFncyA9IDA7DQo= --=-njWBEab4C1fYZfkZoYjg-- --=-Vgsh+LAnOQdJswh284Au Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (FreeBSD) iD8DBQBCy1xxb2iPiv4Uz4cRAi4fAJ0Rw8K2khjFxai9j2NQTJXFVg4mFACfbflk 6Tvjnz5aPnT57LtIHX+aKvc= =oh8j -----END PGP SIGNATURE----- --=-Vgsh+LAnOQdJswh284Au--