Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Jul 1999 10:44:48 -0700
From:      John Armstrong <siberian@siberian.org>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Shared Memory Problem Example Code
Message-ID:  <v0421017ab3b913deebc7@[216.112.76.84]>

next in thread | raw e-mail | index | archive | help
Here are two short scripts to exhibit the Shared memory problem I am 
having. As user root these scripts work perfectly, as any other user 
I get access denied.

These scripts require that shared memory is enabled in the kernel and 
that Perl 5.xxx is installed with the IPC::Shareable modules. It was 
suggested to me that posting some short relevant code may help in the 
debugging process( thanks Charles! ).


Script 1 : Puts a value into shared memory :
-----
#!/usr/local/bin/perl

use IPC::Shareable ;

my %options = ('create' => 'yes' ,
			'exclusive'     => 'no' ,
			'mode'         => '0666',
			'destroy'       => 'no' ,
) ;
my %object ;
 
tie( %object , 'IPC::Shareable' , 'TEST' , { %options } ) || die 
print "tie failed\n\n" ;
tied( %object )->shlock ;
$object{ time() } = "Time is ".localtime( time() ) ;
tied( %object )->shunlock ;
-------
Script 2 : Reads all values in memory segment from shared memory :
--------
#!/usr/local/bin/perl

use IPC::Shareable ;

my %options = ('create' => 'yes' ,
           'exclusive'     => 'no' ,
           'mode'         => '0666',
           'destroy'       => 'no' ,
) ;
  my %object ;
 
tie( %object , 'IPC::Shareable' , 'TEST' , { %options } ) || die 
print "tie failed\n\n" ;
foreach $item ( keys %object ) {
	print "I know that $item = $object{ $item }\n" ;
}
-------


John-



-----Original Message-----
From: John Armstrong [mailto:siberian@siberian.org]
Sent: Monday, July 19, 1999 3:43 AM
To: freebsd-questions@FreeBSD.ORG
Subject: Strange Shared memory problem


Hello all-
	I recently moved a system from 3.0 to 3.2 and some of my code
has broken.

Specifically, I am using Perl 5 and IPC::Shareable to share memory
between apache processes. Under 3.0 ( where we developed the software
) everything worked great. Now that we have moved up to 3.2 the same
exact code breaks with the error :

shmget returned undef: Permission denied at <scriptname> <line #>

I have done a ton of testing on this and the result says this :

If user root uses the scripts everything works great. Memory can be
accessed in both read and write methods.

Any other user can not read or write to any shared memory regardless
of its state.

Were there some security changes or something in 3.2 that would make
it so that users can not access shared memory resources? Was I taking
advantage of a 'feature' in 3.0 that has been closed off in 3.2?

Finally, regardless of the outcome, how can I turn on shared memory
access for all users or given users? Is there a kernel config option
for it?

Thanks for any help. Sorry for the long email but the situation has
gotten desperate.

John-


--------------------------------------------------------------------
Thomas Edison attended school for less then three months in his 
entire life.
	-Uncle John's Fourth Bathroom Reader



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?v0421017ab3b913deebc7>