From owner-freebsd-bugs Wed Jun 28 16:40: 6 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 4D4A437B554 for ; Wed, 28 Jun 2000 16:40:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id QAA32963; Wed, 28 Jun 2000 16:40:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Wed, 28 Jun 2000 16:40:03 -0700 (PDT) Message-Id: <200006282340.QAA32963@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Kelly Yancey Subject: Re: bin/19514: patch to prevent tail'ing directories Reply-To: Kelly Yancey Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/19514; it has been noted by GNATS. From: Kelly Yancey To: Bruce Evans Cc: FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: bin/19514: patch to prevent tail'ing directories Date: Wed, 28 Jun 2000 19:32:53 -0400 (EDT) On Tue, 27 Jun 2000, Bruce Evans wrote: > POSIX.2 (in the old draft that I have) specifically requires "tail -c" > to accept arbitrary data. tail(1) without -c is only required to handle > text files. head(1) is only required to handle text files. cat(1) is > required to handle all types of files. > I just researched this in the SUS and found the same thing. So contrary to my previous post, do not close this PR yet. Instead, please apply the following patch instead. It keeps us SUS and POSIX compliant in this regards, but is still 'user-friendly'. Index: usr.bin/tail/tail.c =================================================================== RCS file: /home/cvs/src/usr.bin/tail/tail.c,v retrieving revision 1.6 diff -u -r1.6 tail.c --- usr.bin/tail/tail.c 1999/07/04 17:26:03 1.6 +++ usr.bin/tail/tail.c 2000/06/28 23:23:24 @@ -69,7 +69,7 @@ FILE *fp; long off; enum STYLE style; - int ch, first; + int ch, first, num; char *p; /* @@ -164,6 +164,7 @@ } } + num = 0; if (*argv) for (first = 1; fname = *argv++;) { if ((fp = fopen(fname, "r")) == NULL || @@ -171,7 +172,25 @@ ierr(); continue; } - if (argc > 1) { + if (style == FLINES || style == RLINES) { + /* + * SUS says that `line' mode is only required + * to support text files. We support everything + * that `makes sense'. + */ + if (S_ISDIR(sb.st_mode)) { + warnx("%s is a directory", fname); + continue; + } else if (S_ISLNK(sb.st_mode)) { + warnx("%s is a symlink", fname); + continue; + } else if (S_ISWHT(sb.st_mode)) { + warnx("%s is a whiteout entry", fname); + continue; + } + } + num++; + if (num > 1) { (void)printf("%s==> %s <==\n", first ? "" : "\n", fname); first = 0; Thanks, Kelly -- Kelly Yancey - kbyanc@posi.net - Belmont, CA System Administrator, eGroups.com http://www.egroups.com/ Maintainer, BSD Driver Database http://www.posi.net/freebsd/drivers/ Coordinator, Team FreeBSD http://www.posi.net/freebsd/Team-FreeBSD/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message