logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 40c908cd00a9f61fc669ff92ced34b99f7423f3f
parent 1f4a0049a80cd9652b552cb945c8b8230fa9c92d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 23 Apr 2025 15:50:58 +0200

cmd/timeout: warning on nanosleep errno != EINTR

Diffstat:

Mcmd/timeout.c26++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/cmd/timeout.c b/cmd/timeout.c @@ -181,9 +181,19 @@ main(int argc, char *argv[]) if(nanosleep(&term, &term) < 0) { - if(errno != EINTR) + if(errno == EINTR) { - fprintf(stderr, "timeout: error: Failed sleeping: %s\n", strerror(errno)); + fprintf(stderr, + "timeout: warning: Interrupted during sleeping for %s, still had %ld.%09ld seconds " + "remaining\n", + term_signame, + term.tv_sec, + term.tv_nsec); + } + else + { + fprintf( + stderr, "timeout: error: Failed sleeping before %s: %s\n", term_signame, strerror(errno)); return CMD_EXIT_FAILURE; } } @@ -210,9 +220,17 @@ main(int argc, char *argv[]) if(nanosleep(&time_kill, &time_kill) < 0) { - if(errno != EINTR) + if(errno == EINTR) + { + fprintf(stderr, + "timeout: warning: Interrupted during KILL-sleep, still had %ld.%09ld seconds " + "remaining\n", + term.tv_sec, + term.tv_nsec); + } + else { - fprintf(stderr, "timeout: error: Failed sleeping: %s\n", strerror(errno)); + fprintf(stderr, "timeout: error: Failed sleeping before KILL: %s\n", strerror(errno)); return CMD_EXIT_FAILURE; } }