From e51a0230e154d65226ca3ff144eaaafcc3074dae Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Fri, 15 May 2015 13:33:44 +0200 Subject: [PATCH 1/4] mx_util: Add mx_calloc*() --- mx_util.c | 17 +++++++++++++++++ mx_util.h | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/mx_util.c b/mx_util.c index 14741ba..0829ae9 100644 --- a/mx_util.c +++ b/mx_util.c @@ -607,3 +607,20 @@ int mx_sleep_nofail(unsigned int seconds) mx_sleep(seconds); return 1; } + +void *mx_calloc_forever_sec(size_t nmemb, size_t size, unsigned int time) +{ + void *ptr; + + while (1) { + ptr = calloc(nmemb, size); + if (ptr) + break; + + mx_log_debug("calloc() failed: %m - retrying (forever) in %d second(s).", time); + if (time) + mx_sleep(time); + } + + return ptr; +} diff --git a/mx_util.h b/mx_util.h index 63af526..9fac460 100644 --- a/mx_util.h +++ b/mx_util.h @@ -96,4 +96,12 @@ int mx_open_newfile(char *fname); int mx_sleep(unsigned int seconds); int mx_sleep_nofail(unsigned int seconds); +#ifndef MX_CALLOC_FAIL_WAIT_DEFAULT +# define MX_CALLOC_FAIL_WAIT_DEFAULT 1 +#endif + +#define mx_calloc_forever(n, s) mx_calloc_forever_sec((n), (s), MX_CALLOC_FAIL_WAIT_DEFAULT) + +void *mx_calloc_forever_sec(size_t nmemb, size_t size, unsigned int time); + #endif From d01b8e5f163e818437cded3c52d8378bcad6488d Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 20 May 2015 16:32:09 +0200 Subject: [PATCH 2/4] mx_util: Remove unused variables --- mx_util.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/mx_util.c b/mx_util.c index 0829ae9..5befe06 100644 --- a/mx_util.c +++ b/mx_util.c @@ -205,7 +205,6 @@ inline int mx_strtoll(char *str, signed long long int *to) int mx_strtoui(char *str, unsigned int *to) { unsigned long int ul; - char *end; int res; assert(str); @@ -226,7 +225,6 @@ int mx_strtoui(char *str, unsigned int *to) int mx_strtou8(char *str, uint8_t *to) { unsigned long int ul; - char *end; int res; assert(str); @@ -247,7 +245,6 @@ int mx_strtou8(char *str, uint8_t *to) int mx_strtou16(char *str, uint16_t *to) { unsigned long int ul; - char *end; int res; assert(str); @@ -268,7 +265,6 @@ int mx_strtou16(char *str, uint16_t *to) int mx_strtou32(char *str, uint32_t *to) { unsigned long int ul; - char *end; int res; assert(str); @@ -289,7 +285,6 @@ int mx_strtou32(char *str, uint32_t *to) int mx_strtou64(char *str, uint64_t *to) { unsigned long long int ull; - char *end; int res; assert(str); @@ -312,7 +307,6 @@ int mx_strtou64(char *str, uint64_t *to) int mx_strtoi(char *str, signed int *to) { signed long int l; - char *end; int res; assert(str); @@ -333,7 +327,6 @@ int mx_strtoi(char *str, signed int *to) int mx_strtoi8(char *str, int8_t *to) { signed long int l; - char *end; int res; assert(str); @@ -354,7 +347,6 @@ int mx_strtoi8(char *str, int8_t *to) int mx_strtoi16(char *str, int16_t *to) { signed long int l; - char *end; int res; assert(str); @@ -375,7 +367,6 @@ int mx_strtoi16(char *str, int16_t *to) int mx_strtoi32(char *str, int32_t *to) { signed long int l; - char *end; int res; assert(str); @@ -396,7 +387,6 @@ int mx_strtoi32(char *str, int32_t *to) int mx_strtoi64(char *str, int64_t *to) { signed long long int ll; - char *end; int res; assert(str); From 97e1062524f8769672b45454a4e9a5988c783673 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 21 May 2015 13:08:48 +0200 Subject: [PATCH 3/4] mx_mysql: Remove duplicate debug message --- mx_mysql.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mx_mysql.c b/mx_mysql.c index cd002b3..2d25f55 100644 --- a/mx_mysql.c +++ b/mx_mysql.c @@ -765,7 +765,6 @@ static int mx_mysql_real_connect(struct mx_mysql *mysql, const char *host, const return 0; } - mx_log_debug("ERROR: mysql_real_connect(): %s", mx__mysql_error(mysql)); return res; } From 874fd1e5e978d00c865558225f99628efe9e7a2a Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Thu, 21 May 2015 13:09:18 +0200 Subject: [PATCH 4/4] mx_util: Assertion loglevel increased to emergency --- mx_util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mx_util.h b/mx_util.h index 9fac460..64f100c 100644 --- a/mx_util.h +++ b/mx_util.h @@ -18,7 +18,7 @@ do {\ if (!(test)) {\ errno=(eno);\ - mx_log_debug("Assertion '" #test "' failed. Returning -(errno=" #eno ") [%d]: %m", -errno);\ + mx_log_emerg("Assertion '" #test "' failed. Returning -(errno=" #eno ") [%d]: %m", -errno);\ return -errno;\ }\ } while (0) @@ -27,7 +27,7 @@ do {\ if (!(test)) {\ errno=(eno);\ - mx_log_debug("Assertion '" #test "' failed. Setting errno=" #eno " [%d] and returning NULL: %m", errno);\ + mx_log_emerg("Assertion '" #test "' failed. Setting errno=" #eno " [%d] and returning NULL: %m", errno);\ return NULL;\ }\ } while (0)