ttyslot(3) - Update for unix98 ptys
authorAlex Hornung <ahornung@gmail.com>
Wed, 2 Sep 2009 08:12:58 +0000 (09:12 +0100)
committerAlex Hornung <ahornung@gmail.com>
Wed, 2 Sep 2009 08:40:24 +0000 (09:40 +0100)
* Update ttyslot(3) to be compatible with unix98 ptys. This fixes
  problems with logins on unix98 ptys not appearing in utmp.

* ttyslot was calling rindex, which is invalid for unix98 pty files,
  so now we just strip "/dev/".

Obtained-from: FreeBSD

lib/libc/gen/ttyslot.c

index 439dbb0..2c7c0c7 100644 (file)
@@ -34,6 +34,7 @@
  * $DragonFly: src/lib/libc/gen/ttyslot.c,v 1.4 2005/11/13 00:07:42 swildner Exp $
  */
 
+#include <paths.h>
 #include <ttyent.h>
 #include <stdio.h>
 #include <string.h>
@@ -44,19 +45,20 @@ ttyslot(void)
 {
        struct ttyent *ttyp;
        int slot;
-       char *p;
        int cnt;
        char *name;
+       size_t len = sizeof(_PATH_DEV) - 1;
 
        setttyent();
        for (cnt = 0; cnt < 3; ++cnt)
                if ( (name = ttyname(cnt)) ) {
-                       if ( (p = rindex(name, '/')) )
-                               ++p;
-                       else
-                               p = name;
+                       if (strncmp(name, _PATH_DEV, len) != 0)
+                               break;
+
+                       name += len;
+
                        for (slot = 1; (ttyp = getttyent()); ++slot)
-                               if (!strcmp(ttyp->ty_name, p)) {
+                               if (!strcmp(ttyp->ty_name, name)) {
                                        endttyent();
                                        return(slot);
                                }