From fb5b810753bb1cdede9632202582c59e1d7e9ce2 Mon Sep 17 00:00:00 2001 From: "Michael J. Pounders" Date: Sat, 22 Nov 2014 22:25:20 -0500 Subject: [PATCH] Code clean up --- shm_utils/mon-umurmurd/CHANGES | 2 +- shm_utils/mon-umurmurd/README.md | 2 -- src/sharedmemory.c | 40 ++++++++++++++------------------ 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/shm_utils/mon-umurmurd/CHANGES b/shm_utils/mon-umurmurd/CHANGES index 8ba9821..93ead4a 100644 --- a/shm_utils/mon-umurmurd/CHANGES +++ b/shm_utils/mon-umurmurd/CHANGES @@ -1,5 +1,5 @@ * Added more client data 99% of the useful client data shown -* removed memcpys (requested by fatbob) +* rework Sharedmemory_update() to not use memcpy (requested by fatbob) * Using a more modern unix sharedmemory API. this requires linking with librt.so (requested by fatbob) diff --git a/shm_utils/mon-umurmurd/README.md b/shm_utils/mon-umurmurd/README.md index eaaeb2b..72473de 100644 --- a/shm_utils/mon-umurmurd/README.md +++ b/shm_utils/mon-umurmurd/README.md @@ -5,5 +5,3 @@ outputs server/client data to term useing the sharedmemory API added to umurmur make ./mon-umurmurd - - diff --git a/src/sharedmemory.c b/src/sharedmemory.c index 46cdc45..0421fe0 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, 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); -} + shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0666 ); + if(shm_fd == -1) + { + Log_fatal( "SHM_API: Open failed:%s\n", strerror(errno)); + 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 ); -- 2.30.2