From 0d0f0c50d3a1d90f03972a6abb82e6413daaa583 Mon Sep 17 00:00:00 2001 From: Shawn Landden Date: Wed, 25 Jul 2012 14:55:59 -0700 Subject: log.h: new log_oom() -> int -ENOMEM, use it also a number of minor fixups and bug fixes: spelling, oom errors that didn't print errors, not properly forwarding error codes, few more consistency issues, et cetera --- src/shared/ask-password-api.c | 3 +-- src/shared/dbus-common.c | 2 +- src/shared/log.h | 6 ++++++ src/shared/logs-show.c | 6 ++---- src/shared/util.c | 8 +++----- 5 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src/shared') diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 005f40fef7..8a0fb89a84 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -281,8 +281,7 @@ static int create_socket(char **name) { } if (!(c = strdup(sa.un.sun_path))) { - r = -ENOMEM; - log_error("Out of memory."); + r = log_oom(); goto fail; } diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c index ab1dc4d7e4..5d64568c34 100644 --- a/src/shared/dbus-common.c +++ b/src/shared/dbus-common.c @@ -1161,7 +1161,7 @@ void bus_async_unregister_and_exit(DBusConnection *bus, const char *name) { return; oom: - log_error("Out of memory."); + log_oom(); if (pending) { dbus_pending_call_cancel(pending); diff --git a/src/shared/log.h b/src/shared/log.h index c986b2579d..7bdb3e0865 100644 --- a/src/shared/log.h +++ b/src/shared/log.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "macro.h" @@ -102,6 +103,11 @@ int log_dump_internal( #define log_warning(...) log_meta(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__) #define log_error(...) log_meta(LOG_ERR, __FILE__, __LINE__, __func__, __VA_ARGS__) +static inline int log_oom(void) { + log_error("Out of memory."); + return -ENOMEM; +} + /* This modifies the buffer passed! */ #define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer) diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index f90f5a1f0d..edb5a9cafb 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -52,10 +52,8 @@ static int parse_field(const void *data, size_t length, const char *field, char buf = malloc(nl+1); memcpy(buf, (const char*) data + fl, nl); ((char*)buf)[nl] = 0; - if (!buf) { - log_error("Out of memory."); - return -ENOMEM; - } + if (!buf) + return log_oom(); free(*target); *target = buf; diff --git a/src/shared/util.c b/src/shared/util.c index 2e7ae63db2..5f360085a2 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -909,8 +909,7 @@ int load_env_file( continue; if (!(u = normalize_env_assignment(p))) { - log_error("Out of memory."); - r = -ENOMEM; + r = log_oom(); goto finish; } @@ -918,8 +917,7 @@ int load_env_file( free(u); if (!t) { - log_error("Out of memory."); - r = -ENOMEM; + r = log_oom(); goto finish; } @@ -4278,7 +4276,7 @@ void execute_directory(const char *directory, DIR *d, char *argv[]) { continue; if (asprintf(&path, "%s/%s", directory, de->d_name) < 0) { - log_error("Out of memory."); + log_oom(); continue; } -- cgit v1.2.3-54-g00ecf