Subject: | Compare inode and device |
reset_pointers contains code to compare inode - as returned by stat - with inode of initial open.
Technically comparing inodes alone is not sufficient.. the device should be compared as well: inodes are unique per device.
Attached patch extends inode check to also check device.
[Note: this patch assumes patch in #125814 is applied]
Subject: | 005-check_dev.patch |
diff --git a/Tail.pm b/Tail.pm
index 327464b..33af23a 100644
--- a/Tail.pm
+++ b/Tail.pm
@@ -380,9 +380,8 @@ sub reset_pointers {
$st=stat($newhandle);
if ($st->ino) {
- if ($st->ino == $object->{"inode"}) {
+ if ($st->ino == $object->{"inode"} && $st->dev == $object->{"dev"}) {
# inode the same --> file not changed --> no reset
- # Note: should also check $st->dev..
return;
}
} else {
@@ -415,6 +414,7 @@ sub reset_pointers {
}
$object->{handle}=$newhandle;
$object->{inode} = $st->ino;
+ $object->{dev} = $st->dev;
$object->position;
$object->{lastread} = $st->mtime;
close($oldhandle);
@@ -422,6 +422,7 @@ sub reset_pointers {
$st=stat($newhandle);
$object->{handle}=$newhandle;
$object->{inode} = $st->ino;
+ $object->{dev} = $st->dev;
$object->position;
$object->{lastread}=$st->mtime; # for better estimate on initial read
}
diff --git a/Tail.pm.debug b/Tail.pm.debug
index ef9cee7..f993cad 100644
--- a/Tail.pm.debug
+++ b/Tail.pm.debug
@@ -384,9 +384,8 @@ sub reset_pointers {
$st=stat($newhandle);
if ($st->ino) {
- if ($st->ino == $object->{"inode"}) {
+ if ($st->ino == $object->{"inode"} && $st->dev == $object->{"dev"}) {
# inode the same --> file not changed --> no reset
- # Note: should also check $st->dev..
$object->logit("inode the same. Reset skipped.");
return;
}
@@ -424,6 +423,7 @@ sub reset_pointers {
$object->logit("reseting file");
$object->{handle}=$newhandle;
$object->{inode} = $st->ino;
+ $object->{dev} = $st->dev;
$object->position;
$object->{lastread} = $st->mtime;
close($oldhandle);
@@ -432,6 +432,7 @@ sub reset_pointers {
$st=stat($newhandle);
$object->{handle}=$newhandle;
$object->{inode} = $st->ino;
+ $object->{dev} = $st->dev;
$object->position;
$object->{lastread}=$st->mtime; # for better estimate on initial read
}