* Odd curses bug - redirected stdout.
@ 1995-01-26 11:02 Glenn Huxtable
1995-01-27 9:49 ` Glenn Huxtable
0 siblings, 1 reply; 2+ messages in thread
From: Glenn Huxtable @ 1995-01-26 11:02 UTC (permalink / raw)
Can anyone explain this wierd behaviour of OSF1 curses?
Curses fails to honour 'nonl', 'noecho' and 'cbreak' (at least) if
stdout has been redirected?
Before you say that I'm silly to expect curses to work if stdout is redirected,
let me say "it fails even if stdout is redirected to stdout!"
Try the following trivial test program. I call it 'ctest'. It shoud set
nonl, noecho and cbreak, then read characters. For each character read, it
should:
1) NOT echo the character (noecho)
2) immediately (nonl + cbreak) print a '.' on the screen.
------------------------------------------------------------------------
#include <curses.h>
main(argc, argv)
int argc; char **argv;
{
int c;
initscr();
cbreak();
noecho();
nonl();
while (c=getch() ) {
if (c=='q') {
endwin();
exit(0);
}
addch('.');
refresh();
}
}
------------------------------------------------------------------------
If you run 'ctest' you should see how it is *expected* to work.
Now, try either of the following, to see it fail:
ctest > /dev/tty
ctest > `tty`
In both cases, it echo's the characters typed, and line buffers them (doesn't
read and print the dots until <return> is pressed).
I might add, this fails under the default curses (SYSV-ish), but appears to
work under the BSD curses (compile with -D_BSD=1).
This test also succeeds under Solaris, HPUX, Ultrix and BSDI curses.
For the life of me, I can't see how curses can tell the difference between
stdout pointing to /dev/ttyp0 (for example), stoud redirected to /dev/ttyp0,
or stdout pointing to /dev/tty (which returns a handle to /dev/ttyp0).
It just occured to me that it could be something environmental that the shell
was doing in redirecting stdout (fiddling processgroups etc), but no - it
fails under /bin/sh, /bin/ksh and /bin/csh too!
Even stranger, running
sh < /dev/tty > /dev/tty 2>/dev/tty
then running
ctest
fails! Now, by induction, init, or login, or something is going to have to have
redirected stdout to the terminal, at some time. Why should the last little
test have failed too?
If anyone from OSF is listening, can you tell me what curses is doing
in 'noecho', 'cbreak' and 'nonl' when stdout is redirected to stdout????
Can anyone explain this odd behaviour? Does the test fail to fail for
anyone?
In case anyone is wondering, WHY I want to redirect stdout to stdout, this is
simply a symptom of a different problem. I am porting a curses tool that
is used in a pipeline. stdin and stdout are passed as the pipeline, file
descriptor 3 is passed as the controlling terminal, and this must be dup'd
to stdout for the curses tool to use for the display (stdout having been
saved first for use in the pipeline).
It's kosher, it works on all other tested platforms. It's not like we are
trying to do anything wrong. It breaks on OSF1 (like so many other things :-()
Unfortunately, I'm not sure that I can simply use the BSD curses, as that is
a very old standard, and does not have some more advanced features that
the tool requires (but then even the SVSV curses is not fully SVR5 compatible
either :-()
Any help will be greatly appreciated
Glenn
--
Email - glenn@fs.com.au ,-_|\ glenn huxtable
phone - +61 9 328 8288 / \ functional software
fax - +61 9 328 8616 *_,-._/ PO box 192
v leederville WA 6903
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: Odd curses bug - redirected stdout.
1995-01-26 11:02 Odd curses bug - redirected stdout Glenn Huxtable
@ 1995-01-27 9:49 ` Glenn Huxtable
0 siblings, 0 replies; 2+ messages in thread
From: Glenn Huxtable @ 1995-01-27 9:49 UTC (permalink / raw)
glenn@fs.com.au (Glenn Huxtable) writes:
>Can anyone explain this wierd behaviour of OSF1 curses?
>Curses fails to honour 'nonl', 'noecho' and 'cbreak' (at least) if
>stdout has been redirected?
>Before you say that I'm silly to expect curses to work if stdout is redirected,
>let me say "it fails even if stdout is redirected to stdout!"
... well, I still haven't solved this problem, but I've narrowed it down
further.
The failing curses routines are calling an ioctl TCSETAW, which drains the
output before setting the 'termio' structure.
If stdout is redirected to either '/dev/tty' or to the real terminal
(ie /dev/ttyp1), then the ioctl returns errno = 13 (EPERM or Permission denied).
This should not be so. I own the terminal, it's mode 666 (just to be sure) and
it's *exactly* the same device that stdout was pointing to before it was
redirected.
I've checked other things such as process groups, session groups, controlling
terminal, and they are all the same as in the case where stdout has not been
redirected (and the test program succeeds).
an anyone explain this unusual behaviour of TCSETAW? Better still, can anyone
suggest how I can fix it so that curses (and ioctl) think the redirected
terminal is ok, and have this TCSETAW succeed?
glenn
--
Email - glenn@fs.com.au ,-_|\ glenn huxtable
phone - +61 9 328 8288 / \ functional software
fax - +61 9 328 8616 *_,-._/ PO box 192
v leederville WA 6903
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1995-01-27 9:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-01-26 11:02 Odd curses bug - redirected stdout Glenn Huxtable
1995-01-27 9:49 ` Glenn Huxtable
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox