From: Karel Zak <kzak@redhat.com>
To: 1003095@bugs.debian.org, Chris Hofstaedtler <zeha@debian.org>,
util-linux@vger.kernel.org
Cc: наб <nabijaczleweli@nabijaczleweli.xyz>
Subject: Re: Bug#1003095: /usr/bin/script: hangs when child doesn't read input fast enough
Date: Mon, 11 Apr 2022 12:08:06 +0200 [thread overview]
Message-ID: <20220411100806.bfplpv36sdixd6uu@ws.net.home> (raw)
In-Reply-To: <20220113232811.puu3pbtzjvzgys3o@tarta.nabijaczleweli.xyz>
On Fri, Jan 14, 2022 at 12:28:11AM +0100, наб wrote:
> -static int write_to_child(struct ul_pty *pty, char *buf, size_t bufsz)
> +static int schedule_child_write(struct ul_pty *pty, char *buf, size_t bufsz, int final)
> {
> - return write_all(pty->master, buf, bufsz);
> + struct ul_pty_child_buffer *stash = calloc(1, sizeof(*stash));
It means that for each activity on the file descriptor it will
allocate a new buffer (in BUFSIZ). It seems pretty expensive.
Cannot we reuse the buffers?
Maybe use include/list.h, define two lists, one for not-yet-written
buffers and another for ready-to-use buffers and move from one list to
another in schedule_child_write() and flush_child_buffers().
> + if (!stash)
> + return -1;
> +
> + memcpy(stash->buf, buf, bufsz);
> + stash->size = bufsz;
> + stash->final_input = final ? 1 : 0;
> +
> + if (pty->child_buffer_head)
> + pty->child_buffer_tail = pty->child_buffer_tail->next = stash;
> + else
> + pty->child_buffer_head = pty->child_buffer_tail = stash;
> + return 0;
> }
>
> /*
> @@ -311,16 +329,13 @@ static int write_to_child(struct ul_pty
> * maintains master+slave tty stuff within the session. Use pipe to write to
> * pty and assume non-interactive (tee-like) behavior is NOT well supported.
> */
> -void ul_pty_write_eof_to_child(struct ul_pty *pty)
> +static void drain(struct ul_pty *pty)
drain_child_buffers() :-)
Anyway, it looks good.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2022-04-11 10:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220103230422.syzm2ryzcixuhl7r@tarta.nabijaczleweli.xyz>
2022-01-04 16:24 ` Bug#1003095: /usr/bin/script: hangs when child doesn't read input fast enough Chris Hofstaedtler
2022-01-04 17:31 ` наб
2022-01-05 15:45 ` Karel Zak
2022-01-08 14:54 ` наб
2022-01-13 23:28 ` наб
2022-02-02 14:49 ` наб
2022-02-03 10:55 ` Karel Zak
2022-04-07 14:22 ` наб
2022-04-11 10:08 ` Karel Zak [this message]
2022-04-12 14:25 ` наб
2022-04-19 10:36 ` Karel Zak
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=20220411100806.bfplpv36sdixd6uu@ws.net.home \
--to=kzak@redhat.com \
--cc=1003095@bugs.debian.org \
--cc=nabijaczleweli@nabijaczleweli.xyz \
--cc=util-linux@vger.kernel.org \
--cc=zeha@debian.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).