From owner-freebsd-bugs Mon Nov 19 11: 0:17 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 6E60E37B419 for ; Mon, 19 Nov 2001 11:00:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id fAJJ02C61064; Mon, 19 Nov 2001 11:00:02 -0800 (PST) (envelope-from gnats) Date: Mon, 19 Nov 2001 11:00:02 -0800 (PST) Message-Id: <200111191900.fAJJ02C61064@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Maxim Konovalov Subject: Re: bin/24955:/usr/bin/tail -F in 4.1+ doesn't work if file inode changes (works in 4.0) Reply-To: Maxim Konovalov Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/24955; it has been noted by GNATS. From: Maxim Konovalov To: Ian Dowse 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