I have this simple perl daemon:
#!/usr/bin/perl
use strict;
use warnings;
use Proc::Daemon;
Proc::Daemon::Init;
my $continue = 1;
$SIG{TERM} = sub { $continue = 0 };
$SIG{USR1} = sub { do_process(1) };
# basic daemon
boxesd_log("started boxesd");
while ($continue) {
do_process(0);
sleep(30);
}
boxesd_log("finished boxesd");
exit(0);
# required subroutines
sub do_process {
my ($notified) = @_;
boxesd_log("doing it $notified");
}
But there is something that is not working right.
When the daemon starts, it logs every 30 seconds without the notification as expected:
Sat Oct 30 21:05:47 2010 doing it 0 Sat Oct 30 21:06:17 2010 doing it 0 Sat Oct 30 21:06:47 2010 doing it 0
The problem comes when I send the USR1
signal to the process using kill -USR1 xxxxx
. The output is not what I expect:
Sat Oct 30 21:08:25 2010 doing it 1 Sat Oct 30 21:08:25 2010 doing it 0
I get two continuous entries, one from the signal handling subroutine and another form the ever running loop. It seems as if the sleep gets interrupted whenever the USR1
signal is received.
What is going on?