s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit 3962885e117e92a9b01d3a9d45895602115e725f
parent e1614d5b8c1d2717c28c8a4d8c60ca293c8f4662
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Fri, 24 Dec 2021 08:26:31 +0000

 s6-log: clarify last_stdin logic

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Msrc/daemontools-extras/s6-log.c | 19++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)

diff --git 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 ;