Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 06 Jul 2005 00:22:09 -0400
From:      Joe Marcus Clarke <marcus@FreeBSD.org>
To:        current@FreeBSD.org
Cc:        phk@FreeBSD.org
Subject:   Re: (problem found) grantpt broken on -CURRENT
Message-ID:  <1120623729.99631.21.camel@shumai.marcuscom.com>
In-Reply-To: <1120539465.3587.19.camel@shumai.marcuscom.com>
References:  <1120539465.3587.19.camel@shumai.marcuscom.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--=-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 <stdlib.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <errno.h>
>=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--




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