Skip to content

Commit

Permalink
Merge pull request #294 from mknos/tail-continue
Browse files Browse the repository at this point in the history
tail: continue on error
  • Loading branch information
briandfoy committed Oct 20, 2023
2 parents 95f7f5b + e0bbdb2 commit ffd869b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bin/tail
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ License: perl

$| = 1;

use strict;

use File::Basename qw(basename);
use Getopt::Long; # because of some special handling on numeric options

use strict;
use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

use vars qw($opt_b $opt_c $opt_f $opt_h $opt_n $opt_r);

use File::Basename;
my $me = basename $0;

sub usage($;$)
Expand Down Expand Up @@ -360,6 +364,7 @@ sub handle_INT()
sub handle_args($$$)
{
my ($point, $type, $files_) = @_;
my $rc = EX_SUCCESS;

# Expand the directories (but not the sub-directories)
my @files;
Expand All @@ -382,10 +387,11 @@ sub handle_args($$$)
# do not die if the file does not exist, when -f is used
next if(!-e $file and ($opt_f or $me eq "xtail"));

open FH, '<', $file
or do { print STDERR
"Couldn't open $file for reading: $!\n";
exit 1 };
unless (open FH, '<', $file) {
warn "$me: Couldn't open '$file': $!\n";
$rc = EX_FAILURE;
next;
}

# Do not print the tail of the files if we are using xtail
unless($me eq "xtail") {
Expand All @@ -405,13 +411,11 @@ sub handle_args($$$)
print_tail \*STDIN, "stdout", $point, $type;
# Ignore the -f option
}

return $rc;
}

my ($point, $type, $files) = parse_args();
handle_args($point, $type, $files);

exit 0;
exit handle_args($point, $type, $files);

__END__
Expand Down

0 comments on commit ffd869b

Please sign in to comment.