Skip Menu |

This queue is for tickets about the Sendmail-PMilter CPAN distribution.

Report information
The Basics
Id: 51759
Status: resolved
Priority: 0/
Queue: Sendmail-PMilter

People
Owner: Nobody in particular
Requestors: mschout [...] gkg.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.20_01



Subject: Add child_init, child_exit hooks to prefork dispatcher
Date: Thu, 19 Nov 2009 16:56:35 -0600
To: bug-sendmail-pmilter [...] rt.cpan.org
From: Michael Schout <mschout [...] gkg.net>
Hi. When writing milters that use a database handle, it is very useful to have a hook called when each child process forks to do database initialization (since db handles should not be shared across fork()'s in general). The attached patch adds two additional parameters to the prefork dispatcher, child_init and child_exit, which take code references. If these are set, then the code references are called when each child process starts up (for child_init), and exits (for child_exit). If you have any questions, please let me know.
From e7b5e6ae34c3410cdb9cd2c6c7fb14571644a26e Mon Sep 17 00:00:00 2001 From: Michael Schout <mschout@gkg.net> Date: Thu, 19 Nov 2009 16:48:24 -0600 Subject: [PATCH] add child_init/child_exit hooks to prefork dispatcher --- lib/Sendmail/PMilter.pm | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diff --git a/lib/Sendmail/PMilter.pm b/lib/Sendmail/PMilter.pm index 54e85d7..afbb6ab 100644 --- a/lib/Sendmail/PMilter.pm +++ b/lib/Sendmail/PMilter.pm @@ -740,6 +740,15 @@ the dispatcher. The available parameters that may be set are: =over 2 +=item child_init + +subroutine reference that will be called after each child process is forked. + +=item child_exit + +subroutine reference that will be called just before each child process +terminates. + =item max_children Maximum number of child processes active at any time. Equivalent to the @@ -774,6 +783,12 @@ sub prefork_dispatcher (@) { warn "$$: requests handled: $i\n"; }; + # call child_init handler if present + if (defined $params{child_init}) { + my $method = $params{child_init}; + $this->$method(); + } + while ($i < $max_requests) { my $socket = $lsocket->accept(); next if $!{EINTR}; @@ -784,6 +799,12 @@ sub prefork_dispatcher (@) { &$handler($socket); $socket->close(); } + + # call child_exit handler if present + if (defined $params{child_exit}) { + my $method = $params{child_exit}; + $this->$method(); + } }; # Propagate some signals down to the entire process group. -- 1.6.5.2
Subject: Re: [rt.cpan.org #51759] Add child_init, child_exit hooks to prefork dispatcher
Date: Thu, 19 Nov 2009 23:48:11 +0000
To: bug-Sendmail-PMilter [...] rt.cpan.org
From: Ævar Arnfjörð Bjarmason <avarab [...] gmail.com>
On Thu, Nov 19, 2009 at 10:57 PM, mschout@gkg.net via RT <bug-Sendmail-PMilter@rt.cpan.org> wrote: Show quoted text
> Thu Nov 19 17:57:04 2009: Request 51759 was acted upon. > Transaction: Ticket created by mschout@gkg.net >       Queue: Sendmail-PMilter >     Subject: Add child_init, child_exit hooks to prefork dispatcher >   Broken in: (no value) >    Severity: (no value) >       Owner: Nobody >  Requestors: mschout@gkg.net >      Status: new >  Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=51759 > > > > Hi. > > When writing milters that use a database handle, it is very useful to > have a hook called when each child process forks to do database > initialization (since db handles should not be shared across fork()'s in > general).  The attached patch adds two additional parameters to the > prefork dispatcher, child_init and child_exit, which take code > references.  If these are set, then the code references are called when > each child process starts up (for child_init), and exits (for child_exit). > > If you have any questions, please let me know.
Thanks for the report. I don't have time to do this soon, but I've given you write access to http://github.com/avar/sendmail-pmilter perhaps you can commit to that & write a changelog entry / make disttest etc. (There's also the outstanding https://rt.cpan.org/Ticket/Display.html?id=51713) I'd give you co-maint so you can upload to pause (and fix any future bugs{ except TVIERLING is still the primary maintainer still. I've e-mailed him about that.
pushed to avar's github repo in b48da5e resolving since this is my own ticket.
On Thu Nov 19 22:43:08 2009, MSCHOUT wrote: Show quoted text
> pushed to avar's github repo in b48da5e > > resolving since this is my own ticket.
Setting this to resolved.