9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Common code - isatty
@ 2005-04-13 13:20 Einar Karttunen
  2005-04-13 21:50 ` Russ Cox
  0 siblings, 1 reply; 18+ messages in thread
From: Einar Karttunen @ 2005-04-13 13:20 UTC (permalink / raw)
  To: Plan9 ML

Hello

While reading source code I noticed several different isatty
implementations. They are slightly different and I would be interested
in 1) which is the correct implementation and 2) whether a patch
to fix the others would be welcome and whether a common location 
in a library or cut-paste is preferred.

The locations include at least:
ape/lib/ap/isatty.c      - check whether fd2path ends in "/dev/cons"
cmd/ip/telnet.c          - dirstat -> "cons"
cmd/rc/plan9.c           - dirstat -> "ptty" or same dev,type,qid as "/dev/cons"
cmd/ssh/ssh.c            - fd2path ends in "/dev/cons"
cmd/upas/common/libsys.c - dirstat -> "cons"
libstdio/setvbuf.c       - dirstat -> same dev,type and qid as "/dev/cons"

- Einar Karttunen


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-13 13:20 [9fans] Common code - isatty Einar Karttunen
@ 2005-04-13 21:50 ` Russ Cox
  2005-04-13 23:26   ` Ronald G. Minnich
  0 siblings, 1 reply; 18+ messages in thread
From: Russ Cox @ 2005-04-13 21:50 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

the correct approach is to check whether the end of
fd2path is /dev/cons.  the qid check is an older approach
that was used before fd2path.

i'm hesitant to put it in a library because most programs
(e.g., ls) should not behave differently when running on
a console.  if it's there, it may be overused like in unix.

but i'd gladly apply a patch fixing telnet, rc, upas,
and libstdio.

russ


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-13 21:50 ` Russ Cox
@ 2005-04-13 23:26   ` Ronald G. Minnich
  2005-04-13 23:52     ` Dan Cross
  0 siblings, 1 reply; 18+ messages in thread
From: Ronald G. Minnich @ 2005-04-13 23:26 UTC (permalink / raw)
  To: Russ Cox, Fans of the OS Plan 9 from Bell Labs



On Wed, 13 Apr 2005, Russ Cox wrote:

> i'm hesitant to put it in a library because most programs (e.g., ls)
> should not behave differently when running on a console.  if it's there,
> it may be overused like in unix.

good call. don't do it. We're fighting a lot of isatty() stupidity on our 
clusters, and it's a nightmare. I agree that it would get overused ...

ron


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-13 23:26   ` Ronald G. Minnich
@ 2005-04-13 23:52     ` Dan Cross
  2005-04-13 23:57       ` boyd, rounin
  2005-04-14  0:01       ` Bruce Ellis
  0 siblings, 2 replies; 18+ messages in thread
From: Dan Cross @ 2005-04-13 23:52 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

"Ronald G. Minnich" <rminnich@lanl.gov> writes:
> On Wed, 13 Apr 2005, Russ Cox wrote:
> > i'm hesitant to put it in a library because most programs (e.g., ls)
> > should not behave differently when running on a console.  if it's there,
> > it may be overused like in unix.
> 
> good call. don't do it. We're fighting a lot of isatty() stupidity on our 
> clusters, and it's a nightmare. I agree that it would get overused ...

Or put it into libidiot.h just so there's only one copy of it.

Oh, you think I'm joking?

	- Dan C.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-13 23:52     ` Dan Cross
@ 2005-04-13 23:57       ` boyd, rounin
  2005-04-14  0:00         ` Russ Cox
  2005-04-14  0:01       ` Bruce Ellis
  1 sibling, 1 reply; 18+ messages in thread
From: boyd, rounin @ 2005-04-13 23:57 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>> good call. don't do it. We're fighting a lot of isatty() stupidity on our 
>> clusters, and it's a nightmare. I agree that it would get overused ...

i agree, but for some unix things you need isatty().  i remember
asking this question some years ago during a Python port.

not sure i'd use fd2path() tho, but that's just me.
--
MGRS 31U DQ 52572 12604




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-13 23:57       ` boyd, rounin
@ 2005-04-14  0:00         ` Russ Cox
  2005-04-14  0:14           ` boyd, rounin
  0 siblings, 1 reply; 18+ messages in thread
From: Russ Cox @ 2005-04-14  0:00 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> i agree, but for some unix things you need isatty().  i remember
> asking this question some years ago during a Python port.

for unix things you should use ape.

> not sure i'd use fd2path() tho, but that's just me.

fd2path is the right answer.  
would you add a system call instead?

russ


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-13 23:52     ` Dan Cross
  2005-04-13 23:57       ` boyd, rounin
@ 2005-04-14  0:01       ` Bruce Ellis
  2005-04-14  0:39         ` Dan Cross
  2005-04-14 17:14         ` Ronald G. Minnich
  1 sibling, 2 replies; 18+ messages in thread
