Help!

shmat fails problem in RedHat Linux 4

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Development RSS
Next:  shmat fails problem in RedHat Linux 4  
Author Message
Rockkon
External


Since: Feb 24, 2006
Posts: 10



PostPosted: Thu Mar 09, 2006 9:35 am    Post subject: shmat fails problem in RedHat Linux 4
Archived from groups: linux>redhat>devel (more info?)

/*

shmtest: Program to exhibit Red Hat Linux 4 shared memory problem.

To exhibit the problem:

Run it once as follows to initialize shared memory:
% shmtest init

Then run it repeatedly as follows to test access to shared memory:
% shmtest

It will sometimes print SUCCESS and sometimes print FAILURE. Why?

Reproducibility:

The problem is reproducible under Red Hat Linux 4, with kernel
version 2.6, both the EL version and the SMP version,
under both the Red Hat Linux Enterprise ES version and the Red Hat
Linux Advanced Server AS version.

The problem occurs with a "default" Red Hat Linux installation as
well as a "complete" installation, with or without patches to the
latest Red Hat Linux 4 version, and with the SELinux component
either enabled or disabled.

The problem DOES NOT occur under Red Hat Linux 3 (kernel version
2.4),
SuSE Linux (kernel version 2.6), nor Debian Linux (kernel version
2.6).

*/

#include <sys/types.h>
#include <sys/ipc.h>
#include <errno.h>

#define KEY1 1111
#define KEY2 2222
#define SIZE1 1000
#define SIZE2 1000

int shmid1, shmid2 ;
char *shmptr1, *shmptr2 ;

main(int argc, char *argv[]) {

errno = 0 ;

/* Initialization: create 2 shared memory partitions. */
if ( argc > 1 ) {

shmid1 = shmget(KEY1, 1000, IPC_CREAT|0666) ;
if ( shmid1 < 0 ) exit(1) ;

shmptr1 = (char *)shmat(shmid1, 0, 0666) ;
if ( (long)shmptr1 == -1 ) exit(2) ;

shmid2 = shmget(KEY2, 1000, IPC_CREAT|0666) ;
if ( shmid2 < 0 ) exit(3) ;

shmptr2 = (char *)shmat(shmid2, 0, 0666) ;
if ( (long)shmptr2 == -1 ) exit(4) ;

/* Save address of 2nd partition in 1st partition. */
*(char **)shmptr1 = shmptr2 ;

printf("Shared memory initialized.\n") ;
exit(0) ;
}

/* Test: locate and access shared memory partitions. */
shmid1 = shmget(KEY1, SIZE1, 0666) ;
if ( shmid1 < 0 ) exit(5) ;

shmptr1 = (char *)shmat(shmid1, 0, 0666) ;
if ( (long)shmptr1 == -1 ) exit(6) ;

/* Fetch address of 2nd partition from 1st partition. */
shmptr2 = *(char **)shmptr1 ;

shmid2 = shmget(KEY2, SIZE2, 0666) ;
if ( shmid2 < 0 ) exit(7) ;

shmptr2 = (char *)shmat(shmid2, shmptr2, 0666) ;
if ( (long)shmptr2 == -1 ) {
printf ("FAILURE, errno = %d\n", errno) ;
exit(Cool ; }

printf("SUCCESS\n") ;
exit(0) ;

}

Thanks for any insight...

Rock
Back to top
Rockkon
External


Since: Feb 24, 2006
Posts: 10



PostPosted: Mon Mar 13, 2006 9:47 am    Post subject: Re: shmat fails problem in RedHat Linux 4 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks. We think we found the problem, we think... There is a
difference in the new gcc compiler. If we compile the program under ES
4 it works without fail. If we compile the program under Red Hat Linux
7.2, the random problem appears.

Rock
Back to top
Christian Ehrhardt
External


Since: Mar 13, 2006
Posts: 1



PostPosted: Mon Mar 13, 2006 11:55 am    Post subject: Re: shmat fails problem in RedHat Linux 4 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi,

On 2006-03-09, Rockkon <rockkon.TakeThisOut@verizon.net> wrote:
> It will sometimes print SUCCESS and sometimes print FAILURE. Why?

if you'd tell us what errno is in this case, we'd be able to make a more
educated guess. Probably the shared memory segment can't be mapped
where you want it to be because there's something else mapped at the same
virtual address.

regards Christian

--
THAT'S ALL FOLKS!
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Development All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum