]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
`tail /proc/ksyms' would segfault on Linux.
authorJim Meyering <jim@meyering.net>
Tue, 13 Nov 2001 10:14:12 +0000 (10:14 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 13 Nov 2001 10:14:12 +0000 (10:14 +0000)
(tail_lines): Use status of lseek (...SEEK_END) call
in deciding whether to call file_lines or pipe_lines.
From Herbert Xu.

src/tail.c

index 4973ef64bdd7b48296b732bf2746bbda30632699..375e6316bd2abff39d2fa913dfbbb7a65c40e00c 100644 (file)
@@ -1095,14 +1095,14 @@ tail_lines (const char *pretty_filename, int fd, long int n_lines)
     {
       /* Use file_lines only if FD refers to a regular file with
          its file pointer positioned at beginning of file.  */
-      /* FIXME: adding the lseek conjunct is a kludge.
+      /* FIXME: this first lseek conjunct is a kludge.
         Once there's a reasonable test suite, fix the true culprit:
         file_lines.  file_lines shouldn't presume that the input
         file pointer is initially positioned to beginning of file.  */
       if (S_ISREG (stats.st_mode)
-         && lseek (fd, (off_t) 0, SEEK_CUR) == (off_t) 0)
+         && lseek (fd, (off_t) 0, SEEK_CUR) == (off_t) 0
+         && (length = lseek (fd, (off_t) 0, SEEK_END)) >= 0)
        {
-         length = lseek (fd, (off_t) 0, SEEK_END);
          if (length != 0 && file_lines (pretty_filename, fd, n_lines, length))
            return 1;
        }