diff options
| author | fukachan <fukachan> | 2002-06-27 08:25:49 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2002-06-27 08:25:49 +0000 |
| commit | d52de31d2d90bfe70329636021be085b46f34d1a (patch) | |
| tree | aab56f274a82184749c87b40fe6657763da9b82f | |
| parent | 3341c7ba22542b5ecd716bba5812c327e8c92987 (diff) | |
| download | fml8-d52de31d2d90bfe70329636021be085b46f34d1a.tar.gz fml8-d52de31d2d90bfe70329636021be085b46f34d1a.tar.bz2 fml8-d52de31d2d90bfe70329636021be085b46f34d1a.zip | |
major overhaul: delayed loading of *.cf files. The loading is done
within prepare() method now to handle virtual domains properly.
| -rw-r--r-- | fml/lib/FML/Process/Alias.pm | 7 | ||||
| -rw-r--r-- | fml/lib/FML/Process/CGI/Kernel.pm | 114 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Command.pm | 12 | ||||
| -rw-r--r-- | fml/lib/FML/Process/ConfViewer.pm | 5 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Configure.pm | 5 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Distribute.pm | 6 | ||||
| -rw-r--r-- | fml/lib/FML/Process/DocViewer.pm | 5 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Error.pm | 7 | ||||
| -rw-r--r-- | fml/lib/FML/Process/HTMLify.pm | 5 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Kernel.pm | 256 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Spool.pm | 5 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Switch.pm | 194 | ||||
| -rw-r--r-- | fml/lib/FML/Process/ThreadTrack.pm | 5 | ||||
| -rw-r--r-- | fml/lib/FML/Process/Utils.pm | 24 |
14 files changed, 396 insertions, 254 deletions
diff --git a/fml/lib/FML/Process/Alias.pm b/fml/lib/FML/Process/Alias.pm index 106ee54f..a7b2c79f 100644 --- a/fml/lib/FML/Process/Alias.pm +++ b/fml/lib/FML/Process/Alias.pm @@ -3,7 +3,7 @@ # Copyright (C) 2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Configure.pm,v 1.39 2002/04/20 05:40:02 fukachan Exp $ +# $FML: Alias.pm,v 1.1 2002/04/25 04:46:09 fukachan Exp $ # package FML::Process::Alias; @@ -73,6 +73,9 @@ sub prepare my $eval = $config->get_hook( 'fmlalias_prepare_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } + # $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $eval = $config->get_hook( 'fmlalias_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } } @@ -222,7 +225,7 @@ sub _fmlalias use FML::MTAControl; my $mta = new FML::MTAControl; - my $aliases = $mta->get_aliases_as_hash_ref($curproc, { + my $aliases = $mta->get_aliases_as_hash_ref($curproc, {}, { mta_type => 'postfix', mode => $mode, }); diff --git a/fml/lib/FML/Process/CGI/Kernel.pm b/fml/lib/FML/Process/CGI/Kernel.pm index 07e8f9b9..f8a4f79c 100644 --- a/fml/lib/FML/Process/CGI/Kernel.pm +++ b/fml/lib/FML/Process/CGI/Kernel.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Kernel.pm,v 1.34 2002/06/25 02:21:20 fukachan Exp $ +# $FML: Kernel.pm,v 1.35 2002/06/25 04:10:51 fukachan Exp $ # package FML::Process::CGI::Kernel; @@ -60,56 +60,13 @@ sub new my ($self, $args) = @_; my $type = ref($self) || $self; - # ml_name: we should get $ml_name from HTTP. - use FML::Process::Utils; - my $ml_name = safe_param_ml_name($self) || do { - my $is_need_ml_name = $args->{ 'need_ml_name' }; - if ($is_need_ml_name) { - my $r = "fail to get ml_name from HTTP"; - croak("__ERROR_cgi.fail_to_get_ml_name__: $r"); - } - }; - - # set up $curproc for further steps - # XXX set up the dummy value for $ml_home_prefix (default value) - # anyway to avoid the error of "new FML::Process::Kernel". - $args->{ ml_home_prefix } = $args->{ main_cf }->{ default_ml_home_prefix }; + # create kernel object and redefine $curproc as the object $type. my $curproc = new FML::Process::Kernel $args; - - # ml_domain - my $hints = $curproc->hints(); - my $ml_domain = $hints->{ ml_domain }; - - # ml_home_prefix - my $ml_home_prefix = $curproc->ml_home_prefix( $ml_domain ); - - # ml_home_dir - my ($ml_home_dir, $config_cf); - if ($ml_name) { - use File::Spec; - $ml_home_dir = $curproc->ml_home_dir($ml_name, $ml_domain); - $config_cf = File::Spec->catfile($ml_home_dir, 'config.cf'); - - # fix $args { cf_list, ml_home_dir }; - my $cflist = $args->{ cf_list }; - push(@$cflist, $config_cf); - $args->{ ml_home_dir } = $ml_home_dir; - } - - # reset $ml_domain to handle virtual domains - my $config = $curproc->{ config }; - $config->set('ml_domain', $ml_domain); - $config->set('ml_home_prefix', $ml_home_prefix); - if (defined $ml_home_dir && $ml_home_dir) { - $config->set('ml_home_dir', $ml_home_dir); - } - - # redefine $curproc as the object $type. return bless $curproc, $type; } -=head2 C<prepare()> +=head2 C<prepare($args)> print HTTP header. The charset is C<euc-jp> by default. @@ -117,24 +74,79 @@ The charset is C<euc-jp> by default. =cut -# Descriptions: html header. -# FML::Process::Kernel::prepare() parses incoming_message -# CGI do not parse incoming_message; -# Arguments: OBJ($curproc) +# Descriptions: print html header. +# analyze cgi data to determine ml_name et.al. +# Arguments: OBJ($curproc) HASH_REF($args) # Side Effects: none # Return Value: none sub prepare { - my ($curproc) = @_; + my ($curproc, $args) = @_; my $config = $curproc->{ config }; my $charset = $config->{ cgi_charset } || 'euc-jp'; + $curproc->_cgi_resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + print header(-type => "text/html; charset=$charset", -charset => $charset, -target => "_top"); } +# Descriptions: analyze data input from CGI +# Arguments: OBJ($curproc) HASH_REF($args) +# Side Effects: update $config{ ml_* }, $args->{ cf_list } +# Return Value: none +sub _cgi_resolve_ml_specific_variables +{ + my ($curproc, $args) = @_; + my $config = $curproc->{ config }; + my ($ml_home_dir, $config_cf); + + # inherit ml_domain from $hints + # which is defined/hard-coded in *.cgi (libexec/loader) script. + my $hints = $curproc->hints(); + my $ml_domain = $hints->{ ml_domain }; + my $ml_home_prefix = $curproc->ml_home_prefix( $ml_domain ); + + # cheap sanity + unless ($ml_home_prefix) { + my $r = "ml_home_prefix undefined"; + croak("__ERROR_cgi.fail_to_get_ml_home_prefix__: $r"); + } + + # reset + $config->set('ml_domain', $ml_domain); + $config->set('ml_home_prefix', $ml_home_prefix); + + # speculate ml_name, which is not used in some cases. + my $ml_name = $curproc->safe_param_ml_name() || do { + my $is_need_ml_name = $args->{ 'need_ml_name' }; + if ($is_need_ml_name) { + my $r = "fail to get ml_name from HTTP"; + croak("__ERROR_cgi.fail_to_get_ml_name__: $r"); + } + }; + + # speculate $ml_home_dir when $ml_name is determined. + if ($ml_name) { + use File::Spec; + $ml_home_dir = $curproc->ml_home_dir($ml_name, $ml_domain); + + $config->set('ml_name', $ml_name); + $config->set('ml_home_dir', $ml_home_dir); + + # fix $args { cf_list, ml_home_dir }; + $config_cf = File::Spec->catfile($ml_home_dir, 'config.cf'); + my $cflist = $args->{ cf_list }; + push(@$cflist, $config_cf); + } + + $curproc->__debug_ml_xxx('cgi:'); +} + + =head2 C<verify_request()> dummy method now. diff --git a/fml/lib/FML/Process/Command.pm b/fml/lib/FML/Process/Command.pm index 239e189a..c64cb55a 100644 --- a/fml/lib/FML/Process/Command.pm +++ b/fml/lib/FML/Process/Command.pm @@ -3,7 +3,7 @@ # Copyright (C) 2000,2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Command.pm,v 1.60 2002/06/01 05:02:33 fukachan Exp $ +# $FML: Command.pm,v 1.61 2002/06/01 05:09:25 fukachan Exp $ # package FML::Process::Command; @@ -67,18 +67,20 @@ forward the request to SUPER CLASS. =cut # Descriptions: dummy -# Arguments: OBJ($self) HASH_REF($args) +# Arguments: OBJ($curproc) HASH_REF($args) # Side Effects: none # Return Value: none sub prepare { - my ($self, $args) = @_; - my $config = $self->{ config }; + my ($curproc, $args) = @_; + my $config = $curproc->{ config }; my $eval = $config->get_hook( 'command_prepare_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } - $self->SUPER::prepare($args); + $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $curproc->parse_incoming_message($args); $eval = $config->get_hook( 'command_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } diff --git a/fml/lib/FML/Process/ConfViewer.pm b/fml/lib/FML/Process/ConfViewer.pm index f853eb7a..5479196f 100644 --- a/fml/lib/FML/Process/ConfViewer.pm +++ b/fml/lib/FML/Process/ConfViewer.pm @@ -3,7 +3,7 @@ # Copyright (C) 2000,2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: ConfViewer.pm,v 1.10 2002/03/17 06:24:31 fukachan Exp $ +# $FML: ConfViewer.pm,v 1.11 2002/04/07 05:08:24 fukachan Exp $ # package FML::Process::ConfViewer; @@ -72,6 +72,9 @@ sub prepare print STDERR $@ if $@; } + $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $eval = $config->get_hook( 'fmlconf_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; diff --git a/fml/lib/FML/Process/Configure.pm b/fml/lib/FML/Process/Configure.pm index e0c5e888..6b7559ed 100644 --- a/fml/lib/FML/Process/Configure.pm +++ b/fml/lib/FML/Process/Configure.pm @@ -3,7 +3,7 @@ # Copyright (C) 2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Configure.pm,v 1.39 2002/04/20 05:40:02 fukachan Exp $ +# $FML: Configure.pm,v 1.40 2002/05/25 06:58:24 fukachan Exp $ # package FML::Process::Configure; @@ -73,6 +73,9 @@ sub prepare my $eval = $config->get_hook( 'makefml_prepare_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } + $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $eval = $config->get_hook( 'makefml_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } } diff --git a/fml/lib/FML/Process/Distribute.pm b/fml/lib/FML/Process/Distribute.pm index 9b2d2540..43bb7da0 100644 --- a/fml/lib/FML/Process/Distribute.pm +++ b/fml/lib/FML/Process/Distribute.pm @@ -3,7 +3,7 @@ # Copyright (C) 2000,2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Distribute.pm,v 1.79 2002/06/01 05:09:25 fukachan Exp $ +# $FML: Distribute.pm,v 1.80 2002/06/01 14:53:39 fukachan Exp $ # package FML::Process::Distribute; @@ -78,7 +78,9 @@ sub prepare my $eval = $config->get_hook( 'distribute_prepare_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } - $curproc->SUPER::prepare($args); + $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $curproc->parse_incoming_message($args); $eval = $config->get_hook( 'distribute_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } diff --git a/fml/lib/FML/Process/DocViewer.pm b/fml/lib/FML/Process/DocViewer.pm index 22f32cff..b76e17ba 100644 --- a/fml/lib/FML/Process/DocViewer.pm +++ b/fml/lib/FML/Process/DocViewer.pm @@ -3,7 +3,7 @@ # Copyright (C) 2000,2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: DocViewer.pm,v 1.15 2002/03/17 06:24:31 fukachan Exp $ +# $FML: DocViewer.pm,v 1.16 2002/04/07 05:05:06 fukachan Exp $ # package FML::Process::DocViewer; @@ -74,6 +74,9 @@ sub prepare my $eval = $config->get_hook( 'fmldoc_prepare_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } + # $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $eval = $config->get_hook( 'fmldoc_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } } diff --git a/fml/lib/FML/Process/Error.pm b/fml/lib/FML/Process/Error.pm index 2978056a..5a3dcfce 100644 --- a/fml/lib/FML/Process/Error.pm +++ b/fml/lib/FML/Process/Error.pm @@ -3,7 +3,7 @@ # Copyright (C) 2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Error.pm,v 1.7 2002/06/01 05:09:26 fukachan Exp $ +# $FML: Error.pm,v 1.8 2002/06/01 14:53:40 fukachan Exp $ # package FML::Process::Error; @@ -74,7 +74,10 @@ sub prepare if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } if ($config->yes('use_error_analyzer')) { - $self->SUPER::prepare($args); + $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $curproc->parse_incoming_message($args); + $config->{ log_format_type } = 'new_style'; } else { diff --git a/fml/lib/FML/Process/HTMLify.pm b/fml/lib/FML/Process/HTMLify.pm index 57600eaf..7ea19818 100644 --- a/fml/lib/FML/Process/HTMLify.pm +++ b/fml/lib/FML/Process/HTMLify.pm @@ -3,7 +3,7 @@ # Copyright (C) 2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: HTMLify.pm,v 1.18 2002/04/20 05:02:27 fukachan Exp $ +# $FML: HTMLify.pm,v 1.19 2002/04/27 05:25:03 fukachan Exp $ # package FML::Process::HTMLify; @@ -71,6 +71,9 @@ sub prepare my $eval = $config->get_hook( 'fmlhtmlify_prepare_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } + $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $eval = $config->get_hook( 'fmlhtmlify_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } } diff --git a/fml/lib/FML/Process/Kernel.pm b/fml/lib/FML/Process/Kernel.pm index 21c7d540..0036346c 100644 --- a/fml/lib/FML/Process/Kernel.pm +++ b/fml/lib/FML/Process/Kernel.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Kernel.pm,v 1.106 2002/06/01 14:53:40 fukachan Exp $ +# $FML: Kernel.pm,v 1.107 2002/06/24 09:43:24 fukachan Exp $ # package FML::Process::Kernel; @@ -74,41 +74,26 @@ parameters. # Descriptions: constructor # Arguments: OBJ($self) HASH_REF($args) -# Side Effects: none -# Return Value: FML::Process::Kernel object +# Side Effects: allocate the current process table on memory +# Return Value: OBJ(FML::Process::Kernel object) sub new { my ($self, $args) = @_; my ($curproc) = {}; # alloc memory as the struct current_process. my ($cfargs) = {}; - # import variables - my (@import_vars) = qw(ml_home_prefix ml_home_dir program_name); - my $var; + # XXX [CAUTION] + # XXX MOVE PARSER FROM Process::Switch to HERE + # XXX - IMPORT_CHECK: - for $var (@import_vars) { + # 1.1 import variables + for my $var (qw(program_name)) { if (defined $args->{ $var }) { $cfargs->{ $var } = $args->{ $var }; } - else { - if ($var eq 'ml_home_dir') { - next IMPORT_CHECK unless $args->{ need_ml_name }; - } - - # critical error - croak("Error: variable=$var is not defined"); - } } - # error if we need $ml_home_dir but is not specified. - if ($args->{ need_ml_name }) { - unless ($cfargs->{ ml_home_dir }) { - croak("specify ml_home_dir or ml_name"); - } - } - - # import XXX_dir variables from /etc/fml/main.cf + # 1.2 import XXX_dir variables from /etc/fml/main.cf for my $dir_var (qw( config_dir default_config_dir @@ -122,40 +107,51 @@ sub new } } - # speculate $fml_owner_home_dir by the current process uid + # 1.3 import $fml_version + if (defined $args->{ fml_version }) { + $cfargs->{ fml_version } = "fml-devel ". $args->{ fml_version }; + } + + # 2.1 speculate $fml_owner_home_dir by the current process uid { my $dir = (getpwuid($<))[7]; $cfargs->{ 'fml_owner_home_dir' } = $dir if defined $dir; } - # import $fml_version - if (defined $args->{ fml_version }) { - $cfargs->{ fml_version } = "fml-devel ". $args->{ fml_version }; - } - # for more convenience, save the parent configuration - $curproc->{ main_cf } = $args->{ main_cf }; + # + # 3. create FML::Process::Kernel object + # + # 3.1 for more convenience, save the parent configuration + $curproc->{ main_cf } = $args->{ main_cf }; $curproc->{ __parent_args } = $args; - # bind FML::Config object to $curproc + # 3.2 bind FML::Config object to $curproc use FML::Config; $curproc->{ config } = new FML::Config $cfargs; - # initialize PCB + # 3.3 initialize PCB use FML::PCB; $curproc->{ pcb } = new FML::PCB; + # 3.4 # object-ify. bless! bless! bless! bless $curproc, $self; - # load config.cf files, which is passed from loader. - $curproc->load_config_files( $args->{ cf_list } ); - - # initialize signal + # 3.5 initialize signal $curproc->_signal_init; + # 4.1 load config.cf files, which is passed from loader. + # XXX we need the following variables are resolved. + # XXX ml_name, ml_domain, ml_home_prefix, ml_home_dir + # $curproc->resolve_ml_specific_variables( $args ); + # $curproc->load_config_files( $args->{ cf_list } ); + # debug - if ($0 =~ /loader/) { + $curproc->__debug_ml_xxx('loaded:'); + + # 5.1 debug + if ($args->{ myname } eq 'loader') { eval q{ require Data::Dumper; Data::Dumper->import(); print "// FML::Process::Kernel::new()\n"; @@ -224,7 +220,7 @@ a set of the header and the body object. sub prepare { my ($curproc, $args) = @_; - $curproc->parse_incoming_message($args); + croak('not call Kernel::prepare()'); } @@ -395,6 +391,188 @@ sub simple_loop_check } +=head2 resolve_ml_specific_variables( $args ) + +determine ml specific variables + $ml_name + $ml_domain + $ml_home_prefix + $ml_home_dir +by command line arguments or CGI environment variables +with considering virtual domains. + +=cut + + +# Descriptions: +# Arguments: OBJ($curproc) HASH_REF($args) +# Side Effects: +# Return Value: none +sub resolve_ml_specific_variables +{ + my ($curproc, $args) = @_; + my ($ml_name, $ml_domain, $ml_home_prefix, $ml_home_dir); + my ($command, @options, $config_cf_path); + my $config = $curproc->{ config }; + my $myname = $args->{ myname }; + my $ml_addr = ''; + + # Example: "| /usr/local/libexec/fml/distribute elena@fml.org" + # makefml COMMAND elena@fml.org ... + # or in the old style + # "| /usr/local/libexec/fml/fml.pl /var/spool/ml/elena" + # + + # 1. virtual domain or not ? + # 1.1 search ml@domain syntax arg in @ARGV + if ($myname eq 'makefml') { + my $default_domain = $curproc->default_domain(); + ($command, $ml_name, @options) = @ARGV; + + # makefml $ml->$command + if ($command =~ /\-\>/) { + ($command, @options) = @ARGV; + ($ml_name, $command) = split('->', $command); + } + # makefml $ml::$command + elsif ($command =~ /::/) { + ($command, @options) = @ARGV; + ($ml_name, $command) = split('::', $command); + } + + if ($ml_name =~ /\@/) { + $ml_addr = $ml_name; + } + else { + $ml_addr = $ml_name . '@'. $default_domain; + } + } + else { + for my $arg (@ARGV) { + if ($arg =~ /\S+\@\S+/) { $ml_addr = $arg;} + } + } + + # 1.2 ml@domain may be specified in command line args. + if ($ml_addr) { + ($ml_name, $ml_domain) = split(/\@/, $ml_addr); + $config->set( 'ml_name', $ml_name ); + $config->set( 'ml_domain', $ml_domain ); + + my $prefix = $curproc->ml_home_prefix( $ml_domain ); + my $home_dir = $curproc->ml_home_dir( $ml_name, $ml_domain ); + $config->set( 'ml_home_prefix', $prefix ); + $config->set( 'ml_home_dir', $home_dir ); + + $config_cf_path = $curproc->config_cf_filepath($ml_name, $ml_domain); + } + # Example: "| /usr/local/libexec/fml/fml.pl /var/spool/ml/elena" + else { + my $r = $curproc->_find_ml_home_dir_in_argv($args->{ main_cf }); + if (defined $r->{ ml_home_dir }) { + use File::Basename; + my $dir = $r->{ ml_home_dir }; + my $prefix = dirname( $dir ); + $config->set( 'ml_home_prefix', $prefix); + $config->set( 'ml_home_dir', $dir); + + use File::Spec; + $config_cf_path = File::Spec->catfile($dir, "config.cf"); + } + } + + # debug + $curproc->__debug_ml_xxx('resolv:'); + + # add this ml's config.cf to the .cf list. + my $list = $args->{ cf_list }; + push(@$list, $config_cf_path); +} + + +# XXX remove this in the future +my @delayed_buffer = (); + +# Descriptions: +# Arguments: OBJ($curproc) +# Side Effects: none +# Return Value: none +sub __debug_ml_xxx +{ + my ($curproc, $str) = @_; + my $config = $curproc->{ config }; + + if (defined $config->{ log_file } && (-w $config->{ log_file })) { + for (@delayed_buffer) { Log( $_ ); } + @delayed_buffer = (); + + for my $var (qw(ml_name ml_domain ml_home_prefix ml_home_dir)) { + Log(sprintf("%-25s = %s", '(debug)'.$str. $var, + (defined $config->{ $var } ? $config->{ $var } : ''))); + } + } + else { + for my $var (qw(ml_name ml_domain ml_home_prefix ml_home_dir)) { + push(@delayed_buffer, + sprintf("%-25s = %s", + '(debug)'.$str. $var, + (defined $config->{$var} ? $config->{$var} : ''))); + } + } +} + + +# Descriptions: analyze argument vector +# Arguments: OBJ($curproc) +# Side Effects: none +# Return Value: HASH_REF +sub _find_ml_home_dir_in_argv +{ + my ($curproc, $main_cf) = @_; + my $ml_home_prefix = $main_cf->{ default_ml_home_prefix }; + my $ml_home_dir = ''; + my $found_cf = 0; + my @cf = (); + + # "elena" is translated to "/var/spool/ml/elena" + ARGV: + for (@ARGV) { + # 1. for the first time + # a) speculate "/var/spool/ml/$_" looks a $ml_home_dir ? + unless ($found_cf) { + my $x = File::Spec->catfile($ml_home_prefix, $_); + my $cf = File::Spec->catfile($x, "config.cf"); + if (-d $x && -f $cf) { + $found_cf = 1; + $ml_home_dir = $x; + push(@cf, $cf); + } + } + + last ARGV if $found_cf; + + # 2. /var/spool/ml/elena looks a $ml_home_dir ? + if (-d $_) { + $ml_home_dir = $_; + my $cf = File::Spec->catfile($_, "config.cf"); + if (-f $cf) { + push(@cf, $cf); + $found_cf = 1; + } + } + # 3. looks a file, so /var/spool/ml/elena/config.cf ? + elsif (-f $_) { + push(@cf, $_); + } + } + + return { + ml_home_dir => $ml_home_dir, + cf_list => \@cf, + }; +} + + =head2 C<load_config_files($files)> read several configuration C<@$files>. diff --git a/fml/lib/FML/Process/Spool.pm b/fml/lib/FML/Process/Spool.pm index da5879ac..8fc54ef0 100644 --- a/fml/lib/FML/Process/Spool.pm +++ b/fml/lib/FML/Process/Spool.pm @@ -3,7 +3,7 @@ # Copyright (C) 2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: Spool.pm,v 1.4 2002/04/19 13:33:20 fukachan Exp $ +# $FML: Spool.pm,v 1.5 2002/06/01 05:02:33 fukachan Exp $ # package FML::Process::Spool; @@ -69,6 +69,9 @@ sub prepare my $eval = $config->get_hook( 'fmlspool_prepare_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } + $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $eval = $config->get_hook( 'fmlspool_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } } diff --git a/fml/lib/FML/Process/Switch.pm b/fml/lib/FML/Process/Switch.pm index bfd0508d..e7bb4d2f 100644 --- a/fml/lib/FML/Process/Switch.pm +++ b/fml/lib/FML/Process/Switch.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Switch.pm,v 1.69 2002/05/29 16:34:26 fukachan Exp $ +# $FML: Switch.pm,v 1.70 2002/06/01 05:09:27 fukachan Exp $ # package FML::Process::Switch; @@ -53,8 +53,10 @@ For example, libexec/distribute (fml.pl) runs in this way. V ProcessSwitch() Process::Switch | - V - FML::Process:Distribute FML::Process::Distribute + | <--- $obj = FML::Process:Distribute + | + V + ProcessStart($obj,$args) Process::Flow =head1 FUNCTIONS @@ -97,7 +99,7 @@ sub main::Bootstrap2 print STDERR "\nsetgid is not set $( != $)\n\n" if $( ne $); # 0.2 - if ($0 =~ /loader/) { + if ($myname eq 'loader') { print "ARGV: @ARGV\n"; } @@ -107,21 +109,26 @@ sub main::Bootstrap2 if (@options) { eval q{ use Getopt::Long; - GetOptions(\%options, _module_specific_options($myname)); + GetOptions(\%options, @options); }; croak($@) if $@; } } - # 2.1 analyze main.cf and get the result in $main_cf - # removed. + # 2.1 removed. + # analyze main.cf and set the result into $main_cf - # 2.2 parse @ARGV and get a list of configuration files + + # 2.2 parse @ARGV to get a list of configuration files. # XXX $main_cf{ ml_home_dir } (e.g. /var/spool/ml/elena) is defined - # if possible. + # if possible. WHY ? # a) resolve $ml_name (e.g. expand "elena" to "/var/spool/ml/elena") # b) but we need special treatment in some cases e.g. makefml - my $cf = _parse_argv($myname, $main_cf); + # + # XXX CAN WE MOVE PARSER TO Process::{Kernel,CGI::Kernel} ? + # XXX ml_name, ml_domain, ml_home_prefix, ml_home_dir + # my $cf = _parse_argv($myname, $main_cf); + my $cf = (); # 2.3 prepare @$cf # XXX hmm, .. '/etc/fml/site_default_config.cf' is good ??? @@ -138,33 +145,42 @@ sub main::Bootstrap2 $ENV{'PERL5LIB'} = $main_cf->{ lib_dir }; # 4. debug - if ($0 =~ /loader/) { + if ($myname eq 'loader') { eval q{ require Data::Dumper; Data::Dumper->import(); $Data::Dumper::Varname = 'main_cf'; print Dumper( $main_cf ); sleep 3; }; - if ($@) { print STDERR $@;} + if ($@) { print STDERR $@; sleep 3;} } - # 5. o.k. here we go! - use FML::Process::Utils; - my $ml_home_prefix = - FML::Process::Utils::__ml_home_prefix_from_main_cf($main_cf); + # 5. resolve $ml_home_prefix + # XXX CAN WE MOVE PARSER TO Process::{Kernel,CGI::Kernel} ? + # XXX ml_name, ml_domain, ml_home_prefix, ml_home_dir + # use FML::Process::Utils; + # my $ml_home_prefix = + # FML::Process::Utils::__ml_home_prefix_from_main_cf($main_cf); + + # 6. o.k. here we go! + # XXX CAN WE MOVE PARSER TO Process::{Kernel,CGI::Kernel} ? + # XXX ml_name, ml_domain, ml_home_prefix, ml_home_dir my $args = { fml_version => $main_cf->{ fml_version }, myname => $myname, program_name => $myname, - ml_home_prefix => $ml_home_prefix, - ml_home_dir => $main_cf->{ ml_home_dir }, - cf_list => $cf, - options => \%options, + # XXX CAN WE MOVE PARSER TO Process::{Kernel,CGI::Kernel} ? + # XXX ml_name, ml_domain, ml_home_prefix, ml_home_dir + # ml_home_prefix => $ml_home_prefix, + # ml_home_dir => $main_cf->{ ml_home_dir }, - argv => \@argv, # pass the original @ARGV - ARGV => \@ARGV, # @ARGV after getopts() + cf_list => $cf, # site_default + default + options => \%options, # options parsed by getopt() + + argv => \@argv, # pass the original @ARGV + ARGV => \@ARGV, # @ARGV after getopts() main_cf => $main_cf, @@ -173,7 +189,7 @@ sub main::Bootstrap2 }; # get the object. The suitable module is speculcated by $0. - my $obj = ProcessSwitch($args); + my $obj = ProcessSwitch($myname, $args); # start the process. eval q{ @@ -183,7 +199,7 @@ sub main::Bootstrap2 my $reason = $@; if ($obj->can('help')) { eval $obj->help();}; - eval q{ __log($args, $reason);}; + eval q{ __log($main_cf, $reason);}; if (defined( $main_cf->{ debug } ) || defined $options{debug}) { @@ -198,17 +214,17 @@ sub main::Bootstrap2 # Descriptions: try to save the error message -# Arguments: STR($s) -# Side Effects: save message to log file if could +# Arguments: HASH_REF($main_cf) STR($s) +# Side Effects: save message to a log file if could # Return Value: none sub __log { - my ($args, $s) = @_; + my ($main_cf, $s) = @_; eval q{ use File::Spec; use FileHandle; - my $dir = $args->{ ml_home_prefix }; + my $dir = $main_cf->{ ml_home_prefix }; my $logf = File::Spec->catfile($dir, '@log.crit@'); my $wh = new FileHandle ">> $logf"; if (defined $wh) { @@ -219,121 +235,6 @@ sub __log } -# Descriptions: analyze argument vector -# Arguments: STR($myname) HASH_REF($main_cf) -# Side Effects: none -# Return Value: ARRAY_REF (list of config.cf's) -sub _parse_argv -{ - my ($myname, $main_cf) = @_; - - if ($myname eq 'makefml') { - _makefml_parse_argv($myname, $main_cf); - } - else { - _usual_parse_argv($myname, $main_cf); - } -} - - -# Descriptions: analyze argument vector -# Arguments: STR($myname) HASH_REF($main_cf) -# Side Effects: none -# Return Value: ARRAY_REF (list of config.cf's) -sub _usual_parse_argv -{ - my ($myname, $main_cf) = @_; - use FML::Process::Utils; - my $ml_home_prefix = - FML::Process::Utils::__ml_home_prefix_from_main_cf($main_cf); - my $ml_home_dir = ''; - my $found_cf = 0; - my @cf = (); - - # "elena" is translated to "/var/spool/ml/elena" - for (@ARGV) { - # 1. for the first time - # a) speculate "/var/spool/ml/$_" looks a $ml_home_dir ? - unless ($found_cf) { - my $x = File::Spec->catfile($ml_home_prefix, $_); - my $cf = File::Spec->catfile($x, "config.cf"); - if (-d $x && -f $cf) { - $found_cf = 1; - $ml_home_dir = $x; - push(@cf, $cf); - } - } - - last if $found_cf; - - # 2. /var/spool/ml/elena looks a $ml_home_dir ? - if (-d $_) { - $ml_home_dir = $_; - my $cf = File::Spec->catfile($_, "config.cf"); - if (-f $cf) { - push(@cf, $cf); - $found_cf = 1; - } - } - # 3. looks a file, so /var/spool/ml/elena/config.cf ? - elsif (-f $_) { - push(@cf, $_); - } - } - - # save $ml_home_dir value in $main_cf directly - $main_cf->{ ml_home_dir } = $ml_home_dir; - - \@cf; -} - - -# Descriptions: analyze argument vector -# Arguments: STR($myname) HASH_REF($main_cf) -# Side Effects: none -# Return Value: ARRAY_REF (list of config.cf's) -sub _makefml_parse_argv -{ - my ($myname, $main_cf) = @_; - use FML::Process::Utils; - my $ml_home_prefix = - FML::Process::Utils::__ml_home_prefix_from_main_cf($main_cf); - - # makefml specific syntax. - if (@ARGV) { - my @cf = (); - my ($command, $ml_name, @options) = @ARGV; - - if ($command =~ /\-\>/) { - ($command, @options) = @ARGV; - ($ml_name, $command) = split('->', $command); - } - elsif ($command =~ /::/) { - ($command, @options) = @ARGV; - ($ml_name, $command) = split('::', $command); - } - - # save $ml_home_dir value in $main_cf directly - if (defined $ml_name) { - $main_cf->{ ml_home_dir } = - File::Spec->catfile($ml_home_prefix, $ml_name); - # config.cf - my $cf = - File::Spec->catfile($ml_home_prefix, $ml_name, "config.cf"); - @cf = ($cf); - } - else { - warn("\$ml_name not specified") if $debug; - } - - return \@cf; - } - else { - return []; - } -} - - =head2 C<ProcessSwitch($args)> load the library and prepare environment to use it. @@ -381,7 +282,7 @@ C<$args> is like this: # Return Value: STR(package name) sub ProcessSwitch { - my ($args) = @_; + my ($myname, $args) = @_; # Firstly, create process # $pkg is a package name, for exampl,e "FML::Process::Distribute". @@ -391,7 +292,7 @@ sub ProcessSwitch } # debug, ignore this - if ($0 =~ /loader/) { print "use $pkg\n"; sleep 2;} + if ($myname eq 'loader') { print "use $pkg\n"; sleep 2;} eval qq{ require $pkg; $pkg->import();}; croak($@) if $@; @@ -487,6 +388,9 @@ sub _ml_name_is_required elsif ($myname eq 'fmlalias') { return 0; } + elsif ($myname eq 'fmlhtmlify') { + return 0; + } elsif ($myname eq 'menu.cgi' || $myname eq 'config.cgi' || $myname eq 'thread.cgi') { diff --git a/fml/lib/FML/Process/ThreadTrack.pm b/fml/lib/FML/Process/ThreadTrack.pm index 82b07b6a..d5d37f0b 100644 --- a/fml/lib/FML/Process/ThreadTrack.pm +++ b/fml/lib/FML/Process/ThreadTrack.pm @@ -3,7 +3,7 @@ # Copyright (C) 2001,2002 Ken'ichi Fukamachi # All rights reserved. # -# $FML: ThreadTrack.pm,v 1.27 2002/04/10 09:57:24 fukachan Exp $ +# $FML: ThreadTrack.pm,v 1.28 2002/06/01 05:02:33 fukachan Exp $ # package FML::Process::ThreadTrack; @@ -68,6 +68,9 @@ sub prepare my $eval = $config->get_hook( 'fmlthread_prepare_start_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } + $curproc->resolve_ml_specific_variables( $args ); + $curproc->load_config_files( $args->{ cf_list } ); + $eval = $config->get_hook( 'fmlthread_prepare_end_hook' ); if ($eval) { eval qq{ $eval; }; LogWarn($@) if $@; } } diff --git a/fml/lib/FML/Process/Utils.pm b/fml/lib/FML/Process/Utils.pm index 7457a4e3..cf9c4fb6 100644 --- a/fml/lib/FML/Process/Utils.pm +++ b/fml/lib/FML/Process/Utils.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Utils.pm,v 1.28 2002/06/24 13:40:07 fukachan Exp $ +# $FML: Utils.pm,v 1.29 2002/06/25 04:02:11 fukachan Exp $ # package FML::Process::Utils; @@ -379,7 +379,7 @@ sub __ml_home_prefix_from_main_cf return $main_cf->{ default_ml_home_prefix }; } else { - croak("ml_home_prefix: unknown domain"); + croak("ml_home_prefix: unknown domain ($domain)"); } } } @@ -669,6 +669,26 @@ sub rewrite_config_if_needed my $ml_home_prefix = ''; my $ml_home_dir = ''; + # debug + # XXX remove this function in the future ? + if (0) { + my @c = caller; + + print STDERR "rewrite_config_if_needed input:\n"; + print STDERR " $c[1] $c[2]\n"; + + for (qw(ml_name ml_domain ml_home_prefix ml_home_dir)) { + if (defined $config->{ $_ }) { + print STDERR "$_ => $config->{ $_ }\n"; + } + else { + print STDERR "$_ => \n"; + } + } + } + + return; + # ml_domain if (defined $params->{ 'ml_domain' }) { $ml_domain = $params->{ 'ml_domain' }; |
