Logo Search packages:      
Sourcecode: maxdb-7.5.00 version File versions

externC void* sqlAllocSharedMem ( const char *  Path,
const unsigned int  SizeInBytes 
)

Allocate a shared memory chunk identified by path

If path points to an existing Shared Memory Object in the file system, it is opened, otherwise it is created (Read/Writable). The path does not only uniquely identifies the shared memory chunk, but allows to access the information even if the creator process already terminated. Path [in] Path to Shared memory chunk SizeInBytes [in] Size of Chunk in Bytes value Address of Shared Memory Segment or NULL if call failed or Path is not Read/Writable

Definition at line 1686 of file ven41.c.

{
#undef MF__
#define MF__ MOD__"sqlAllocSharedMem"

    void * ShmAddress = NULL;
    int    Fd;

    /* PTS 1105151 */
    /* For SharedMemory '0666' is default to allow all users to use it. use UMASK if you want to restrict it */
    Fd = open(Path, O_RDWR|O_CREAT|O_SYNC, 0666);
    if ( Fd >= 0 )
    {
        char Buffer = 0;
        struct stat statbuf ;

        /* PTS 1108861 */
        /* Check that R+W for all (0666) is still set for the file */
        if ( (fstat(Fd, &statbuf) < 0) )
        {
                  MSGD (( ERR_IPC_CHECK_DIR_STAT, Path , sqlerrs() ));
                  close(Fd);
                  Fd = -1;
        }
        else
        {
        /* Make sure file has at least this size! (SUN would dump core otherwise...) */
        if ( (off_t)-1 != lseek(Fd, SizeInBytes-1, SEEK_SET) )
        {
            if ( read(Fd, &Buffer, 1) == 0 )
            {
                /* We are at or beyond end of file... Write a single 0 byte at end position helps */
                if ( (off_t)-1 != lseek(Fd, SizeInBytes-1, SEEK_SET) )
                {
                    if ( write(Fd, &Buffer, 1) != 1 )
                    {
                       MSGD ((ERR_WRITE_FILE, Path, errno ));
                       close(Fd);
                       Fd = -1;
                    }
                }
                else
                {
                    MSGD ((ERR_LSEEK_SYSCALL, Path, SizeInBytes, "SET", sqlerrs()));
                    close(Fd);
                    Fd = -1;
                }
            }
            if ( Fd >= 0 )
            {
                ShmAddress = mmap( (caddr_t)0, (size_t)SizeInBytes, (PROT_READ|PROT_WRITE),
                                MAP_SHARED, Fd, (off_t)0 );
                if ( -1 == ( ((char *)ShmAddress) - ((char *)0) ) )
                {
                    ShmAddress = 0;
                    MSGD ((ERR_MMAP_SYSCALL, (caddr_t)0, SizeInBytes, sqlerrs()));
                }
            }
        }
        else
        {
            MSGD ((ERR_LSEEK_SYSCALL, Path, SizeInBytes, "SET", sqlerrs()));
        }
        }

        if ( Fd >= 0 )
        {
            close(Fd);
        }
    }
    else
    {
      /* PTS 1106834 */
      MSGD (( ERR_OPEN_SYSCALL, Path, O_RDWR|O_CREAT|O_SYNC, sqlerrs() ));
    }

    return (ShmAddress);
}


Generated by  Doxygen 1.6.0   Back to index