From df6314fc7947b16e5c38f201c2264d2a92778156 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 12 Feb 2009 19:00:13 +0000 Subject: Make ttyslot(3) work with pts(4) devices. It seems ttyslot() calls rindex(), to strip the device name to the last slash, but this is obviously invalid. /dev/pts/0 should be stripped until pts/0. Because /etc/ttys only supports TTY names in /dev/, just strip this piece of the pathname. --- lib/libc/gen/ttyslot.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/libc/gen/ttyslot.c b/lib/libc/gen/ttyslot.c index a434626..31cc156 100644 --- a/lib/libc/gen/ttyslot.c +++ b/lib/libc/gen/ttyslot.c @@ -33,6 +33,7 @@ static char sccsid[] = "@(#)ttyslot.c 8.1 (Berkeley) 6/4/93"; #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -43,19 +44,17 @@ ttyslot() { struct ttyent *ttyp; int slot; - char *p; int cnt; char *name; setttyent(); for (cnt = 0; cnt < 3; ++cnt) if ( (name = ttyname(cnt)) ) { - if ( (p = rindex(name, '/')) ) - ++p; - else - p = name; + if (strncmp(name, _PATH_DEV, sizeof _PATH_DEV - 1) != 0) + break; + name += sizeof _PATH_DEV - 1; for (slot = 1; (ttyp = getttyent()); ++slot) - if (!strcmp(ttyp->ty_name, p)) { + if (!strcmp(ttyp->ty_name, name)) { endttyent(); return(slot); } -- cgit v1.1