From 3aaf4e0c892590c3b46d0a99bb00607ddac2c37a Mon Sep 17 00:00:00 2001 From: Petr Spacek Date: Nov 23 2012 09:58:40 +0000 Subject: Log memory allocation failures. Signed-off-by: Petr Spacek --- diff --git a/src/log.h b/src/log.h index 9062a4e..d6a4015 100644 --- a/src/log.h +++ b/src/log.h @@ -23,6 +23,7 @@ #include #include +#include #ifdef LOG_AS_ERROR #define GET_LOG_LEVEL(level) ISC_LOG_ERROR @@ -31,7 +32,7 @@ #endif #define fatal_error(...) \ - isc_error_fatal(__FILE__, __LINE__, __VA_ARGS__) + isc_error_fatal(__FILE__, __LINE__, __VA_ARGS__) #define log_bug(fmt, ...) \ log_error("bug in %s(): " fmt, __func__,##__VA_ARGS__) @@ -39,6 +40,10 @@ #define log_error_r(fmt, ...) \ log_error(fmt ": %s", ##__VA_ARGS__, dns_result_totext(result)) +#define log_error_position(format, ...) \ + log_error("[%-15s: %4d: %-21s] " format, \ + __FILE__, __LINE__, __func__, ##__VA_ARGS__) + /* Basic logging functions */ #define log_error(format, ...) \ log_write(GET_LOG_LEVEL(ISC_LOG_ERROR), format, ##__VA_ARGS__) diff --git a/src/util.h b/src/util.h index 2b8f10e..c61f4e7 100644 --- a/src/util.h +++ b/src/util.h @@ -21,6 +21,8 @@ #ifndef _LD_UTIL_H_ #define _LD_UTIL_H_ +#include "log.h" + #define CLEANUP_WITH(result_code) \ do { \ result = (result_code); \ @@ -46,6 +48,7 @@ (target_ptr) = isc_mem_allocate((m), (s)); \ if ((target_ptr) == NULL) { \ result = ISC_R_NOMEMORY; \ + log_error_position("Memory allocation failed"); \ goto cleanup; \ } \ } while (0) @@ -55,6 +58,7 @@ (target_ptr) = isc_mem_get((m), (s)); \ if ((target_ptr) == NULL) { \ result = ISC_R_NOMEMORY; \ + log_error_position("Memory allocation failed"); \ goto cleanup; \ } \ } while (0) @@ -67,6 +71,7 @@ (target) = isc_mem_strdup((m), (source)); \ if ((target) == NULL) { \ result = ISC_R_NOMEMORY; \ + log_error_position("Memory allocation failed"); \ goto cleanup; \ } \ } while (0)