summaryrefslogtreecommitdiff
path: root/fml/lib/FML/Process
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-03-10 09:03:07 +0000
committerfukachan <fukachan>2001-03-10 09:03:07 +0000
commit83e47bae1d7a9765066c4f1820cbeaeb4ac61714 (patch)
tree3268f5febcbbcbe9ccd933f59714b13e83e53871 /fml/lib/FML/Process
parent3d25acd1a1e237619d71bae595033a3204171fc5 (diff)
downloadfml8-83e47bae1d7a9765066c4f1820cbeaeb4ac61714.tar.gz
fml8-83e47bae1d7a9765066c4f1820cbeaeb4ac61714.tar.bz2
fml8-83e47bae1d7a9765066c4f1820cbeaeb4ac61714.zip
clean up documents and codes
modify Bootstrap2() to use _parse_argv() check $ml_home_dir existence in bootstrap modify debug codes to load Data::Dumper dinamically
Diffstat (limited to 'fml/lib/FML/Process')
-rw-r--r--fml/lib/FML/Process/Kernel.pm11
-rw-r--r--fml/lib/FML/Process/Switch.pm197
2 files changed, 116 insertions, 92 deletions
diff --git a/fml/lib/FML/Process/Kernel.pm b/fml/lib/FML/Process/Kernel.pm
index ed3b1584..8fdf5b77 100644
--- a/fml/lib/FML/Process/Kernel.pm
+++ b/fml/lib/FML/Process/Kernel.pm
@@ -29,6 +29,9 @@ sub new
my ($curproc) = {}; # alloc memory as the struct current_process.
my ($cfargs) = {};
+ # fndamental checks
+ croak("Error: \$ml_home_dir not defined") unless $args->{ ml_home_dir };
+
# import variables
my (@import_vars) = qw(ml_home_prefix ml_home_dir);
for my $var (@import_vars) {
@@ -66,7 +69,13 @@ sub new
$curproc->_signal_init;
# debug
- if ($0 =~ /loader/) { $curproc->debug; sleep 3;}
+ if ($0 =~ /loader/) {
+ eval q{
+ require Data::Dumper; Data::Dumper->import();
+ print Dumper( $curproc );
+ sleep 3;
+ };
+ }
return $curproc;
}
diff --git a/fml/lib/FML/Process/Switch.pm b/fml/lib/FML/Process/Switch.pm
index bcd8abee..80b81a11 100644
--- a/fml/lib/FML/Process/Switch.pm
+++ b/fml/lib/FML/Process/Switch.pm
@@ -13,72 +13,83 @@ package FML::Process::Switch;
use strict;
use Carp;
use vars qw($debug);
-use Standalone;
+
+
+=head1 NAME
+
+FML::Process::Switch - switch or dispather table to run the suitable library
+
+=head1 SYNOPSIS
+
+ require "$libexec_dir/process_switch";
+ ProcessSwitch( {
+ fml_version => $main_cf->{ fml_version },
+
+ myname => $myname,
+ ml_home_prefix => $main_cf->{ ml_home_prefix },
+ ml_home_dir => $ml_home_dir,
+
+ cf_list => \@cf,
+ options => \%options,
+ });
+
+See also C<libexec/fml/loader>.
+
+=head1 DESCRIPTION
+
+C<libexec/loader> (C<libexec/fml/loader>), the wrapper, loads this
+program and calls C<Bootstrap2()> and C<ProcessSwitch()>.
+C<ProcessSwitch()> emulates "use $package" to load a program specified
+by the arguments.
+
+The details of each program exists in FML::Process:: class.
+
+=head1 FUNCTIONS
+
+=head2 C<main::Bootstrap2()>
+
+kick off the second phase of bootstrap.
+
+It reads *.cf files, parses them and set the result to C<@cf>
+array variable.
+We pass it to C<ProcessSwitch()> later.
+
+ @cf = ( /etc/fml/defaults/$VERSION/default_config.cf
+ /etc/fml/site_default_config.cf (required ?)
+ /etc/fml/domains/$DOMAIN/default_config.cf
+ /var/spool/ml/elena/config.cf
+ );
+
+=cut
+
sub main::Bootstrap2
{
- my ($main_cf_file) = @_;
-
- # 2. pick up *.cf files to read and set them to @cf.
- # We pass it to fml_loader.
- # pass *.cf files to libexec/{distribute,command}
- # for example
- # @cf = ( /etc/fml/defaults/$VERSION/default_config.cf
- # /etc/fml/site_default_config.cf (required ?)
- # /etc/fml/domains/$DOMAIN/default_config.cf
- # /var/spool/ml/elena/config.cf
- # );
- my @argv = @ARGV; # save the original arguments
- my @cf = ();
- my %options = ();
- my $my_default_config = '';
+ my ($main_cf_file) = @_;
+ my @argv = @ARGV; # save the original argument vector
+ my @cf = ();
+ my %options = ();
my $ml_home_dir = ''; # e.g. /var/spool/ml/elena
- # inspect my name from $0
use File::Basename;
- my $myname = basename($0);
+ my $myname = basename($0); # inspect my name from $0
-
- # parse command line options (preliminary)
+ # 2.0 parse command line options (preliminary)
use Getopt::Long;
GetOptions(\%options, _module_specific_options($myname));
- my $main_cf = Standalone::load_cf($options{'c'} || $main_cf_file,
- $options{'params'}
- );
+ # 2.1 analyze main.cf and get the result in $main_cf
+ use Standalone;
+ my $main_cf =
+ Standalone::load_cf($options{'c'} || $main_cf_file, $options{'params'});
- my $default_config = $my_default_config || $main_cf->{ default_config };
-
# 2.2 parse @ARGV ..
- my $ml_home_prefix = $main_cf->{ ml_home_prefix };
- my $found_cf = 0;
- for (@ARGV) {
- # elena is translated to "/var/spool/ml/elena"
- unless ($found_cf) {
- my $x = "$ml_home_prefix/$_";
- if (-d $x && -f "$x/config.cf") {
- $found_cf = 1;
- $ml_home_dir = $x;
- push(@cf, "$x/config.cf");
- }
- }
-
- if (-d $_) {
- $ml_home_dir = $_;
- if (-f "$_/config.cf") {
- push(@cf, "$_/config.cf");
- $found_cf = 1;
- }
- }
- elsif (-f $_) {
- push(@cf, $_);
- }
- }
+ my $cf = _parse_argv($main_cf);
- # 2.3 prepare @cf
+ # 2.3 prepare @$cf
# XXX hmm, .. '/etc/fml/site_default_config.cf' is good ???
- unshift(@cf, '/etc/fml/site_default_config.cf');
- unshift(@cf, $default_config);
+ unshift(@$cf, '/etc/fml/site_default_config.cf');
+ unshift(@$cf, $main_cf->{ default_config });
# 3. reset @INC
unshift(@INC, split(/\s+/, $main_cf->{ lib_dir }));
@@ -90,24 +101,21 @@ sub main::Bootstrap2
# 4. debug
if ($0 =~ /loader/) {
eval q#
- require Data::Dumper;
- Data::Dumper->import();
+ require Data::Dumper; Data::Dumper->import();
print Dumper( $main_cf );
sleep 3;
#;
}
# 5. o.k. here we go!
- my ($args, $pkg);
-
- $args = {
+ my $args = {
fml_version => $main_cf->{ fml_version },
myname => $myname,
ml_home_prefix => $main_cf->{ ml_home_prefix },
- ml_home_dir => $ml_home_dir,
+ ml_home_dir => $main_cf->{ ml_home_dir },
- cf_list => \@cf,
+ cf_list => $cf,
options => \%options,
# pass the original information to each process
@@ -119,13 +127,51 @@ sub main::Bootstrap2
};
# See libexec/process_switch on ProcessSwitch()
- $pkg = ProcessSwitch($args);
+ my $pkg = ProcessSwitch($args);
# See FML::Process::Kernel module on ProcessStart()
FML::Process::Flow::ProcessStart($pkg, $args);
}
+sub _parse_argv
+{
+ my ($main_cf) = @_;
+ my $ml_home_prefix = $main_cf->{ ml_home_prefix };
+ my $ml_home_dir = '';
+ my $found_cf = 0;
+ my @cf = ();
+
+ for (@ARGV) {
+ # elena is translated to "/var/spool/ml/elena"
+ unless ($found_cf) {
+ my $x = "$ml_home_prefix/$_";
+ if (-d $x && -f "$x/config.cf") {
+ $found_cf = 1;
+ $ml_home_dir = $x;
+ push(@cf, "$x/config.cf");
+ }
+ }
+
+ if (-d $_) {
+ $ml_home_dir = $_;
+ if (-f "$_/config.cf") {
+ push(@cf, "$_/config.cf");
+ $found_cf = 1;
+ }
+ }
+ elsif (-f $_) {
+ push(@cf, $_);
+ }
+ }
+
+ # save $ml_home_dir value in $main_cf directly
+ $main_cf->{ ml_home_dir } = $ml_home_dir;
+
+ \@cf;
+}
+
+
# Descriptions: top level process switch
# emulates "use $package" but $package is dynamically
# determined by e.g. $0.
@@ -234,37 +280,6 @@ sub _module_we_use
}
-=head1 NAME
-
-process_switch - switch or dispacther table to execute real fml programs
-
-=head1 SYNOPSIS
-
- require "$libexec_dir/process_switch";
- ProcessSwitch(
- {
- fml_version => $main_cf->{ fml_version },
-
- myname => $myname,
- ml_home_prefix => $main_cf->{ ml_home_prefix },
- ml_home_dir => $ml_home_dir,
-
- cf_list => \@cf,
- options => \%options,
- });
-
-See also C<libexec/fml/loader>.
-
-=head1 DESCRIPTION
-
-C<libexec/loader>
-(C<libexec/fml/loader>),
-the wrapper, loads this program and calls C<ProcessSwitch()>.
-C<ProcessSwitch()> emulates "use $package" for a program specified by
-the arguments.
-
-The details of each program exists in FML::Process:: class.
-
=head1 SEE ALSO
L<FML::Process::Distribute>,