Index: DJabberd/lib/DJabberd.pm =================================================================== --- DJabberd/lib/DJabberd.pm (révision 728) +++ DJabberd/lib/DJabberd.pm (copie de travail) @@ -41,6 +41,7 @@ use Carp qw(croak); use DJabberd::Util qw(tsub as_bool as_num as_abs_path); +use File::Pid; our $VERSION = '0.81'; our $logger = DJabberd::Log->get_logger(); @@ -55,6 +56,7 @@ my $self = { 'daemonize' => delete $opts{daemonize}, + 'pid_file' => delete $opts{pid_file}, 's2s_port' => delete $opts{s2s_port}, 'c2s_port' => delete($opts{c2s_port}) || 5222, # {=clientportnumber} 'old_ssl' => delete $opts{old_ssl}, @@ -268,7 +270,7 @@ sub run { my $self = shift; - daemonize() if $self->{daemonize}; + daemonize($self->{pid_file}) if $self->{daemonize}; local $SIG{'PIPE'} = "IGNORE"; # handled manually $self->start_c2s_server(); @@ -282,6 +284,7 @@ DJabberd::Connection::Admin->on_startup; Danga::Socket->EventLoop(); + unlink($self->{pid_file}); } sub _start_server { @@ -525,6 +512,7 @@ } sub daemonize { + my ($pid_file) = @_; my($pid, $sess_id, $i); ## Fork and exit parent @@ -536,7 +524,15 @@ ## Prevent possibility of acquiring a controling terminal $SIG{'HUP'} = 'IGNORE'; - if ($pid = fork) { exit 0; } + if ($pid = fork) { + my $pidfile = File::Pid->new({ + file => $pid_file, + pid => $pid, + }); + + $pidfile->write; + exit 0; + } ## Change working directory chdir "/"; Index: DJabberd/djabberd =================================================================== --- DJabberd/djabberd (révision 728) +++ DJabberd/djabberd (copie de travail) @@ -30,7 +33,7 @@ $DEBUG = 0; -my ($daemonize); +my ($daemonize, $pid_file); my $conffile; @@ -38,10 +41,12 @@ 'd|daemon' => \$daemonize, 'debug=i' => \$DEBUG, 'conffile=s' => \$conffile, + 'pidfile=s' => \$pid_file, ); my $server = DJabberd->new( - daemonize => $daemonize + daemonize => $daemonize, + pid_file => $pid_file, ); my @try_conf = ( $conffile, "/etc/djabberd/djabberd.conf", "djabberd.conf" );