Now tidies up shared memory on startup and shutdown.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@565 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2003-06-12 14:25:42 +00:00
parent 0ed0065964
commit 28c310b2e0
1 changed files with 25 additions and 1 deletions

View File

@ -41,12 +41,12 @@ use constant ZM_DB_SERVER => "<from zmconfig>";
use constant ZM_DB_NAME => "<from zmconfig>"; use constant ZM_DB_NAME => "<from zmconfig>";
use constant ZM_DB_USERA => "<from zmconfig>"; use constant ZM_DB_USERA => "<from zmconfig>";
use constant ZM_DB_PASSA => "<from zmconfig>"; use constant ZM_DB_PASSA => "<from zmconfig>";
use constant ZM_SHM_KEY => "<from zmconfig>";
use constant ZM_OPT_FAST_DELETE => "<from zmconfig>"; use constant ZM_OPT_FAST_DELETE => "<from zmconfig>";
use constant ZM_OPT_X10 => "<from zmconfig>"; use constant ZM_OPT_X10 => "<from zmconfig>";
use constant ZM_OPT_FRAME_SERVER => "<from zmconfig>"; use constant ZM_OPT_FRAME_SERVER => "<from zmconfig>";
use constant LOG_FILE => ZM_PATH_LOGS.'/zmpkg.log'; use constant LOG_FILE => ZM_PATH_LOGS.'/zmpkg.log';
use constant WEB_USER => '@WEB_USER@/';
use constant VERBOSE => 0; # Whether to output more verbose debug use constant VERBOSE => 0; # Whether to output more verbose debug
# ========================================================================== # ==========================================================================
@ -69,6 +69,28 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status)$/ )
exit( -1 ); exit( -1 );
} }
sub remove_shm
{
print( STDERR "Removing shared memory\n" );
# Find ZoneMinder shared memory
my $command = "ipcs -m | grep '^".substr( sprintf( "0x%x", ZM_SHM_KEY ), 0, -2 )."'";
print( "Checking for shared memory with '$command'\n" ) if ( VERBOSE );
open( CMD, "$command |" ) or die( "Can't execute '$command': $!" );
while( <CMD> )
{
chomp;
my ( $key, $id ) = split( /\s+/ );
if ( $id =~ /^(\d+)/ )
{
$id = $1;
my $command = "ipcrm shm $id";
print( "Removing shared memory with '$command'\n" ) if ( VERBOSE );
qx( $command );
}
}
close( CMD );
}
sub execute sub execute
{ {
my $command = shift; my $command = shift;
@ -108,6 +130,7 @@ if ( $command =~ /^(?:stop|restart)$/ )
if ( $status eq "running" ) if ( $status eq "running" )
{ {
execute( ZM_PATH_BIN."/zmdc.pl shutdown" ); execute( ZM_PATH_BIN."/zmdc.pl shutdown" );
remove_shm();
} }
else else
{ {
@ -121,6 +144,7 @@ if ( $command =~ /^(?:start|restart)$/ )
chomp( $status ); chomp( $status );
if ( $status eq "stopped" ) if ( $status eq "stopped" )
{ {
remove_shm();
execute( ZM_PATH_BIN."/zmfix" ); execute( ZM_PATH_BIN."/zmfix" );
execute( ZM_PATH_BIN."/zmdc.pl status" ); execute( ZM_PATH_BIN."/zmdc.pl status" );