{
if ($ENV{'SCRIPT_FILENAME'} =~ m{^(/.+)/bin/[^/]+$})
{
- $BASE_DIR = $1;
- unshift (@INC, "$BASE_DIR/lib");
+ $::BASE_DIR = $1;
+ unshift (@::INC, "$::BASE_DIR/lib");
}
}
}
epoch_to_rfc1123 flush_files));
use Collectd::Graph::Type ();
-$::MODPERL = 1;
-
-my $have_init = 0;
-sub init
+sub base_dir
{
- if ($have_init)
+ if (defined $::BASE_DIR)
+ {
+ return ($::BASE_DIR);
+ }
+
+ if (!defined ($ENV{'SCRIPT_FILENAME'}))
{
return;
}
- #gc_read_config ("$RealBin/../etc/collection.conf");
- gc_read_config ("$BASE_DIR/etc/collection.conf");
+ if ($ENV{'SCRIPT_FILENAME'} =~ m{^(/.+)/bin/[^/]+$})
+ {
+ $::BASE_DIR = $1;
+ return ($::BASE_DIR);
+ }
- $have_init = 1;
+ return;
+}
+
+sub lib_dir
+{
+ my $base = base_dir ();
+
+ if ($base)
+ {
+ return "$base/lib";
+ }
+ else
+ {
+ return "../lib";
+ }
+}
+
+sub sysconf_dir
+{
+ my $base = base_dir ();
+
+ if ($base)
+ {
+ return "$base/etc";
+ }
+ else
+ {
+ return "../etc";
+ }
+}
+
+sub init
+{
+ my $lib_dir = lib_dir ();
+ my $sysconf_dir = sysconf_dir ();
+
+ if (!grep { $lib_dir eq $_ } (@::INC))
+ {
+ unshift (@::INC, $lib_dir);
+ }
+
+ gc_read_config ("$sysconf_dir/collection.conf");
}
sub main
my $OutputFormat = 'PNG';
my $ContentType = 'image/png';
+ init ();
+
if (param ('format'))
{
my $temp = param ('format') || '';
$ContentType = 'text/plain';
}
- init ();
-
if ($GraphWidth)
{
$GraphWidth =~ s/\D//g;
{
if ($ENV{'SCRIPT_FILENAME'} =~ m{^(/.+)/bin/[^/]+$})
{
- $BASE_DIR = $1;
- unshift (@INC, "$BASE_DIR/lib");
+ $::BASE_DIR = $1;
+ unshift (@::INC, "$::BASE_DIR/lib");
}
}
}
show_selection => \&action_show_selection
);
-my $have_init = 0;
-sub init
+sub base_dir
{
- if ($have_init)
+ if (defined $::BASE_DIR)
+ {
+ return ($::BASE_DIR);
+ }
+
+ if (!defined ($ENV{'SCRIPT_FILENAME'}))
{
return;
}
- print STDERR "INC = (" . join (', ', @INC) . ");\n";
+ if ($ENV{'SCRIPT_FILENAME'} =~ m{^(/.+)/bin/[^/]+$})
+ {
+ $::BASE_DIR = $1;
+ return ($::BASE_DIR);
+ }
+
+ return;
+}
+
+sub lib_dir
+{
+ my $base = base_dir ();
- gc_read_config ("$BASE_DIR/etc/collection.conf");
+ if ($base)
+ {
+ return "$base/lib";
+ }
+ else
+ {
+ return "../lib";
+ }
+}
+
+sub sysconf_dir
+{
+ my $base = base_dir ();
+
+ if ($base)
+ {
+ return "$base/etc";
+ }
+ else
+ {
+ return "../etc";
+ }
+}
+
+sub init
+{
+ my $lib_dir = lib_dir ();
+ my $sysconf_dir = sysconf_dir ();
+
+ if (!grep { $lib_dir eq $_ } (@::INC))
+ {
+ unshift (@::INC, $lib_dir);
+ }
- $have_init = 1;
+ gc_read_config ("$sysconf_dir/collection.conf");
}
sub main
$types->{$type} = tl_load_type ($file->{'type'});
if (!$types->{$type})
{
- cluck ("tl_load_type (" . $file->{'type'} . ") failed");
+ warn ("tl_load_type (" . $file->{'type'} . ") failed");
next;
}
}
$obj = _create_object ($module);
if (!$obj)
{
- cluck ("Creating an $module object failed");
+ #cluck ("Creating an $module object failed");
+ warn ("Creating an $module object failed");
return;
}
}