X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fsharedmemory.c;h=46f54f2b095d54311f82028cd7d8f36b648559b2;hb=ff147af7bc38ad24a846cdfbb0a5616b7296a42a;hp=46cdc45340a22857dc06d0b104c921b394ef90b7;hpb=38d77b3cbee831144dcfdb2b79c93bc6d494f7fe;p=umurmur.git diff --git a/src/sharedmemory.c b/src/sharedmemory.c index 46cdc45..46f54f2 100644 --- a/src/sharedmemory.c +++ b/src/sharedmemory.c @@ -7,33 +7,29 @@ void Sharedmemory_init(void) int bindport = getIntConf(BINDPORT); //MJP BUG commandline option for address and port dont work this way going to have int server_max_clients = getIntConf(MAX_CLIENTS); //to bring them across as prameters to Sharedmemory_init(void) int shmptr_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients); - - sprintf( shm_file_name, "umurmurd:%i", bindport ); + Log_info("SHM_API: shm_fd=\"%s\"", shm_file_name ); - Log_info("SHM_FD: %s", shm_file_name ); + shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0660 ); + if(shm_fd == -1) + { + Log_fatal( "SHM_API: Open failed:%s\n", strerror(errno)); + exit(1); + } -shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0666 ); -if(shm_fd == -1) -{ - fprintf(stderr, "Open failed:%s\n", strerror(errno)); //MJP BUG make this Log_ calls once I get this working - exit(1); -} - -if( ftruncate( shm_fd, shmptr_size ) == -1 ) -{ - fprintf(stderr, "ftruncate : %s\n", strerror(errno)); //MJP BUG make this Log_ calls once I get this working - exit(1); -} - - shmptr = mmap(0, shmptr_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); - if (shmptr == (void *) -1) - { - fprintf(stderr, "mmap failed : %s\n", strerror(errno)); //MJP BUG make this Log_ calls once I get this working - exit(1); - } + if( ftruncate( shm_fd, shmptr_size ) == -1 ) + { + Log_fatal( "SHM_API: ftruncate : %s\n", strerror(errno)); + exit(1); + } + shmptr = mmap(0, shmptr_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); + if (shmptr == (void *) -1) + { + Log_fatal( "SHM_API: mmap failed : %s\n", strerror(errno)); + exit(1); + } memset( shmptr, 0, shmptr_size ); @@ -109,6 +105,6 @@ void Sharedmemory_alivetick(void) void Sharedmemory_deinit(void) { close( shm_fd ); - unlink( shm_file_name ); + shm_unlink( shm_file_name ); shmptr->umurmurd_pid = 0; -} \ No newline at end of file +}