Description: Changes that were previously applied to source
Author: David William Richmond Davies-Jones <david@exultantmonkey.co.uk>
Forwarded: not-needed
Last-Update: 2017-07-19

--- entryfuncs.c.orig
+++ entryfuncs.c
@@ -75,6 +75,8 @@ struct entry_descrip *new_entry(struct e
     entryp->fd = 0;
     entryp->size =  0;
     entryp->mtime = 0;
+    entryp->dev = 0;
+    entryp->ino = 0;
 
     return E_append(listp,entryp);
 }
@@ -118,6 +120,8 @@ void move_entry(struct entry_list *dst_l
     if (Reset_status) {
 	entryp->size = 0;
 	entryp->mtime = 0;
+	entryp->dev = 0;
+	entryp->ino = 0;
     }
 }
 
--- miscfuncs.c.orig
+++ miscfuncs.c
@@ -107,6 +107,8 @@ int scan_directory(const char *dirname)
 	} else {
 	    entryp->mtime = sbuf.st_mtime;
 	    entryp->size = sbuf.st_size;
+	    entryp->dev = sbuf.st_dev;
+	    entryp->ino = sbuf.st_ino;
 	}
 
     }
--- xtail.1.orig
+++ xtail.1
@@ -1,5 +1,5 @@
 .\" $Id: xtail.1,v 2.2 1996/06/25 00:31:15 chip Exp $
-.TH XTAIL 1L
+.TH XTAIL 1
 .SH NAME
 xtail - Watch the growth of files.
 .SH SYNTAX
@@ -31,9 +31,7 @@ most recently modified files being watch
 tail(1)
 .SH NOTES
 .I Xtail
-may be easily confused.  For example, if a file is renamed,
-.I xtail
-may or may not continue to monitor it.  If you ask it to monitor a file
+may be easily confused.  For example, if you ask it to monitor a file
 multiple times, it probably will.  If you misspell a filename,
 .I xtail
 will treat it as a nonexistent entry and happily wait for its creation.
--- xtail.c.orig
+++ xtail.c
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
 {
     int open_files_only, already_open, iteration, i;
     struct entry_descrip *entryp;
-    struct stat sbuf;
+    struct stat sbuf, path_sbuf;
 
     /* 
      * Initialize.
@@ -61,6 +61,8 @@ int main(int argc, char *argv[])
 	    move_entry(List_file, List_zap, last_entry(List_zap));
 	    entryp->size = sbuf.st_size;
 	    entryp->mtime = sbuf.st_mtime;
+	    entryp->dev = sbuf.st_dev;
+	    entryp->ino = sbuf.st_ino;
 	    break;
 
 	case ENTRY_DIR:			/* move entry to dir list	*/
@@ -195,6 +197,20 @@ int main(int argc, char *argv[])
 	    }
 
 	    /*
+	     * See if an open file has been renamed.  Occasionally do
+	     * an extra stat on the file's name, and compare that to the
+	     * info which fstat() returned.
+	     */
+	    if (already_open && !open_files_only
+    	    	    && (stat(entryp->name, &path_sbuf) != 0
+			|| path_sbuf.st_dev != entryp->dev
+			|| path_sbuf.st_ino != entryp->ino)) {
+		message(MSSG_RENAMED, entryp);
+		move_entry(List_zap, List_file, i--);
+		continue;
+	    }
+
+	    /*
 	     * If nothing has changed then continue on.
 	     */
 	    if (entryp->size==sbuf.st_size && entryp->mtime==sbuf.st_mtime)
@@ -247,9 +263,11 @@ int main(int argc, char *argv[])
 	    }
 
 	    /*
-	     * Update the modification time.
+	     * Update the other saved info about this entry.
 	     */
 	    entryp->mtime = sbuf.st_mtime;
+	    entryp->dev = sbuf.st_dev;
+	    entryp->ino = sbuf.st_ino;
 
 	    /*
 	     * Since we've changed the mtime, the list might no longer be
--- xtail.h.orig
+++ xtail.h
@@ -36,11 +36,6 @@
  */
 #define MAX_OPEN 8
 
-/*
- * MAX_ENTRIES - This is *BOGUS*  I should get rid of this.
- */
-#define MAX_ENTRIES 512
-
 
 
 /*****************************************************************************
@@ -75,12 +70,13 @@
 #define MSSG_CREATED	2	/* file has been created		*/
 #define MSSG_ZAPPED	3	/* file has been deleted		*/
 #define MSSG_TRUNC	4	/* file has been truncated		*/
-#define MSSG_NOTAFIL	5	/* error - not a regular file or dir	*/
-#define MSSG_STAT	6	/* error - stat() failed		*/
-#define MSSG_OPEN	7	/* error - open() failed		*/
-#define MSSG_SEEK	8	/* error - lseek() failed		*/
-#define MSSG_READ	9	/* error - read() failed		*/
-#define MSSG_UNKNOWN	10	/* unknown error - must be last in list */
+#define MSSG_RENAMED	5	/* file has been renamed		*/
+#define MSSG_NOTAFIL	6	/* error - not a regular file or dir	*/
+#define MSSG_STAT	7	/* error - stat() failed		*/
+#define MSSG_OPEN	8	/* error - open() failed		*/
+#define MSSG_SEEK	9	/* error - lseek() failed		*/
+#define MSSG_READ	10	/* error - read() failed		*/
+#define MSSG_UNKNOWN	11	/* unknown error - must be last in list */
 
 
 #ifdef INTERN
@@ -113,6 +109,8 @@ struct entry_descrip {
     int fd;		/* opened fd, or <= 0 if not opened		*/
     long size;		/* size of entry last time checked		*/
     long mtime;		/* modification time last time checked		*/
+    dev_t dev;		/* device number last time, if file is opened	*/
+    ino_t ino;		/* inode number last time, if file is opened	*/
 };
 
 struct entry_list {
@@ -171,6 +169,7 @@ EXTERN char *Progname;
 	"\n*** '%s' has been created ***\n",			/*MSSG_CREATED*/
 	"\n*** '%s' has been deleted ***\n",			/*MSSG_ZAPPED */
 	"\n*** '%s' has been truncated - rewinding ***\n",	/*MSSG_TRUNC  */
+	"\n*** '%s' has been renamed - closing ***\n",		/*MSSG_RENAMED */
 	"\n*** error - '%s' not a file or dir - removed ***\n",	/*MSSG_NOTAFIL*/
 	"\n*** error - couldn't stat '%s' (%s) - removed ***\n",/*MSSG_STAT   */
 	"\n*** error - couldn't open '%s' (%s) - removed ***\n",/*MSSG_OPEN   */
