bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

shmget problems using glibc-2.2.4


From: Mark Hounschell
Subject: shmget problems using glibc-2.2.4
Date: Fri, 14 Dec 2001 15:48:40 -0500

I have an app that runs fine using glibc 2.2.2 on a SuSE 7.2 dist. As
soon as I upgraded to
SuSE 7.3 (glibc-2.2.4) this app no longer runs. I didn't even recompile
it. The  executable that worked with glibc-2.2.2 just doesn't work any
more. I recompiled it to see if that would help but to no avail. I've
pinned it down to shmget/shmat calls. The shmat is segfaulting. It is
fairly consistant but sometimes appears to work like I think it should.
Again, using SuSE-7.2 with glibc2.2.2 this routine works. What I'm doing
is trying to have a number of memory partitions virtually contiguous in
this app. I didn't see any bugs posted on this so I'm here hoping
someone might be able to help me.

Thanks and regards
Mark 

This is the routine I'm using to get/attach memory partition partitions
/*******************************************************************************
       attachp: Attach partition
       Calling syntax:
       ataddr = attachp(key, size, address, errmsg);
       where: key      is the partition key.
              size     is the partition size in bytes required if the
                       partition is to be created.  If the partition
                       already exists, a size of zero may be used to
                       attach the whole partition.
              address  is the partition start address.
              errmsg   is an error message if the attach failed.
       attachp returns the attach address if successful, or 0 if not.
*******************************************************************************/
#include "defs.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <errno.h>
#include "extern.h"
#include <prm.h>
#include <stdlib.h>
int shmid;                      /* Shared Memory ID of partition */

char *attachp(
        key_t key,              /* partition key */
        size_t size,            /* partition size */
        void *address,          /* attach address */
        char *errmsg,           /* return error message */
        int *id                 /* shmid return for delete later */
)
{
//  char *pstart = NULL;            /* Start address of partition */
  char *pstart;            /* Start address of partition */

  *errmsg = 0;                    /* Clear error message */

  shmid = shmget(key,size,SHM_R | SHM_W | IPC_CREAT | 00666);
//  printf(" %d = shmget(%x,%d,%x)\n",
//           shmid,key,size,(SHM_R | SHM_W | IPC_CREAT | 00666) );

  if (shmid <0)
  {
    perror("shmget");
    if ( (errno == EINVAL) || (errno == EACCES) )
    {
      printf("---> Emulator exiting due to shared memory allocation
error\n\n");
      printf("-->    ***********  Error Help  ***********\n");
      printf("--> The shared memory partition with key:
%d(0x%x)\n",key,key);
      printf("--> probably already exists and is either the wrong
size,\n");
      printf("--> or is owned by someone else. \n");
      printf("--> Use ipcs to check existing partitions for the key\n");
      printf("--> displayed in the first line of this message.\n");
      printf("-->    ************************************\n");
      exit (1);
    }

  }

  pstart = (char *)shmat(shmid,address,SHM_RND);

//  printf("%x = shmat(%d,%x,%x)\n",pstart,shmid,address,SHM_RND);

  if ( (adr_int) pstart == -1 )
    {
//    sprintf(errmsg,"shmat for key %d failed:
%s\n",key,sys_errlist[errno]);
    sprintf(errmsg,"shmat for key %d failed. Return: %x
%d\n",key,pstart,errno);
    perror("shmat ");
    return((char *)0);
    }

#if 0
  printf("Shared memory attached at %x\n",pstart);
#endif

  *id = shmid;
  return(pstart);                 /* Return attach address */
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]