Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

du: runtime error for bad environment value #784

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions bin/du
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use strict;
use File::Spec;
use Getopt::Std;

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

use vars qw($opt_H $opt_L $opt_P $opt_a $opt_c $opt_k $opt_l $opt_r $opt_s $opt_x);
use vars qw(%inodes $depth $blocksize $grandtotal $filesystem);

Expand All @@ -30,15 +33,18 @@ $blocksize = 512; # Default block size
$grandtotal = 0; # Total of all command line argument totals
$filesystem = 0; # Current file system (used for -x processing)

$blocksize = $ENV{BLOCKSIZE} if $ENV{BLOCKSIZE}; # use environment if present

# Process command line options
getopts('HLPacklrsx') or usage();

$blocksize = $ENV{'BLOCKSIZE'} if defined $ENV{'BLOCKSIZE'};
$blocksize = 1024 if $opt_k;
if ($blocksize =~ m/[^0-9]/ || $blocksize == 0) {
warn "$0: unexpected block size: $blocksize\n";
exit EX_FAILURE;
}

if ($opt_a && $opt_s) {
print STDERR "$0: cannot both summarize and show all entries\n";
warn "$0: cannot both summarize and show all entries\n";
usage();
}

Expand Down Expand Up @@ -92,15 +98,15 @@ sub traverse {
closedir $dh;
print "$total\t$fn\n" unless $opt_s;
} else {
print STDERR "$0: could not read directory $fn: $!\n";
warn "$0: could not read directory $fn: $!\n";
}
print "$total\t$fn\n" if $opt_s && $depth == 1;
return $total;
}

sub usage {
print STDERR "Usage: $0 [-H | -L | -P] [-a | -s] [-cklrx] [file ...]\n";
exit 1;
print "usage: $0 [-H | -L | -P] [-a | -s] [-cklrx] [file ...]\n";
exit EX_FAILURE;
}

=head1 NAME
Expand Down
Loading