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