From: Bruce Ellis @ 2005-04-14  0:01 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Dan!  Stop being so blunt and correct!

20 years ago it became clear that there was no bloody way
to determine if a program was being run interactively.

Given that ... the various hacks are convenient.
e.g. "rc" rather than "rc -i" but still ... It is a cesspool.

brucee

On 4/14/05, Dan Cross <cross@math.psu.edu> wrote:
> "Ronald G. Minnich" <rminnich@lanl.gov> writes:
> > On Wed, 13 Apr 2005, Russ Cox wrote:
> > > i'm hesitant to put it in a library because most programs (e.g., ls)
> > > should not behave differently when running on a console.  if it's there,
> > > it may be overused like in unix.
> >
> > good call. don't do it. We're fighting a lot of isatty() stupidity on our
> > clusters, and it's a nightmare. I agree that it would get overused ...
> 
> Or put it into libidiot.h just so there's only one copy of it.
> 
> Oh, you think I'm joking?
> 
>        - Dan C.
> 
>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14  0:00         ` Russ Cox
@ 2005-04-14  0:14           ` boyd, rounin
  2005-04-14  0:18             ` Russ Cox
  0 siblings, 1 reply; 18+ messages in thread
From: boyd, rounin @ 2005-04-14  0:14 UTC (permalink / raw)
  To: Russ Cox, Fans of the OS Plan 9 from Bell Labs

> fd2path is the right answer. 

sure looks nice, 'cept for the strings.

> would you add a system call instead?

nope, call me old fashioned -- stat(2).
--
MGRS 31U DQ 52572 12604




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14  0:14           ` boyd, rounin
@ 2005-04-14  0:18             ` Russ Cox
  2005-04-14  0:22               ` Bruce Ellis
  0 siblings, 1 reply; 18+ messages in thread
From: Russ Cox @ 2005-04-14  0:18 UTC (permalink / raw)
  To: boyd, rounin; +Cc: Fans of the OS Plan 9 from Bell Labs

> sure looks nice, 'cept for the strings.

then plan 9 is not for you.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14  0:18             ` Russ Cox
@ 2005-04-14  0:22               ` Bruce Ellis
  2005-04-14  0:38                 ` Dan Cross
  2005-04-14  0:56                 ` jmk
  0 siblings, 2 replies; 18+ messages in thread
From: Bruce Ellis @ 2005-04-14  0:22 UTC (permalink / raw)
  To: Russ Cox, Fans of the OS Plan 9 from Bell Labs

sure, strcmp() is great for implementing isatty().
let's have a "best hack" bake-off.

brucee

On 4/14/05, Russ Cox <russcox@gmail.com> wrote:
> > sure looks nice, 'cept for the strings.
> 
> then plan 9 is not for you.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14  0:22               ` Bruce Ellis
@ 2005-04-14  0:38                 ` Dan Cross
  2005-04-14  1:02                   ` boyd, rounin
  2005-04-14  0:56                 ` jmk
  1 sibling, 1 reply; 18+ messages in thread
From: Dan Cross @ 2005-04-14  0:38 UTC (permalink / raw)
  To: Bruce Ellis, Fans of the OS Plan 9 from Bell Labs

Bruce Ellis <bruce.ellis@gmail.com> writes:
> sure, strcmp() is great for implementing isatty().
> let's have a "best hack" bake-off.

Ever use a spent 7.62mm round to short out a blown resister?

Where's Boyd.... 

	- Dan ``Reaches...'' C.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14  0:01       ` Bruce Ellis
@ 2005-04-14  0:39         ` Dan Cross
  2005-04-14 17:14         ` Ronald G. Minnich
  1 sibling, 0 replies; 18+ messages in thread
From: Dan Cross @ 2005-04-14  0:39 UTC (permalink / raw)
  To: Bruce Ellis, Fans of the OS Plan 9 from Bell Labs

Bruce Ellis <bruce.ellis@gmail.com> writes:
> Dan!  Stop being so blunt and correct!

Sorry, I just got out of the Marine Corps (hooray!  And there was
much rejoicing...).  It'll take me a few months before I can do
the former.  The latter is a new phenomenon.

	- Dan C.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14  0:22               ` Bruce Ellis
  2005-04-14  0:38                 ` Dan Cross
@ 2005-04-14  0:56                 ` jmk
  1 sibling, 0 replies; 18+ messages in thread
