9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: presotto@closedmind.org
To: 9fans@cse.psu.edu
Subject: Re: [9fans] isatty
Date: Wed, 23 Jan 2002 08:13:44 -0500	[thread overview]
Message-ID: <20020123131345.E12DA199BF@mail.cse.psu.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 588 bytes --]

The version comparison is an overkill and potentially wrong since
whatever is implementing /dev/cons may decide to update the
version each write, as is our practice in other places.

That should work in general as long as the namespace hasn't
been changed twixt the opening of the fd and the dirstat.
Otherwise /dev/cons may be under a different mount point
number and hence a different c.dev.

The question isatty is usually trying to answer is
"does the fd has an interacting user behind it?".  A
hard question to answer in a world where the geography
can shift so easily.

[-- Attachment #2: Type: message/rfc822, Size: 2165 bytes --]

From: Boyd Roberts <boyd@strakt.com>
To: "9fans@cse.psu.edu" <9fans@cse.psu.edu>
Subject: [9fans] isatty
Date: Wed, 23 Jan 2002 12:56:44 +0100
Message-ID: <3C4EA4FC.A777CA4D@strakt.com>

Given I had to implement this 'thing' on Plan 9 I decided on:

#include <u.h>
#include <libc.h>

static char *cons = "/dev/cons";

/*
 * Compare fd to cons should get it right.
 */
int
isatty(int fd)
{
	Dir c;
	Dir f;

	if (dirstat(cons, &c) != 0)
		return 0;

	if (dirfstat(fd, &f) != 0)
		return 0;

	return f.type == c.type &&
		f.dev == c.dev &&
		f.qid.path == c.qid.path &&
		f.qid.vers == c.qid.vers;
}

Seemed obvious to me, but is this a good plan?

The overkill on the multiple dirstat's on /dev/cons and
qid comparison I thought would ensure that I wouldn't
get fooled [again].

             reply	other threads:[~2002-01-23 13:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-23 13:13 presotto [this message]
2002-01-23 13:43 ` Boyd Roberts
  -- strict thread matches above, loose matches on Subject: below --
2002-01-23 15:26 Russ Cox
2002-01-23 11:56 Boyd Roberts
2001-02-14 15:45 rog
2001-02-14 15:09 Yehuda Tiram
     [not found] <rob@plan9.bell-labs.com>
2001-02-14 13:51 ` rob pike
2001-02-14 16:42   ` Scott Schwartz
2001-02-14 13:48 rog

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020123131345.E12DA199BF@mail.cse.psu.edu \
    --to=presotto@closedmind.org \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).