[PATCH][makedumpfile -R] Promptly return error on truncated regular file. When reaching the end-of-file on a truncated input regular file, makedumpfile -R is looping for 10 minutes before producing an error. This is confusing for users. When stdin is a regular file, an improved behavior is to promptly return an EOF error.
Signed-off-by: Georges Aureau <[email protected]> -- diff --git a/makedumpfile.c b/makedumpfile.c index 12fb0d8..295b3cc 100644 --- a/makedumpfile.c +++ b/makedumpfile.c @@ -5135,6 +5135,21 @@ write_cache_zero(struct cache_data *cd, size_t size) return write_cache_bufsz(cd); } +int +is_stdin_regular_file(void) +{ + struct stat st; + static int regular_file = -1; + if (regular_file == -1) { + if (fstat(STDIN_FILENO, &st) == -1) { + regular_file = FALSE; + } else { + regular_file = S_ISREG(st.st_mode) ? TRUE : FALSE; + } + } + return regular_file; +} + int read_buf_from_stdin(void *buf, int buf_size) { @@ -5154,11 +5169,12 @@ read_buf_from_stdin(void *buf, int buf_size) } else if (0 == tmp_read_size) { /* - * If it cannot get any data from a standard input + * If we reach end-of-file on regular file, or + * if we cannot get any data from a standard input * for a long time, break this loop. */ tm = time(NULL); - if (TIMEOUT_STDIN < (tm - last_time)) { + if (is_stdin_regular_file() || TIMEOUT_STDIN < (tm - last_time)) { ERRMSG("Can't get any data from STDIN.\n"); return FALSE; }
