util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Asbjørn Sloth Tønnesen" <asbjorn@asbjorn.st>
To: util-linux@vger.kernel.org
Cc: "Asbjørn Sloth Tønnesen" <asbjorn@asbjorn.st>
Subject: [PATCH 1/2] script: move output limit check to dedicated function
Date: Sun, 19 Aug 2018 17:16:57 +0000	[thread overview]
Message-ID: <20180819171658.20285-1-asbjorn@asbjorn.st> (raw)

Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.st>
---
 term-utils/script.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index 6d5ddd84a..dfea87463 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -414,6 +414,19 @@ static void write_eof_to_shell(struct script_control *ctl)
 	write_to_shell(ctl, &c, sizeof(char));
 }
 
+static void check_output_limit(struct script_control *ctl)
+{
+	if (ctl->maxsz != 0 && ctl->outsz >= ctl->maxsz) {
+		if (!ctl->quiet)
+			printf(_("Script terminated, max output file size "
+				"%"PRIu64" exceeded.\n"), ctl->maxsz);
+
+		DBG(IO, ul_debug("output size %"PRIu64", exceeded limit %"PRIu64,
+			ctl->outsz, ctl->maxsz));
+		done_log(ctl, _("max output size exceeded"));
+	}
+}
+
 static void handle_io(struct script_control *ctl, int fd, int *eof)
 {
 	char buf[BUFSIZ];
@@ -451,13 +464,7 @@ static void handle_io(struct script_control *ctl, int fd, int *eof)
 		DBG(IO, ul_debug(" master --> stdout %zd bytes", bytes));
 		write_output(ctl, buf, bytes);
 
-		/* check output limit */
-		if (ctl->maxsz != 0 && ctl->outsz >= ctl->maxsz) {
-			if (!ctl->quiet)
-				printf(_("Script terminated, max output file size %"PRIu64" exceeded.\n"), ctl->maxsz);
-			DBG(IO, ul_debug("output size %"PRIu64", exceeded limit %"PRIu64, ctl->outsz, ctl->maxsz));
-			done_log(ctl, _("max output size exceeded"));
-		}
+		check_output_limit(ctl);
 	}
 }
 
-- 
2.16.1

             reply	other threads:[~2018-08-19 20:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-19 17:16 Asbjørn Sloth Tønnesen [this message]
2018-08-19 17:16 ` [PATCH 2/2] script: add input log feature Asbjørn Sloth Tønnesen
2018-08-20  8:46   ` Karel Zak
2018-09-25 20:44     ` Asbjørn Sloth Tønnesen

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=20180819171658.20285-1-asbjorn@asbjorn.st \
    --to=asbjorn@asbjorn.st \
    --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).