X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=.inspircd.inc;h=76e7248c192a31e72d0d8fe22ed32e1b4123af44;hb=de8be466941204bf47c9ed821b2e5a0a79ae64f1;hp=781e745afd452efdb0f6e070733be30c529ebaab;hpb=bbc7915f36c38f974ebd61ce4dbdad4995f2ba69;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/.inspircd.inc b/.inspircd.inc index 781e745af..76e7248c1 100644 --- a/.inspircd.inc +++ b/.inspircd.inc @@ -3,14 +3,14 @@ # | Inspire Internet Relay Chat Daemon | # +------------------------------------+ # -# (C) 2002-2008 InspIRCd Development Team -# http://www.inspircd.org/wiki/index.php/Credits +# InspIRCd: (C) 2002-2008 InspIRCd Development Team +# See: http://www.inspircd.org/wiki/index.php/Credits # -# Written by Craig Edwards, Craig McLure, and others. # This program is free but copyrighted software; see -# the file COPYING for details. +# the file COPYING for details. # # --------------------------------------------------- +# use POSIX; my $basepath = "@BASE_DIR@"; @@ -177,11 +177,17 @@ sub valdebugunattended # NOTE: Saving the debug log (redirected stdout), while useful, is a potential security risk AND one hell of a spacehog. DO NOT SAVE THIS WHERE EVERYONE HAS ACCESS! # Redirect stdout to /dev/null if you're worried about the security. # - # Note the & at the end. We *must* detach otherwise the script hangs. - system("valgrind -v --tool=memcheck --leak-check=yes --num-callers=10 --time-stamp=yes --log-file=$valgrindlogpath/valdebug.%p $binpath/$executable -nofork -debug -nolog >> $basepath/valdebug.insp.out &"); - # Sleep 5 seconds to give valgrind time to initialize before chmodding the logdir for apache access. - sleep(5); - system("chmod 644 $valgrindlogpath/*"); + my $pid = fork; + if ($pid == 0) { + POSIX::setsid(); + umask 022; + open STDERR, '>', "$valgrindlogpath/valdebug.$$" or die $!; + umask 066; + open STDIN, '/dev/null' or die $!; + open STDOUT, '>', "$valgrindlogpath/out.$$" or die $!; + exec "valgrind -v --tool=memcheck --leak-check=yes --num-callers=10 --time-stamp=yes --log-fd=2 $binpath/$executable -nofork -debug -nolog"; + exit 1; + } } sub screenvaldebug @@ -208,16 +214,17 @@ sub stop { # Get to here, we have something to kill. my $pid = getprocessid(); print "Stopping InspIRCd (pid: $pid)...\n"; - system("kill -TERM $pid >/dev/null 2>&1"); - # Give it twenty seconds to exit, otherwise valgrind can't write out all output before being killed -9 - # TODO make this a variable number based on if it's valgrind or normal start. - sleep(20); - if (getstatus() == 1) - { - print "InspIRCd not dying quietly -- forcing kill\n"; - system("kill -9 $pid >/dev/null 2>&1"); + my $maxwait = (`ps -o command $pid` =~ /valgrind/i) ? 30 : 5; + kill TERM => $pid; + for (1..$maxwait) { + sleep 1; + if (getstatus() == 1) { + print "InspIRCd Stopped.\n"; + return; + } } - print "InspIRCd Stopped.\n"; + print "InspIRCd not dying quietly -- forcing kill\n"; + kill KILL => $pid; } # GetPidfile Version 2 - Now With Include Support.. @@ -297,10 +304,8 @@ sub getpidfile { sub getstatus { my $pid = getprocessid(); - if ($pid == 0) { return 0; } - $status = system("kill -0 $pid >/dev/null 2>&1") / 256; - if ($status == 0) { return 1; } - else { return 0; } + return 0 if $pid == 0; + return kill 0, $pid; }