diff options
Diffstat (limited to 'pr/src/md/unix/uxshm.c')
-rw-r--r-- | pr/src/md/unix/uxshm.c | 122 |
1 files changed, 62 insertions, 60 deletions
diff --git a/pr/src/md/unix/uxshm.c b/pr/src/md/unix/uxshm.c index 92bd5b9f..29a6030f 100644 --- a/pr/src/md/unix/uxshm.c +++ b/pr/src/md/unix/uxshm.c @@ -53,7 +53,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); + ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); return( NULL ); } @@ -105,7 +105,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname)); + ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname)); PR_FREEIF( shm->ipcname ); PR_DELETE( shm ); return( NULL ); @@ -120,7 +120,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ((errno == EEXIST) && (flags & PR_SHM_EXCL)) { PR_SetError( PR_FILE_EXISTS_ERROR, errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno)); + ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno)); PR_FREEIF(shm->ipcname); PR_DELETE(shm); return(NULL); @@ -131,7 +131,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( -1 == shm->id ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno)); + ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno)); PR_FREEIF(shm->ipcname); PR_DELETE(shm); return(NULL); @@ -154,8 +154,8 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d", - shm->ipcname, PR_GetOSError() )); + ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d", + shm->ipcname, PR_GetOSError() )); addr = NULL; } @@ -175,7 +175,7 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr ) rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname )); + ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname )); } return rc; @@ -202,9 +202,9 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm ); if ( PR_FAILURE == rc ) { - PR_SetError( PR_UNKNOWN_ERROR , errno ); + PR_SetError( PR_UNKNOWN_ERROR, errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); + ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); return(PR_FAILURE); } @@ -228,14 +228,14 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname)); + ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname)); } id = shmget( key, 0, 0 ); if ( -1 == id ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno)); + ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno)); return(PR_FAILURE); } @@ -244,7 +244,7 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname )); + ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname )); return(PR_FAILURE); } @@ -252,7 +252,7 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) if ( -1 == urc ) { _PR_MD_MAP_UNLINK_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname )); + ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname )); return(PR_FAILURE); } @@ -290,9 +290,9 @@ extern PRSharedMemory * _MD_OpenSharedMemory( rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm ); if ( PR_FAILURE == rc ) { - PR_SetError( PR_UNKNOWN_ERROR , errno ); + PR_SetError( PR_UNKNOWN_ERROR, errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); + ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); return( NULL ); } @@ -325,8 +325,9 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( flags & PR_SHM_CREATE ) { int oflag = (O_CREAT | O_RDWR); - if ( flags & PR_SHM_EXCL ) + if ( flags & PR_SHM_EXCL ) { oflag |= O_EXCL; + } shm->id = shm_open( shm->ipcname, oflag, shm->mode ); } else { shm->id = shm_open( shm->ipcname, O_RDWR, shm->mode ); @@ -335,7 +336,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( -1 == shm->id ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d", + ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d", shm->ipcname, PR_GetOSError())); PR_DELETE( shm->ipcname ); PR_DELETE( shm ); @@ -346,7 +347,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory( if ( -1 == end ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d", + ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d", PR_GetOSError())); PR_DELETE( shm->ipcname ); PR_DELETE( shm ); @@ -363,20 +364,21 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags ) PR_ASSERT( shm->ident == _PR_SHM_IDENT ); - if ( PR_SHM_READONLY == flags) + if ( PR_SHM_READONLY == flags) { prot ^= PROT_WRITE; + } addr = mmap( (void*)0, shm->size, prot, MAP_SHARED, shm->id, 0 ); if ((void*)-1 == addr ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d", - shm->ipcname, PR_GetOSError())); + ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d", + shm->ipcname, PR_GetOSError())); addr = NULL; } else { PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr)); + ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr)); } return addr; @@ -395,8 +397,8 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr ) rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d", - shm->ipcname, PR_GetOSError())); + ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d", + shm->ipcname, PR_GetOSError())); } return rc; } @@ -411,7 +413,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm ) if ( -1 == urc ) { _PR_MD_MAP_CLOSE_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError())); + ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError())); return(PR_FAILURE); } PR_DELETE( shm->ipcname ); @@ -428,9 +430,9 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm ); if ( PR_FAILURE == rc ) { - PR_SetError( PR_UNKNOWN_ERROR , errno ); + PR_SetError( PR_UNKNOWN_ERROR, errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); + ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name )); return rc; } @@ -439,11 +441,11 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name ) rc = PR_FAILURE; _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d", - ipcname, PR_GetOSError())); + ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d", + ipcname, PR_GetOSError())); } else { PR_LOG( _pr_shm_lm, PR_LOG_DEBUG, - ("_MD_DeleteSharedMemory(): %s, success", ipcname)); + ("_MD_DeleteSharedMemory(): %s, success", ipcname)); } return rc; @@ -485,86 +487,86 @@ extern PRFileMap* _md_OpenAnonFileMap( for ( incr = 0; incr < maxTries ; incr++ ) { #define NSPR_AFM_FILENAME "%s/.NSPR-AFM-%d-%p.%d" genName = PR_smprintf( NSPR_AFM_FILENAME, - dirName, (int) pid, tid, incr ); + dirName, (int) pid, tid, incr ); if ( NULL == genName ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename")); + ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename")); goto Finished; } /* create the file */ osfd = open(genName, (O_CREAT | O_EXCL | O_RDWR), mode); if (-1 == osfd) { - if (EEXIST == errno) { + if (EEXIST == errno) { + PR_smprintf_free(genName); + continue; /* name exists, try again */ + } + _PR_MD_MAP_OPEN_ERROR(errno); + PR_LOG( + _pr_shma_lm, + PR_LOG_DEBUG, + ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d", + genName, + PR_GetOSError())); PR_smprintf_free(genName); - continue; /* name exists, try again */ - } - _PR_MD_MAP_OPEN_ERROR(errno); - PR_LOG( - _pr_shma_lm, - PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d", - genName, - PR_GetOSError())); - PR_smprintf_free(genName); - goto Finished; + goto Finished; } break; /* name generation and open successful, break; */ } /* end for() */ if (incr == maxTries) { - PR_ASSERT(-1 == osfd); - PR_ASSERT(EEXIST == errno); - _PR_MD_MAP_OPEN_ERROR(errno); - goto Finished; + PR_ASSERT(-1 == osfd); + PR_ASSERT(EEXIST == errno); + _PR_MD_MAP_OPEN_ERROR(errno); + goto Finished; } urc = unlink( genName ); if ( -1 == urc ) { _PR_MD_MAP_UNLINK_ERROR( errno ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno)); + ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno)); PR_smprintf_free( genName ); close( osfd ); goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): unlink(): %s", genName )); + ("_md_OpenAnonFileMap(): unlink(): %s", genName )); PR_smprintf_free( genName ); fd = PR_ImportFile( osfd ); if ( NULL == fd ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): PR_ImportFile(): failed")); + ("_md_OpenAnonFileMap(): PR_ImportFile(): failed")); goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): fd: %p", fd )); + ("_md_OpenAnonFileMap(): fd: %p", fd )); urc = ftruncate( fd->secret->md.osfd, size ); if ( -1 == urc ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno)); + ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno)); PR_Close( fd ); goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size )); + ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size )); LL_UI2L(size64, size); /* PRSize (size_t) is unsigned */ fm = PR_CreateFileMap( fd, size64, prot ); if ( NULL == fm ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("PR_OpenAnonFileMap(): failed")); + ("PR_OpenAnonFileMap(): failed")); PR_Close( fd ); goto Finished; } fm->md.isAnonFM = PR_TRUE; /* set fd close */ PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm )); + ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm )); Finished: return(fm); @@ -585,7 +587,7 @@ extern PRStatus _md_ExportFileMapAsString( PRIntn prot = (PRIntn)fm->prot; written = PR_snprintf( buf, bufSize, "%ld:%d", - fm->fd->secret->md.osfd, prot ); + fm->fd->secret->md.osfd, prot ); return((written == -1)? PR_FAILURE : PR_SUCCESS); } /* end _md_ExportFileMapAsString() */ @@ -608,21 +610,21 @@ extern PRFileMap * _md_ImportFileMapFromString( fd = PR_ImportFile( osfd ); if ( NULL == fd ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ImportFileMapFromString(): PR_ImportFile() failed")); + ("_md_ImportFileMapFromString(): PR_ImportFile() failed")); goto Finished; } rc = PR_GetOpenFileInfo64( fd, &info ); if ( PR_FAILURE == rc ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed")); + ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed")); goto Finished; } fm = PR_CreateFileMap( fd, info.size, (PRFileMapProtect)prot ); if ( NULL == fm ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, - ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed")); + ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed")); } Finished: |