Date: Mon, 19 Nov 2001 11:00:02 -0800 (PST) From: Maxim Konovalov <maxim@macomnet.ru> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/24955:/usr/bin/tail -F in 4.1+ doesn't work if file inode changes (works in 4.0) Message-ID: <200111191900.fAJJ02C61064@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/24955; it has been noted by GNATS.
From: Maxim Konovalov <maxim@macomnet.ru>
To: Ian Dowse <iedowse@maths.tcd.ie>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/24955:/usr/bin/tail -F in 4.1+ doesn't work if file inode
changes (works in 4.0)
Date: Mon, 19 Nov 2001 21:53:45 +0300 (MSK)
Hello,
On Sun, 18 Nov 2001, Ian Dowse wrote:
[...]
> Hi,
>
> While this patch should address the particular case mentioned in this
> PR (tail is pointed at a symlink, but the symlink changes), it doesn't
> solve the general problem of any other component in the specified
> path changing. Maybe it is best to just resort to a polling approach
> when the '-F' flag is specified? It could still use kqueue, but just
> re-stat the path every ~1-10 seconds to check if the inode changed.
What about this one:
Index: forward.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/tail/forward.c,v
retrieving revision 1.27
diff -u -r1.27 forward.c
--- forward.c 1 Sep 2001 22:22:44 -0000 1.27
+++ forward.c 19 Nov 2001 18:31:49 -0000
@@ -180,6 +180,9 @@
}
for (;;) {
+ struct timespec ts;
+ int n;
+
while ((ch = getc(fp)) != EOF)
if (putchar(ch) == EOF)
oerr();
@@ -194,8 +197,9 @@
switch (action) {
case ADD_EVENTS: {
- int n = 0;
- struct timespec ts = { 0, 0 };
+ n = 0;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
if (Fflag && fileno(fp) != STDIN_FILENO) {
EV_SET(&ev[n], fileno(fp), EVFILT_VNODE,
@@ -218,10 +222,16 @@
}
case USE_KQUEUE:
- if (kevent(kq, NULL, 0, ev, 1, NULL) < 0)
+ ts.tv_sec = 0;
+ ts.tv_nsec = 250000;
+
+ if ((n = kevent(kq, NULL, 0, ev, 1, &ts)) < 0)
err(1, "kevent");
- if (ev->filter == EVFILT_VNODE) {
+ if (n == 0) {
+ /* timeout */
+ action = USE_SLEEP;
+ } else if (ev->filter == EVFILT_VNODE) {
/* file was rotated, wait until it reappears */
action = USE_SLEEP;
} else if (ev->data < 0) {
@@ -234,7 +244,7 @@
break;
case USE_SLEEP:
- (void) usleep(250000);
+ (void)usleep(250000);
clearerr(fp);
if (Fflag && fileno(fp) != STDIN_FILENO &&
> Ian
- -maxim
--
Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200111191900.fAJJ02C61064>
