summaryrefslogtreecommitdiff
path: root/usr.bin/write
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2007-11-12 20:02:21 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2007-11-12 20:02:21 +0000
commita4cc298ac968fd275219d04f2a6fef7b73594253 (patch)
treea658e77dca52f1e0e063068647a50ee8b39ae282 /usr.bin/write
parentd518b2ba09f398be939899286b94e497cb097d10 (diff)
downloadsrc-test-a4cc298ac968fd275219d04f2a6fef7b73594253.tar.gz
src-test-a4cc298ac968fd275219d04f2a6fef7b73594253.zip
write(1) needs to strip off the leading /dev/ from the tty name for the
current tty as returned from ttyname(3) so it can try to avoid writing to the current tty if possible. Previously, it did this by trimming off any leading directory (effectively performing a basename(3) on the path returned from ttyname(3)). However, this chopped off too much of the path for ttys who have directories in their name such as pts(4). Instead, just strip off the leading /dev/ from the path returned by ttyname(3). This fixes write(1) when using pts(4). MFC after: 1 week Reported by: rwatson
Notes
Notes: svn path=/head/; revision=173572
Diffstat (limited to 'usr.bin/write')
-rw-r--r--usr.bin/write/write.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/usr.bin/write/write.c b/usr.bin/write/write.c
index b0e0a1f91b8db..878c8c1d0ba1a 100644
--- a/usr.bin/write/write.c
+++ b/usr.bin/write/write.c
@@ -76,7 +76,6 @@ int utmp_chk(char *, char *);
int
main(int argc, char **argv)
{
- char *cp;
time_t atime;
uid_t myuid;
int msgsok, myttyfd;
@@ -100,8 +99,8 @@ main(int argc, char **argv)
errx(1, "can't find your tty");
if (!(mytty = ttyname(myttyfd)))
errx(1, "can't find your tty's name");
- if ((cp = rindex(mytty, '/')))
- mytty = cp + 1;
+ if (!strncmp(mytty, _PATH_DEV, strlen(_PATH_DEV)))
+ mytty += strlen(_PATH_DEV);
if (term_chk(mytty, &msgsok, &atime, 1))
exit(1);
if (!msgsok)