Ted Unangst wrote:
> > > Modified files:
> > > usr.bin/tail : extern.h forward.c misc.c read.c reverse.c
> > > tail.c
> > >
> > > Log message:
> > > another try to allow tailing multiple files. maybe it works?
> > > commit now to allow people to test.
> >
> > I just updated to very latest snapshot and tail with plus num doesn't
> > work:
> >
> > OpenBSD 5.8-current (GENERIC.MP) #1636: Thu Nov 19 14:05:34 MST 2015
> > [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> >
> > $ ps auxwww | tail -n +3 | wc -l
> > 0
>
> (Everyone else: Please report all tail bugs to either tech or bugs.)
>
> Definitely a regression here, the rewrite of forward() is apparently not
> counting the offset correctly.
So the problem is that after the for loop over files, we have:
(void)fflush(stdout);
if (!fflag || kq < 0)
return;
That code used to live a little farther down, in the loop that copied data,
and didn't break until after we hit EOF.
I think it may make sense to do the copying in the file loop instead. This
handles one case, but I think there are more. We also need to reset the offset
for each file, or later ones don't print anything.
Index: forward.c
===================================================================
RCS file: /cvs/src/usr.bin/tail/forward.c,v
retrieving revision 1.27
diff -u -p -r1.27 forward.c
--- forward.c 19 Nov 2015 17:50:04 -0000 1.27
+++ forward.c 20 Nov 2015 00:25:17 -0000
@@ -52,6 +52,16 @@ static const struct timespec *tfreopen(s
static int kq = -1;
+static void
+printtail(FILE *fp)
+{
+ int ch;
+
+ while (!feof(fp) && (ch = getc(fp)) != EOF)
+ if (putchar(ch) == EOF)
+ oerr();
+}
+
/*
* forward -- display the file, from an offset, forward.
*
@@ -75,7 +85,7 @@ static int kq = -1;
* NOREG cyclically read lines into a wrap-around array of buffers
*/
void
-forward(struct tailfile *tf, int nfiles, enum STYLE style, off_t off)
+forward(struct tailfile *tf, int nfiles, enum STYLE style, off_t origoff)
{
int ch;
struct tailfile *ctf, *ltf;
@@ -91,6 +101,7 @@ forward(struct tailfile *tf, int nfiles,
warn("kqueue");
for (i = 0; i < nfiles; i++) {
+ off_t off = origoff;
if (nfiles > 1)
printfname(tf[i].fname);
@@ -125,8 +136,11 @@ forward(struct tailfile *tf, int nfiles,
}
break;
}
- if (ch == '\n' && !--off)
+ if (ch == '\n' && !--off) {
+ if (!fflag)
+ printtail(tf[i].fp);
break;
+ }
}
break;
case RBYTES: