From be02291ee05e867c05ef70cdf2c227b759dc8364 Mon Sep 17 00:00:00 2001 From: espie Date: Mon, 27 Jun 2016 06:10:04 +0000 Subject: [PATCH] make the fallback code more accurate (in particular, it should return names based on the actual device, not any kind of inode equality which won't hold for duplicates of the dev tree in a chroot) no bump as it doesn't change any API. okay and improvements guenther@ --- lib/libc/gen/ttyname.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c index 9e8580c52a8..456fe798087 100644 --- a/lib/libc/gen/ttyname.c +++ b/lib/libc/gen/ttyname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ttyname.c,v 1.16 2015/10/12 19:53:58 naddy Exp $ */ +/* $OpenBSD: ttyname.c,v 1.17 2016/06/27 06:10:04 espie Exp $ */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -120,7 +120,7 @@ oldttyname(struct stat *sb, char *buf, size_t len) return (errno); while ((dirp = readdir(dp))) { - if (dirp->d_fileno != sb->st_ino) + if (dirp->d_type != DT_CHR && dirp->d_type != DT_UNKNOWN) continue; if (dirp->d_namlen > len - sizeof(_PATH_DEV)) { (void)closedir(dp); @@ -128,8 +128,8 @@ oldttyname(struct stat *sb, char *buf, size_t len) } memcpy(buf + sizeof(_PATH_DEV) - 1, dirp->d_name, dirp->d_namlen + 1); - if (stat(buf, &dsb) || sb->st_dev != dsb.st_dev || - sb->st_ino != dsb.st_ino) + if (lstat(buf, &dsb) || !S_ISCHR(dsb.st_mode) || + sb->st_rdev != dsb.st_rdev) continue; (void)closedir(dp); return (0); -- 2.20.1