On 2006-05-03 10:12:19 -0400, John Peacock wrote:
> David Sparks wrote:
> >Background: I have several hundred lines of yaml config that map
> >user/host names at connect/mail/rcpt time to specific actions.  The
> >action is immediate reject/tempfail or deferred by adding an entry to
> >notes(); queue plugins use the notes entries to write the message with
> >some metadata (ie envelope information to relay the msg).
> 
> Good, now we are getting somewhere.  The connection object is only good 
> as long as the connection exists and the transaction object (wait for 
> it!) is good only as long as the individual transaction exists.  Neither 
> of them is suitable for "read once" configurations.  The plugin object 
> themselves, however, is persistent across connections/transactions.
> 
> So, this is what you do:
> 
> 1) Create a closure in your plugin; the compile() action might do this 
> for you but it is safer to just surround all of your plugin code with an 
> additional layer of {}'s).
> 
> 2) Create a lexically scoped (my) variable to store your YAML config 
> into, inside that closure; this is now effectively your own private 
> storage class.
> 
> 3) Populate the above lexical in the init() sub, which is called once 
> when the plugin is loaded (which in forkserver happens very early, even 
> before the fork happens).

Presumably the config file is changed every now and then and you don't
want to restart forkserver every time to reload it. In this case you can
check the file in the pre_connection hook. This is executed in the
parent process and hence any change there will propagate into all
susequently forked child processes.

For example, in my aliases plugin (which seems a bit similar to what you
have, except I didn't use yaml but invented my own format), the the
pre_connect hook does this:

    # check if on disk config has changed 
    for my $file ("$configdir/aliases", "$configdir/aliases.d", 
glob("$configdir/aliases.d/*")) {
        my $filets = (stat($file))[9];
        $ts = $filets if ($filets > $ts); 
    }

    # reload if it has
    if ($ts > $al_ts) {
        $al = undef;
        for my $file ("$configdir/aliases", glob("$configdir/aliases.d/*")) {
            $self->parse_al1($file);
        }
        $al_ts = $ts;
    }

($al and $al_ts are lexically scoped variables in the plugin containing
a reference to the aliases and the timestamp of the last change,
respectively)

        hp

-- 
   _  | Peter J. Holzer    | Ich sehe nun ein, dass Computer wenig
|_|_) | Sysadmin WSR       | geeignet sind, um sich was zu merken.
| |   | [EMAIL PROTECTED]         |
__/   | http://www.hjp.at/ |    -- Holger Lembke in dan-am

Attachment: pgpqacy1hMBeB.pgp
Description: PGP signature

Reply via email to