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
This commit is contained in:
Shawn Landden 2012-07-25 14:55:59 -07:00 committed by Kay Sievers
parent e146e4516b
commit 0d0f0c50d3
40 changed files with 183 additions and 310 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -297,7 +297,7 @@ int main(int argc, char *argv[]) {
}
if (!(udev = udev_new())) {
log_error("Out of memory.");
log_oom();
goto finish;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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)

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}