Sujet : Re: Faking a TTY on a pipe/socketpair
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.programmerDate : 17. Nov 2024, 18:48:23
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20241117093714.675@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-11-16,
Muttley@dastardlyhq.com <
Muttley@dastardlyhq.com> wrote:
So my question is - is there a way to set up a pipe or socketpair** so that
it appears to be a tty from the exec'd programs point of view, eg ttyname()
returns non null?
[...]
** Yes I know about the master-slave ptm,pts approach and I have done that in
the past but its complete overkill for this purpose.
No; you need a master/slave pseudo TTY pair connected to an active
process, which forwards between that and the socketpair or pipe.
Sockets and pipes cannot be given window dressing so that they look
like tty's. When the standard input (or output) of a process is a tty,
and that process cares about it, it will likely try operations like
tcgetattr.
Programs that use stdio standard input are affected by whether the
output is a TTY or not because the standard libraries on Unixes call
isatty() to determine whether the input constitutes an "interactive
device" according to ISO C, and hence whether to make the output fully
buffered.
The GNU C Library has a mechanism to override this, driven by
environment variables, and a wrapper utility callet "stdbuf"
which uses the environment variables to tell a child process
what buffering discipline to use for stdin, stdour or stderr.
So for that one small way in which it matters whether the standard
input or output is a TTY, at least one platform has a solution:
you don't have to fake out a TTY to trick a program into stdout
or stderr line buffering.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca