From: Karel Zak <kzak@redhat.com>
To: Iain Paton <selsinork@gmail.com>
Cc: util-linux@vger.kernel.org
Subject: Re: problem with script -e
Date: Tue, 4 Sep 2012 17:45:04 +0200 [thread overview]
Message-ID: <20120904154504.GE21432@x2.net.home> (raw)
In-Reply-To: <4FEF26A0.3010901@gmail.com>
On Sat, Jun 30, 2012 at 05:17:36PM +0100, Iain Paton wrote:
> Came across an unexpected feature with script today. Can't make my mind up if
> it's a bug or not, but it certainly makes some things difficult.
Sorry for delay...
> Seems that there's an implicit assumption that stdin will always be a tty for
> the script process - strace shows all sorts of -ENOTTY stuff when it's not.
Yes, "script - make typescript of terminal sessions". It initializes
a new pseudoterminal and makes connection between the current session
and the new terminal.
> I came up with the following that works for my use case, but maybe there's a
> better way ?
>
> --- script.c.org 2011-08-29 09:31:19.000000000 +0100
> +++ script.c 2012-06-30 16:24:42.896997422 +0100
> @@ -295,18 +295,29 @@
>
> fclose(fscript);
>
> - while (die == 0) {
> - if ((cc = read(STDIN_FILENO, ibuf, BUFSIZ)) > 0) {
> - ssize_t wrt = write(master, ibuf, cc);
> - if (wrt < 0) {
> - warn (_("write failed"));
> - fail();
> + if(isatty(STDIN_FILENO)) {
> +
> + while (die == 0) {
> + if ((cc = read(STDIN_FILENO, ibuf, BUFSIZ)) > 0) {
> + ssize_t wrt = write(master, ibuf, cc);
> + if (wrt < 0) {
> + warn (_("write failed"));
> + fail();
> + }
> }
> + else if (cc < 0 && errno == EINTR && resized)
> + resized = 0;
> + else
> + break;
> + }
> + } else {
> +
> + while(die == 0) {
> +
> + fd_set fs;
> + FD_ZERO(&fs);
> + select(1, &fs, &fs, &fs, NULL);
Hmm... what the others things like tcsetattr(), etc. Anyway, I'll try
to play with the patch. It seems like interesting idea.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
prev parent reply other threads:[~2012-09-04 15:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-30 16:17 problem with script -e Iain Paton
2012-09-04 15:45 ` Karel Zak [this message]
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=20120904154504.GE21432@x2.net.home \
--to=kzak@redhat.com \
--cc=selsinork@gmail.com \
--cc=util-linux@vger.kernel.org \
/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).