]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
wip reorg move Logtailer into own file
authorIan Jackson <iwj@woking.cam.xci-test.com>
Tue, 16 Oct 2012 14:08:44 +0000 (15:08 +0100)
committerIan Jackson <iwj@woking.cam.xci-test.com>
Tue, 16 Oct 2012 14:08:44 +0000 (15:08 +0100)
Osstest/Executive.pm
Osstest/Logtailer.pm [new file with mode: 0644]
Osstest/TestSupport.pm
ts-host-install

index a8b9bbf75b4ad311fe5ad91265f12336f61f3d6c..a45d289597ada7951f53969e6b7d7fbbb70e4271 100644 (file)
@@ -715,90 +715,4 @@ END
     };
 }
 
-#---------- logtailer ----------
-
-package Osstest::Logtailer;
-use Fcntl qw(:seek);
-use POSIX;
-
-sub new ($$) {
-    my ($class, $fn) = @_;
-    my $fh= new IO::File $fn,'r';
-    my $ino= -1;
-    if (!$fh) {
-        $!==&ENOENT or die "$fn $!";
-    } else {
-        seek $fh, 0, SEEK_END or die "$fn $!";
-        stat $fh or die "$fn $!";
-        $ino= (stat _)[1];
-    }
-    my $lt= { Path => $fn, Handle => $fh, Ino => $ino, Buf => '' };
-    bless $lt, $class;
-    return $lt;
-}
-
-sub getline ($) {
-    my ($lt) = @_;
-
-    for (;;) {
-        if ($lt->{Buf} =~ s/^(.*)\n//) {
-            return $1;
-        }
-
-        if ($lt->{Handle}) {
-            seek $lt->{Handle}, 0, SEEK_CUR or die "$lt->{Path} $!";
-
-            my $more;
-            my $got= read $lt->{Handle}, $more, 4096;
-            die "$lt->{Path} $!" unless defined $got;
-            if ($got) {
-                $lt->{Buf} .= $more;
-                next;
-            }
-        }
-
-        if (!stat $lt->{Path}) {
-            $!==&ENOENT or die "$lt->{Path} $!";
-            return undef;
-        }
-        my $nino= (stat _)[1];
-        return undef
-            unless $nino != $lt->{Ino};
-
-        my $nfh= new IO::File $lt->{Path},'r';
-        if (!$nfh) {
-            $!==&ENOENT or die "$lt->{Path} $!";
-            warn "newly-created $lt->{Path} vanished again";
-            return undef;
-        }
-        stat $nfh or die $!;
-        $nino= (stat _)[1];
-
-        $lt->_close();
-        $lt->{Handle}= $nfh;
-        $lt->{Ino}= $nino;
-    }
-}
-
-sub _close ($) {
-    my ($lt) = @_;
-    if ($lt->{Handle}) {
-        close $lt->{Handle} or die "$lt->{Path} $!";
-        $lt->{Handle}= undef;
-        $lt->{Ino}= -1;
-    }
-}
-
-sub close ($) {
-    my ($lt) = @_;
-    $lt->_close();
-    $lt->{Buf}= '';
-}
-
-sub DESTROY ($) {
-    my ($lt) = @_;
-    local $!;
-    $lt->_close();
-}
-
 1;
diff --git a/Osstest/Logtailer.pm b/Osstest/Logtailer.pm
new file mode 100644 (file)
index 0000000..3a40e24
--- /dev/null
@@ -0,0 +1,103 @@
+#---------- logtailer ----------
+
+use strict;
+use warnings;
+
+package Osstest::Logtailer;
+
+use Fcntl qw(:seek);
+use POSIX;
+
+BEGIN {
+    use Exporter ();
+    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
+    $VERSION     = 1.00;
+    @ISA         = qw(Exporter);
+    @EXPORT      = qw();
+    %EXPORT_TAGS = (
+       );
+
+    @EXPORT_OK   = qw();
+}
+
+sub new ($$) {
+    my ($class, $fn) = @_;
+    my $fh= new IO::File $fn,'r';
+    my $ino= -1;
+    if (!$fh) {
+        $!==&ENOENT or die "$fn $!";
+    } else {
+        seek $fh, 0, SEEK_END or die "$fn $!";
+        stat $fh or die "$fn $!";
+        $ino= (stat _)[1];
+    }
+    my $lt= { Path => $fn, Handle => $fh, Ino => $ino, Buf => '' };
+    bless $lt, $class;
+    return $lt;
+}
+
+sub getline ($) {
+    my ($lt) = @_;
+
+    for (;;) {
+        if ($lt->{Buf} =~ s/^(.*)\n//) {
+            return $1;
+        }
+
+        if ($lt->{Handle}) {
+            seek $lt->{Handle}, 0, SEEK_CUR or die "$lt->{Path} $!";
+
+            my $more;
+            my $got= read $lt->{Handle}, $more, 4096;
+            die "$lt->{Path} $!" unless defined $got;
+            if ($got) {
+                $lt->{Buf} .= $more;
+                next;
+            }
+        }
+
+        if (!stat $lt->{Path}) {
+            $!==&ENOENT or die "$lt->{Path} $!";
+            return undef;
+        }
+        my $nino= (stat _)[1];
+        return undef
+            unless $nino != $lt->{Ino};
+
+        my $nfh= new IO::File $lt->{Path},'r';
+        if (!$nfh) {
+            $!==&ENOENT or die "$lt->{Path} $!";
+            warn "newly-created $lt->{Path} vanished again";
+            return undef;
+        }
+        stat $nfh or die $!;
+        $nino= (stat _)[1];
+
+        $lt->_close();
+        $lt->{Handle}= $nfh;
+        $lt->{Ino}= $nino;
+    }
+}
+
+sub _close ($) {
+    my ($lt) = @_;
+    if ($lt->{Handle}) {
+        close $lt->{Handle} or die "$lt->{Path} $!";
+        $lt->{Handle}= undef;
+        $lt->{Ino}= -1;
+    }
+}
+
+sub close ($) {
+    my ($lt) = @_;
+    $lt->_close();
+    $lt->{Buf}= '';
+}
+
+sub DESTROY ($) {
+    my ($lt) = @_;
+    local $!;
+    $lt->_close();
+}
+
+1;
index 4587e6baad010a4f50d6281dafe324138c15d2a4..543af2fec093c9fafde19b3e9f31e270bba5f2e2 100644 (file)
@@ -10,6 +10,7 @@ use IO::File;
 use IO::Socket::INET;
 
 use Osstest;
+use Osstest::Logtailer;
 
 BEGIN {
     use Exporter ();
index a1ae3203788452a7fdb5fbaa270924e33b17d792..834ba627f69cd47d0d36c3478e7f791d93779b2c 100755 (executable)
@@ -7,6 +7,7 @@ use POSIX;
 use Osstest;
 use Osstest::Debian;
 use Osstest::TestSupport;
+use Osstest::Logtailer;
 
 tsreadconfig();