From owner-freebsd-hackers Tue Feb 10 09:18:25 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id JAA02456 for hackers-outgoing; Tue, 10 Feb 1998 09:18:25 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from services.BSDI.COM (services.BSDI.COM [205.230.225.19]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id JAA02349 for ; Tue, 10 Feb 1998 09:18:15 -0800 (PST) (envelope-from owner-support@bsdi.com) Received: from support.BSDI.COM (daemon@support.BSDI.COM [205.230.224.45]) by services.BSDI.COM (8.8.8+ESF/8.8.8) with ESMTP id KAA23675; Tue, 10 Feb 1998 10:18:07 -0700 (MST) Received: (from daemon@localhost) by support.BSDI.COM (8.8.5/8.7.3) id KAA01927; Tue, 10 Feb 1998 10:20:14 -0700 (MST) Date: Tue, 10 Feb 1998 10:20:14 -0700 (MST) Message-Id: <199802101720.KAA01927@support.BSDI.COM> From: BSDI Customer Support To: cjs@netbsd.org, freebsd-hackers@FreeBSD.ORG Subject: tail -F patches [BSDI-Support-Request #47019] Reply-to: support@bsdi.com Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This is an automated response. There is no need to reply now. Your message regarding: tail -F patches was received by BSDI Support on Tuesday, 10-Feb-1998 10:20:13. and was assigned request number 47019. In order help us track the progress of this request, we ask that you please include the exact string [BSDI-Support-Request #47019] in the subject line of any further mail about this particular request. For example: Subject: tail -F patches [BSDI-Support-Request #47019] You may do this simply by replying to this email. See also the Problem Reporting Procedures in the release notes. For releases prior to BSD/OS V2.0 see the file: ftp://ftp.bsdi.com/bsdi/support/misc/problem-reporting For timely resolution of your problem (*especially kernel panics*) you need to be sure to send us all the information requested. Please read that section now and follow up with any additional information that you can. See Our Web Site ---------------- The BSDI Support team now has information available on the web. See the following: http://www.bsdi.com/support BSD/OS Quick FAQs ----------------- Be sure you have installed all the current patches for your release. Email ``help'' to patches@bsdi.com for information about getting patches. These will fix most common problems that people report. Email ``send index'' to patches@bsdi.com for a complete list of available patches and updates. Quick Tips ---------- Digiboards: If you have problems with output on a Digiboard (or similar kinds of problems on anything, including ethernet cards) you should try a configuration at a different IRQ. IRQ 15 is most often a problem on PCI machines that have stolen for other purposes, but we have seen problems with other IRQ's as well. If changing IRQ's doesn't help then send us details per the Problem Reporting Procedures in the release notes and let us know what you have tried. The new /dev/sr* cdrom devices are not created on upgrades: # cd /dev # mknod /dev/sr0a b 34 0 0 # mount -t cd9660 /dev/sr0a /cdrom # mv MAKEDEV MAKEDEV.orig # cp /cdrom/dev/MAKEDEV . # ./MAKEDEV sr0 sr1 sr2 sr3 make any other cdrom devices you need and merge in any local changes you have made to MAKEDEV. SENDMAIL and DNS: Users running systems without Domain Name Service (DNS) will need to create an /etc/service.switch file and add ``hostsfiles'' to it, this can be done with this command: printf 'hosts\tfiles\n' >> /etc/service.switch For details see ``man -M sendmail op'' (section 2.4. The Service Switch) If you have problems with a Seagate Barracuda SCSI hard drive contact your hardware vendor for a firmware upgrade and/or swap. Firmware revs before 15 seem to have lots of problems. US Customer Support Voice: +1 800 ITS BSD8 Berkeley Software Design, Inc. Voice: +1 719 260 8114 7759 Delmonico Drive Voice: +1 512 219 5879 Colorado Springs, CO 80919 FAX: +1 719 598 4238 EMAIL: For reference purposes, your mail has been included below. ------------------------------------------------------------------- Received: from services.BSDI.COM (services.BSDI.COM [205.230.225.19]) by support.BSDI.COM (8.8.5/8.7.3) with ESMTP id KAA01919 for ; Tue, 10 Feb 1998 10:20:11 -0700 (MST) Received: from cynic.portal.ca (root@cynic.portal.ca [204.174.36.7]) by services.BSDI.COM (8.8.8+ESF/8.8.8) with ESMTP id KAA23639 for ; Tue, 10 Feb 1998 10:18:02 -0700 (MST) Received: from localhost ([[UNIX: localhost]]) by cynic.portal.ca (8.8.5/8.8.5) with SMTP id JAA05718; Tue, 10 Feb 1998 09:17:38 -0800 (PST) X-Authentication-Warning: cynic.portal.ca: cjs owned process doing -bs Date: Tue, 10 Feb 1998 09:17:37 -0800 (PST) From: Curt Sampson X-Sender: cjs@cynic.portal.ca Reply-To: cjs@netbsd.org, freebsd-hackers@freebsd.org To: freebsd-hackers@freebsd.org, support@bsdi.com Subject: tail -F patches [BSDI-Support-Request #47019] Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Request-Do: class support Cc: support@bsdi.com This was really popular with the NetBSD crowd, so I thought I'd forward it on to you folks. The following patches to tail(1) add a -F option which will make it continue to follow data appended to a file even if the file is rotated by newsyslog(8) or something similar, or truncated. cjs Curt Sampson cjs@portal.ca Info at http://www.portal.ca/ Internet Portal Services, Inc. Through infinite mist, software reverberates Vancouver, BC (604) 257-9400 In code possess'd of invisible folly. Index: forward.c =================================================================== RCS file: /cvsroot/src/usr.bin/tail/forward.c,v retrieving revision 1.8 diff -u -r1.8 forward.c --- forward.c 1997/10/19 23:45:08 1.8 +++ forward.c 1998/02/09 19:21:43 @@ -91,6 +91,15 @@ { int ch; struct timeval second; + int dostat = 0; + struct stat statbuf; + off_t lastsize = 0; + dev_t lastdev; + ino_t lastino; + + /* Keep track of file's previous incarnation. */ + lastdev = sbp->st_dev; + lastino = sbp->st_ino; switch(style) { case FBYTES: @@ -166,9 +175,11 @@ } for (;;) { - while ((ch = getc(fp)) != EOF) + while ((ch = getc(fp)) != EOF) { + lastsize++; /* track size changes between stats */ if (putchar(ch) == EOF) oerr(); + } if (ferror(fp)) { ierr(); return; @@ -186,6 +197,39 @@ if (select(0, NULL, NULL, NULL, &second) == -1) err(1, "select: %s", strerror(errno)); clearerr(fp); + + if (fflag == 1) + continue; + /* + * We restat the original filename every five seconds. If + * the size is ever smaller than the last time we read it, + * the file has probably been truncated; if the inode or + * or device number are different, it has been rotated. + * This causes us to close it, reopen it, and continue + * the tail -f. If stat returns an error (say, because + * the file has been removed), just continue with what + * we've got open now. + */ + if (dostat > 0) { + dostat -= 1; + } else { + dostat = 5; + if (stat(fname, &statbuf) == 0) { + if (statbuf.st_dev != lastdev || + statbuf.st_ino != lastino || + statbuf.st_size < lastsize) { + lastdev = statbuf.st_dev; + lastino = statbuf.st_ino; + lastsize = 0; + fclose(fp); + if ((fp = fopen(fname, "r")) == NULL) + err(1, "can't reopen %s: %s", + fname, strerror(errno)); + } else { + lastsize = statbuf.st_size; + } + } + } } } Index: tail.1 =================================================================== RCS file: /cvsroot/src/usr.bin/tail/tail.1,v retrieving revision 1.5 diff -u -r1.5 tail.1 --- tail.1 1997/10/19 23:45:11 1.5 +++ tail.1 1998/02/09 19:21:44 @@ -44,7 +44,11 @@ .Nd display the last part of a file .Sh SYNOPSIS .Nm -.Op Fl f Li | Fl r +.Oo +.Fl f | +.Fl F | +.Fl r +.Oc .Oo .Fl b Ar number | .Fl c Ar number | @@ -93,6 +97,21 @@ The .Fl f option is ignored if the standard input is a pipe, but not if it is a FIFO. +.It Fl F +The +.Fl F +option is the same as the +.Fl f +option, except that every five seconds +.Nm +will check to see if the file named on the command line has been +shortened or moved (it is considered moved if the inode or device +number changes) and, if so, it will close +the current file, open the filename given, print out the entire +contents, and continue to wait for more data to be appended. +This option is used to follow log files though rotation by +.Xr newsyslog 8 +or similar programs. .It Fl n Ar number The location is .Ar number Index: tail.c =================================================================== RCS file: /cvsroot/src/usr.bin/tail/tail.c,v retrieving revision 1.5 diff -u -r1.5 tail.c --- tail.c 1997/10/19 23:45:11 1.5 +++ tail.c 1998/02/09 19:21:44 @@ -111,8 +111,11 @@ obsolete(argv); style = NOTSET; - while ((ch = getopt(argc, argv, "b:c:fn:r")) != -1) + while ((ch = getopt(argc, argv, "Fb:c:fn:r")) != -1) switch(ch) { + case 'F': + fflag = 2; + break; case 'b': ARG(512, FBYTES, RBYTES); break; @@ -136,7 +139,7 @@ argv += optind; if (fflag && argc > 1) - err(1, "-f option only appropriate for a single file"); + err(1, "-f and -F options only appropriate for a single file"); /* * If displaying in reverse, don't permit follow option, and convert To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe hackers" in the body of the message