diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-12-24 08:26:31 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2021-12-24 08:26:31 +0000 |
commit | 3962885e117e92a9b01d3a9d45895602115e725f (patch) | |
tree | 35e1ddf57d6ffce186be45b2e40c3f1fd9a649c7 /src/daemontools-extras | |
parent | e1614d5b8c1d2717c28c8a4d8c60ca293c8f4662 (diff) | |
download | s6-3962885e117e92a9b01d3a9d45895602115e725f.tar.xz |
s6-log: clarify last_stdin logic
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/daemontools-extras')
-rw-r--r-- | src/daemontools-extras/s6-log.c | 19 |
1 files changed, 6 insertions, 13 deletions
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 ; |