From 3962885e117e92a9b01d3a9d45895602115e725f Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 24 Dec 2021 08:26:31 +0000 Subject: s6-log: clarify last_stdin logic Signed-off-by: Laurent Bercot --- src/daemontools-extras/s6-log.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/daemontools-extras') diff --git a/src/daemontools-extras/s6-log.c b/src/daemontools-extras/s6-log.c index 92e3886..60de6b3 100644 --- a/src/daemontools-extras/s6-log.c +++ b/src/daemontools-extras/s6-log.c @@ -1058,23 +1058,15 @@ static void normal_stdin (scriptelem_t const *script, unsigned int scriptlen, si static void last_stdin (scriptelem_t const *script, unsigned int scriptlen, size_t linelimit, unsigned int gflags) { - int cont = 1 ; - while (cont) + for (;;) { char c ; switch (sanitize_read(fd_read(0, &c, 1))) { - case 0 : - cont = 0 ; - break ; + case 0 : return ; case -1 : if ((errno != EPIPE) && verbosity) strerr_warnwu1sys("read from stdin") ; - if (!indata.len) - { - prepare_to_exit() ; - cont = 0 ; - break ; - } + if (!indata.len) goto eof ; addfinalnewline: c = '\n' ; case 1 : @@ -1082,8 +1074,7 @@ static void last_stdin (scriptelem_t const *script, unsigned int scriptlen, size if (c == '\n') { script_run(script, scriptlen, indata.s, indata.len - 1, gflags) ; - prepare_to_exit() ; - cont = 0 ; + goto eof ; } else if (linelimit && indata.len > linelimit) { @@ -1093,6 +1084,8 @@ static void last_stdin (scriptelem_t const *script, unsigned int scriptlen, size break ; } } + eof: + prepare_to_exit() ; } static inputproc_func_ref handle_stdin = &normal_stdin ; -- cgit v1.2.3