summaryrefslogtreecommitdiff
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
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
-rw-r--r--src/cgtop/cgtop.c3
-rw-r--r--src/core/cgroup.c3
-rw-r--r--src/core/dbus.c41
-rw-r--r--src/core/manager.c14
-rw-r--r--src/cryptsetup/cryptsetup-generator.c8
-rw-r--r--src/cryptsetup/cryptsetup.c8
-rw-r--r--src/fsck/fsck.c2
-rw-r--r--src/fstab-generator/fstab-generator.c57
-rw-r--r--src/getty-generator/getty-generator.c11
-rw-r--r--src/hostname/hostnamed.c3
-rw-r--r--src/journal/cat.c6
-rw-r--r--src/journal/coredump.c3
-rw-r--r--src/journal/journalctl.c3
-rw-r--r--src/journal/journald.c31
-rw-r--r--src/locale/localed.c17
-rw-r--r--src/login/logind-button.c6
-rw-r--r--src/login/logind-session.c21
-rw-r--r--src/login/logind-user.c12
-rw-r--r--src/login/logind.c18
-rw-r--r--src/login/multi-seat-x.c4
-rw-r--r--src/modules-load/modules-load.c12
-rw-r--r--src/nspawn/nspawn.c42
-rw-r--r--src/rc-local-generator/rc-local-generator.c3
-rw-r--r--src/readahead/readahead-collect.c9
-rw-r--r--src/readahead/readahead-replay.c3
-rw-r--r--src/remount-fs/remount-fs.c2
-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
-rw-r--r--src/shutdownd/shutdownd.c6
-rw-r--r--src/sysctl/sysctl.c12
-rw-r--r--src/system-update-generator/system-update-generator.c6
-rw-r--r--src/systemctl/systemctl.c40
-rw-r--r--src/timedate/timedated.c19
-rw-r--r--src/tmpfiles/tmpfiles.c19
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c6
-rw-r--r--src/udev/scsi_id/scsi_id.c12
-rw-r--r--src/vconsole/vconsole-setup.c6
40 files changed, 183 insertions, 310 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index c3824c7979..f0ca83fd45 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -608,8 +608,7 @@ int main(int argc, char *argv[]) {
a = hashmap_new(string_hash_func, string_compare_func);
b = hashmap_new(string_hash_func, string_compare_func);
if (!a || !b) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 1322f63eee..8ddb1118ed 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -330,8 +330,7 @@ int manager_setup_cgroup(Manager *m) {
/* We need a new root cgroup */
m->cgroup_hierarchy = NULL;
if (asprintf(&m->cgroup_hierarchy, "%s%s", streq(current, "/") ? "" : current, suffix) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
}
diff --git a/src/core/dbus.c b/src/core/dbus.c
index 0c13517143..9db172b6e6 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -723,15 +723,11 @@ static int bus_setup_loop(Manager *m, DBusConnection *bus) {
dbus_connection_set_exit_on_disconnect(bus, FALSE);
if (!dbus_connection_set_watch_functions(bus, bus_add_watch, bus_remove_watch, bus_toggle_watch, m, NULL) ||
- !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL)) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL))
+ return log_oom();
- if (set_put(m->bus_connections_for_dispatch, bus) < 0) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (set_put(m->bus_connections_for_dispatch, bus) < 0)
+ return log_oom();
dbus_connection_set_dispatch_status_function(bus, bus_dispatch_status, m, NULL);
return 0;
@@ -764,7 +760,7 @@ static void bus_new_connection(
!dbus_connection_register_fallback(new_connection, "/org/freedesktop/systemd1/unit", &bus_unit_vtable, m) ||
!dbus_connection_register_fallback(new_connection, "/org/freedesktop/systemd1/job", &bus_job_vtable, m) ||
!dbus_connection_add_filter(new_connection, private_bus_message_filter, m, NULL)) {
- log_error("Out of memory.");
+ log_oom();
return;
}
@@ -776,10 +772,8 @@ static void bus_new_connection(
static int init_registered_system_bus(Manager *m) {
char *id;
- if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL)) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL))
+ return log_oom();
if (m->running_as != MANAGER_SYSTEM) {
DBusError error;
@@ -814,10 +808,8 @@ static int init_registered_api_bus(Manager *m) {
if (!dbus_connection_register_object_path(m->api_bus, "/org/freedesktop/systemd1", &bus_manager_vtable, m) ||
!dbus_connection_register_fallback(m->api_bus, "/org/freedesktop/systemd1/unit", &bus_unit_vtable, m) ||
!dbus_connection_register_fallback(m->api_bus, "/org/freedesktop/systemd1/job", &bus_job_vtable, m) ||
- !dbus_connection_add_filter(m->api_bus, api_bus_message_filter, m, NULL)) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ !dbus_connection_add_filter(m->api_bus, api_bus_message_filter, m, NULL))
+ return log_oom();
/* Get NameOwnerChange messages */
dbus_bus_add_match(m->api_bus,
@@ -1090,8 +1082,7 @@ static int bus_init_private(Manager *m) {
return 0;
if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto fail;
}
@@ -1110,8 +1101,7 @@ static int bus_init_private(Manager *m) {
if (!dbus_server_set_auth_mechanisms(m->private_bus, (const char**) external_only) ||
!dbus_server_set_watch_functions(m->private_bus, bus_add_watch, bus_remove_watch, bus_toggle_watch, m, NULL) ||
!dbus_server_set_timeout_functions(m->private_bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL)) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto fail;
}
@@ -1158,8 +1148,7 @@ int bus_init(Manager *m, bool try_bus_connect) {
return 0;
oom:
- log_error("Out of memory.");
- return -ENOMEM;
+ return log_oom();
}
static void shutdown_connection(Manager *m, DBusConnection *c) {
@@ -1458,7 +1447,7 @@ void bus_broadcast_finished(
message = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartupFinished");
if (!message) {
- log_error("Out of memory.");
+ log_oom();
return;
}
@@ -1469,13 +1458,13 @@ void bus_broadcast_finished(
DBUS_TYPE_UINT64, &userspace_usec,
DBUS_TYPE_UINT64, &total_usec,
DBUS_TYPE_INVALID)) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
if (bus_broadcast(m, message) < 0) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
diff --git a/src/core/manager.c b/src/core/manager.c
index 42a9490242..bcaf913b5a 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1625,7 +1625,7 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
}
if (asprintf(&message, "U\002%c%s%n", (int) (strlen(u->id) + 1), u->id, &n) < 0) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
@@ -2073,10 +2073,8 @@ static int create_generator_dir(Manager *m, char **generator, const char *name)
if (m->running_as == MANAGER_SYSTEM && getpid() == 1) {
p = strappend("/run/systemd/", name);
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
r = mkdir_p_label(p, 0755);
if (r < 0) {
@@ -2086,10 +2084,8 @@ static int create_generator_dir(Manager *m, char **generator, const char *name)
}
} else {
p = strjoin("/tmp/systemd-", name, ".XXXXXX", NULL);
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
if (!mkdtemp(p)) {
free(p);
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index fb6b4d25c0..c6bc65aecf 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -303,8 +303,7 @@ static int parse_proc_cmdline(void) {
t = strv_append(arg_proc_cmdline_disks, word + 10);
if (!t) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
strv_free(arg_proc_cmdline_disks);
@@ -317,8 +316,7 @@ static int parse_proc_cmdline(void) {
t = strv_append(arg_proc_cmdline_disks, word + 13);
if (!t) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
strv_free(arg_proc_cmdline_disks);
@@ -380,7 +378,7 @@ int main(int argc, char *argv[]) {
device = strappend("UUID=", *i);
if (!name || !device) {
- log_error("Out of memory.");
+ log_oom();
r = EXIT_FAILURE;
free(name);
free(device);
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 9d4e77364d..cc30e50003 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -343,7 +343,7 @@ int main(int argc, char *argv[]) {
l = strcspn(opt_cipher, "-");
if (!(truncated_cipher = strndup(opt_cipher, l))) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
@@ -365,7 +365,7 @@ int main(int argc, char *argv[]) {
char **p;
if (asprintf(&text, "Please enter passphrase for disk %s!", name) < 0) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
@@ -383,7 +383,7 @@ int main(int argc, char *argv[]) {
assert(strv_length(passwords) == 1);
if (asprintf(&text, "Please enter passphrase for disk %s! (verification)", name) < 0) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
@@ -416,7 +416,7 @@ int main(int argc, char *argv[]) {
/* Pad password if necessary */
if (!(c = new(char, opt_key_size))) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index 036d3c5b41..058f34d64f 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -297,7 +297,7 @@ int main(int argc, char *argv[]) {
}
if (!(udev = udev_new())) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 89a4d13504..251a346c4d 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -47,7 +47,7 @@ static int device_name(const char *path, char **unit) {
p = unit_name_from_path(path, ".device");
if (!p)
- return -ENOMEM;
+ return log_oom();
*unit = p;
return 1;
@@ -98,15 +98,13 @@ static int add_swap(const char *what, struct mntent *me) {
name = unit_name_from_path(what, ".swap");
if (!name) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
unit = strjoin(arg_dest, "/", name, NULL);
if (!unit) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -148,8 +146,7 @@ static int add_swap(const char *what, struct mntent *me) {
if (!noauto) {
lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
if (!lnk) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -161,18 +158,14 @@ static int add_swap(const char *what, struct mntent *me) {
}
r = device_name(what, &device);
- if (r < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ if (r < 0)
goto finish;
- }
if (r > 0) {
free(lnk);
lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL);
if (!lnk) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -255,16 +248,14 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
}
name = unit_name_from_path(where, ".mount");
- if (!name) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ if (!name) {
+ r = log_oom();
goto finish;
}
unit = strjoin(arg_dest, "/", name, NULL);
if (!unit) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -323,8 +314,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
if (!noauto) {
lnk = strjoin(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
if (!lnk) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -339,24 +329,20 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
!path_equal(where, "/")) {
r = device_name(what, &device);
- if (r < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ if (r < 0)
goto finish;
- }
if (r > 0) {
free(lnk);
lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL);
if (!lnk) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
- log_error("Failed to creat symlink: %m");
+ log_error("Failed to create symlink: %m");
r = -errno;
goto finish;
}
@@ -367,15 +353,13 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
if (automount && !path_equal(where, "/")) {
automount_name = unit_name_from_path(where, ".automount");
if (!name) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
automount_unit = strjoin(arg_dest, "/", automount_name, NULL);
if (!automount_unit) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -410,8 +394,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
free(lnk);
lnk = strjoin(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL);
if (!lnk) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -459,16 +442,14 @@ static int parse_fstab(void) {
what = fstab_node_to_udev_node(me->mnt_fsname);
if (!what) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
where = strdup(me->mnt_dir);
if (!where) {
- log_error("Out of memory.");
+ r = log_oom();
free(what);
- r = -ENOMEM;
goto finish;
}
@@ -513,7 +494,7 @@ static int parse_proc_cmdline(void) {
word = strndup(w, l);
if (!word) {
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c
index 9e46a47a9a..1cef6aeae9 100644
--- a/src/getty-generator/getty-generator.c
+++ b/src/getty-generator/getty-generator.c
@@ -42,8 +42,7 @@ static int add_symlink(const char *fservice, const char *tservice) {
to = strjoin(arg_dest,"/getty.target.wants/", tservice, NULL);
if (!from || !to) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -77,10 +76,8 @@ static int add_serial_getty(const char *tty) {
log_debug("Automatically adding serial getty for /dev/%s.", tty);
n = unit_name_replace_instance("serial-getty@.service", tty);
- if (!n) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!n)
+ return log_oom();
r = add_symlink("serial-getty@.service", n);
free(n);
@@ -160,7 +157,7 @@ int main(int argc, char *argv[]) {
int k;
if (asprintf(&p, "/sys/class/tty/%s", j) < 0) {
- log_error("Out of memory.");
+ log_oom();
r = EXIT_FAILURE;
goto finish;
}
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 7dab5f40df..8f9d5a04f5 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -532,8 +532,7 @@ static int connect_bus(DBusConnection **_bus) {
if (!dbus_connection_register_object_path(bus, "/org/freedesktop/hostname1", &hostname_vtable, NULL) ||
!dbus_connection_add_filter(bus, bus_exit_idle_filter, &remain_until, NULL)) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto fail;
}
diff --git a/src/journal/cat.c b/src/journal/cat.c
index cdd46bcf5b..523a7a2eda 100644
--- a/src/journal/cat.c
+++ b/src/journal/cat.c
@@ -91,10 +91,8 @@ static int parse_argv(int argc, char *argv[]) {
arg_identifier = NULL;
else {
arg_identifier = strdup(optarg);
- if (!arg_identifier) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!arg_identifier)
+ return log_oom();
}
break;
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index cfd3a910d9..a507fc65f8 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -239,8 +239,7 @@ int main(int argc, char* argv[]) {
p = malloc(9 + COREDUMP_MAX);
if (!p) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index a9cf9cd957..c924afbccc 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -256,8 +256,7 @@ static int add_matches(sd_journal *j, char **args) {
t = strappend("_EXE=", path);
if (!t) {
free(p);
- log_error("Out of memory.");
- return -ENOMEM;
+ return log_oom();
}
r = sd_journal_add_match(j, t, 0);
diff --git a/src/journal/journald.c b/src/journal/journald.c
index ae1fbc4bd4..5602e362df 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -393,7 +393,7 @@ static void server_vacuum(Server *s) {
if (s->system_journal) {
if (asprintf(&p, "/var/log/journal/%s", ids) < 0) {
- log_error("Out of memory.");
+ log_oom();
return;
}
@@ -405,7 +405,7 @@ static void server_vacuum(Server *s) {
if (s->runtime_journal) {
if (asprintf(&p, "/run/log/journal/%s", ids) < 0) {
- log_error("Out of memory.");
+ log_oom();
return;
}
@@ -1270,7 +1270,7 @@ static void process_native_message(
u = MAX((n+N_IOVEC_META_FIELDS+1) * 2U, 4U);
c = realloc(iovec, u * sizeof(struct iovec));
if (!c) {
- log_error("Out of memory.");
+ log_oom();
break;
}
@@ -1357,7 +1357,7 @@ static void process_native_message(
k = malloc((e - p) + 1 + l);
if (!k) {
- log_error("Out of memory.");
+ log_oom();
break;
}
@@ -1450,7 +1450,7 @@ static void process_native_file(
p = malloc(st.st_size);
if (!p) {
- log_error("Out of memory.");
+ log_oom();
return;
}
@@ -1542,10 +1542,8 @@ static int stdout_stream_line(StdoutStream *s, char *p) {
s->identifier = NULL;
else {
s->identifier = strdup(p);
- if (!s->identifier) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!s->identifier)
+ return log_oom();
}
s->state = STDOUT_STREAM_UNIT_ID;
@@ -1557,10 +1555,8 @@ static int stdout_stream_line(StdoutStream *s, char *p) {
s->unit_id = NULL;
else {
s->unit_id = strdup(p);
- if (!s->unit_id) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!s->unit_id)
+ return log_oom();
}
}
@@ -1761,9 +1757,8 @@ static int stdout_stream_new(Server *s) {
stream = new0(StdoutStream, 1);
if (!stream) {
- log_error("Out of memory.");
close_nointr_nofail(fd);
- return -ENOMEM;
+ return log_oom();
}
stream->fd = fd;
@@ -2753,10 +2748,8 @@ static int server_init(Server *s) {
server_parse_proc_cmdline(s);
s->user_journals = hashmap_new(trivial_hash_func, trivial_compare_func);
- if (!s->user_journals) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!s->user_journals)
+ return log_oom();
s->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (s->epoll_fd < 0) {
diff --git a/src/locale/localed.c b/src/locale/localed.c
index b8007d72fd..22950a60a9 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -425,7 +425,7 @@ static void push_data(DBusConnection *bus) {
l_set = new0(char*, _PROP_MAX);
l_unset = new0(char*, _PROP_MAX);
if (!l_set || !l_unset) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
@@ -438,7 +438,7 @@ static void push_data(DBusConnection *bus) {
char *s;
if (asprintf(&s, "%s=%s", names[p], data[p]) < 0) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
@@ -456,30 +456,30 @@ static void push_data(DBusConnection *bus) {
dbus_message_iter_init_append(m, &iter);
if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
STRV_FOREACH(t, l_unset)
if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
if (!dbus_message_iter_close_container(&iter, &sub) ||
!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
STRV_FOREACH(t, l_set)
if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
if (!dbus_message_iter_close_container(&iter, &sub)) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
@@ -1344,8 +1344,7 @@ static int connect_bus(DBusConnection **_bus) {
if (!dbus_connection_register_object_path(bus, "/org/freedesktop/locale1", &locale_vtable, NULL) ||
!dbus_connection_add_filter(bus, bus_exit_idle_filter, &remain_until, NULL)) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto fail;
}
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index 62e0c3dbba..d023294a59 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -107,10 +107,8 @@ int button_open(Button *b) {
}
p = strappend("/dev/input/", b->name);
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
b->fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
free(p);
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index a43ecad2b1..16d4955d5d 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -374,10 +374,8 @@ static int session_link_x11_socket(Session *s) {
k = strspn(s->display+1, "0123456789");
f = new(char, sizeof("/tmp/.X11-unix/X") + k);
- if (!f) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!f)
+ return log_oom();
c = stpcpy(f, "/tmp/.X11-unix/X");
memcpy(c, s->display+1, k);
@@ -395,9 +393,8 @@ static int session_link_x11_socket(Session *s) {
t = strappend(s->user->runtime_path, "/X11-display");
if (!t) {
- log_error("Out of memory.");
free(f);
- return -ENOMEM;
+ return log_oom();
}
if (link(f, t) < 0) {
@@ -468,10 +465,8 @@ static int session_create_cgroup(Session *s) {
assert(s->user->cgroup_path);
if (!s->cgroup_path) {
- if (asprintf(&p, "%s/%s", s->user->cgroup_path, s->id) < 0) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (asprintf(&p, "%s/%s", s->user->cgroup_path, s->id) < 0)
+ return log_oom();
} else
p = s->cgroup_path;
@@ -669,10 +664,8 @@ static int session_unlink_x11_socket(Session *s) {
s->user->display = NULL;
t = strappend(s->user->runtime_path, "/X11-display");
- if (!t) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!t)
+ return log_oom();
r = unlink(t);
free(t);
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index fca68159a7..aa9c3f1a31 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -259,10 +259,8 @@ static int user_mkdir_runtime_path(User *u) {
}
if (!u->runtime_path) {
- if (asprintf(&p, "/run/user/%lu", (unsigned long) u->uid) < 0) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (asprintf(&p, "/run/user/%lu", (unsigned long) u->uid) < 0)
+ return log_oom();
} else
p = u->runtime_path;
@@ -286,10 +284,8 @@ static int user_create_cgroup(User *u) {
assert(u);
if (!u->cgroup_path) {
- if (asprintf(&p, "%s/%s", u->manager->cgroup_path, u->name) < 0) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (asprintf(&p, "%s/%s", u->manager->cgroup_path, u->name) < 0)
+ return log_oom();
} else
p = u->cgroup_path;
diff --git a/src/login/logind.c b/src/login/logind.c
index 1cfb7fa9ac..bae9a95f38 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1020,10 +1020,8 @@ int manager_get_session_by_cgroup(Manager *m, const char *cgroup, Session **sess
}
p = strdup(cgroup);
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
for (;;) {
char *e;
@@ -1061,10 +1059,8 @@ int manager_get_user_by_cgroup(Manager *m, const char *cgroup, User **user) {
}
p = strdup(cgroup);
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
for (;;) {
char *e;
@@ -1176,8 +1172,7 @@ static int manager_connect_bus(Manager *m) {
!dbus_connection_register_fallback(m->bus, "/org/freedesktop/login1/session", &bus_session_vtable, m) ||
!dbus_connection_register_fallback(m->bus, "/org/freedesktop/login1/user", &bus_user_vtable, m) ||
!dbus_connection_add_filter(m->bus, bus_message_filter, m, NULL)) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto fail;
}
@@ -1611,8 +1606,7 @@ int main(int argc, char *argv[]) {
m = manager_new();
if (!m) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/login/multi-seat-x.c b/src/login/multi-seat-x.c
index a1fab86f6a..59f70882d4 100644
--- a/src/login/multi-seat-x.c
+++ b/src/login/multi-seat-x.c
@@ -97,7 +97,7 @@ int main(int argc, char *argv[]) {
device_node = strdup(dn);
if (!device_node) {
udev_device_unref(d);
- log_error("Out of memory.");
+ log_oom();
goto fail;
}
}
@@ -121,7 +121,7 @@ int main(int argc, char *argv[]) {
path = strappend("/run/systemd/multi-session-x/", seat);
if (!path) {
- log_error("Out of memory.");
+ log_oom();
goto fail;
}
diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c
index e73ba7f241..6aeaf459af 100644
--- a/src/modules-load/modules-load.c
+++ b/src/modules-load/modules-load.c
@@ -49,17 +49,13 @@ static int add_modules(const char *p) {
char **t, **k;
k = strv_split(p, ",");
- if (!k) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!k)
+ return log_oom();
t = strv_merge(arg_proc_cmdline_modules, k);
strv_free(k);
- if (!t) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!t)
+ return log_oom();
strv_free(arg_proc_cmdline_modules);
arg_proc_cmdline_modules = t;
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 355a103edf..b9fa02dc76 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -205,10 +205,8 @@ static int parse_argv(int argc, char *argv[]) {
char *t;
t = strndup(word, length);
- if (!t) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!t)
+ return log_oom();
if (cap_from_name(t, &cap) < 0) {
log_error("Failed to parse capability %s.", t);
@@ -289,7 +287,7 @@ static int mount_all(const char *dest) {
int t;
if (asprintf(&where, "%s/%s", dest, mount_table[k].where) < 0) {
- log_error("Out of memory.");
+ log_oom();
if (r == 0)
r = -ENOMEM;
@@ -335,20 +333,16 @@ static int setup_timezone(const char *dest) {
assert(dest);
/* Fix the timezone, if possible */
- if (asprintf(&where, "%s/etc/localtime", dest) < 0) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (asprintf(&where, "%s/etc/localtime", dest) < 0)
+ return log_oom();
if (mount("/etc/localtime", where, "bind", MS_BIND, NULL) >= 0)
mount("/etc/localtime", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
free(where);
- if (asprintf(&where, "%s/etc/timezone", dest) < 0) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (asprintf(&where, "%s/etc/timezone", dest) < 0)
+ return log_oom();
if (mount("/etc/timezone", where, "bind", MS_BIND, NULL) >= 0)
mount("/etc/timezone", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
@@ -368,8 +362,7 @@ static int setup_resolv_conf(const char *dest) {
/* Fix resolv.conf, if possible */
if (asprintf(&where, "%s/etc/resolv.conf", dest) < 0) {
- log_error("Out of memory.");
- return -ENOMEM;
+ return log_oom();
}
if (mount("/etc/resolv.conf", where, "bind", MS_BIND, NULL) >= 0)
@@ -480,8 +473,7 @@ static int setup_dev_console(const char *dest, const char *console) {
}
if (asprintf(&to, "%s/dev/console", dest) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -535,14 +527,12 @@ static int setup_kmsg(const char *dest, int kmsg_socket) {
* avoid any problems with containers deadlocking due to this
* we simply make /dev/kmsg unavailable to the container. */
if (asprintf(&from, "%s/dev/kmsg", dest) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
if (asprintf(&to, "%s/proc/kmsg", dest) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -639,8 +629,7 @@ static int setup_journal(const char *directory) {
p = strappend(directory, "/etc/machine-id");
if (!p) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -670,8 +659,7 @@ static int setup_journal(const char *directory) {
p = strappend("/var/log/journal/", l);
q = strjoin(directory, "/var/log/journal/", l, NULL);
if (!p || !q) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -1296,13 +1284,13 @@ int main(int argc, char *argv[]) {
if ((asprintf((char**)(envp + 3), "HOME=%s", home ? home: "/root") < 0) ||
(asprintf((char**)(envp + 4), "USER=%s", arg_user ? arg_user : "root") < 0) ||
(asprintf((char**)(envp + 5), "LOGNAME=%s", arg_user ? arg_user : "root") < 0)) {
- log_error("Out of memory.");
+ log_oom();
goto child_fail;
}
if (arg_uuid) {
if (asprintf((char**)(envp + 6), "container_uuid=%s", arg_uuid) < 0) {
- log_error("Out of memory.");
+ log_oom();
goto child_fail;
}
}
diff --git a/src/rc-local-generator/rc-local-generator.c b/src/rc-local-generator/rc-local-generator.c
index 9fafa29f22..c219e77047 100644
--- a/src/rc-local-generator/rc-local-generator.c
+++ b/src/rc-local-generator/rc-local-generator.c
@@ -48,8 +48,7 @@ static int add_symlink(const char *service, const char *where) {
asprintf(&to, "%s/%s.wants/%s", arg_dest, where, service);
if (!from || !to) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index 45d489a60e..4fcf64c24d 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -242,8 +242,7 @@ static int collect(const char *root) {
assert(root);
if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -477,8 +476,7 @@ done:
log_debug("On btrfs: %s", yes_no(on_btrfs));
if (asprintf(&pack_fn_new, "%s/.readahead.new", root) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -510,8 +508,7 @@ done:
n = hashmap_size(files);
if (!(ordered = new(struct item, n))) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/readahead/readahead-replay.c b/src/readahead/readahead-replay.c
index f90821e831..a1ac6b0c91 100644
--- a/src/readahead/readahead-replay.c
+++ b/src/readahead/readahead-replay.c
@@ -150,8 +150,7 @@ static int replay(const char *root) {
block_bump_request_nr(root);
if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
index 8b3aaeb32c..636c46f0f3 100644
--- a/src/remount-fs/remount-fs.c
+++ b/src/remount-fs/remount-fs.c
@@ -114,7 +114,7 @@ int main(int argc, char *argv[]) {
s = strdup(me->mnt_dir);
if (!s) {
- log_error("Out of memory.");
+ log_oom();
ret = EXIT_FAILURE;
continue;
}
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;
}
diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c
index 9dd1336133..d426d9833d 100644
--- a/src/shutdownd/shutdownd.c
+++ b/src/shutdownd/shutdownd.c
@@ -212,10 +212,8 @@ static int update_schedule_file(struct sd_shutdown_command *c) {
}
t = cescape(c->wall_message);
- if (!t) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!t)
+ return log_oom();
r = fopen_temporary("/run/systemd/shutdown/scheduled", &f, &temp_path);
if (r < 0) {
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index b463c7fac7..3bfc454c04 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -45,10 +45,8 @@ static int apply_sysctl(const char *property, const char *value) {
log_debug("Setting '%s' to '%s'", property, value);
p = new(char, sizeof(PROC_SYS_PREFIX) + strlen(property));
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
n = stpcpy(p, PROC_SYS_PREFIX);
strcpy(n, property);
@@ -191,10 +189,8 @@ static int parse_argv(int argc, char *argv[]) {
*p = '/';
l = strv_append(arg_prefixes, optarg);
- if (!l) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!l)
+ return log_oom();
strv_free(arg_prefixes);
arg_prefixes = l;
diff --git a/src/system-update-generator/system-update-generator.c b/src/system-update-generator/system-update-generator.c
index abda5a0190..6660192f5e 100644
--- a/src/system-update-generator/system-update-generator.c
+++ b/src/system-update-generator/system-update-generator.c
@@ -47,10 +47,8 @@ static int generate_symlink(void) {
}
p = strappend(arg_dest, "/default.target");
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
if (symlink(SYSTEM_DATA_UNIT_PATH "/system-update.target", p) < 0) {
free(p);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index d493733761..ef8ab2dc14 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -657,10 +657,8 @@ static int list_unit_files(DBusConnection *bus, char **args) {
Iterator i;
h = hashmap_new(string_hash_func, string_compare_func);
- if (!h) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!h)
+ return log_oom();
r = unit_file_get_list(arg_scope, arg_root, h);
if (r < 0) {
@@ -673,8 +671,7 @@ static int list_unit_files(DBusConnection *bus, char **args) {
units = new(UnitFileList, n_units);
if (!units) {
unit_file_list_free(h);
- log_error("Out of memory.");
- return -ENOMEM;
+ return log_oom();
}
HASHMAP_FOREACH(u, h, i) {
@@ -2630,14 +2627,14 @@ static void show_unit_help(UnitStatusInfo *i) {
if (e) {
page = strndup((*p) + 4, e - *p - 4);
if (!page) {
- log_error("Out of memory.");
+ log_oom();
return;
}
section = strndup(e + 1, *p + k - e - 2);
if (!section) {
free(page);
- log_error("Out of memory.");
+ log_oom();
return;
}
@@ -3282,10 +3279,8 @@ static int show(DBusConnection *bus, char **args) {
n = unit_name_mangle(*name);
p = unit_dbus_path_from_name(n ? n : *name);
free(n);
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
r = show_one(args[0], bus, p, show_properties, &new_line);
free(p);
@@ -3298,10 +3293,8 @@ static int show(DBusConnection *bus, char **args) {
/* Interpret as job id */
char *p;
- if (asprintf(&p, "/org/freedesktop/systemd1/job/%u", id) < 0) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (asprintf(&p, "/org/freedesktop/systemd1/job/%u", id) < 0)
+ return log_oom();
r = show_one(args[0], bus, p, show_properties, &new_line);
free(p);
@@ -3974,8 +3967,7 @@ static int enable_sysv_units(char **args) {
asprintf(&p, "%s/%s", *k, name);
if (!p) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -3995,8 +3987,7 @@ static int enable_sysv_units(char **args) {
else
asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name);
if (!p) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -4024,10 +4015,9 @@ static int enable_sysv_units(char **args) {
l = strv_join((char**)argv, " ");
if (!l) {
- log_error("Out of memory.");
free(q);
free(p);
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -4184,8 +4174,7 @@ static int enable_unit(DBusConnection *bus, char **args) {
"org.freedesktop.systemd1.Manager",
method);
if (!m) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -4339,8 +4328,7 @@ static int unit_is_enabled(DBusConnection *bus, char **args) {
"org.freedesktop.systemd1.Manager",
"GetUnitFileState");
if (!m) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 3fef9e8844..09fd808332 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -153,7 +153,7 @@ static void verify_timezone(void) {
p = strappend("/usr/share/zoneinfo/", tz.zone);
if (!p) {
- log_error("Out of memory.");
+ log_oom();
return;
}
@@ -219,10 +219,8 @@ static int write_data_timezone(void) {
}
p = strappend("/usr/share/zoneinfo/", tz.zone);
- if (!p) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!p)
+ return log_oom();
r = symlink_or_copy_atomic(p, "/etc/localtime");
free(p);
@@ -341,7 +339,7 @@ static char** get_ntp_services(void) {
q = strv_append(r, l);
if (!q) {
- log_error("Out of memory.");
+ log_oom();
break;
}
@@ -379,16 +377,14 @@ static int read_ntp(DBusConnection *bus) {
"org.freedesktop.systemd1.Manager",
"GetUnitFileState");
if (!m) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
if (!dbus_message_append_args(m,
DBUS_TYPE_STRING, i,
DBUS_TYPE_INVALID)) {
- log_error("Could not append arguments to message.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -943,8 +939,7 @@ static int connect_bus(DBusConnection **_bus) {
if (!dbus_connection_register_object_path(bus, "/org/freedesktop/timedate1", &timedate_vtable, NULL) ||
!dbus_connection_add_filter(bus, bus_exit_idle_filter, &remain_until, NULL)) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto fail;
}
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index f8d89218c9..e70332ca06 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -260,8 +260,7 @@ static int dir_cleanup(
sub_path = NULL;
if (asprintf(&sub_path, "%s/%s", p, dent->d_name) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -969,10 +968,8 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
assert(buffer);
i = new0(Item, 1);
- if (!i) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!i)
+ return log_oom();
if (sscanf(buffer,
"%c "
@@ -998,10 +995,8 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
n += strspn(buffer+n, WHITESPACE);
if (buffer[n] != 0 && (buffer[n] != '-' || buffer[n+1] != 0)) {
i->argument = unquote(buffer+n, "\"");
- if (!i->argument) {
- log_error("Out of memory.");
- return -ENOMEM;
- }
+ if (!i->argument)
+ return log_oom();
}
}
@@ -1302,7 +1297,7 @@ static char *resolve_fragment(const char *fragment, const char **search_paths) {
STRV_FOREACH(p, search_paths) {
resolved_path = strjoin(*p, "/", fragment, NULL);
if (resolved_path == NULL) {
- log_error("Out of memory.");
+ log_oom();
return NULL;
}
@@ -1337,7 +1332,7 @@ int main(int argc, char *argv[]) {
globs = hashmap_new(string_hash_func, string_compare_func);
if (!items || !globs) {
- log_error("Out of memory.");
+ log_oom();
r = EXIT_FAILURE;
goto finish;
}
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index 403e8cd3c6..052c10e7d5 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -315,8 +315,7 @@ static int parse_password(const char *filename, char **wall) {
*wall ? "\r\n\r\n" : "",
message,
pid) < 0) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
@@ -533,8 +532,7 @@ static int show_passwords(void) {
continue;
if (!(p = strappend("/run/systemd/ask-password/", de->d_name))) {
- log_error("Out of memory.");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
index 0bb1bc495a..b1e089cb7c 100644
--- a/src/udev/scsi_id/scsi_id.c
+++ b/src/udev/scsi_id/scsi_id.c
@@ -198,8 +198,7 @@ static int get_file_options(struct udev *udev,
buffer = malloc(MAX_BUFFER_LEN);
if (!buffer) {
fclose(fd);
- log_error("Out of memory.");
- return -1;
+ return log_oom();
}
*newargv = NULL;
@@ -231,7 +230,7 @@ static int get_file_options(struct udev *udev,
if (str1 && strcasecmp(str1, "VENDOR") == 0) {
str1 = get_value(&buf);
if (!str1) {
- retval = -1;
+ retval = log_oom();
break;
}
vendor_in = str1;
@@ -240,7 +239,7 @@ static int get_file_options(struct udev *udev,
if (str1 && strcasecmp(str1, "MODEL") == 0) {
str1 = get_value(&buf);
if (!str1) {
- retval = -1;
+ retval = log_oom();
break;
}
model_in = str1;
@@ -251,7 +250,7 @@ static int get_file_options(struct udev *udev,
if (str1 && strcasecmp(str1, "OPTIONS") == 0) {
str1 = get_value(&buf);
if (!str1) {
- retval = -1;
+ retval = log_oom();
break;
}
options_in = str1;
@@ -294,8 +293,7 @@ static int get_file_options(struct udev *udev,
c = argc_count(buffer) + 2;
*newargv = calloc(c, sizeof(**newargv));
if (!*newargv) {
- log_error("Out of memory.");
- retval = -1;
+ retval = log_oom();
} else {
*argc = c;
c = 0;
diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c
index 7679d446e3..62d9c8d7b5 100644
--- a/src/vconsole/vconsole-setup.c
+++ b/src/vconsole/vconsole-setup.c
@@ -274,7 +274,7 @@ int main(int argc, char **argv) {
t = strdup("/etc/sysconfig/console/default.kmap");
if (!t) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
@@ -415,7 +415,7 @@ int main(int argc, char **argv) {
free(vc_keytable);
if (!vc_keymap) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}
}
@@ -425,7 +425,7 @@ int main(int argc, char **argv) {
t = strdup("/etc/sysconfig/console/default.kmap");
if (!t) {
- log_error("Out of memory.");
+ log_oom();
goto finish;
}