1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
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
@@ -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;
}
}
@@ -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;
}
}
@@ -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.
@@ -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
@@ -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 */
|