summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorShawn Landden <shawnlandden@gmail.com>2012-07-25 14:55:59 -0700
committerKay Sievers <kay@vrfy.org>2012-07-26 11:48:26 +0200
commit0d0f0c50d3a1d90f03972a6abb82e6413daaa583 (patch)
tree74f41c8455dbd78599f49300315a2569a8989992 /src/shared
parente146e4516b9ea9907852e7ad609de39dca9e8769 (diff)
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
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/ask-password-api.c3
-rw-r--r--src/shared/dbus-common.c2
-rw-r--r--src/shared/log.h6
-rw-r--r--src/shared/logs-show.c6
-rw-r--r--src/shared/util.c8
5 files changed, 13 insertions, 12 deletions
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 <syslog.h>
#include <stdbool.h>
#include <stdarg.h>
+#include <errno.h>
#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;
}