in reply to Re: Perl Daemons and SIGHUP
in thread Perl Daemons and SIGHUP

Hi -

I have installed the signal handler as you advised me. but still the exec call terminates the process and i don't know why.

Here is the code:
#!/usr/bin/perl -w use strict; use Socket; use Carp; use MTS; use MTS qw(prepare_transaction); use Proc::Daemon; use File::Temp qw(tempfile); use Data::Dumper; use Logger::Syslog; use JSON; use File::Find; use File::Basename; use Cwd 'realpath'; use POSIX (); #use FindBin(); use File::Spec::Functions qw(rel2abs catfile); no warnings 'File::Find'; my $SELF = rel2abs($0); my @argv = @ARGV; # Daemonizing Proc::Daemon::Init unless defined($ENV{"DEBUG"}); use vars qw($mts $qtime $qattr $qsender $qempty $qxtra $qend @template + $PORT @rcpts $pid $lock_dir @children $cfg $CONFIG_FILE); $CONFIG_FILE = '/etc/mts/mts.conf'; # # Forward Declarations # sub spawn; sub _dispatcher; sub _check_spam; sub _process_request; sub _build_msg; sub _enqueue_messages; sub _prepare_message; sub _notify; sub _signal_handler; sub _recover_transactions; sub _lock_maildrop_dir; sub _read_config; sub _reload_config; $SIG{CHLD} = \&REAPER; $SIG{HUP} = \&sigHUP_handler; #$SIG{__DIE__} = 'IGNORE'; $SIG{ABRT} = \&_signal_handler; $SIG{TERM} = \&_signal_handler; $SIG{INT} = \&_signal_handler; _read_config; #print Dumper $cfg; sub sigHUP_handler { #_reload_config; debug("Restarting daemon with: \$SELF=$SELF and \@argv=@argv "); exec($SELF,@argv); } # POSIX unmasks the sigprocmask properly #my $sigset = POSIX::SigSet->new(); #my $action = POSIX::SigAction->new('sigHUP_handler', $sigset, &POSIX: +:SA_NODEFER); #POSIX::sigaction(&POSIX::SIGHUP, $action); #$action = POSIX::SigAction->new('_signal_handler', $sigset, &POSIX::S +A_NODEFER); #POSIX::sigaction(&POSIX::SIGTERM, $action); #POSIX::sigaction(&POSIX::SIGINT, $action); #POSIX::sigaction(&POSIX::SIGABRT, $action);

pay attention to the commented code block which uses POSIX. This does the same problem too

10x

Replies are listed 'Best First'.
Re^3: Perl Daemons and SIGHUP
by moritz (Cardinal) on Feb 24, 2010 at 13:09 UTC
    Is the debug()-line executed at all?
    Perl 6 - links to (nearly) everything that is Perl 6.
      yes. but the exec call takes the process out.
      After that when i do on shell: ps aux | grep mtsd i get nothing

        If you are using warnings you should get a warning for that exec since exec says Since it's a common mistake to use "exec" instead of "system", Perl warns you if there is a following statement which isn't "die", "warn", or "exit"

        Why not check exec worked as described in the exec pod.

        How many arguments are in @argv (and what do they contain?) as that affects whether the command in passed to your shell or to execve?

        You could always run strace (or whatever depending on your platform) to see what is really going on - although remember to follow children.