Add a test to see if a logfile has been turned over, and, if it has,

start watching the new log file, rather than the old one.

Bump revision to nb1.
This commit is contained in:
agc 2002-07-04 13:32:20 +00:00
parent 6b43b58e9d
commit 256ba26477
3 changed files with 122 additions and 2 deletions

View file

@ -1,6 +1,7 @@
# $NetBSD: Makefile,v 1.1.1.1 2001/11/20 23:19:16 hubertf Exp $
# $NetBSD: Makefile,v 1.2 2002/07/04 13:32:20 agc Exp $
DISTNAME= root-tail-0.0.10
PKGREVISION= 1
CATEGORIES= x11
MASTER_SITES= http://www.goof.com/pcg/marc/data/

View file

@ -1,4 +1,5 @@
$NetBSD: distinfo,v 1.1.1.1 2001/11/20 23:19:16 hubertf Exp $
$NetBSD: distinfo,v 1.2 2002/07/04 13:32:20 agc Exp $
SHA1 (root-tail-0.0.10.tar.gz) = 19963087202e6b365f8d9820bdee283ace16caa4
Size (root-tail-0.0.10.tar.gz) = 7816 bytes
SHA1 (patch-aa) = dba9a38b50e538171cf060ad1ef2e035717037c5

View file

@ -0,0 +1,118 @@
$NetBSD: patch-aa,v 1.1 2002/07/04 13:32:21 agc Exp $
Add a test to see if the log file has been turned over, and to re-open
files if it has.
--- root-tail.c 2002/07/04 13:05:32 1.1
+++ root-tail.c 2002/07/04 13:18:38
@@ -27,14 +27,6 @@
#define VERSION "0.0.10"
-/*---------------- Let's define signals functions -------------*/
-
-static void reopen (int);
-static void list_files (int);
-static void force_refresh (int);
-static void InstallSigHandler (void);
-FILE *openLog (const char *);
-
/*------------------------ initalize variables -----------------*/
int geom_mask, noinitial;
int screen, listlen = STD_HEIGHT, width = STD_WIDTH, ScreenWidth, ScreenHeight,
@@ -58,6 +50,7 @@
char desc[255]; /* alternative description */
FILE *f; /* FILE struct associated with file */
Pixel color; /* color to be used for printing */
+ struct stat st; /* stat buffer from previous */
struct logfile_entry *next;
};
@@ -70,6 +63,14 @@
Pixel color;
};
+/*---------------- Let's define signals functions -------------*/
+
+static void reopen (int);
+static void list_files (int);
+static void force_refresh (int);
+static void InstallSigHandler (void);
+FILE *openLog (struct logfile_entry *, const char *);
+
/*----------------------------- start code ---------------------*/
@@ -83,7 +84,7 @@
{
printf ("reopenin as %p (%s)\n", e->f, e->fname);
fclose (e->f);
- e->f = openLog (e->fname);
+ e->f = openLog (e, e->fname);
printf ("reopened as %p\n", e->f);
if (e->f == NULL)
{
@@ -226,15 +227,15 @@
}
FILE *
-openLog (const char *name)
+openLog (struct logfile_entry *e, const char *name)
{
FILE *f = fopen (name, "r");
- struct stat statbuf;
off_t size;
+
if (f == NULL)
return NULL;
- stat (name, &statbuf);
- size = statbuf.st_size;
+ stat (name, &e->st);
+ size = e->st.st_size;
if (size > (listlen+1) * width)
{
char dummy[255];
@@ -363,8 +364,16 @@
for (current = loglist; current != NULL; current = current->next)
{
+ struct stat st;
clearerr (current->f);
+ if (stat(current->fname, &st) < 0) {
+ continue;
+ }
+ if (st.st_ino != current->st.st_ino) {
+ need_reopen = 1;
+ }
+
while (!lineinput (temp, width + 2, current->f))
{
/*
@@ -418,7 +427,7 @@
if (need_reopen)
reopen (1);
- /* we ignore possible errors due to windo resizing &c */
+ /* we ignore possible errors due to window resizing &c */
while (XPending (disp))
{
XNextEvent (disp, &xev);
@@ -607,13 +616,14 @@
}
}
- if ((f = openLog (fname)) == NULL)
+ e = (struct logfile_entry *)
+ malloc (sizeof (struct logfile_entry));
+
+ if ((f = openLog (e, fname)) == NULL)
{
perror (fname);
exit (-1);
}
- e = (struct logfile_entry *)
- malloc (sizeof (struct logfile_entry));
strncpy (e->fname, fname, 255);
e->fname[255] = '\0'; /* just in case */