From ad5e1b6fff3aeca619daa3a061ee510d8ce5893f Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Sun, 2 Nov 2003 17:36:36 +0000 Subject: [PATCH] Support SIGTERM git-svn-id: https://svn.perl.org/qpsmtpd/trunk@188 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd/SelectServer.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Qpsmtpd/SelectServer.pm b/lib/Qpsmtpd/SelectServer.pm index dcce633..f990c67 100644 --- a/lib/Qpsmtpd/SelectServer.pm +++ b/lib/Qpsmtpd/SelectServer.pm @@ -23,6 +23,10 @@ tie %ready, 'Tie::RefHash'; my $server; my $select; +our $QUIT = 0; + +$SIG{INT} = $SIG{TERM} = sub { $QUIT++ }; + sub main { my $class = shift; my %opts = (LocalPort => 25, Reuse => 1, Listen => SOMAXCONN, @_); @@ -34,7 +38,9 @@ sub main { $select = IO::Select->new($server); my $res = Net::DNS::Resolver->new; - while (1) { + # TODO - make this more graceful - let all current SMTP sessions finish + # before quitting! + while (!$QUIT) { foreach my $client ($select->can_read(1)) { if ($client == $server) { my $client_addr;