From: jmk @ 2005-04-14  0:56 UTC (permalink / raw)
  To: bruce.ellis, 9fans

make it consistent and rename it:

int ismaybesomethinglikeaterminal(int);


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14  0:38                 ` Dan Cross
@ 2005-04-14  1:02                   ` boyd, rounin
  0 siblings, 0 replies; 18+ messages in thread
From: boyd, rounin @ 2005-04-14  1:02 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> Ever use a spent 7.62mm round to short out a blown resister?

no, i like the 9x19mm 124gr FMJ, but you can't argue with the 7.62 ...
--
MGRS 31U DQ 52572 12604

>



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14  0:01       ` Bruce Ellis
  2005-04-14  0:39         ` Dan Cross
@ 2005-04-14 17:14         ` Ronald G. Minnich
  2005-04-14 17:29           ` Rob Pike
  1 sibling, 1 reply; 18+ messages in thread
From: Ronald G. Minnich @ 2005-04-14 17:14 UTC (permalink / raw)
  To: Bruce Ellis, Fans of the OS Plan 9 from Bell Labs



On Thu, 14 Apr 2005, Bruce Ellis wrote:

> 20 years ago it became clear that there was no bloody way to determine
>    if a program was being run interactively.

yeah, it's why so many of our fortran runtimes guess wrong ...  they do
something stupid like "oh, this is !isatty(), I'll buffer stdout".  then
they core dump. Then users get no error message. Then users yell at me.

I really do hate isatty()

ron


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14 17:14         ` Ronald G. Minnich
@ 2005-04-14 17:29           ` Rob Pike
  2005-04-14 19:25             ` Ronald G. Minnich
  2005-04-14 23:23             ` Bruce Ellis
  0 siblings, 2 replies; 18+ messages in thread
From: Rob Pike @ 2005-04-14 17:29 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

following jim's lead, you could make it
  whocaresifitsatty()
or maybe the best thing is to put into libc
  int isatty(int) {return 0;}

-rob


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14 17:29           ` Rob Pike
@ 2005-04-14 19:25             ` Ronald G. Minnich
  2005-04-14 23:23             ` Bruce Ellis
  1 sibling, 0 replies; 18+ messages in thread
From: Ronald G. Minnich @ 2005-04-14 19:25 UTC (permalink / raw)
  To: Rob Pike, Fans of the OS Plan 9 from Bell Labs



On Thu, 14 Apr 2005, Rob Pike wrote:

>   int isatty(int) {return 0;}

excellent. 

You know, we did do this on linux via LD_PRELOAD hackery, and of course it
didn't work with glibc, since library functions in glibc don't bother
calling that function -- inlines, macros, all that great stuff you know --
it's really important to optimize isatty() calls, as they are so frequent.

ron


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [9fans] Common code - isatty
  2005-04-14 17:29           ` Rob Pike
  2005-04-14 19:25             ` Ronald G. Minnich
@ 2005-04-14 23:23             ` Bruce Ellis
  1 sibling, 0 replies; 18+ messages in thread
From: Bruce Ellis @ 2005-04-14 23:23 UTC (permalink / raw)
  To: Rob Pike, Fans of the OS Plan 9 from Bell Labs

i kinda like that approach.  a lot of POSIX garabage
coud be replaced with stubs.  then python written in perl
written in bash would never make it to plan9.

brucee

On 4/15/05, Rob Pike <robpike@gmail.com> wrote:
> following jim's lead, you could make it
>  whocaresifitsatty()
> or maybe the best thing is to put into libc
>  int isatty(int) {return 0;}
> 
> -rob


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2005-04-14 23:23 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-13 13:20 [9fans] Common code - isatty Einar Karttunen
2005-04-13 21:50 ` Russ Cox
2005-04-13 23:26   ` Ronald G. Minnich
2005-04-13 23:52     ` Dan Cross
2005-04-13 23:57       ` boyd, rounin
2005-04-14  0:00         ` Russ Cox
2005-04-14  0:14           ` boyd, rounin
2005-04-14  0:18             ` Russ Cox
2005-04-14  0:22               ` Bruce Ellis
2005-04-14  0:38                 ` Dan Cross
2005-04-14  1:02                   ` boyd, rounin
2005-04-14  0:56                 ` jmk
2005-04-14  0:01       ` Bruce Ellis
2005-04-14  0:39         ` Dan Cross
2005-04-14 17:14         ` Ronald G. Minnich
2005-04-14 17:29           ` Rob Pike
2005-04-14 19:25             ` Ronald G. Minnich
2005-04-14 23:23             ` Bruce Ellis

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).