From fbf4e190ce9d1340ec2278b616d18e30c2ca0fcc Mon Sep 17 00:00:00 2001 From: John Sully Date: Sat, 2 Mar 2019 20:43:03 -0500 Subject: [PATCH] Fix issue #2, check posix return values Former-commit-id: 01a529cbda919d5514a4a445b26a0408115173ca --- src/bio.c | 6 +++--- src/redis-benchmark.c | 20 +++++++++++++------- src/server.c | 6 +++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/bio.c b/src/bio.c index 499a33054..023340b97 100644 --- a/src/bio.c +++ b/src/bio.c @@ -101,9 +101,9 @@ void bioInit(void) { /* Initialization of state vars and objects */ for (j = 0; j < BIO_NUM_OPS; j++) { - pthread_mutex_init(&bio_mutex[j],NULL); - pthread_cond_init(&bio_newjob_cond[j],NULL); - pthread_cond_init(&bio_step_cond[j],NULL); + serverAssert(pthread_mutex_init(&bio_mutex[j],NULL) == 0); + serverAssert(pthread_cond_init(&bio_newjob_cond[j],NULL) == 0); + serverAssert(pthread_cond_init(&bio_step_cond[j],NULL) == 0); bio_jobs[j] = listCreate(); bio_pending[j] = 0; } diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index 55b3415d9..da9522482 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -1534,13 +1534,19 @@ int main(int argc, const char **argv) { } if (config.num_threads > 0) { - pthread_mutex_init(&(config.requests_issued_mutex), NULL); - pthread_mutex_init(&(config.requests_finished_mutex), NULL); - pthread_mutex_init(&(config.liveclients_mutex), NULL); - pthread_mutex_init(&(config.is_fetching_slots_mutex), NULL); - pthread_mutex_init(&(config.is_updating_slots_mutex), NULL); - pthread_mutex_init(&(config.updating_slots_mutex), NULL); - pthread_mutex_init(&(config.slots_last_update_mutex), NULL); + int err = 0; + err |= pthread_mutex_init(&(config.requests_issued_mutex), NULL); + err |= pthread_mutex_init(&(config.requests_finished_mutex), NULL); + err |= pthread_mutex_init(&(config.liveclients_mutex), NULL); + err |= pthread_mutex_init(&(config.is_fetching_slots_mutex), NULL); + err |= pthread_mutex_init(&(config.is_updating_slots_mutex), NULL); + err |= pthread_mutex_init(&(config.updating_slots_mutex), NULL); + err |= pthread_mutex_init(&(config.slots_last_update_mutex), NULL); + if (err != 0) + { + perror("Failed to initialize mutex"); + exit(EXIT_FAILURE); + } } if (config.keepalive == 0) { diff --git a/src/server.c b/src/server.c index 09467e760..bdeff0e45 100644 --- a/src/server.c +++ b/src/server.c @@ -2250,9 +2250,9 @@ void createSharedObjects(void) { void initServerConfig(void) { int j; - pthread_mutex_init(&server.next_client_id_mutex,NULL); - pthread_mutex_init(&server.lruclock_mutex,NULL); - pthread_mutex_init(&server.unixtime_mutex,NULL); + serverAssert(pthread_mutex_init(&server.next_client_id_mutex,NULL) == 0); + serverAssert(pthread_mutex_init(&server.lruclock_mutex,NULL) == 0); + serverAssert(pthread_mutex_init(&server.unixtime_mutex,NULL) == 0); updateCachedTime(); getRandomHexChars(server.runid,CONFIG_RUN_ID_SIZE);