From: Jim Meyering Date: Sat, 10 Jul 1999 09:56:37 +0000 (+0000) Subject: (struct File_spec): New member, errnum. X-Git-Tag: TEXTUTILS-1_22n~45 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ae1e1e5e19f4e8f4c7e574772c7d19404a124d52;p=thirdparty%2Fcoreutils.git (struct File_spec): New member, errnum. (recheck): Record the new value of errno in f->errnum. Don't output an error message unless the new value of errno differs from the old one. Output a message if previously-inaccessible file becomes accessible. (tail_forever): Always recheck files whose fd is negative. If the file cannot be fstat'ed, record the errno value in f[i].errnum. (tail_file): If the file cannot be open, record the errno value in f->errnum. If it can be opened, initialize f->errnum to zero. If it's a non-regular non-fifo file, initialize f->errnum to -1. --- diff --git a/src/tail.c b/src/tail.c index da64f653fe..12f4720734 100644 --- a/src/tail.c +++ b/src/tail.c @@ -113,6 +113,10 @@ struct File_spec /* FIXME: describe */ int missing; + + /* The value of errno seen last time we checked this file. */ + int errnum; + }; /* FIXME: describe */ @@ -653,6 +657,7 @@ recheck (struct File_spec *f) int fail = 0; int is_stdin = (STREQ (f->name, "-")); int was_missing = f->missing; + int prev_errnum = f->errnum; int new_file; fd = (is_stdin ? STDIN_FILENO : open (f->name, O_RDONLY)); @@ -664,6 +669,7 @@ recheck (struct File_spec *f) if (fd == -1 || fstat (fd, &new_stats) < 0) { fail = 1; + f->errnum = errno; if (f->missing) { if (!was_missing) @@ -673,7 +679,7 @@ recheck (struct File_spec *f) /* say nothing... it's still missing */ } } - else + else if (prev_errnum != errno) { error (0, errno, "%s", pretty_name (f)); } @@ -682,11 +688,14 @@ recheck (struct File_spec *f) && !S_ISFIFO (new_stats.st_mode)) { fail = 1; + f->errnum = -1; /* FIXME */ error (0, 0, _("`%s' has been replaced with a non-regular file; \ cannot follow end of non-regular file"), pretty_name (f)); } + else + f->errnum = 0; new_file = 0; if (fail) @@ -695,6 +704,13 @@ cannot follow end of non-regular file"), close_fd (f->fd, pretty_name (f)); f->fd = -1; } + else if (prev_errnum && prev_errnum != ENOENT) + { + new_file = 1; + if (f->fd != -1) + close_fd (f->fd, pretty_name (f)); /* close the old handle */ + error (0, 0, _("`%s' has become accessible"), pretty_name (f)); + } else if (f->ino != new_stats.st_ino || f->dev != new_stats.st_dev) { new_file = 1; @@ -783,8 +799,7 @@ tail_forever (struct File_spec *f, int nfiles) if (f[i].fd < 0) { - if (f[i].missing) - recheck (&f[i]); + recheck (&f[i]); continue; } @@ -792,6 +807,7 @@ tail_forever (struct File_spec *f, int nfiles) { error (0, errno, "%s", pretty_name (&f[i])); f[i].fd = -1; + f[i].errnum = errno; continue; } @@ -1022,7 +1038,10 @@ tail_file (struct File_spec *f, off_t n_units) if (fd == -1) { if (forever) - f->fd = -1; + { + f->fd = -1; + f->errnum = errno; + } error (0, errno, "%s", pretty_name (f)); errors = 1; } @@ -1033,17 +1052,20 @@ tail_file (struct File_spec *f, off_t n_units) errors = tail (pretty_name (f), fd, n_units); if (forever) { + f->errnum = 0; /* FIXME: duplicate code */ if (fstat (fd, &stats) < 0) { error (0, errno, "%s", pretty_name (f)); errors = 1; + f->errnum = errno; } else if (!S_ISREG (stats.st_mode) && !S_ISFIFO (stats.st_mode)) { error (0, 0, _("%s: cannot follow end of non-regular file"), pretty_name (f)); errors = 1; + f->errnum = -1; /* FIXME */ } if (errors) {