From mboxrd@z Thu Jan 1 00:00:00 1970 From: presotto@closedmind.org To: 9fans@cse.psu.edu Subject: Re: [9fans] isatty MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-qmqgwwpuzbbtrpfponmkrxflxc" Message-Id: <20020123131345.E12DA199BF@mail.cse.psu.edu> Date: Wed, 23 Jan 2002 08:13:44 -0500 Topicbox-Message-UUID: 41f38fae-eaca-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. --upas-qmqgwwpuzbbtrpfponmkrxflxc Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit 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. --upas-qmqgwwpuzbbtrpfponmkrxflxc Content-Type: message/rfc822 Content-Disposition: inline Received: from plan9.cs.bell-labs.com ([135.104.9.2]) by plan9; Wed Jan 23 06:57:37 EST 2002 Received: from mail.cse.psu.edu ([130.203.4.6]) by plan9; Wed Jan 23 06:57:36 EST 2002 Received: from psuvax1.cse.psu.edu (psuvax1.cse.psu.edu [130.203.20.6]) by mail.cse.psu.edu (CSE Mail Server) with ESMTP id DB00019A02; Wed, 23 Jan 2002 06:57:06 -0500 (EST) Delivered-To: 9fans@cse.psu.edu Received: from theraft.strakt.com (theraft.strakt.com [62.13.29.34]) by mail.cse.psu.edu (CSE Mail Server) with ESMTP id C5749199F2 for <9fans@cse.psu.edu>; Wed, 23 Jan 2002 06:56:46 -0500 (EST) Received: from strakt.com (zode.strakt.com [62.13.29.39]) by theraft.strakt.com (8.12.1/8.12.1/Debian -5) with ESMTP id g0NBui7U014950 for <9fans@cse.psu.edu>; Wed, 23 Jan 2002 12:56:44 +0100 Message-ID: <3C4EA4FC.A777CA4D@strakt.com> From: Boyd Roberts Organization: AB Strakt X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.17 i686) X-Accept-Language: en MIME-Version: 1.0 To: "9fans@cse.psu.edu" <9fans@cse.psu.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: [9fans] isatty Sender: 9fans-admin@cse.psu.edu Errors-To: 9fans-admin@cse.psu.edu X-BeenThere: 9fans@cse.psu.edu X-Mailman-Version: 2.0.8 Precedence: bulk Reply-To: 9fans@cse.psu.edu List-Help: List-Id: Fans of the OS Plan 9 from Bell Labs <9fans.cse.psu.edu> List-Archive: Date: Wed, 23 Jan 2002 12:56:44 +0100 Given I had to implement this 'thing' on Plan 9 I decided on: #include #include 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]. --upas-qmqgwwpuzbbtrpfponmkrxflxc--