From dce818b390a857a11f7dd634684500675cf79833 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 12 Apr 2012 17:15:18 +0200 Subject: move all tools to subdirs --- src/cgtop/cgtop.c | 729 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 729 insertions(+) create mode 100644 src/cgtop/cgtop.c (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c new file mode 100644 index 0000000000..1fe247c667 --- /dev/null +++ b/src/cgtop/cgtop.c @@ -0,0 +1,729 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "hashmap.h" +#include "cgroup-util.h" + +typedef struct Group { + char *path; + + bool n_tasks_valid:1; + bool cpu_valid:1; + bool memory_valid:1; + bool io_valid:1; + + unsigned n_tasks; + + unsigned cpu_iteration; + uint64_t cpu_usage; + struct timespec cpu_timestamp; + double cpu_fraction; + + uint64_t memory; + + unsigned io_iteration; + uint64_t io_input, io_output; + struct timespec io_timestamp; + uint64_t io_input_bps, io_output_bps; +} Group; + +static unsigned arg_depth = 2; +static usec_t arg_delay = 1*USEC_PER_SEC; + +static enum { + ORDER_PATH, + ORDER_TASKS, + ORDER_CPU, + ORDER_MEMORY, + ORDER_IO +} arg_order = ORDER_CPU; + +static void group_free(Group *g) { + assert(g); + + free(g->path); + free(g); +} + +static void group_hashmap_clear(Hashmap *h) { + Group *g; + + while ((g = hashmap_steal_first(h))) + group_free(g); +} + +static void group_hashmap_free(Hashmap *h) { + group_hashmap_clear(h); + hashmap_free(h); +} + +static int process(const char *controller, const char *path, Hashmap *a, Hashmap *b, unsigned iteration) { + Group *g; + int r; + FILE *f; + pid_t pid; + unsigned n; + + assert(controller); + assert(path); + assert(a); + + g = hashmap_get(a, path); + if (!g) { + g = hashmap_get(b, path); + if (!g) { + g = new0(Group, 1); + if (!g) + return -ENOMEM; + + g->path = strdup(path); + if (!g->path) { + group_free(g); + return -ENOMEM; + } + + r = hashmap_put(a, g->path, g); + if (r < 0) { + group_free(g); + return r; + } + } else { + assert_se(hashmap_move_one(a, b, path) == 0); + g->cpu_valid = g->memory_valid = g->io_valid = g->n_tasks_valid = false; + } + } + + /* Regardless which controller, let's find the maximum number + * of processes in any of it */ + + r = cg_enumerate_tasks(controller, path, &f); + if (r < 0) + return r; + + n = 0; + while (cg_read_pid(f, &pid) > 0) + n++; + fclose(f); + + if (n > 0) { + if (g->n_tasks_valid) + g->n_tasks = MAX(g->n_tasks, n); + else + g->n_tasks = n; + + g->n_tasks_valid = true; + } + + if (streq(controller, "cpuacct")) { + uint64_t new_usage; + char *p, *v; + struct timespec ts; + + r = cg_get_path(controller, path, "cpuacct.usage", &p); + if (r < 0) + return r; + + r = read_one_line_file(p, &v); + free(p); + if (r < 0) + return r; + + r = safe_atou64(v, &new_usage); + free(v); + if (r < 0) + return r; + + assert_se(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); + + if (g->cpu_iteration == iteration - 1) { + uint64_t x, y; + + x = ((uint64_t) ts.tv_sec * 1000000000ULL + (uint64_t) ts.tv_nsec) - + ((uint64_t) g->cpu_timestamp.tv_sec * 1000000000ULL + (uint64_t) g->cpu_timestamp.tv_nsec); + + y = new_usage - g->cpu_usage; + + if (y > 0) { + g->cpu_fraction = (double) y / (double) x; + g->cpu_valid = true; + } + } + + g->cpu_usage = new_usage; + g->cpu_timestamp = ts; + g->cpu_iteration = iteration; + + } else if (streq(controller, "memory")) { + char *p, *v; + + r = cg_get_path(controller, path, "memory.usage_in_bytes", &p); + if (r < 0) + return r; + + r = read_one_line_file(p, &v); + free(p); + if (r < 0) + return r; + + r = safe_atou64(v, &g->memory); + free(v); + if (r < 0) + return r; + + if (g->memory > 0) + g->memory_valid = true; + + } else if (streq(controller, "blkio")) { + char *p; + uint64_t wr = 0, rd = 0; + struct timespec ts; + + r = cg_get_path(controller, path, "blkio.io_service_bytes", &p); + if (r < 0) + return r; + + f = fopen(p, "re"); + free(p); + + if (!f) + return -errno; + + for (;;) { + char line[LINE_MAX], *l; + uint64_t k, *q; + + if (!fgets(line, sizeof(line), f)) + break; + + l = strstrip(line); + l += strcspn(l, WHITESPACE); + l += strspn(l, WHITESPACE); + + if (first_word(l, "Read")) { + l += 4; + q = &rd; + } else if (first_word(l, "Write")) { + l += 5; + q = ≀ + } else + continue; + + l += strspn(l, WHITESPACE); + r = safe_atou64(l, &k); + if (r < 0) + continue; + + *q += k; + } + + fclose(f); + + assert_se(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); + + if (g->io_iteration == iteration - 1) { + uint64_t x, yr, yw; + + x = ((uint64_t) ts.tv_sec * 1000000000ULL + (uint64_t) ts.tv_nsec) - + ((uint64_t) g->io_timestamp.tv_sec * 1000000000ULL + (uint64_t) g->io_timestamp.tv_nsec); + + yr = rd - g->io_input; + yw = wr - g->io_output; + + if (yr > 0 || yw > 0) { + g->io_input_bps = (yr * 1000000000ULL) / x; + g->io_output_bps = (yw * 1000000000ULL) / x; + g->io_valid = true; + + } + } + + g->io_input = rd; + g->io_output = wr; + g->io_timestamp = ts; + g->io_iteration = iteration; + } + + return 0; +} + +static int refresh_one( + const char *controller, + const char *path, + Hashmap *a, + Hashmap *b, + unsigned iteration, + unsigned depth) { + + DIR *d = NULL; + int r; + + assert(controller); + assert(path); + assert(a); + + if (depth > arg_depth) + return 0; + + r = process(controller, path, a, b, iteration); + if (r < 0) + return r; + + r = cg_enumerate_subgroups(controller, path, &d); + if (r < 0) { + if (r == ENOENT) + return 0; + + return r; + } + + for (;;) { + char *fn, *p; + + r = cg_read_subgroup(d, &fn); + if (r <= 0) + goto finish; + + p = join(path, "/", fn, NULL); + free(fn); + + if (!p) { + r = -ENOMEM; + goto finish; + } + + path_kill_slashes(p); + + r = refresh_one(controller, p, a, b, iteration, depth + 1); + free(p); + + if (r < 0) + goto finish; + } + +finish: + if (d) + closedir(d); + + return r; +} + +static int refresh(Hashmap *a, Hashmap *b, unsigned iteration) { + int r; + + assert(a); + + r = refresh_one("name=systemd", "/", a, b, iteration, 0); + if (r < 0) + return r; + + r = refresh_one("cpuacct", "/", a, b, iteration, 0); + if (r < 0) + return r; + + r = refresh_one("memory", "/", a, b, iteration, 0); + if (r < 0) + return r; + + return refresh_one("blkio", "/", a, b, iteration, 0); +} + +static int group_compare(const void*a, const void *b) { + const Group *x = *(Group**)a, *y = *(Group**)b; + + if (path_startswith(y->path, x->path)) + return -1; + if (path_startswith(x->path, y->path)) + return 1; + + if (arg_order == ORDER_CPU) { + if (x->cpu_valid && y->cpu_valid) { + + if (x->cpu_fraction > y->cpu_fraction) + return -1; + else if (x->cpu_fraction < y->cpu_fraction) + return 1; + } else if (x->cpu_valid) + return -1; + else if (y->cpu_valid) + return 1; + } + + if (arg_order == ORDER_TASKS) { + + if (x->n_tasks_valid && y->n_tasks_valid) { + if (x->n_tasks > y->n_tasks) + return -1; + else if (x->n_tasks < y->n_tasks) + return 1; + } else if (x->n_tasks_valid) + return -1; + else if (y->n_tasks_valid) + return 1; + } + + if (arg_order == ORDER_MEMORY) { + if (x->memory_valid && y->memory_valid) { + if (x->memory > y->memory) + return -1; + else if (x->memory < y->memory) + return 1; + } else if (x->memory_valid) + return -1; + else if (y->memory_valid) + return 1; + } + + if (arg_order == ORDER_IO) { + if (x->io_valid && y->io_valid) { + if (x->io_input_bps + x->io_output_bps > y->io_input_bps + y->io_output_bps) + return -1; + else if (x->io_input_bps + x->io_output_bps < y->io_input_bps + y->io_output_bps) + return 1; + } else if (x->io_valid) + return -1; + else if (y->io_valid) + return 1; + } + + return strcmp(x->path, y->path); +} + +static int display(Hashmap *a) { + Iterator i; + Group *g; + Group **array; + unsigned rows, n = 0, j; + + assert(a); + + /* Set cursor to top left corner and clear screen */ + fputs("\033[H" + "\033[2J", stdout); + + array = alloca(sizeof(Group*) * hashmap_size(a)); + + HASHMAP_FOREACH(g, a, i) + if (g->n_tasks_valid || g->cpu_valid || g->memory_valid || g->io_valid) + array[n++] = g; + + qsort(array, n, sizeof(Group*), group_compare); + + rows = fd_lines(STDOUT_FILENO); + if (rows <= 0) + rows = 25; + + printf("%s%-37s%s %s%7s%s %s%6s%s %s%8s%s %s%8s%s %s%8s%s\n\n", + arg_order == ORDER_PATH ? ANSI_HIGHLIGHT_ON : "", "Path", arg_order == ORDER_PATH ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_TASKS ? ANSI_HIGHLIGHT_ON : "", "Tasks", arg_order == ORDER_TASKS ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_CPU ? ANSI_HIGHLIGHT_ON : "", "%CPU", arg_order == ORDER_CPU ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_MEMORY ? ANSI_HIGHLIGHT_ON : "", "Memory", arg_order == ORDER_MEMORY ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_IO ? ANSI_HIGHLIGHT_ON : "", "Input/s", arg_order == ORDER_IO ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_IO ? ANSI_HIGHLIGHT_ON : "", "Output/s", arg_order == ORDER_IO ? ANSI_HIGHLIGHT_OFF : ""); + + for (j = 0; j < n; j++) { + char *p; + char m[FORMAT_BYTES_MAX]; + + if (j + 5 > rows) + break; + + g = array[j]; + + p = ellipsize(g->path, 37, 33); + printf("%-37s", p ? p : g->path); + free(p); + + if (g->n_tasks_valid) + printf(" %7u", g->n_tasks); + else + fputs(" -", stdout); + + if (g->cpu_valid) + printf(" %6.1f", g->cpu_fraction*100); + else + fputs(" -", stdout); + + if (g->memory_valid) + printf(" %8s", format_bytes(m, sizeof(m), g->memory)); + else + fputs(" -", stdout); + + if (g->io_valid) { + printf(" %8s", + format_bytes(m, sizeof(m), g->io_input_bps)); + printf(" %8s", + format_bytes(m, sizeof(m), g->io_output_bps)); + } else + fputs(" - -", stdout); + + putchar('\n'); + } + + return 0; +} + +static void help(void) { + + printf("%s [OPTIONS...]\n\n" + "Show top control groups by their resource usage.\n\n" + " -h --help Show this help\n" + " -p Order by path\n" + " -t Order by number of tasks\n" + " -c Order by CPU load\n" + " -m Order by memory load\n" + " -i Order by IO load\n" + " -d --delay=DELAY Specify delay\n" + " --depth=DEPTH Maximum traversal depth (default: 2)\n", + program_invocation_short_name); +} + +static int parse_argv(int argc, char *argv[]) { + + enum { + ARG_DEPTH = 0x100 + }; + + static const struct option options[] = { + { "help", no_argument, NULL, 'h' }, + { "delay", required_argument, NULL, 'd' }, + { "depth", required_argument, NULL, ARG_DEPTH }, + { NULL, 0, NULL, 0 } + }; + + int c; + int r; + + assert(argc >= 1); + assert(argv); + + while ((c = getopt_long(argc, argv, "hptcmid:", options, NULL)) >= 0) { + + switch (c) { + + case 'h': + help(); + return 0; + + case ARG_DEPTH: + r = safe_atou(optarg, &arg_depth); + if (r < 0) { + log_error("Failed to parse depth parameter."); + return -EINVAL; + } + + break; + + case 'd': + r = parse_usec(optarg, &arg_delay); + if (r < 0 || arg_delay <= 0) { + log_error("Failed to parse delay parameter."); + return -EINVAL; + } + + break; + + case 'p': + arg_order = ORDER_PATH; + break; + + case 't': + arg_order = ORDER_TASKS; + break; + + case 'c': + arg_order = ORDER_CPU; + break; + + case 'm': + arg_order = ORDER_MEMORY; + break; + + case 'i': + arg_order = ORDER_IO; + break; + + case '?': + return -EINVAL; + + default: + log_error("Unknown option code %c", c); + return -EINVAL; + } + } + + if (optind < argc) { + log_error("Too many arguments."); + return -EINVAL; + } + + return 1; +} + +int main(int argc, char *argv[]) { + int r; + Hashmap *a = NULL, *b = NULL; + unsigned iteration = 0; + usec_t last_refresh = 0; + bool quit = false, immediate_refresh = false; + + log_parse_environment(); + log_open(); + + r = parse_argv(argc, argv); + if (r <= 0) + goto finish; + + 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; + goto finish; + } + + while (!quit) { + Hashmap *c; + usec_t t; + char key; + char h[FORMAT_TIMESPAN_MAX]; + + t = now(CLOCK_MONOTONIC); + + if (t >= last_refresh + arg_delay || immediate_refresh) { + + r = refresh(a, b, iteration++); + if (r < 0) + goto finish; + + group_hashmap_clear(b); + + c = a; + a = b; + b = c; + + last_refresh = t; + immediate_refresh = false; + } + + r = display(b); + if (r < 0) + goto finish; + + r = read_one_char(stdin, &key, last_refresh + arg_delay - t, NULL); + if (r == -ETIMEDOUT) + continue; + if (r < 0) { + log_error("Couldn't read key: %s", strerror(-r)); + goto finish; + } + + fputs("\r \r", stdout); + fflush(stdout); + + switch (key) { + + case ' ': + immediate_refresh = true; + break; + + case 'q': + quit = true; + break; + + case 'p': + arg_order = ORDER_PATH; + break; + + case 't': + arg_order = ORDER_TASKS; + break; + + case 'c': + arg_order = ORDER_CPU; + break; + + case 'm': + arg_order = ORDER_MEMORY; + break; + + case 'i': + arg_order = ORDER_IO; + break; + + case '+': + if (arg_delay < USEC_PER_SEC) + arg_delay += USEC_PER_MSEC*250; + else + arg_delay += USEC_PER_SEC; + + fprintf(stdout, "\nIncreased delay to %s.", format_timespan(h, sizeof(h), arg_delay)); + fflush(stdout); + sleep(1); + break; + + case '-': + if (arg_delay <= USEC_PER_MSEC*500) + arg_delay = USEC_PER_MSEC*250; + else if (arg_delay < USEC_PER_MSEC*1250) + arg_delay -= USEC_PER_MSEC*250; + else + arg_delay -= USEC_PER_SEC; + + fprintf(stdout, "\nDecreased delay to %s.", format_timespan(h, sizeof(h), arg_delay)); + fflush(stdout); + sleep(1); + break; + + case '?': + case 'h': + fprintf(stdout, + "\t<" ANSI_HIGHLIGHT_ON "P" ANSI_HIGHLIGHT_OFF "> By path; <" ANSI_HIGHLIGHT_ON "T" ANSI_HIGHLIGHT_OFF "> By tasks; <" ANSI_HIGHLIGHT_ON "C" ANSI_HIGHLIGHT_OFF "> By CPU; <" ANSI_HIGHLIGHT_ON "M" ANSI_HIGHLIGHT_OFF "> By memory; <" ANSI_HIGHLIGHT_ON "I" ANSI_HIGHLIGHT_OFF "> By I/O\n" + "\t<" ANSI_HIGHLIGHT_ON "Q" ANSI_HIGHLIGHT_OFF "> Quit; <" ANSI_HIGHLIGHT_ON "+" ANSI_HIGHLIGHT_OFF "> Increase delay; <" ANSI_HIGHLIGHT_ON "-" ANSI_HIGHLIGHT_OFF "> Decrease delay; <" ANSI_HIGHLIGHT_ON "SPACE" ANSI_HIGHLIGHT_OFF "> Refresh"); + fflush(stdout); + sleep(3); + break; + + default: + fprintf(stdout, "\nUnknown key '%c'. Ignoring.", key); + fflush(stdout); + sleep(1); + break; + } + } + + log_info("Exiting."); + + r = 0; + +finish: + group_hashmap_free(a); + group_hashmap_free(b); + + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} -- cgit v1.2.3-54-g00ecf From b562f5a57d11d356aab26b08481f3befffff0822 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 13 Apr 2012 21:36:37 +0200 Subject: build-sys: add stub makefiles to all subdirs to ease development with emacs --- .gitignore | 138 ++++++++++++++++++------------------ src/ac-power/Makefile | 1 + src/analyze/Makefile | 1 + src/ask-password/Makefile | 1 + src/cgls/Makefile | 1 + src/cgroups-agent/Makefile | 1 + src/cgtop/Makefile | 1 + src/detect-virt/Makefile | 1 + src/fsck/Makefile | 1 + src/getty-generator/Makefile | 1 + src/gudev/Makefile | 1 + src/initctl/Makefile | 1 + src/libsystemd-daemon/Makefile | 1 + src/libsystemd-id128/Makefile | 1 + src/libudev/Makefile | 1 + src/modules-load/Makefile | 1 + src/notify/Makefile | 1 + src/nspawn/Makefile | 1 + src/quotacheck/Makefile | 1 + src/random-seed/Makefile | 1 + src/rc-local-generator/Makefile | 1 + src/remount-api-vfs/Makefile | 1 + src/reply-password/Makefile | 1 + src/shutdownd/Makefile | 1 + src/stdio-bridge/Makefile | 1 + src/sysctl/Makefile | 1 + src/systemctl/Makefile | 1 + src/timestamp/Makefile | 1 + src/tmpfiles/Makefile | 1 + src/tty-ask-password-agent/Makefile | 1 + src/udev/Makefile | 1 + src/update-utmp/Makefile | 1 + 32 files changed, 99 insertions(+), 70 deletions(-) create mode 120000 src/ac-power/Makefile create mode 120000 src/analyze/Makefile create mode 120000 src/ask-password/Makefile create mode 120000 src/cgls/Makefile create mode 120000 src/cgroups-agent/Makefile create mode 120000 src/cgtop/Makefile create mode 120000 src/detect-virt/Makefile create mode 120000 src/fsck/Makefile create mode 120000 src/getty-generator/Makefile create mode 120000 src/gudev/Makefile create mode 120000 src/initctl/Makefile create mode 120000 src/libsystemd-daemon/Makefile create mode 120000 src/libsystemd-id128/Makefile create mode 120000 src/libudev/Makefile create mode 120000 src/modules-load/Makefile create mode 120000 src/notify/Makefile create mode 120000 src/nspawn/Makefile create mode 120000 src/quotacheck/Makefile create mode 120000 src/random-seed/Makefile create mode 120000 src/rc-local-generator/Makefile create mode 120000 src/remount-api-vfs/Makefile create mode 120000 src/reply-password/Makefile create mode 120000 src/shutdownd/Makefile create mode 120000 src/stdio-bridge/Makefile create mode 120000 src/sysctl/Makefile create mode 120000 src/systemctl/Makefile create mode 120000 src/timestamp/Makefile create mode 120000 src/tmpfiles/Makefile create mode 120000 src/tty-ask-password-agent/Makefile create mode 120000 src/udev/Makefile create mode 120000 src/update-utmp/Makefile (limited to 'src/cgtop') diff --git a/.gitignore b/.gitignore index ba34a3a076..2bfc77c7f8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,73 +6,71 @@ /systemd-cat /systemd-rc-local-generator /libsystemd-id128.pc -journalctl -systemd-journald -test-id128 -test-journal -test-install -org.freedesktop.hostname1.xml -org.freedesktop.locale1.xml -libsystemd-daemon.pc -libsystemd-login.pc -test-login -loginctl -systemd-localed -systemd-timedated -org.freedesktop.timedate1.xml -systemd-logind -systemd-uaccess -systemd-hostnamed -systemd-binfmt -systemd-getty-generator -systemd-nspawn -systemd-stdio-bridge -systemd-machine-id-setup -systemd-detect-virt -systemd-sysctl -test-strv -systemd-ac-power -systemd-timestamp -systemd-cryptsetup -systemd-cryptsetup-generator -systemd-tty-ask-password-agent -systemd-fsck -systemd-quotacheck -systemd-user-sessions -systemd-shutdown -systemd-tmpfiles -systemd-readahead-collect -systemd-readahead-replay -systemd-reply-password -systemd-gnome-ask-password-agent -systemd-ask-password -systemd-kmsg-syslogd -systemd-remount-api-vfs -test-hostname -systemd-modules-load -systemd-vconsole-setup -systemd-shutdownd -systemd-random-seed -systemd-update-utmp -test-env-replace -systemd-cgls -systemd.pc -test-cgroup +/journalctl +/systemd-journald +/test-id128 +/test-journal +/test-install +/org.freedesktop.hostname1.xml +/org.freedesktop.locale1.xml +/libsystemd-daemon.pc +/libsystemd-login.pc +/test-login +/loginctl +/systemd-localed +/systemd-timedated +/org.freedesktop.timedate1.xml +/systemd-logind +/systemd-uaccess +/systemd-hostnamed +/systemd-binfmt +/systemd-getty-generator +/systemd-nspawn +/systemd-stdio-bridge +/systemd-machine-id-setup +/systemd-detect-virt +/systemd-sysctl +/test-strv +/systemd-ac-power +/systemd-timestamp +/systemd-cryptsetup +/systemd-cryptsetup-generator +/systemd-tty-ask-password-agent +/systemd-fsck +/systemd-quotacheck +/systemd-user-sessions +/systemd-shutdown +/systemd-tmpfiles +/systemd-readahead-collect +/systemd-readahead-replay +/systemd-reply-password +/systemd-gnome-ask-password-agent +/systemd-ask-password +/systemd-kmsg-syslogd +/systemd-remount-api-vfs +/test-hostname +/systemd-modules-load +/systemd-vconsole-setup +/systemd-shutdownd +/systemd-random-seed +/systemd-update-utmp +/test-env-replace +/systemd-cgls +/systemd.pc +/test-cgroup .libs/ -systemd-notify -test-daemon -systemd-install -org.freedesktop.systemd1.*.xml -test-ns -test-loopback -systemd-cgroups-agent -systemd-initctl +/systemd-notify +/test-daemon +/org.freedesktop.systemd1.*.xml +/test-ns +/test-loopback +/systemd-cgroups-agent +/systemd-initctl /systemd -test-engine -test-job-type -systemd-stdout-syslog-bridge -systemctl -systemadm +/test-engine +/test-job-type +/systemctl +/systemadm .dirstamp *.1 *.3 @@ -103,11 +101,11 @@ missing stamp-* *.stamp /Makefile -ltmain.sh -*.tar.xz -*.tar.gz -*.tar.bz2 -libtool +/ltmain.sh +/*.tar.xz +/*.tar.gz +/*.tar.bz2 +/libtool /accelerometer /ata_id /cdrom_id diff --git a/src/ac-power/Makefile b/src/ac-power/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/ac-power/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/analyze/Makefile b/src/analyze/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/analyze/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/ask-password/Makefile b/src/ask-password/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/ask-password/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/cgls/Makefile b/src/cgls/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/cgls/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/cgroups-agent/Makefile b/src/cgroups-agent/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/cgroups-agent/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/cgtop/Makefile b/src/cgtop/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/cgtop/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/detect-virt/Makefile b/src/detect-virt/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/detect-virt/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/fsck/Makefile b/src/fsck/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/fsck/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/getty-generator/Makefile b/src/getty-generator/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/getty-generator/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/gudev/Makefile b/src/gudev/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/gudev/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/initctl/Makefile b/src/initctl/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/initctl/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/libsystemd-daemon/Makefile b/src/libsystemd-daemon/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/libsystemd-daemon/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/libsystemd-id128/Makefile b/src/libsystemd-id128/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/libsystemd-id128/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/libudev/Makefile b/src/libudev/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/libudev/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/modules-load/Makefile b/src/modules-load/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/modules-load/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/notify/Makefile b/src/notify/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/notify/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/nspawn/Makefile b/src/nspawn/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/nspawn/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/quotacheck/Makefile b/src/quotacheck/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/quotacheck/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/random-seed/Makefile b/src/random-seed/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/random-seed/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/rc-local-generator/Makefile b/src/rc-local-generator/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/rc-local-generator/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/remount-api-vfs/Makefile b/src/remount-api-vfs/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/remount-api-vfs/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/reply-password/Makefile b/src/reply-password/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/reply-password/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/shutdownd/Makefile b/src/shutdownd/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/shutdownd/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/stdio-bridge/Makefile b/src/stdio-bridge/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/stdio-bridge/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/sysctl/Makefile b/src/sysctl/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/sysctl/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/systemctl/Makefile b/src/systemctl/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/systemctl/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/timestamp/Makefile b/src/timestamp/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/timestamp/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/tmpfiles/Makefile b/src/tmpfiles/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/tmpfiles/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/tty-ask-password-agent/Makefile b/src/tty-ask-password-agent/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/tty-ask-password-agent/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/udev/Makefile b/src/udev/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/udev/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/update-utmp/Makefile b/src/update-utmp/Makefile new file mode 120000 index 0000000000..d0b0e8e008 --- /dev/null +++ b/src/update-utmp/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 9eb977db5b89b44f254ab40c1876a76b7d7ea2d0 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 7 May 2012 21:36:12 +0200 Subject: util: split-out path-util.[ch] --- Makefile.am | 2 + src/cgls/cgls.c | 1 + src/cgtop/cgtop.c | 1 + src/core/automount.c | 1 + src/core/cgroup.c | 1 + src/core/condition.c | 1 + src/core/device.c | 1 + src/core/execute.c | 7 +- src/core/load-fragment.c | 3 +- src/core/manager.c | 3 +- src/core/mount-setup.c | 1 + src/core/mount.c | 1 + src/core/namespace.c | 1 + src/core/path.c | 1 + src/core/service.c | 5 +- src/core/socket.c | 1 + src/core/swap.c | 1 + src/core/umount.c | 1 + src/core/unit.c | 7 +- src/cryptsetup/cryptsetup.c | 1 + src/journal/sd-journal.c | 3 +- src/login/logind-dbus.c | 1 + src/login/logind-inhibit.c | 4 +- src/login/logind-seat.c | 3 +- src/login/logind-session.c | 3 +- src/login/sysfs-show.c | 1 + src/nspawn/nspawn.c | 3 +- src/remount-fs/remount-fs.c | 1 + src/shared/cgroup-show.c | 5 +- src/shared/cgroup-util.c | 3 +- src/shared/conf-files.c | 7 +- src/shared/conf-parser.c | 1 + src/shared/install.c | 11 +- src/shared/label.c | 1 + src/shared/path-lookup.c | 22 +- src/shared/path-util.c | 371 +++++++++++++++++++++ src/shared/path-util.h | 46 +++ src/shared/socket-util.c | 1 + src/shared/unit-name.c | 1 + src/shared/util.c | 350 +------------------ src/shared/util.h | 27 -- src/shared/utmp-wtmp.c | 3 +- src/sysctl/sysctl.c | 1 + src/systemctl/systemctl.c | 10 +- src/test/test-cgroup.c | 1 + src/test/test-install.c | 19 +- src/tmpfiles/tmpfiles.c | 1 + .../tty-ask-password-agent.c | 1 + src/udev/udev-rules.c | 3 +- 49 files changed, 521 insertions(+), 424 deletions(-) create mode 100644 src/shared/path-util.c create mode 100644 src/shared/path-util.h (limited to 'src/cgtop') diff --git a/Makefile.am b/Makefile.am index a6c4988382..dbcfeb384f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -526,6 +526,8 @@ libsystemd_shared_la_SOURCES = \ src/shared/util.h \ src/shared/virt.c \ src/shared/virt.h \ + src/shared/path-util.c \ + src/shared/path-util.h \ src/shared/hashmap.c \ src/shared/hashmap.h \ src/shared/set.c \ diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c index 4bec6a827e..b2cd968e46 100644 --- a/src/cgls/cgls.c +++ b/src/cgls/cgls.c @@ -29,6 +29,7 @@ #include "cgroup-show.h" #include "cgroup-util.h" #include "log.h" +#include "path-util.h" #include "util.h" #include "pager.h" #include "build.h" diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 1fe247c667..cc7a99f3df 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -26,6 +26,7 @@ #include #include +#include "path-util.h" #include "util.h" #include "hashmap.h" #include "cgroup-util.h" diff --git a/src/core/automount.c b/src/core/automount.c index 11c217beb9..c31e3d8bac 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -39,6 +39,7 @@ #include "special.h" #include "label.h" #include "mkdir.h" +#include "path-util.h" static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = { [AUTOMOUNT_DEAD] = UNIT_INACTIVE, diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 713c1ca768..5513f6560c 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -31,6 +31,7 @@ #include "cgroup-util.h" #include "log.h" #include "strv.h" +#include "path-util.h" int cgroup_bonding_realize(CGroupBonding *b) { int r; diff --git a/src/core/condition.c b/src/core/condition.c index 5d44039e5d..e4080d569d 100644 --- a/src/core/condition.c +++ b/src/core/condition.c @@ -33,6 +33,7 @@ #include "util.h" #include "condition.h" #include "virt.h" +#include "path-util.h" Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) { Condition *c; diff --git a/src/core/device.c b/src/core/device.c index 88ce0cdd18..f2bb656397 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -30,6 +30,7 @@ #include "unit-name.h" #include "dbus-device.h" #include "def.h" +#include "path-util.h" static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = { [DEVICE_DEAD] = UNIT_INACTIVE, diff --git a/src/core/execute.c b/src/core/execute.c index 99a7881f1c..953cfa2baa 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -59,6 +59,7 @@ #include "utmp-wtmp.h" #include "def.h" #include "loopback-setup.h" +#include "path-util.h" /* This assumes there is a 'tty' group */ #define TTY_MODE 0620 @@ -929,7 +930,7 @@ static void rename_process_from_path(const char *path) { /* This resulting string must fit in 10 chars (i.e. the length * of "/sbin/init") to look pretty in /bin/ps */ - p = file_name_from_path(path); + p = path_get_file_name(path); if (isempty(p)) { rename_process("(...)"); return; @@ -1152,14 +1153,14 @@ int exec_spawn(ExecCommand *command, } if (!keep_stdout) { - err = setup_output(context, socket_fd, file_name_from_path(command->path), apply_tty_stdin); + err = setup_output(context, socket_fd, path_get_file_name(command->path), apply_tty_stdin); if (err < 0) { r = EXIT_STDOUT; goto fail_child; } } - err = setup_error(context, socket_fd, file_name_from_path(command->path), apply_tty_stdin); + err = setup_error(context, socket_fd, path_get_file_name(command->path), apply_tty_stdin); if (err < 0) { r = EXIT_STDERR; goto fail_child; diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index d24919f998..c2efec6657 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -44,6 +44,7 @@ #include "unit-name.h" #include "bus-errors.h" #include "utf8.h" +#include "path-util.h" #ifndef HAVE_SYSV_COMPAT int config_parse_warn_compat( @@ -2089,7 +2090,7 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) { /* Add the file name we are currently looking at to * the names of this unit, but only if it is a valid * unit name. */ - name = file_name_from_path(*filename); + name = path_get_file_name(*filename); if (unit_name_is_valid(name, true)) { diff --git a/src/core/manager.c b/src/core/manager.c index 62222e6c7a..c6baf22ae5 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -65,6 +65,7 @@ #include "virt.h" #include "watchdog.h" #include "cgroup-util.h" +#include "path-util.h" /* As soon as 16 units are in our GC queue, make sure to run a gc sweep */ #define GC_QUEUE_ENTRIES_MAX 16 @@ -785,7 +786,7 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DB } if (!name) - name = file_name_from_path(path); + name = path_get_file_name(path); t = unit_name_to_type(name); diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 6d37bbde3c..56ce2ae71a 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -38,6 +38,7 @@ #include "set.h" #include "strv.h" #include "mkdir.h" +#include "path-util.h" #ifndef TTY_GID #define TTY_GID 5 diff --git a/src/core/mount.c b/src/core/mount.c index 8bdd462ea1..01e9d78ad5 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -32,6 +32,7 @@ #include "log.h" #include "strv.h" #include "mkdir.h" +#include "path-util.h" #include "mount-setup.h" #include "unit-name.h" #include "dbus-mount.h" diff --git a/src/core/namespace.c b/src/core/namespace.c index 7ac6b381ab..ba1edbe512 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -33,6 +33,7 @@ #include "strv.h" #include "util.h" +#include "path-util.h" #include "namespace.h" #include "missing.h" diff --git a/src/core/path.c b/src/core/path.c index 0f23f1494d..d6fedc736a 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -32,6 +32,7 @@ #include "dbus-path.h" #include "special.h" #include "bus-errors.h" +#include "path-util.h" static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = { [PATH_DEAD] = UNIT_INACTIVE, diff --git a/src/core/service.c b/src/core/service.c index 40f1682784..e9a7000bae 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -38,6 +38,7 @@ #include "bus-errors.h" #include "exit-status.h" #include "def.h" +#include "path-util.h" #include "util.h" #include "utf8.h" @@ -722,7 +723,7 @@ static int service_load_sysv_path(Service *s, const char *path) { goto finish; } - r = sysv_translate_facility(n, file_name_from_path(path), &m); + r = sysv_translate_facility(n, path_get_file_name(path), &m); free(n); if (r < 0) @@ -772,7 +773,7 @@ static int service_load_sysv_path(Service *s, const char *path) { goto finish; } - r = sysv_translate_facility(n, file_name_from_path(path), &m); + r = sysv_translate_facility(n, path_get_file_name(path), &m); if (r < 0) { log_error("[%s:%u] Failed to translate LSB dependency %s, ignoring: %s", path, line, n, strerror(-r)); diff --git a/src/core/socket.c b/src/core/socket.c index 60ea3cb25c..37e85d5fbe 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -37,6 +37,7 @@ #include "load-fragment.h" #include "strv.h" #include "mkdir.h" +#include "path-util.h" #include "unit-name.h" #include "dbus-socket.h" #include "missing.h" diff --git a/src/core/swap.c b/src/core/swap.c index 3881d2831f..a7e2126edd 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -38,6 +38,7 @@ #include "bus-errors.h" #include "exit-status.h" #include "def.h" +#include "path-util.h" static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = { [SWAP_DEAD] = UNIT_INACTIVE, diff --git a/src/core/umount.c b/src/core/umount.c index 488e1e4a4d..71ad4b623d 100644 --- a/src/core/umount.c +++ b/src/core/umount.c @@ -32,6 +32,7 @@ #include "list.h" #include "mount-setup.h" #include "umount.h" +#include "path-util.h" #include "util.h" typedef struct MountPoint { diff --git a/src/core/unit.c b/src/core/unit.c index fea75e88fe..68948574ed 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -33,6 +33,7 @@ #include "unit.h" #include "macro.h" #include "strv.h" +#include "path-util.h" #include "load-fragment.h" #include "load-dropin.h" #include "log.h" @@ -1670,7 +1671,7 @@ static const char *resolve_template(Unit *u, const char *name, const char*path, assert(name || path); if (!name) - name = file_name_from_path(path); + name = path_get_file_name(path); if (!unit_name_is_template(name)) { *p = NULL; @@ -2179,7 +2180,7 @@ static char *specifier_cgroup_root(char specifier, void *data, void *userdata) { if (specifier == 'r') return strdup(u->manager->cgroup_hierarchy); - if (parent_of_path(u->manager->cgroup_hierarchy, &p) < 0) + if (path_get_parent(u->manager->cgroup_hierarchy, &p) < 0) return strdup(""); if (streq(p, "/")) { @@ -2681,7 +2682,7 @@ UnitFileState unit_get_unit_file_state(Unit *u) { if (u->unit_file_state < 0 && u->fragment_path) u->unit_file_state = unit_file_get_state( u->manager->running_as == MANAGER_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER, - NULL, file_name_from_path(u->fragment_path)); + NULL, path_get_file_name(u->fragment_path)); return u->unit_file_state; } diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 3ff0ddf2cc..6d4e965fe1 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -29,6 +29,7 @@ #include "log.h" #include "util.h" +#include "path-util.h" #include "strv.h" #include "ask-password-api.h" #include "def.h" diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 9d381e044c..4f3f1b5ff3 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -30,6 +30,7 @@ #include "journal-file.h" #include "hashmap.h" #include "list.h" +#include "path-util.h" #include "lookup3.h" #include "compress.h" #include "journal-internal.h" @@ -765,7 +766,7 @@ _public_ int sd_journal_get_cursor(sd_journal *j, char **cursor) { bid, (unsigned long long) le64toh(o->entry.monotonic), (unsigned long long) le64toh(o->entry.realtime), (unsigned long long) le64toh(o->entry.xor_hash), - file_name_from_path(j->current_file->path)) < 0) + path_get_file_name(j->current_file->path)) < 0) return -ENOMEM; return 1; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index a361b93dc7..9fc3a14317 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -28,6 +28,7 @@ #include "dbus-common.h" #include "strv.h" #include "mkdir.h" +#include "path-util.h" #include "polkit.h" #include "special.h" diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index e4eefd0def..b5b801e5e0 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -28,7 +28,7 @@ #include "util.h" #include "mkdir.h" - +#include "path-util.h" #include "logind-inhibit.h" Inhibitor* inhibitor_new(Manager *m, const char* id) { @@ -46,7 +46,7 @@ Inhibitor* inhibitor_new(Manager *m, const char* id) { return NULL; } - i->id = file_name_from_path(i->state_file); + i->id = path_get_file_name(i->state_file); if (hashmap_put(m->inhibitors, i->id, i) < 0) { free(i->state_file); diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 1bae6f6e07..06debf887a 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -31,6 +31,7 @@ #include "logind-acl.h" #include "util.h" #include "mkdir.h" +#include "path-util.h" Seat *seat_new(Manager *m, const char *id) { Seat *s; @@ -48,7 +49,7 @@ Seat *seat_new(Manager *m, const char *id) { return NULL; } - s->id = file_name_from_path(s->state_file); + s->id = path_get_file_name(s->state_file); s->manager = m; if (hashmap_put(m->seats, s->id, s) < 0) { diff --git a/src/login/logind-session.c b/src/login/logind-session.c index e297d3feeb..475ebcaa5e 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -28,6 +28,7 @@ #include "strv.h" #include "util.h" #include "mkdir.h" +#include "path-util.h" #include "cgroup-util.h" #include "logind-session.h" @@ -49,7 +50,7 @@ Session* session_new(Manager *m, User *u, const char *id) { return NULL; } - s->id = file_name_from_path(s->state_file); + s->id = path_get_file_name(s->state_file); if (hashmap_put(m->sessions, s->id, s) < 0) { free(s->state_file); diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index b0edc33b80..bc1bbccff7 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -25,6 +25,7 @@ #include "util.h" #include "sysfs-show.h" +#include "path-util.h" static int show_sysfs_one( struct udev *udev, diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 2a1f37bffc..31e8b015df 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -50,6 +50,7 @@ #include "missing.h" #include "cgroup-util.h" #include "strv.h" +#include "path-util.h" #include "loopback-setup.h" static char *arg_directory = NULL; @@ -524,7 +525,7 @@ static int setup_hostname(void) { char *hn; int r = 0; - hn = file_name_from_path(arg_directory); + hn = path_get_file_name(arg_directory); if (hn) { hn = strdup(hn); if (!hn) diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c index 35b71548a3..ef68e506e5 100644 --- a/src/remount-fs/remount-fs.c +++ b/src/remount-fs/remount-fs.c @@ -29,6 +29,7 @@ #include "log.h" #include "util.h" +#include "path-util.h" #include "set.h" #include "mount-setup.h" #include "exit-status.h" diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index 19f87e4bc6..9003a1228e 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -26,6 +26,7 @@ #include "util.h" #include "macro.h" +#include "path-util.h" #include "cgroup-util.h" #include "cgroup-show.h" @@ -205,7 +206,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns } if (last) { - printf("%s\342\224\234 %s\n", prefix, file_name_from_path(last)); + printf("%s\342\224\234 %s\n", prefix, path_get_file_name(last)); if (!p1) { p1 = strappend(prefix, "\342\224\202 "); @@ -230,7 +231,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns show_cgroup_one_by_path(path, prefix, n_columns, !!last, kernel_threads); if (last) { - printf("%s\342\224\224 %s\n", prefix, file_name_from_path(last)); + printf("%s\342\224\224 %s\n", prefix, path_get_file_name(last)); if (!p2) { p2 = strappend(prefix, " "); diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 1f310d31f0..8d3bdce0f5 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -34,6 +34,7 @@ #include "set.h" #include "macro.h" #include "util.h" +#include "path-util.h" #include "strv.h" int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) { @@ -673,7 +674,7 @@ int cg_delete(const char *controller, const char *path) { assert(controller); assert(path); - if ((r = parent_of_path(path, &parent)) < 0) + if ((r = path_get_parent(path, &parent)) < 0) return r; r = cg_migrate_recursive(controller, path, parent, false, true); diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c index 019fadcf5e..487c9a5e68 100644 --- a/src/shared/conf-files.c +++ b/src/shared/conf-files.c @@ -33,6 +33,7 @@ #include "missing.h" #include "log.h" #include "strv.h" +#include "path-util.h" #include "hashmap.h" #include "conf-files.h" @@ -69,7 +70,7 @@ static int files_add(Hashmap *h, const char *path, const char *suffix) { goto finish; } - if (hashmap_put(h, file_name_from_path(p), p) <= 0) { + if (hashmap_put(h, path_get_file_name(p), p) <= 0) { log_debug("Skip overridden file: %s.", p); free(p); } @@ -85,7 +86,7 @@ static int base_cmp(const void *a, const void *b) { s1 = *(char * const *)a; s2 = *(char * const *)b; - return strcmp(file_name_from_path(s1), file_name_from_path(s2)); + return strcmp(path_get_file_name(s1), path_get_file_name(s2)); } int conf_files_list_strv(char ***strv, const char *suffix, const char **dirs) { @@ -137,7 +138,7 @@ int conf_files_list(char ***strv, const char *suffix, const char *dir, ...) { goto finish; } - if (!strv_path_canonicalize(dirs)) { + if (!path_strv_canonicalize(dirs)) { r = -ENOMEM; goto finish; } diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 30980a3ea2..65035e4c6a 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -31,6 +31,7 @@ #include "strv.h" #include "log.h" #include "utf8.h" +#include "path-util.h" int config_item_table_lookup( void *table, diff --git a/src/shared/install.c b/src/shared/install.c index a77dfc77e4..fc1bf96207 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -29,6 +29,7 @@ #include "mkdir.h" #include "hashmap.h" #include "set.h" +#include "path-util.h" #include "path-lookup.h" #include "strv.h" #include "unit-name.h" @@ -283,7 +284,7 @@ static int remove_marked_symlinks_fd( found = set_get(remove_symlinks_to, dest) || - set_get(remove_symlinks_to, file_name_from_path(dest)); + set_get(remove_symlinks_to, path_get_file_name(dest)); if (found) { @@ -468,7 +469,7 @@ static int find_symlinks_fd( if (path_is_absolute(name)) found_dest = path_equal(dest, name); else - found_dest = streq(file_name_from_path(dest), name); + found_dest = streq(path_get_file_name(dest), name); free(dest); @@ -754,7 +755,7 @@ int unit_file_link( char *path, *fn; struct stat st; - fn = file_name_from_path(*i); + fn = path_get_file_name(*i); if (!path_is_absolute(*i) || !unit_name_is_valid_no_type(fn, true)) { @@ -917,7 +918,7 @@ static int install_info_add( assert(name || path); if (!name) - name = file_name_from_path(path); + name = path_get_file_name(path); if (!unit_name_is_valid_no_type(name, true)) return -EINVAL; @@ -1915,7 +1916,7 @@ int unit_file_get_list( continue; found: - r = hashmap_put(h, file_name_from_path(f->path), f); + r = hashmap_put(h, path_get_file_name(f->path), f); if (r < 0) { free(f->path); free(f); diff --git a/src/shared/label.c b/src/shared/label.c index bd38f0ba67..2d7d42a40e 100644 --- a/src/shared/label.c +++ b/src/shared/label.c @@ -28,6 +28,7 @@ #include "label.h" #include "util.h" +#include "path-util.h" #ifdef HAVE_SELINUX #include diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 1d95f7d1f8..41ebc7f5b3 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -28,7 +28,7 @@ #include "util.h" #include "mkdir.h" #include "strv.h" - +#include "path-util.h" #include "path-lookup.h" int user_config_home(char **config_home) { @@ -165,7 +165,7 @@ static char** user_dirs(void) { strv_free(r); r = t; - if (!strv_path_make_absolute_cwd(r)) + if (!path_strv_make_absolute_cwd(r)) goto fail; finish: @@ -191,7 +191,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal /* First priority is whatever has been passed to us via env * vars */ if ((e = getenv("SYSTEMD_UNIT_PATH"))) - if (!(p->unit_path = split_path_and_make_absolute(e))) + if (!(p->unit_path = path_split_and_make_absolute(e))) return -ENOMEM; if (strv_isempty(p->unit_path)) { @@ -239,11 +239,11 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal } if (p->unit_path) - if (!strv_path_canonicalize(p->unit_path)) + if (!path_strv_canonicalize(p->unit_path)) return -ENOMEM; strv_uniq(p->unit_path); - strv_path_remove_empty(p->unit_path); + path_strv_remove_empty(p->unit_path); if (!strv_isempty(p->unit_path)) { @@ -262,7 +262,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal /* /etc/init.d/ compatibility does not matter to users */ if ((e = getenv("SYSTEMD_SYSVINIT_PATH"))) - if (!(p->sysvinit_path = split_path_and_make_absolute(e))) + if (!(p->sysvinit_path = path_split_and_make_absolute(e))) return -ENOMEM; if (strv_isempty(p->sysvinit_path)) { @@ -275,7 +275,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal } if ((e = getenv("SYSTEMD_SYSVRCND_PATH"))) - if (!(p->sysvrcnd_path = split_path_and_make_absolute(e))) + if (!(p->sysvrcnd_path = path_split_and_make_absolute(e))) return -ENOMEM; if (strv_isempty(p->sysvrcnd_path)) { @@ -288,18 +288,18 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal } if (p->sysvinit_path) - if (!strv_path_canonicalize(p->sysvinit_path)) + if (!path_strv_canonicalize(p->sysvinit_path)) return -ENOMEM; if (p->sysvrcnd_path) - if (!strv_path_canonicalize(p->sysvrcnd_path)) + if (!path_strv_canonicalize(p->sysvrcnd_path)) return -ENOMEM; strv_uniq(p->sysvinit_path); strv_uniq(p->sysvrcnd_path); - strv_path_remove_empty(p->sysvinit_path); - strv_path_remove_empty(p->sysvrcnd_path); + path_strv_remove_empty(p->sysvinit_path); + path_strv_remove_empty(p->sysvrcnd_path); if (!strv_isempty(p->sysvinit_path)) { diff --git a/src/shared/path-util.c b/src/shared/path-util.c new file mode 100644 index 0000000000..ccd7667608 --- /dev/null +++ b/src/shared/path-util.c @@ -0,0 +1,371 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010-2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "macro.h" +#include "util.h" +#include "log.h" +#include "strv.h" +#include "path-util.h" + +bool path_is_absolute(const char *p) { + return p[0] == '/'; +} + +bool is_path(const char *p) { + return !!strchr(p, '/'); +} + +char *path_get_file_name(const char *p) { + char *r; + + assert(p); + + if ((r = strrchr(p, '/'))) + return r + 1; + + return (char*) p; +} + +int path_get_parent(const char *path, char **_r) { + const char *e, *a = NULL, *b = NULL, *p; + char *r; + bool slash = false; + + assert(path); + assert(_r); + + if (!*path) + return -EINVAL; + + for (e = path; *e; e++) { + + if (!slash && *e == '/') { + a = b; + b = e; + slash = true; + } else if (slash && *e != '/') + slash = false; + } + + if (*(e-1) == '/') + p = a; + else + p = b; + + if (!p) + return -EINVAL; + + if (p == path) + r = strdup("/"); + else + r = strndup(path, p-path); + + if (!r) + return -ENOMEM; + + *_r = r; + return 0; +} + +char **path_split_and_make_absolute(const char *p) { + char **l; + assert(p); + + if (!(l = strv_split(p, ":"))) + return NULL; + + if (!path_strv_make_absolute_cwd(l)) { + strv_free(l); + return NULL; + } + + return l; +} + +char *path_make_absolute(const char *p, const char *prefix) { + assert(p); + + /* Makes every item in the list an absolute path by prepending + * the prefix, if specified and necessary */ + + if (path_is_absolute(p) || !prefix) + return strdup(p); + + return join(prefix, "/", p, NULL); +} + +char *path_make_absolute_cwd(const char *p) { + char *cwd, *r; + + assert(p); + + /* Similar to path_make_absolute(), but prefixes with the + * current working directory. */ + + if (path_is_absolute(p)) + return strdup(p); + + if (!(cwd = get_current_dir_name())) + return NULL; + + r = path_make_absolute(p, cwd); + free(cwd); + + return r; +} + +char **path_strv_make_absolute_cwd(char **l) { + char **s; + + /* Goes through every item in the string list and makes it + * absolute. This works in place and won't rollback any + * changes on failure. */ + + STRV_FOREACH(s, l) { + char *t; + + if (!(t = path_make_absolute_cwd(*s))) + return NULL; + + free(*s); + *s = t; + } + + return l; +} + +char **path_strv_canonicalize(char **l) { + char **s; + unsigned k = 0; + bool enomem = false; + + if (strv_isempty(l)) + return l; + + /* Goes through every item in the string list and canonicalize + * the path. This works in place and won't rollback any + * changes on failure. */ + + STRV_FOREACH(s, l) { + char *t, *u; + + t = path_make_absolute_cwd(*s); + free(*s); + + if (!t) { + enomem = true; + continue; + } + + errno = 0; + u = canonicalize_file_name(t); + free(t); + + if (!u) { + if (errno == ENOMEM || !errno) + enomem = true; + + continue; + } + + l[k++] = u; + } + + l[k] = NULL; + + if (enomem) + return NULL; + + return l; +} + +char **path_strv_remove_empty(char **l) { + char **f, **t; + + if (!l) + return NULL; + + for (f = t = l; *f; f++) { + + if (dir_is_empty(*f) > 0) { + free(*f); + continue; + } + + *(t++) = *f; + } + + *t = NULL; + return l; +} + +char *path_kill_slashes(char *path) { + char *f, *t; + bool slash = false; + + /* Removes redundant inner and trailing slashes. Modifies the + * passed string in-place. + * + * ///foo///bar/ becomes /foo/bar + */ + + for (f = path, t = path; *f; f++) { + + if (*f == '/') { + slash = true; + continue; + } + + if (slash) { + slash = false; + *(t++) = '/'; + } + + *(t++) = *f; + } + + /* Special rule, if we are talking of the root directory, a + trailing slash is good */ + + if (t == path && slash) + *(t++) = '/'; + + *t = 0; + return path; +} + +bool path_startswith(const char *path, const char *prefix) { + assert(path); + assert(prefix); + + if ((path[0] == '/') != (prefix[0] == '/')) + return false; + + for (;;) { + size_t a, b; + + path += strspn(path, "/"); + prefix += strspn(prefix, "/"); + + if (*prefix == 0) + return true; + + if (*path == 0) + return false; + + a = strcspn(path, "/"); + b = strcspn(prefix, "/"); + + if (a != b) + return false; + + if (memcmp(path, prefix, a) != 0) + return false; + + path += a; + prefix += b; + } +} + +bool path_equal(const char *a, const char *b) { + assert(a); + assert(b); + + if ((a[0] == '/') != (b[0] == '/')) + return false; + + for (;;) { + size_t j, k; + + a += strspn(a, "/"); + b += strspn(b, "/"); + + if (*a == 0 && *b == 0) + return true; + + if (*a == 0 || *b == 0) + return false; + + j = strcspn(a, "/"); + k = strcspn(b, "/"); + + if (j != k) + return false; + + if (memcmp(a, b, j) != 0) + return false; + + a += j; + b += k; + } +} + +int path_is_mount_point(const char *t, bool allow_symlink) { + struct stat a, b; + char *parent; + int r; + + if (allow_symlink) + r = stat(t, &a); + else + r = lstat(t, &a); + + if (r < 0) { + if (errno == ENOENT) + return 0; + + return -errno; + } + + r = path_get_parent(t, &parent); + if (r < 0) + return r; + + r = lstat(parent, &b); + free(parent); + + if (r < 0) + return -errno; + + return a.st_dev != b.st_dev; +} + +int path_is_read_only_fs(const char *path) { + struct statvfs st; + + assert(path); + + if (statvfs(path, &st) < 0) + return -errno; + + return !!(st.f_flag & ST_RDONLY); +} diff --git a/src/shared/path-util.h b/src/shared/path-util.h new file mode 100644 index 0000000000..181b981224 --- /dev/null +++ b/src/shared/path-util.h @@ -0,0 +1,46 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#ifndef foopathutilhfoo +#define foopathutilhfoo + +/*** + This file is part of systemd. + + Copyright 2010-2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include "stdbool.h" + +bool is_path(const char *p); +char **path_split_and_make_absolute(const char *p); +char *path_get_file_name(const char *p); +int path_get_parent(const char *path, char **parent); +bool path_is_absolute(const char *p); +char *path_make_absolute(const char *p, const char *prefix); +char *path_make_absolute_cwd(const char *p); +int path_parent(const char *path, char **parent); +char *path_kill_slashes(char *path); +bool path_startswith(const char *path, const char *prefix); +bool path_equal(const char *a, const char *b); + +char **path_strv_make_absolute_cwd(char **l); +char **path_strv_canonicalize(char **l); +char **path_strv_remove_empty(char **l); + +int path_is_mount_point(const char *path, bool allow_symlink); +int path_is_read_only_fs(const char *path); + +#endif diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c index 471b6dc284..7e65f8a691 100644 --- a/src/shared/socket-util.c +++ b/src/shared/socket-util.c @@ -35,6 +35,7 @@ #include "macro.h" #include "util.h" #include "mkdir.h" +#include "path-util.h" #include "socket-util.h" #include "missing.h" diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index 566cdc51cc..e0a18d1357 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -23,6 +23,7 @@ #include #include +#include "path-util.h" #include "util.h" #include "unit-name.h" diff --git a/src/shared/util.c b/src/shared/util.c index a055ce197d..8a0b2a1b46 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -55,7 +55,6 @@ #include #include #include -#include #include "macro.h" #include "util.h" @@ -64,6 +63,7 @@ #include "log.h" #include "strv.h" #include "label.h" +#include "path-util.h" #include "exit-status.h" #include "hashmap.h" @@ -486,21 +486,6 @@ char *split_quoted(const char *c, size_t *l, char **state) { return (char*) current; } -char **split_path_and_make_absolute(const char *p) { - char **l; - assert(p); - - if (!(l = strv_split(p, ":"))) - return NULL; - - if (!strv_path_make_absolute_cwd(l)) { - strv_free(l); - return NULL; - } - - return l; -} - int get_parent_of_pid(pid_t pid, pid_t *_ppid) { int r; FILE *f; @@ -1313,187 +1298,6 @@ int readlink_and_canonicalize(const char *p, char **r) { return 0; } -int parent_of_path(const char *path, char **_r) { - const char *e, *a = NULL, *b = NULL, *p; - char *r; - bool slash = false; - - assert(path); - assert(_r); - - if (!*path) - return -EINVAL; - - for (e = path; *e; e++) { - - if (!slash && *e == '/') { - a = b; - b = e; - slash = true; - } else if (slash && *e != '/') - slash = false; - } - - if (*(e-1) == '/') - p = a; - else - p = b; - - if (!p) - return -EINVAL; - - if (p == path) - r = strdup("/"); - else - r = strndup(path, p-path); - - if (!r) - return -ENOMEM; - - *_r = r; - return 0; -} - - -char *file_name_from_path(const char *p) { - char *r; - - assert(p); - - if ((r = strrchr(p, '/'))) - return r + 1; - - return (char*) p; -} - -bool path_is_absolute(const char *p) { - assert(p); - - return p[0] == '/'; -} - -bool is_path(const char *p) { - - return !!strchr(p, '/'); -} - -char *path_make_absolute(const char *p, const char *prefix) { - assert(p); - - /* Makes every item in the list an absolute path by prepending - * the prefix, if specified and necessary */ - - if (path_is_absolute(p) || !prefix) - return strdup(p); - - return join(prefix, "/", p, NULL); -} - -char *path_make_absolute_cwd(const char *p) { - char *cwd, *r; - - assert(p); - - /* Similar to path_make_absolute(), but prefixes with the - * current working directory. */ - - if (path_is_absolute(p)) - return strdup(p); - - if (!(cwd = get_current_dir_name())) - return NULL; - - r = path_make_absolute(p, cwd); - free(cwd); - - return r; -} - -char **strv_path_make_absolute_cwd(char **l) { - char **s; - - /* Goes through every item in the string list and makes it - * absolute. This works in place and won't rollback any - * changes on failure. */ - - STRV_FOREACH(s, l) { - char *t; - - if (!(t = path_make_absolute_cwd(*s))) - return NULL; - - free(*s); - *s = t; - } - - return l; -} - -char **strv_path_canonicalize(char **l) { - char **s; - unsigned k = 0; - bool enomem = false; - - if (strv_isempty(l)) - return l; - - /* Goes through every item in the string list and canonicalize - * the path. This works in place and won't rollback any - * changes on failure. */ - - STRV_FOREACH(s, l) { - char *t, *u; - - t = path_make_absolute_cwd(*s); - free(*s); - - if (!t) { - enomem = true; - continue; - } - - errno = 0; - u = canonicalize_file_name(t); - free(t); - - if (!u) { - if (errno == ENOMEM || !errno) - enomem = true; - - continue; - } - - l[k++] = u; - } - - l[k] = NULL; - - if (enomem) - return NULL; - - return l; -} - -char **strv_path_remove_empty(char **l) { - char **f, **t; - - if (!l) - return NULL; - - for (f = t = l; *f; f++) { - - if (dir_is_empty(*f) > 0) { - free(*f); - continue; - } - - *(t++) = *f; - } - - *t = NULL; - return l; -} - int reset_all_signal_handlers(void) { int sig; @@ -1972,107 +1776,6 @@ char *bus_path_unescape(const char *f) { return r; } -char *path_kill_slashes(char *path) { - char *f, *t; - bool slash = false; - - /* Removes redundant inner and trailing slashes. Modifies the - * passed string in-place. - * - * ///foo///bar/ becomes /foo/bar - */ - - for (f = path, t = path; *f; f++) { - - if (*f == '/') { - slash = true; - continue; - } - - if (slash) { - slash = false; - *(t++) = '/'; - } - - *(t++) = *f; - } - - /* Special rule, if we are talking of the root directory, a - trailing slash is good */ - - if (t == path && slash) - *(t++) = '/'; - - *t = 0; - return path; -} - -bool path_startswith(const char *path, const char *prefix) { - assert(path); - assert(prefix); - - if ((path[0] == '/') != (prefix[0] == '/')) - return false; - - for (;;) { - size_t a, b; - - path += strspn(path, "/"); - prefix += strspn(prefix, "/"); - - if (*prefix == 0) - return true; - - if (*path == 0) - return false; - - a = strcspn(path, "/"); - b = strcspn(prefix, "/"); - - if (a != b) - return false; - - if (memcmp(path, prefix, a) != 0) - return false; - - path += a; - prefix += b; - } -} - -bool path_equal(const char *a, const char *b) { - assert(a); - assert(b); - - if ((a[0] == '/') != (b[0] == '/')) - return false; - - for (;;) { - size_t j, k; - - a += strspn(a, "/"); - b += strspn(b, "/"); - - if (*a == 0 && *b == 0) - return true; - - if (*a == 0 || *b == 0) - return false; - - j = strcspn(a, "/"); - k = strcspn(b, "/"); - - if (j != k) - return false; - - if (memcmp(a, b, j) != 0) - return false; - - a += j; - b += k; - } -} - char *ascii_strlower(char *t) { char *p; @@ -2986,36 +2689,6 @@ ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) { return n; } -int path_is_mount_point(const char *t, bool allow_symlink) { - struct stat a, b; - char *parent; - int r; - - if (allow_symlink) - r = stat(t, &a); - else - r = lstat(t, &a); - - if (r < 0) { - if (errno == ENOENT) - return 0; - - return -errno; - } - - r = parent_of_path(t, &parent); - if (r < 0) - return r; - - r = lstat(parent, &b); - free(parent); - - if (r < 0) - return -errno; - - return a.st_dev != b.st_dev; -} - int parse_usec(const char *t, usec_t *usec) { static const struct { const char *suffix; @@ -4746,7 +4419,7 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) { if (!t) return -ENOMEM; - fn = file_name_from_path(path); + fn = path_get_file_name(path); k = fn-path; memcpy(t, path, k); t[k] = '.'; @@ -4928,8 +4601,8 @@ int symlink_or_copy(const char *from, const char *to) { assert(from); assert(to); - if (parent_of_path(from, &pf) < 0 || - parent_of_path(to, &pt) < 0) { + if (path_get_parent(from, &pf) < 0 || + path_get_parent(to, &pt) < 0) { r = -ENOMEM; goto finish; } @@ -4976,7 +4649,7 @@ int symlink_or_copy_atomic(const char *from, const char *to) { if (!t) return -ENOMEM; - fn = file_name_from_path(to); + fn = path_get_file_name(to); k = fn-to; memcpy(t, to, k); t[k] = '.'; @@ -5218,7 +4891,7 @@ int in_search_path(const char *path, char **search) { char **i, *parent; int r; - r = parent_of_path(path, &parent); + r = path_get_parent(path, &parent); if (r < 0) return r; @@ -5857,17 +5530,6 @@ int setrlimit_closest(int resource, const struct rlimit *rlim) { return 0; } -int path_is_read_only_fs(const char *path) { - struct statvfs st; - - assert(path); - - if (statvfs(path, &st) < 0) - return -errno; - - return !!(st.f_flag & ST_RDONLY); -} - int getenv_for_pid(pid_t pid, const char *field, char **_value) { char path[sizeof("/proc/")-1+10+sizeof("/environ")], *value = NULL; int r; diff --git a/src/shared/util.h b/src/shared/util.h index cca6118363..59a69a898a 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -122,10 +122,6 @@ static inline const char *strna(const char *s) { return s ? s : "n/a"; } -static inline bool is_path_absolute(const char *p) { - return *p == '/'; -} - static inline bool isempty(const char *p) { return !p || !p[0]; } @@ -205,8 +201,6 @@ char *split_quoted(const char *c, size_t *l, char **state); #define FOREACH_WORD_QUOTED(word, length, s, state) \ for ((state) = NULL, (word) = split_quoted((s), &(length), &(state)); (word); (word) = split_quoted((s), &(length), &(state))) -char **split_path_and_make_absolute(const char *p); - pid_t get_parent_of_pid(pid_t pid, pid_t *ppid); int get_starttime_of_pid(pid_t pid, unsigned long long *st); @@ -229,17 +223,6 @@ int readlink_malloc(const char *p, char **r); int readlink_and_make_absolute(const char *p, char **r); int readlink_and_canonicalize(const char *p, char **r); -char *file_name_from_path(const char *p); -bool is_path(const char *p); - -bool path_is_absolute(const char *p); -char *path_make_absolute(const char *p, const char *prefix); -char *path_make_absolute_cwd(const char *p); - -char **strv_path_make_absolute_cwd(char **l); -char **strv_path_canonicalize(char **l); -char **strv_path_remove_empty(char **l); - int reset_all_signal_handlers(void); char *strstrip(char *s); @@ -248,8 +231,6 @@ char *truncate_nl(char *s); char *file_in_same_dir(const char *path, const char *filename); -int parent_of_path(const char *path, char **parent); - int rmdir_parents(const char *path, const char *stop); int get_process_comm(pid_t pid, char **name); @@ -273,11 +254,6 @@ char *xescape(const char *s, const char *bad); char *bus_path_escape(const char *s); char *bus_path_unescape(const char *s); -char *path_kill_slashes(char *path); - -bool path_startswith(const char *path, const char *prefix); -bool path_equal(const char *a, const char *b); - char *ascii_strlower(char *path); bool dirent_is_file(const struct dirent *de); @@ -351,9 +327,6 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path); ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll); ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll); -int path_is_mount_point(const char *path, bool allow_symlink); -int path_is_read_only_fs(const char *path); - bool is_device_path(const char *path); int dir_is_empty(const char *path); diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 6bba325d3e..046fb584fb 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -29,6 +29,7 @@ #include #include "macro.h" +#include "path-util.h" #include "utmp-wtmp.h" int utmp_get_runlevel(int *runlevel, int *previous) { @@ -224,7 +225,7 @@ int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line strncpy(store.ut_id, sanitize_id(id), sizeof(store.ut_id)); if (line) - strncpy(store.ut_line, file_name_from_path(line), sizeof(store.ut_line)); + strncpy(store.ut_line, path_get_file_name(line), sizeof(store.ut_line)); return write_entry_both(&store); } diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index 575095f812..72a74f9e44 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -31,6 +31,7 @@ #include "strv.h" #include "util.h" #include "strv.h" +#include "path-util.h" #include "conf-files.h" #define PROC_SYS_PREFIX "/proc/sys/" diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index c08d80912a..acede4e765 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -45,6 +45,7 @@ #include "utmp-wtmp.h" #include "special.h" #include "initreq.h" +#include "path-util.h" #include "strv.h" #include "dbus-common.h" #include "cgroup-show.h" @@ -61,6 +62,7 @@ #include "spawn-polkit-agent.h" #include "install.h" #include "logs-show.h" +#include "path-util.h" static const char *arg_type = NULL; static char **arg_property = NULL; @@ -560,7 +562,7 @@ static int compare_unit_file_list(const void *a, const void *b) { return r; } - return strcasecmp(file_name_from_path(u->path), file_name_from_path(v->path)); + return strcasecmp(path_get_file_name(u->path), path_get_file_name(v->path)); } static bool output_show_unit_file(const UnitFileList *u) { @@ -579,7 +581,7 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { if (!output_show_unit_file(u)) continue; - max_id_len = MAX(max_id_len, strlen(file_name_from_path(u->path))); + max_id_len = MAX(max_id_len, strlen(path_get_file_name(u->path))); state_cols = MAX(state_cols, strlen(unit_file_state_to_string(u->state))); } @@ -616,7 +618,7 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { } else on = off = ""; - id = file_name_from_path(u->path); + id = path_get_file_name(u->path); e = arg_full ? NULL : ellipsize(id, id_cols, 33); @@ -3721,7 +3723,7 @@ static int enable_sysv_units(char **args) { if (!isempty(arg_root)) argv[c++] = q = strappend("--root=", arg_root); - argv[c++] = file_name_from_path(p); + argv[c++] = path_get_file_name(p); argv[c++] = streq(verb, "enable") ? "on" : streq(verb, "disable") ? "off" : "--level=5"; diff --git a/src/test/test-cgroup.c b/src/test/test-cgroup.c index e742632032..6d64a4e47f 100644 --- a/src/test/test-cgroup.c +++ b/src/test/test-cgroup.c @@ -23,6 +23,7 @@ #include #include "cgroup-util.h" +#include "path-util.h" #include "util.h" #include "log.h" diff --git a/src/test/test-install.c b/src/test/test-install.c index 709974f9e5..2c1b9efcb8 100644 --- a/src/test/test-install.c +++ b/src/test/test-install.c @@ -25,6 +25,7 @@ #include #include "util.h" +#include "path-util.h" #include "install.h" static void dump_changes(UnitFileChange *c, unsigned n) { @@ -57,7 +58,7 @@ int main(int argc, char* argv[]) { HASHMAP_FOREACH(p, h, i) { UnitFileState s; - s = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(p->path)); + s = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(p->path)); assert_se(p->state == s); @@ -175,7 +176,7 @@ int main(int argc, char* argv[]) { dump_changes(changes, n_changes); unit_file_changes_free(changes, n_changes); - assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == UNIT_FILE_ENABLED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == UNIT_FILE_ENABLED); log_error("disable files2"); changes = NULL; @@ -187,7 +188,7 @@ int main(int argc, char* argv[]) { dump_changes(changes, n_changes); unit_file_changes_free(changes, n_changes); - assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == _UNIT_FILE_STATE_INVALID); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID); log_error("link files2"); changes = NULL; @@ -199,7 +200,7 @@ int main(int argc, char* argv[]) { dump_changes(changes, n_changes); unit_file_changes_free(changes, n_changes); - assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == UNIT_FILE_LINKED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == UNIT_FILE_LINKED); log_error("disable files2"); changes = NULL; @@ -211,7 +212,7 @@ int main(int argc, char* argv[]) { dump_changes(changes, n_changes); unit_file_changes_free(changes, n_changes); - assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == _UNIT_FILE_STATE_INVALID); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID); log_error("link files2"); changes = NULL; @@ -223,7 +224,7 @@ int main(int argc, char* argv[]) { dump_changes(changes, n_changes); unit_file_changes_free(changes, n_changes); - assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == UNIT_FILE_LINKED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == UNIT_FILE_LINKED); log_error("reenable files2"); changes = NULL; @@ -235,7 +236,7 @@ int main(int argc, char* argv[]) { dump_changes(changes, n_changes); unit_file_changes_free(changes, n_changes); - assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == UNIT_FILE_ENABLED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == UNIT_FILE_ENABLED); log_error("disable files2"); changes = NULL; @@ -247,7 +248,7 @@ int main(int argc, char* argv[]) { dump_changes(changes, n_changes); unit_file_changes_free(changes, n_changes); - assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files2[0])) == _UNIT_FILE_STATE_INVALID); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files2[0])) == _UNIT_FILE_STATE_INVALID); log_error("preset files"); changes = NULL; n_changes = 0; @@ -258,7 +259,7 @@ int main(int argc, char* argv[]) { dump_changes(changes, n_changes); unit_file_changes_free(changes, n_changes); - assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, file_name_from_path(files[0])) == UNIT_FILE_ENABLED); + assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, NULL, path_get_file_name(files[0])) == UNIT_FILE_ENABLED); return 0; } diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 16666ce5a6..235617853b 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -42,6 +42,7 @@ #include "log.h" #include "util.h" #include "mkdir.h" +#include "path-util.h" #include "strv.h" #include "label.h" #include "set.h" 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 9fbd7f5fb2..de843b437e 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -34,6 +34,7 @@ #include "util.h" #include "mkdir.h" +#include "path-util.h" #include "conf-parser.h" #include "utmp-wtmp.h" #include "socket-util.h" diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 45a611474d..930c4770fe 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -31,6 +31,7 @@ #include #include "udev.h" +#include "path-util.h" #include "conf-files.h" #define PREALLOC_TOKEN 2048 @@ -1764,7 +1765,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) log_error("failed to build config directory array"); return NULL; } - if (!strv_path_canonicalize(rules->dirs)) { + if (!path_strv_canonicalize(rules->dirs)) { log_error("failed to canonicalize config directories\n"); return NULL; } -- cgit v1.2.3-54-g00ecf From 30edf1161600fe1b18f30264f05b4f602eb0e8a3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 May 2012 01:48:40 +0200 Subject: cgtop: change default depth to 3 https://bugs.freedesktop.org/show_bug.cgi?id=49778 --- man/systemd-cgtop.xml | 2 +- src/cgtop/cgtop.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cgtop') diff --git a/man/systemd-cgtop.xml b/man/systemd-cgtop.xml index 9322fb0920..14d47353cc 100644 --- a/man/systemd-cgtop.xml +++ b/man/systemd-cgtop.xml @@ -166,7 +166,7 @@ the root group is monitored, for 1 only the first level of control groups is monitored, and so on. Defaults to - 2. + 3. diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index cc7a99f3df..ddb57094b1 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -54,7 +54,7 @@ typedef struct Group { uint64_t io_input_bps, io_output_bps; } Group; -static unsigned arg_depth = 2; +static unsigned arg_depth = 3; static usec_t arg_delay = 1*USEC_PER_SEC; static enum { -- cgit v1.2.3-54-g00ecf From 63210a15e1efdbda3fb3abd9a6ae9961fd0ea153 Mon Sep 17 00:00:00 2001 From: Shawn Landden Date: Mon, 21 May 2012 22:54:41 -0700 Subject: cgtop: work even if not all cgroups are available cgtop quits on startup if all the cgroup mounts it expects are not available. Just continue without nonexistant ones. --- src/cgtop/cgtop.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index ddb57094b1..f988adb363 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -341,17 +341,22 @@ static int refresh(Hashmap *a, Hashmap *b, unsigned iteration) { r = refresh_one("name=systemd", "/", a, b, iteration, 0); if (r < 0) - return r; - + if (r != -ENOENT) + return r; r = refresh_one("cpuacct", "/", a, b, iteration, 0); if (r < 0) - return r; - + if (r != -ENOENT) + return r; r = refresh_one("memory", "/", a, b, iteration, 0); if (r < 0) - return r; + if (r != -ENOENT) + return r; - return refresh_one("blkio", "/", a, b, iteration, 0); + r = refresh_one("blkio", "/", a, b, iteration, 0); + if (r < 0) + if (r != -ENOENT) + return r; + return 0; } static int group_compare(const void*a, const void *b) { -- cgit v1.2.3-54-g00ecf From b7def684941808600c344f0be7a2b9fcdda97e0f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 13 Jul 2012 13:41:01 +0200 Subject: util: rename join() to strjoin() This is to match strappend() and the other string related functions. --- TODO | 4 ++++ src/cgtop/cgtop.c | 2 +- src/core/cgroup.c | 4 ++-- src/core/dbus-manager.c | 2 +- src/core/load-dropin.c | 6 +++--- src/core/manager.c | 4 ++-- src/core/mount.c | 2 +- src/core/service.c | 14 +++++++------- src/core/unit.c | 4 ++-- src/cryptsetup/cryptsetup-generator.c | 10 +++++----- src/delta/delta.c | 4 ++-- src/fstab-generator/fstab-generator.c | 16 ++++++++-------- src/getty-generator/getty-generator.c | 2 +- src/journal/coredump.c | 4 ++-- src/journal/journald.c | 4 ++-- src/journal/sd-journal.c | 10 +++++----- src/shared/cgroup-util.c | 10 +++++----- src/shared/conf-parser.c | 2 +- src/shared/hwclock.c | 2 +- src/shared/path-util.c | 2 +- src/shared/unit-name.c | 4 ++-- src/shared/util.c | 4 ++-- src/shared/util.h | 2 +- src/tmpfiles/tmpfiles.c | 2 +- 24 files changed, 62 insertions(+), 58 deletions(-) (limited to 'src/cgtop') diff --git a/TODO b/TODO index 25266b2845..c0a553bf82 100644 --- a/TODO +++ b/TODO @@ -34,6 +34,10 @@ Bugfixes: Features: +* logind: wakelock/opportunistic suspend support + +* seccomp filters for services + * replace BindTo= by BindsTo=, but keep old name for compat * switch-root: sockets need relabelling diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index f988adb363..5557094a4f 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -310,7 +310,7 @@ static int refresh_one( if (r <= 0) goto finish; - p = join(path, "/", fn, NULL); + p = strjoin(path, "/", fn, NULL); free(fn); if (!p) { diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 5513f6560c..aaea96b820 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -120,7 +120,7 @@ int cgroup_bonding_install(CGroupBonding *b, pid_t pid, const char *cgroup_suffi assert(pid >= 0); if (cgroup_suffix) { - p = join(b->path, "/", cgroup_suffix, NULL); + p = strjoin(b->path, "/", cgroup_suffix, NULL); if (!p) return -ENOMEM; @@ -208,7 +208,7 @@ int cgroup_bonding_kill(CGroupBonding *b, int sig, bool sigcont, bool rem, Set * return 0; if (cgroup_suffix) { - p = join(b->path, "/", cgroup_suffix, NULL); + p = strjoin(b->path, "/", cgroup_suffix, NULL); if (!p) return -ENOMEM; diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index f8a5400055..67b7b13eac 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1179,7 +1179,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, else { char *p; - p = join(switch_root, "/", switch_root_init, NULL); + p = strjoin(switch_root, "/", switch_root_init, NULL); if (!p) goto oom; diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c index 4323147a01..86f81c7484 100644 --- a/src/core/load-dropin.c +++ b/src/core/load-dropin.c @@ -51,7 +51,7 @@ static int iterate_dir(Unit *u, const char *path, UnitDependency dependency) { if (ignore_file(de->d_name)) continue; - f = join(path, "/", de->d_name, NULL); + f = strjoin(path, "/", de->d_name, NULL); if (!f) { r = -ENOMEM; goto finish; @@ -80,7 +80,7 @@ static int process_dir(Unit *u, const char *unit_path, const char *name, const c assert(name); assert(suffix); - path = join(unit_path, "/", name, suffix, NULL); + path = strjoin(unit_path, "/", name, suffix, NULL); if (!path) return -ENOMEM; @@ -102,7 +102,7 @@ static int process_dir(Unit *u, const char *unit_path, const char *name, const c if (!template) return -ENOMEM; - path = join(unit_path, "/", template, suffix, NULL); + path = strjoin(unit_path, "/", template, suffix, NULL); free(template); if (!path) diff --git a/src/core/manager.c b/src/core/manager.c index 7bd484be6c..8f2635051e 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -590,7 +590,7 @@ static void manager_build_unit_path_cache(Manager *m) { if (ignore_file(de->d_name)) continue; - p = join(streq(*i, "/") ? "" : *i, "/", de->d_name, NULL); + p = strjoin(streq(*i, "/") ? "" : *i, "/", de->d_name, NULL); if (!p) { r = -ENOMEM; goto fail; @@ -2085,7 +2085,7 @@ static int create_generator_dir(Manager *m, char **generator, const char *name) return r; } } else { - p = join("/tmp/systemd-", name, ".XXXXXX", NULL); + p = strjoin("/tmp/systemd-", name, ".XXXXXX", NULL); if (!p) { log_error("Out of memory"); return -ENOMEM; diff --git a/src/core/mount.c b/src/core/mount.c index fab922ea9e..15d5f21530 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -1534,7 +1534,7 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) { goto clean_up; } - o = join(options, ",", options2, NULL); + o = strjoin(options, ",", options2, NULL); if (!o) { r = -ENOMEM; goto finish; diff --git a/src/core/service.c b/src/core/service.c index e57b0e970c..2be6ee5d99 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -722,7 +722,7 @@ static int service_load_sysv_path(Service *s, const char *path) { char *d = NULL; if (chkconfig_description) - d = join(chkconfig_description, " ", j, NULL); + d = strjoin(chkconfig_description, " ", j, NULL); else d = strdup(j); @@ -879,7 +879,7 @@ static int service_load_sysv_path(Service *s, const char *path) { char *d = NULL; if (long_description) - d = join(long_description, " ", t, NULL); + d = strjoin(long_description, " ", t, NULL); else d = strdup(j); @@ -1001,7 +1001,7 @@ static int service_load_sysv_name(Service *s, const char *name) { char *path; int r; - path = join(*p, "/", name, NULL); + path = strjoin(*p, "/", name, NULL); if (!path) return -ENOMEM; @@ -1023,7 +1023,7 @@ static int service_load_sysv_name(Service *s, const char *name) { if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) { /* Try SUSE style boot.* init scripts */ - path = join(*p, "/boot.", name, NULL); + path = strjoin(*p, "/boot.", name, NULL); if (!path) return -ENOMEM; @@ -1038,7 +1038,7 @@ static int service_load_sysv_name(Service *s, const char *name) { if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) { /* Try Frugalware style rc.* init scripts */ - path = join(*p, "/rc.", name, NULL); + path = strjoin(*p, "/rc.", name, NULL); if (!path) return -ENOMEM; @@ -3407,7 +3407,7 @@ static int service_enumerate(Manager *m) { struct dirent *de; free(path); - path = join(*p, "/", rcnd_table[i].path, NULL); + path = strjoin(*p, "/", rcnd_table[i].path, NULL); if (!path) { r = -ENOMEM; goto finish; @@ -3442,7 +3442,7 @@ static int service_enumerate(Manager *m) { continue; free(fpath); - fpath = join(path, "/", de->d_name, NULL); + fpath = strjoin(path, "/", de->d_name, NULL); if (!fpath) { r = -ENOMEM; goto finish; diff --git a/src/core/unit.c b/src/core/unit.c index 37711afeaf..516f4fad8b 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1891,10 +1891,10 @@ static char *default_cgroup_path(Unit *u) { if (!t) return NULL; - p = join(u->manager->cgroup_hierarchy, "/", t, "/", u->instance, NULL); + p = strjoin(u->manager->cgroup_hierarchy, "/", t, "/", u->instance, NULL); free(t); } else - p = join(u->manager->cgroup_hierarchy, "/", u->id, NULL); + p = strjoin(u->manager->cgroup_hierarchy, "/", u->id, NULL); return p; } diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index f714c8c241..7801de64b5 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -88,7 +88,7 @@ static int create_disk( goto fail; } - p = join(arg_dest, "/", n, NULL); + p = strjoin(arg_dest, "/", n, NULL); if (!p) { r = -ENOMEM; log_error("Failed to allocate unit file name."); @@ -175,7 +175,7 @@ static int create_disk( if (!noauto) { - to = join(arg_dest, "/", d, ".wants/", n, NULL); + to = strjoin(arg_dest, "/", d, ".wants/", n, NULL); if (!to) { r = -ENOMEM; goto fail; @@ -191,9 +191,9 @@ static int create_disk( free(to); if (!nofail) - to = join(arg_dest, "/cryptsetup.target.requires/", n, NULL); + to = strjoin(arg_dest, "/cryptsetup.target.requires/", n, NULL); else - to = join(arg_dest, "/cryptsetup.target.wants/", n, NULL); + to = strjoin(arg_dest, "/cryptsetup.target.wants/", n, NULL); if (!to) { r = -ENOMEM; goto fail; @@ -211,7 +211,7 @@ static int create_disk( } e = unit_name_escape(name); - to = join(arg_dest, "/dev-mapper-", e, ".device.requires/", n, NULL); + to = strjoin(arg_dest, "/dev-mapper-", e, ".device.requires/", n, NULL); if (!to) { r = -ENOMEM; goto fail; diff --git a/src/delta/delta.c b/src/delta/delta.c index 01c6335315..eef6536b01 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -192,7 +192,7 @@ static int enumerate_dir(Hashmap *top, Hashmap *bottom, const char *path) { if (!dirent_is_file(de)) continue; - p = join(path, "/", de->d_name, NULL); + p = strjoin(path, "/", de->d_name, NULL); if (!p) { r = -ENOMEM; goto finish; @@ -254,7 +254,7 @@ static int process_suffix(const char *prefixes, const char *suffix) { NULSTR_FOREACH(p, prefixes) { char *t; - t = join(p, "/", suffix, NULL); + t = strjoin(p, "/", suffix, NULL); if (!t) { r = -ENOMEM; goto finish; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index f832730b40..3a59b85d66 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -103,7 +103,7 @@ static int add_swap(const char *what, struct mntent *me) { goto finish; } - unit = join(arg_dest, "/", name, NULL); + unit = strjoin(arg_dest, "/", name, NULL); if (!unit) { log_error("Out of memory"); r = -ENOMEM; @@ -146,7 +146,7 @@ static int add_swap(const char *what, struct mntent *me) { } if (!noauto) { - lnk = join(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL); + lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL); if (!lnk) { log_error("Out of memory"); r = -ENOMEM; @@ -169,7 +169,7 @@ static int add_swap(const char *what, struct mntent *me) { if (r > 0) { free(lnk); - lnk = join(arg_dest, "/", device, ".wants/", name, NULL); + lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL); if (!lnk) { log_error("Out of memory"); r = -ENOMEM; @@ -261,7 +261,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) { goto finish; } - unit = join(arg_dest, "/", name, NULL); + unit = strjoin(arg_dest, "/", name, NULL); if (!unit) { log_error("Out of memory"); r = -ENOMEM; @@ -321,7 +321,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) { } if (!noauto) { - lnk = join(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL); + lnk = strjoin(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL); if (!lnk) { log_error("Out of memory"); r = -ENOMEM; @@ -347,7 +347,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) { if (r > 0) { free(lnk); - lnk = join(arg_dest, "/", device, ".wants/", name, NULL); + lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL); if (!lnk) { log_error("Out of memory"); r = -ENOMEM; @@ -372,7 +372,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) { goto finish; } - automount_unit = join(arg_dest, "/", automount_name, NULL); + automount_unit = strjoin(arg_dest, "/", automount_name, NULL); if (!automount_unit) { log_error("Out of memory"); r = -ENOMEM; @@ -408,7 +408,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) { } free(lnk); - lnk = join(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL); + lnk = strjoin(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL); if (!lnk) { log_error("Out of memory"); r = -ENOMEM; diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index bb7c225e02..b2e3eb6393 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -39,7 +39,7 @@ static int add_symlink(const char *fservice, const char *tservice) { assert(tservice); from = strappend(SYSTEM_DATA_UNIT_PATH "/", fservice); - to = join(arg_dest,"/getty.target.wants/", tservice, NULL); + to = strjoin(arg_dest,"/getty.target.wants/", tservice, NULL); if (!from || !to) { log_error("Out of memory"); diff --git a/src/journal/coredump.c b/src/journal/coredump.c index 300677bb92..fcd0d1e625 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -213,14 +213,14 @@ int main(int argc, char* argv[]) { IOVEC_SET_STRING(iovec[j++], core_cmdline); } - core_timestamp = join("COREDUMP_TIMESTAMP=", argv[ARG_TIMESTAMP], "000000", NULL); + core_timestamp = strjoin("COREDUMP_TIMESTAMP=", argv[ARG_TIMESTAMP], "000000", NULL); if (core_timestamp) IOVEC_SET_STRING(iovec[j++], core_timestamp); IOVEC_SET_STRING(iovec[j++], "MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1"); IOVEC_SET_STRING(iovec[j++], "PRIORITY=2"); - core_message = join("MESSAGE=Process ", argv[ARG_PID], " (", argv[ARG_COMM], ") dumped core.", NULL); + core_message = strjoin("MESSAGE=Process ", argv[ARG_PID], " (", argv[ARG_COMM], ") dumped core.", NULL); if (core_message) IOVEC_SET_STRING(iovec[j++], core_message); diff --git a/src/journal/journald.c b/src/journal/journald.c index 2402f7f6d0..fd292f019e 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -1976,7 +1976,7 @@ static int system_journal_open(Server *s) { (void) mkdir(fn, 0755); free(fn); - fn = join("/var/log/journal/", ids, "/system.journal", NULL); + fn = strjoin("/var/log/journal/", ids, "/system.journal", NULL); if (!fn) return -ENOMEM; @@ -2002,7 +2002,7 @@ static int system_journal_open(Server *s) { if (!s->runtime_journal && (s->storage != STORAGE_NONE)) { - fn = join("/run/log/journal/", ids, "/system.journal", NULL); + fn = strjoin("/run/log/journal/", ids, "/system.journal", NULL); if (!fn) return -ENOMEM; diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 4bcc65c5c7..57572d4f01 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -313,7 +313,7 @@ static char *match_make_string(Match *m) { } if (p) { - k = join(p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t, NULL); + k = strjoin(p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t, NULL); free(p); free(t); @@ -330,7 +330,7 @@ static char *match_make_string(Match *m) { } if (enclose) { - r = join("(", p, ")", NULL); + r = strjoin("(", p, ")", NULL); free(p); return r; } @@ -1101,7 +1101,7 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) { (startswith(filename, "system@") && endswith(filename, ".journal")))) return 0; - path = join(prefix, "/", filename, NULL); + path = strjoin(prefix, "/", filename, NULL); if (!path) return -ENOMEM; @@ -1149,7 +1149,7 @@ static int remove_file(sd_journal *j, const char *prefix, const char *filename) assert(prefix); assert(filename); - path = join(prefix, "/", filename, NULL); + path = strjoin(prefix, "/", filename, NULL); if (!path) return -ENOMEM; @@ -1184,7 +1184,7 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname) !sd_id128_equal(id, mid))) return 0; - path = join(prefix, "/", dirname, NULL); + path = strjoin(prefix, "/", dirname, NULL); if (!path) return -ENOMEM; diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 6740d3b885..b0d378de5a 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -522,16 +522,16 @@ static int join_path(const char *controller, const char *path, const char *suffi if (controller) { if (path && suffix) - t = join("/sys/fs/cgroup/", controller, "/", path, "/", suffix, NULL); + t = strjoin("/sys/fs/cgroup/", controller, "/", path, "/", suffix, NULL); else if (path) - t = join("/sys/fs/cgroup/", controller, "/", path, NULL); + t = strjoin("/sys/fs/cgroup/", controller, "/", path, NULL); else if (suffix) - t = join("/sys/fs/cgroup/", controller, "/", suffix, NULL); + t = strjoin("/sys/fs/cgroup/", controller, "/", suffix, NULL); else - t = join("/sys/fs/cgroup/", controller, NULL); + t = strjoin("/sys/fs/cgroup/", controller, NULL); } else { if (path && suffix) - t = join(path, "/", suffix, NULL); + t = strjoin(path, "/", suffix, NULL); else if (path) t = strdup(path); } diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 8c62fb959b..1eccec5989 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -90,7 +90,7 @@ int config_item_perf_lookup( else { char *key; - key = join(section, ".", lvalue, NULL); + key = strjoin(section, ".", lvalue, NULL); if (!key) return -ENOMEM; diff --git a/src/shared/hwclock.c b/src/shared/hwclock.c index d40bb2653f..9f8ab08e2b 100644 --- a/src/shared/hwclock.c +++ b/src/shared/hwclock.c @@ -74,7 +74,7 @@ static int rtc_open(int flags) { if (ignore_file(de->d_name)) continue; - p = join("/sys/class/rtc/", de->d_name, "/hctosys", NULL); + p = strjoin("/sys/class/rtc/", de->d_name, "/hctosys", NULL); if (!p) { closedir(d); return -ENOMEM; diff --git a/src/shared/path-util.c b/src/shared/path-util.c index ccd7667608..8bc7955020 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -120,7 +120,7 @@ char *path_make_absolute(const char *p, const char *prefix) { if (path_is_absolute(p) || !prefix) return strdup(p); - return join(prefix, "/", p, NULL); + return strjoin(prefix, "/", p, NULL); } char *path_make_absolute_cwd(const char *p) { diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index 3e437b77a1..fcf5902c78 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -208,7 +208,7 @@ char *unit_name_build(const char *prefix, const char *instance, const char *suff if (!instance) return strappend(prefix, suffix); - return join(prefix, "@", instance, suffix, NULL); + return strjoin(prefix, "@", instance, suffix, NULL); } static char *do_escape_char(char c, char *t) { @@ -425,7 +425,7 @@ char *unit_name_from_path_instance(const char *prefix, const char *path, const c if (!p) return NULL; - r = join(prefix, "@", p, suffix, NULL); + r = strjoin(prefix, "@", p, suffix, NULL); free(p); return r; diff --git a/src/shared/util.c b/src/shared/util.c index 63471899fd..2aabd8d634 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1083,7 +1083,7 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * if (h < 0) return h; - r = join("[", t, "]", NULL); + r = strjoin("[", t, "]", NULL); free(t); if (!r) @@ -5145,7 +5145,7 @@ finish: return r; } -char *join(const char *x, ...) { +char *strjoin(const char *x, ...) { va_list ap; size_t l; char *r, *p; diff --git a/src/shared/util.h b/src/shared/util.h index c8d048f9b2..d9b656d2ca 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -451,7 +451,7 @@ int dirent_ensure_type(DIR *d, struct dirent *de); int in_search_path(const char *path, char **search); int get_files_in_directory(const char *path, char ***list); -char *join(const char *x, ...) _sentinel_; +char *strjoin(const char *x, ...) _sentinel_; bool is_main_thread(void); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 2d5d90d265..3b52b9889c 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1297,7 +1297,7 @@ static char *resolve_fragment(const char *fragment, const char **search_paths) { return strdup(fragment); STRV_FOREACH(p, search_paths) { - resolved_path = join(*p, "/", fragment, NULL); + resolved_path = strjoin(*p, "/", fragment, NULL); if (resolved_path == NULL) { log_error("Out of memory"); return NULL; -- cgit v1.2.3-54-g00ecf From 669241a076108e0483d7d8475beaa506106d077e Mon Sep 17 00:00:00 2001 From: Shawn Landden Date: Tue, 24 Jul 2012 21:12:43 -0700 Subject: use "Out of memory." consistantly (or with "\n") glibc/glib both use "out of memory" consistantly so maybe we should consider that instead of this. Eliminates one string out of a number of binaries. Also fixes extra newline in udev/scsi_id --- src/cgtop/cgtop.c | 2 +- src/core/cgroup.c | 2 +- src/core/dbus.c | 16 ++++++------ src/core/manager.c | 6 ++--- src/cryptsetup/cryptsetup-generator.c | 6 ++--- src/cryptsetup/cryptsetup.c | 6 ++--- src/fsck/fsck.c | 2 +- src/fstab-generator/fstab-generator.c | 30 +++++++++++----------- src/getty-generator/getty-generator.c | 6 ++--- src/hostname/hostnamed.c | 2 +- src/journal/coredump.c | 2 +- src/journal/journalctl.c | 2 +- src/journal/journald.c | 10 ++++---- src/locale/localed.c | 6 ++--- src/login/logind-button.c | 2 +- src/login/logind-session.c | 8 +++--- src/login/logind-user.c | 4 +-- src/login/logind.c | 4 +-- src/login/multi-seat-x.c | 2 +- src/modules-load/modules-load.c | 4 +-- src/nspawn/nspawn.c | 22 ++++++++-------- src/rc-local-generator/rc-local-generator.c | 2 +- src/readahead/readahead-collect.c | 6 ++--- src/readahead/readahead-replay.c | 2 +- src/shared/ask-password-api.c | 2 +- src/shared/dbus-common.c | 2 +- src/shared/logs-show.c | 2 +- src/shared/util.c | 6 ++--- src/shutdownd/shutdownd.c | 2 +- src/sysctl/sysctl.c | 4 +-- src/systemctl/systemctl.c | 20 +++++++-------- src/timedate/timedated.c | 10 ++++---- src/tmpfiles/tmpfiles.c | 10 ++++---- .../tty-ask-password-agent.c | 4 +-- src/udev/collect/collect.c | 2 +- src/udev/scsi_id/scsi_id.c | 4 +-- 36 files changed, 111 insertions(+), 111 deletions(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 5557094a4f..c3824c7979 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -608,7 +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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/core/cgroup.c b/src/core/cgroup.c index aaea96b820..1322f63eee 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -330,7 +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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/core/dbus.c b/src/core/dbus.c index 1bc83a2c2a..0c13517143 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -724,12 +724,12 @@ static int bus_setup_loop(Manager *m, DBusConnection *bus) { 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("Not enough memory"); + log_error("Out of memory."); return -ENOMEM; } if (set_put(m->bus_connections_for_dispatch, bus) < 0) { - log_error("Not enough memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -764,7 +764,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("Not enough memory."); + log_error("Out of memory."); return; } @@ -777,7 +777,7 @@ 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("Not enough memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -815,7 +815,7 @@ static int init_registered_api_bus(Manager *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("Not enough memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -1090,7 +1090,7 @@ static int bus_init_private(Manager *m) { return 0; if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) { - log_error("Not enough memory"); + log_error("Out of memory."); r = -ENOMEM; goto fail; } @@ -1110,7 +1110,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("Not enough memory"); + log_error("Out of memory."); r = -ENOMEM; goto fail; } @@ -1158,7 +1158,7 @@ int bus_init(Manager *m, bool try_bus_connect) { return 0; oom: - log_error("Not enough memory"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/core/manager.c b/src/core/manager.c index 48305e373a..42a9490242 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_error("Out of memory."); goto finish; } @@ -2074,7 +2074,7 @@ static int create_generator_dir(Manager *m, char **generator, const char *name) p = strappend("/run/systemd/", name); if (!p) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -2087,7 +2087,7 @@ 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"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index d0984242c8..fb6b4d25c0 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -303,7 +303,7 @@ static int parse_proc_cmdline(void) { t = strv_append(arg_proc_cmdline_disks, word + 10); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -317,7 +317,7 @@ static int parse_proc_cmdline(void) { t = strv_append(arg_proc_cmdline_disks, word + 13); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -380,7 +380,7 @@ int main(int argc, char *argv[]) { device = strappend("UUID=", *i); if (!name || !device) { - log_error("Out of memory"); + log_error("Out of memory."); r = EXIT_FAILURE; free(name); free(device); diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index f570724b9d..9d4e77364d 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_error("Out of memory."); 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_error("Out of memory."); 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_error("Out of memory."); goto finish; } diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 833f3f74a6..036d3c5b41 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_error("Out of memory."); goto finish; } diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 3a59b85d66..89a4d13504 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -98,14 +98,14 @@ static int add_swap(const char *what, struct mntent *me) { name = unit_name_from_path(what, ".swap"); if (!name) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } unit = strjoin(arg_dest, "/", name, NULL); if (!unit) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -148,7 +148,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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -162,7 +162,7 @@ static int add_swap(const char *what, struct mntent *me) { r = device_name(what, &device); if (r < 0) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -171,7 +171,7 @@ static int add_swap(const char *what, struct mntent *me) { free(lnk); lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL); if (!lnk) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -256,14 +256,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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } unit = strjoin(arg_dest, "/", name, NULL); if (!unit) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -323,7 +323,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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -340,7 +340,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) { r = device_name(what, &device); if (r < 0) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -349,7 +349,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) { free(lnk); lnk = strjoin(arg_dest, "/", device, ".wants/", name, NULL); if (!lnk) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -367,14 +367,14 @@ 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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } automount_unit = strjoin(arg_dest, "/", automount_name, NULL); if (!automount_unit) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -410,7 +410,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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -459,14 +459,14 @@ static int parse_fstab(void) { what = fstab_node_to_udev_node(me->mnt_fsname); if (!what) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } where = strdup(me->mnt_dir); if (!where) { - log_error("Out of memory"); + log_error("Out of memory."); free(what); r = -ENOMEM; goto finish; diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index b2e3eb6393..9e46a47a9a 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -42,7 +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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -78,7 +78,7 @@ static int add_serial_getty(const char *tty) { n = unit_name_replace_instance("serial-getty@.service", tty); if (!n) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -160,7 +160,7 @@ int main(int argc, char *argv[]) { int k; if (asprintf(&p, "/sys/class/tty/%s", j) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); r = EXIT_FAILURE; goto finish; } diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 67c56f3313..7dab5f40df 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -532,7 +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("Not enough memory"); + log_error("Out of memory."); r = -ENOMEM; goto fail; } diff --git a/src/journal/coredump.c b/src/journal/coredump.c index fcd0d1e625..cfd3a910d9 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -239,7 +239,7 @@ int main(int argc, char* argv[]) { p = malloc(9 + COREDUMP_MAX); if (!p) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index e633dd34d7..a9cf9cd957 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -256,7 +256,7 @@ static int add_matches(sd_journal *j, char **args) { t = strappend("_EXE=", path); if (!t) { free(p); - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/journal/journald.c b/src/journal/journald.c index 36f9abe47e..ae1fbc4bd4 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -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_error("Out of memory."); break; } @@ -1357,7 +1357,7 @@ static void process_native_message( k = malloc((e - p) + 1 + l); if (!k) { - log_error("Out of memory"); + log_error("Out of memory."); break; } @@ -1450,7 +1450,7 @@ static void process_native_file( p = malloc(st.st_size); if (!p) { - log_error("Out of memory"); + log_error("Out of memory."); return; } @@ -1543,7 +1543,7 @@ static int stdout_stream_line(StdoutStream *s, char *p) { else { s->identifier = strdup(p); if (!s->identifier) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } } @@ -1558,7 +1558,7 @@ static int stdout_stream_line(StdoutStream *s, char *p) { else { s->unit_id = strdup(p); if (!s->unit_id) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } } diff --git a/src/locale/localed.c b/src/locale/localed.c index 56fb339e19..b8007d72fd 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_error("Out of memory."); 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_error("Out of memory."); goto finish; } @@ -1344,7 +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("Not enough memory"); + log_error("Out of memory."); r = -ENOMEM; goto fail; } diff --git a/src/login/logind-button.c b/src/login/logind-button.c index 8b59c2b0c3..62e0c3dbba 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -108,7 +108,7 @@ int button_open(Button *b) { p = strappend("/dev/input/", b->name); if (!p) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 819596ddbe..a43ecad2b1 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -375,7 +375,7 @@ 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"); + log_error("Out of memory."); return -ENOMEM; } @@ -395,7 +395,7 @@ static int session_link_x11_socket(Session *s) { t = strappend(s->user->runtime_path, "/X11-display"); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); free(f); return -ENOMEM; } @@ -469,7 +469,7 @@ static int session_create_cgroup(Session *s) { if (!s->cgroup_path) { if (asprintf(&p, "%s/%s", s->user->cgroup_path, s->id) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } } else @@ -670,7 +670,7 @@ static int session_unlink_x11_socket(Session *s) { t = strappend(s->user->runtime_path, "/X11-display"); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 0a3f22ce99..fca68159a7 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -260,7 +260,7 @@ 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"); + log_error("Out of memory."); return -ENOMEM; } } else @@ -287,7 +287,7 @@ static int user_create_cgroup(User *u) { if (!u->cgroup_path) { if (asprintf(&p, "%s/%s", u->manager->cgroup_path, u->name) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } } else diff --git a/src/login/logind.c b/src/login/logind.c index 0775583147..1cfb7fa9ac 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1176,7 +1176,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("Not enough memory"); + log_error("Out of memory."); r = -ENOMEM; goto fail; } @@ -1611,7 +1611,7 @@ int main(int argc, char *argv[]) { m = manager_new(); if (!m) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/login/multi-seat-x.c b/src/login/multi-seat-x.c index 92014f5316..a1fab86f6a 100644 --- a/src/login/multi-seat-x.c +++ b/src/login/multi-seat-x.c @@ -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_error("Out of memory."); goto fail; } diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c index d6bc16d340..e73ba7f241 100644 --- a/src/modules-load/modules-load.c +++ b/src/modules-load/modules-load.c @@ -50,14 +50,14 @@ static int add_modules(const char *p) { k = strv_split(p, ","); if (!k) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } t = strv_merge(arg_proc_cmdline_modules, k); strv_free(k); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 1d7511e2ab..355a103edf 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -289,7 +289,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_error("Out of memory."); if (r == 0) r = -ENOMEM; @@ -336,7 +336,7 @@ static int setup_timezone(const char *dest) { /* Fix the timezone, if possible */ if (asprintf(&where, "%s/etc/localtime", dest) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -346,7 +346,7 @@ static int setup_timezone(const char *dest) { free(where); if (asprintf(&where, "%s/etc/timezone", dest) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -368,7 +368,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"); + log_error("Out of memory."); return -ENOMEM; } @@ -480,7 +480,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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -535,13 +535,13 @@ 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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } if (asprintf(&to, "%s/proc/kmsg", dest) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -639,7 +639,7 @@ static int setup_journal(const char *directory) { p = strappend(directory, "/etc/machine-id"); if (!p) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -670,7 +670,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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -1296,13 +1296,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_error("Out of memory."); goto child_fail; } if (arg_uuid) { if (asprintf((char**)(envp + 6), "container_uuid=%s", arg_uuid) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); goto child_fail; } } diff --git a/src/rc-local-generator/rc-local-generator.c b/src/rc-local-generator/rc-local-generator.c index f41a6bf265..9fafa29f22 100644 --- a/src/rc-local-generator/rc-local-generator.c +++ b/src/rc-local-generator/rc-local-generator.c @@ -48,7 +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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c index 8dacf6af5c..45d489a60e 100644 --- a/src/readahead/readahead-collect.c +++ b/src/readahead/readahead-collect.c @@ -242,7 +242,7 @@ static int collect(const char *root) { assert(root); if (asprintf(&pack_fn, "%s/.readahead", root) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -477,7 +477,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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -510,7 +510,7 @@ done: n = hashmap_size(files); if (!(ordered = new(struct item, n))) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/readahead/readahead-replay.c b/src/readahead/readahead-replay.c index 7bd079aae5..f90821e831 100644 --- a/src/readahead/readahead-replay.c +++ b/src/readahead/readahead-replay.c @@ -150,7 +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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 4333bfb564..005f40fef7 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -282,7 +282,7 @@ static int create_socket(char **name) { if (!(c = strdup(sa.un.sun_path))) { r = -ENOMEM; - log_error("Out of memory"); + log_error("Out of memory."); goto fail; } diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c index 7d57680cfc..ab1dc4d7e4 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_error("Out of memory."); if (pending) { dbus_pending_call_cancel(pending); diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index a68cd3de57..f90f5a1f0d 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -53,7 +53,7 @@ static int parse_field(const void *data, size_t length, const char *field, char memcpy(buf, (const char*) data + fl, nl); ((char*)buf)[nl] = 0; if (!buf) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/shared/util.c b/src/shared/util.c index 43ec62eac6..2e7ae63db2 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -909,7 +909,7 @@ int load_env_file( continue; if (!(u = normalize_env_assignment(p))) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -918,7 +918,7 @@ int load_env_file( free(u); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -4278,7 +4278,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_error("Out of memory."); continue; } diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c index 6eb8ed9bf8..9dd1336133 100644 --- a/src/shutdownd/shutdownd.c +++ b/src/shutdownd/shutdownd.c @@ -213,7 +213,7 @@ static int update_schedule_file(struct sd_shutdown_command *c) { t = cescape(c->wall_message); if (!t) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index 72a74f9e44..b463c7fac7 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -46,7 +46,7 @@ static int apply_sysctl(const char *property, const char *value) { p = new(char, sizeof(PROC_SYS_PREFIX) + strlen(property)); if (!p) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -192,7 +192,7 @@ static int parse_argv(int argc, char *argv[]) { l = strv_append(arg_prefixes, optarg); if (!l) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index a13fc1a8f0..d493733761 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -658,7 +658,7 @@ static int list_unit_files(DBusConnection *bus, char **args) { h = hashmap_new(string_hash_func, string_compare_func); if (!h) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -673,7 +673,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"); + log_error("Out of memory."); return -ENOMEM; } @@ -2637,7 +2637,7 @@ static void show_unit_help(UnitStatusInfo *i) { section = strndup(e + 1, *p + k - e - 2); if (!section) { free(page); - log_error("Out of memory"); + log_error("Out of memory."); return; } @@ -3283,7 +3283,7 @@ static int show(DBusConnection *bus, char **args) { p = unit_dbus_path_from_name(n ? n : *name); free(n); if (!p) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -3299,7 +3299,7 @@ static int show(DBusConnection *bus, char **args) { char *p; if (asprintf(&p, "/org/freedesktop/systemd1/job/%u", id) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -3974,7 +3974,7 @@ static int enable_sysv_units(char **args) { asprintf(&p, "%s/%s", *k, name); if (!p) { - log_error("No memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -3995,7 +3995,7 @@ static int enable_sysv_units(char **args) { else asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name); if (!p) { - log_error("No memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -4024,7 +4024,7 @@ static int enable_sysv_units(char **args) { l = strv_join((char**)argv, " "); if (!l) { - log_error("No memory."); + log_error("Out of memory."); free(q); free(p); r = -ENOMEM; @@ -4184,7 +4184,7 @@ static int enable_unit(DBusConnection *bus, char **args) { "org.freedesktop.systemd1.Manager", method); if (!m) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -4339,7 +4339,7 @@ static int unit_is_enabled(DBusConnection *bus, char **args) { "org.freedesktop.systemd1.Manager", "GetUnitFileState"); if (!m) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 237eb24894..3fef9e8844 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_error("Out of memory."); return; } @@ -220,7 +220,7 @@ static int write_data_timezone(void) { p = strappend("/usr/share/zoneinfo/", tz.zone); if (!p) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -341,7 +341,7 @@ static char** get_ntp_services(void) { q = strv_append(r, l); if (!q) { - log_error("Out of memory"); + log_error("Out of memory."); break; } @@ -379,7 +379,7 @@ static int read_ntp(DBusConnection *bus) { "org.freedesktop.systemd1.Manager", "GetUnitFileState"); if (!m) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -943,7 +943,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("Not enough memory"); + log_error("Out of memory."); r = -ENOMEM; goto fail; } diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 45125b7b94..f8d89218c9 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -260,7 +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"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -970,7 +970,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) { i = new0(Item, 1); if (!i) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } @@ -999,7 +999,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) { if (buffer[n] != 0 && (buffer[n] != '-' || buffer[n+1] != 0)) { i->argument = unquote(buffer+n, "\""); if (!i->argument) { - log_error("Out of memory"); + log_error("Out of memory."); return -ENOMEM; } } @@ -1302,7 +1302,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_error("Out of memory."); return NULL; } @@ -1337,7 +1337,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_error("Out of memory."); 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 2ab3401e6f..403e8cd3c6 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -315,7 +315,7 @@ static int parse_password(const char *filename, char **wall) { *wall ? "\r\n\r\n" : "", message, pid) < 0) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } @@ -533,7 +533,7 @@ static int show_passwords(void) { continue; if (!(p = strappend("/run/systemd/ask-password/", de->d_name))) { - log_error("Out of memory"); + log_error("Out of memory."); r = -ENOMEM; goto finish; } diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index 80f464aff0..4162c436b0 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -141,7 +141,7 @@ static int checkout(int fd) len = bufsize >> 1; buf = calloc(1,bufsize + 1); if (!buf) { - fprintf(stderr, "Out of memory\n"); + fprintf(stderr, "Out of memory.\n"); return -1; } memset(buf, ' ', bufsize); diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c index 6fc41e94fb..0bb1bc495a 100644 --- a/src/udev/scsi_id/scsi_id.c +++ b/src/udev/scsi_id/scsi_id.c @@ -198,7 +198,7 @@ static int get_file_options(struct udev *udev, buffer = malloc(MAX_BUFFER_LEN); if (!buffer) { fclose(fd); - log_error("can't allocate memory\n"); + log_error("Out of memory."); return -1; } @@ -294,7 +294,7 @@ static int get_file_options(struct udev *udev, c = argc_count(buffer) + 2; *newargv = calloc(c, sizeof(**newargv)); if (!*newargv) { - log_error("can't allocate memory\n"); + log_error("Out of memory."); retval = -1; } else { *argc = c; -- cgit v1.2.3-54-g00ecf 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/cgtop/cgtop.c | 3 +- src/core/cgroup.c | 3 +- src/core/dbus.c | 41 ++++++---------- src/core/manager.c | 14 ++---- src/cryptsetup/cryptsetup-generator.c | 8 ++- src/cryptsetup/cryptsetup.c | 8 +-- src/fsck/fsck.c | 2 +- src/fstab-generator/fstab-generator.c | 57 ++++++++-------------- src/getty-generator/getty-generator.c | 11 ++--- src/hostname/hostnamed.c | 3 +- src/journal/cat.c | 6 +-- src/journal/coredump.c | 3 +- src/journal/journalctl.c | 3 +- src/journal/journald.c | 31 +++++------- src/locale/localed.c | 17 +++---- src/login/logind-button.c | 6 +-- src/login/logind-session.c | 21 +++----- src/login/logind-user.c | 12 ++--- src/login/logind.c | 18 +++---- src/login/multi-seat-x.c | 4 +- src/modules-load/modules-load.c | 12 ++--- src/nspawn/nspawn.c | 42 ++++++---------- src/rc-local-generator/rc-local-generator.c | 3 +- src/readahead/readahead-collect.c | 9 ++-- src/readahead/readahead-replay.c | 3 +- src/remount-fs/remount-fs.c | 2 +- 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 ++- src/shutdownd/shutdownd.c | 6 +-- src/sysctl/sysctl.c | 12 ++--- .../system-update-generator.c | 6 +-- src/systemctl/systemctl.c | 40 ++++++--------- src/timedate/timedated.c | 19 +++----- src/tmpfiles/tmpfiles.c | 19 +++----- .../tty-ask-password-agent.c | 6 +-- src/udev/scsi_id/scsi_id.c | 12 ++--- src/vconsole/vconsole-setup.c | 6 +-- 40 files changed, 183 insertions(+), 310 deletions(-) (limited to 'src/cgtop') 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 #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; } 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; } -- cgit v1.2.3-54-g00ecf From a152771af17da095fc58302de5ea330f394f89c9 Mon Sep 17 00:00:00 2001 From: David Strauss Date: Wed, 25 Jul 2012 16:33:06 -0700 Subject: Add an 'n' option to cgtop (equivalent to top) --- src/cgtop/cgtop.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index f0ca83fd45..c439d09fd6 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -55,6 +55,7 @@ typedef struct Group { } Group; static unsigned arg_depth = 3; +static unsigned arg_iterations = 0; static usec_t arg_delay = 1*USEC_PER_SEC; static enum { @@ -505,6 +506,7 @@ static void help(void) { " -m Order by memory load\n" " -i Order by IO load\n" " -d --delay=DELAY Specify delay\n" + " -n --iterations=N Run for N iterations before exiting\n" " --depth=DEPTH Maximum traversal depth (default: 2)\n", program_invocation_short_name); } @@ -516,10 +518,11 @@ static int parse_argv(int argc, char *argv[]) { }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "delay", required_argument, NULL, 'd' }, - { "depth", required_argument, NULL, ARG_DEPTH }, - { NULL, 0, NULL, 0 } + { "help", no_argument, NULL, 'h' }, + { "delay", required_argument, NULL, 'd' }, + { "iterations", required_argument, NULL, 'n' }, + { "depth", required_argument, NULL, ARG_DEPTH }, + { NULL, 0, NULL, 0 } }; int c; @@ -528,7 +531,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 1); assert(argv); - while ((c = getopt_long(argc, argv, "hptcmid:", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hptcmin:d:", options, NULL)) >= 0) { switch (c) { @@ -554,6 +557,15 @@ static int parse_argv(int argc, char *argv[]) { break; + case 'n': + r = safe_atou(optarg, &arg_iterations); + if (r < 0) { + log_error("Failed to parse iterations parameter."); + return -EINVAL; + } + + break; + case 'p': arg_order = ORDER_PATH; break; @@ -640,6 +652,9 @@ int main(int argc, char *argv[]) { if (r < 0) goto finish; + if (arg_iterations && iteration >= arg_iterations) + break; + r = read_one_char(stdin, &key, last_refresh + arg_delay - t, NULL); if (r == -ETIMEDOUT) continue; -- cgit v1.2.3-54-g00ecf From e66bb58bed3fe5ef152268ac257b2801a7679549 Mon Sep 17 00:00:00 2001 From: David Strauss Date: Wed, 25 Jul 2012 16:33:07 -0700 Subject: Add a 'b' option to cgtop, equivalent to the same option in top [zj: use static] --- src/cgtop/cgtop.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index c439d09fd6..3009589597 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -56,6 +56,7 @@ typedef struct Group { static unsigned arg_depth = 3; static unsigned arg_iterations = 0; +static bool arg_batch = false; static usec_t arg_delay = 1*USEC_PER_SEC; static enum { @@ -507,6 +508,7 @@ static void help(void) { " -i Order by IO load\n" " -d --delay=DELAY Specify delay\n" " -n --iterations=N Run for N iterations before exiting\n" + " -b --batch Run in batch mode, accepting no input\n" " --depth=DEPTH Maximum traversal depth (default: 2)\n", program_invocation_short_name); } @@ -521,6 +523,7 @@ static int parse_argv(int argc, char *argv[]) { { "help", no_argument, NULL, 'h' }, { "delay", required_argument, NULL, 'd' }, { "iterations", required_argument, NULL, 'n' }, + { "batch", no_argument, NULL, 'b' }, { "depth", required_argument, NULL, ARG_DEPTH }, { NULL, 0, NULL, 0 } }; @@ -531,7 +534,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 1); assert(argv); - while ((c = getopt_long(argc, argv, "hptcmin:d:", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hptcmin:bd:", options, NULL)) >= 0) { switch (c) { @@ -566,6 +569,10 @@ static int parse_argv(int argc, char *argv[]) { break; + case 'b': + arg_batch = true; + break; + case 'p': arg_order = ORDER_PATH; break; @@ -655,17 +662,25 @@ int main(int argc, char *argv[]) { if (arg_iterations && iteration >= arg_iterations) break; - r = read_one_char(stdin, &key, last_refresh + arg_delay - t, NULL); - if (r == -ETIMEDOUT) - continue; - if (r < 0) { - log_error("Couldn't read key: %s", strerror(-r)); - goto finish; + if (arg_batch) { + usleep(last_refresh + arg_delay - t); + } else { + r = read_one_char(stdin, &key, + last_refresh + arg_delay - t, NULL); + if (r == -ETIMEDOUT) + continue; + if (r < 0) { + log_error("Couldn't read key: %s", strerror(-r)); + goto finish; + } } fputs("\r \r", stdout); fflush(stdout); + if (arg_batch) + continue; + switch (key) { case ' ': -- cgit v1.2.3-54-g00ecf From 11f96fac8f30423cb14f84622de9ed56b3b8f093 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 26 Jul 2012 20:23:28 +0200 Subject: cgtop: use full terminal width --- src/cgtop/cgtop.c | 30 ++++++++++++++++++++---------- src/shared/util.c | 31 ++++++++++++++++++++++++------- src/shared/util.h | 1 + 3 files changed, 45 insertions(+), 17 deletions(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 3009589597..d8d36b3619 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -426,7 +426,7 @@ static int display(Hashmap *a) { Iterator i; Group *g; Group **array; - unsigned rows, n = 0, j; + unsigned rows, path_columns, n = 0, j; assert(a); @@ -446,13 +446,23 @@ static int display(Hashmap *a) { if (rows <= 0) rows = 25; - printf("%s%-37s%s %s%7s%s %s%6s%s %s%8s%s %s%8s%s %s%8s%s\n\n", - arg_order == ORDER_PATH ? ANSI_HIGHLIGHT_ON : "", "Path", arg_order == ORDER_PATH ? ANSI_HIGHLIGHT_OFF : "", - arg_order == ORDER_TASKS ? ANSI_HIGHLIGHT_ON : "", "Tasks", arg_order == ORDER_TASKS ? ANSI_HIGHLIGHT_OFF : "", - arg_order == ORDER_CPU ? ANSI_HIGHLIGHT_ON : "", "%CPU", arg_order == ORDER_CPU ? ANSI_HIGHLIGHT_OFF : "", - arg_order == ORDER_MEMORY ? ANSI_HIGHLIGHT_ON : "", "Memory", arg_order == ORDER_MEMORY ? ANSI_HIGHLIGHT_OFF : "", - arg_order == ORDER_IO ? ANSI_HIGHLIGHT_ON : "", "Input/s", arg_order == ORDER_IO ? ANSI_HIGHLIGHT_OFF : "", - arg_order == ORDER_IO ? ANSI_HIGHLIGHT_ON : "", "Output/s", arg_order == ORDER_IO ? ANSI_HIGHLIGHT_OFF : ""); + path_columns = columns_uncached() - 42; + if (path_columns < 10) + path_columns = 10; + + printf("%s%-*s%s %s%7s%s %s%6s%s %s%8s%s %s%8s%s %s%8s%s\n\n", + arg_order == ORDER_PATH ? ANSI_HIGHLIGHT_ON : "", path_columns, "Path", + arg_order == ORDER_PATH ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_TASKS ? ANSI_HIGHLIGHT_ON : "", "Tasks", + arg_order == ORDER_TASKS ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_CPU ? ANSI_HIGHLIGHT_ON : "", "%CPU", + arg_order == ORDER_CPU ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_MEMORY ? ANSI_HIGHLIGHT_ON : "", "Memory", + arg_order == ORDER_MEMORY ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_IO ? ANSI_HIGHLIGHT_ON : "", "Input/s", + arg_order == ORDER_IO ? ANSI_HIGHLIGHT_OFF : "", + arg_order == ORDER_IO ? ANSI_HIGHLIGHT_ON : "", "Output/s", + arg_order == ORDER_IO ? ANSI_HIGHLIGHT_OFF : ""); for (j = 0; j < n; j++) { char *p; @@ -463,8 +473,8 @@ static int display(Hashmap *a) { g = array[j]; - p = ellipsize(g->path, 37, 33); - printf("%-37s", p ? p : g->path); + p = ellipsize(g->path, path_columns, 33); + printf("%-*s", path_columns, p ? p : g->path); free(p); if (g->n_tasks_valid) diff --git a/src/shared/util.c b/src/shared/util.c index 5f360085a2..af975956db 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3774,18 +3774,27 @@ int fd_columns(int fd) { return ws.ws_col; } -unsigned columns(void) { - static __thread int parsed_columns = 0; +static unsigned columns_cached(bool cached) { + static __thread int parsed_columns = 0, env_columns = -1; const char *e; - if (_likely_(parsed_columns > 0)) + if (_likely_(parsed_columns > 0 && cached)) return parsed_columns; - e = getenv("COLUMNS"); - if (e) - parsed_columns = atoi(e); + if (_unlikely_(env_columns == -1)) { + e = getenv("COLUMNS"); + if (e) + env_columns = atoi(e); + else + env_columns = 0; + } - if (parsed_columns <= 0) + if (env_columns > 0) { + parsed_columns = env_columns; + return parsed_columns; + } + + if (parsed_columns <= 0 || !cached) parsed_columns = fd_columns(STDOUT_FILENO); if (parsed_columns <= 0) @@ -3794,6 +3803,14 @@ unsigned columns(void) { return parsed_columns; } +unsigned columns(void) { + return columns_cached(true); +} + +unsigned columns_uncached(void) { + return columns_cached(false); +} + int fd_lines(int fd) { struct winsize ws; zero(ws); diff --git a/src/shared/util.h b/src/shared/util.h index d25b7ee1ee..b315593bba 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -374,6 +374,7 @@ void status_welcome(void); int fd_columns(int fd); unsigned columns(void); +unsigned columns_uncached(void); int fd_lines(int fd); unsigned lines(void); -- cgit v1.2.3-54-g00ecf From 0d7e32fa0a8e5f21a66c2f5504adabfa40523efc Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 26 Jul 2012 23:09:02 +0200 Subject: cgtop: add --version option --- src/cgtop/cgtop.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index d8d36b3619..a57a468b2c 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -30,6 +30,7 @@ #include "util.h" #include "hashmap.h" #include "cgroup-util.h" +#include "build.h" typedef struct Group { char *path; @@ -511,6 +512,7 @@ static void help(void) { printf("%s [OPTIONS...]\n\n" "Show top control groups by their resource usage.\n\n" " -h --help Show this help\n" + " --version Print version and exit\n" " -p Order by path\n" " -t Order by number of tasks\n" " -c Order by CPU load\n" @@ -523,19 +525,25 @@ static void help(void) { program_invocation_short_name); } +static void version(void) { + puts(PACKAGE_STRING " cgtop"); +} + static int parse_argv(int argc, char *argv[]) { enum { - ARG_DEPTH = 0x100 + ARG_VERSION = 0x100, + ARG_DEPTH, }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "delay", required_argument, NULL, 'd' }, - { "iterations", required_argument, NULL, 'n' }, - { "batch", no_argument, NULL, 'b' }, - { "depth", required_argument, NULL, ARG_DEPTH }, - { NULL, 0, NULL, 0 } + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, + { "delay", required_argument, NULL, 'd' }, + { "iterations", required_argument, NULL, 'n' }, + { "batch", no_argument, NULL, 'b' }, + { "depth", required_argument, NULL, ARG_DEPTH }, + { NULL, 0, NULL, 0 } }; int c; @@ -552,6 +560,10 @@ static int parse_argv(int argc, char *argv[]) { help(); return 0; + case ARG_VERSION: + version(); + return 0; + case ARG_DEPTH: r = safe_atou(optarg, &arg_depth); if (r < 0) { -- cgit v1.2.3-54-g00ecf From 1421211924ff05af3b0c0d52f1c84472d0307456 Mon Sep 17 00:00:00 2001 From: Shawn Landden Date: Fri, 3 Aug 2012 17:22:09 -0700 Subject: continue work with error messages, log_oom() Adds messages for formally silent errors: new "Failed on cmdline argument %s: %s". Removes some specific error messages for -ENOMEM in mount-setup.c. A few specific ones have been left in other binaries. --- TODO | 2 +- src/binfmt/binfmt.c | 4 ++-- src/cgtop/cgtop.c | 7 ++++++- src/core/main.c | 34 ++++++++++++++++++++-------------- src/core/mount-setup.c | 12 ++++-------- 5 files changed, 33 insertions(+), 26 deletions(-) (limited to 'src/cgtop') diff --git a/TODO b/TODO index 41d09434e6..6dc36cb99d 100644 --- a/TODO +++ b/TODO @@ -479,7 +479,7 @@ Regularly: * Use PR_SET_PROCTITLE_AREA if it becomes available in the kernel -* %m in printf() instead of strerror(); +* %m in printf() instead of strerror(errno); * pahole diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index 0399ab75e0..788fd4b1a4 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -40,7 +40,7 @@ static int delete_rule(const char *rule) { assert(rule[0]); if (!(x = strdup(rule))) - return -ENOMEM; + return log_oom(); e = strchrnul(x+1, x[0]); *e = 0; @@ -49,7 +49,7 @@ static int delete_rule(const char *rule) { free(x); if (!fn) - return -ENOMEM; + return log_oom(); r = write_one_line_file(fn, "-1"); free(fn); diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index a57a468b2c..3756328fa7 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -782,5 +782,10 @@ finish: group_hashmap_free(a); group_hashmap_free(b); - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + if (r < 0) { + log_error("Exiting with failure: %s", strerror(-r)); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; } diff --git a/src/core/main.c b/src/core/main.c index 1326b94f68..3c0f5f9a94 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -168,12 +168,12 @@ _noreturn_ static void crash(int sig) { pid = fork(); if (pid < 0) - log_error("Failed to fork off crash shell: %s", strerror(errno)); + log_error("Failed to fork off crash shell: %m"); else if (pid == 0) { make_console_stdio(); execl("/bin/sh", "/bin/sh", NULL); - log_error("execl() failed: %s", strerror(errno)); + log_error("execl() failed: %m"); _exit(1); } @@ -350,12 +350,12 @@ static int parse_proc_cmdline_word(const char *word) { if (!eq) { r = unsetenv(cenv); if (r < 0) - log_warning("unsetenv failed %s. Ignoring.", strerror(errno)); + log_warning("unsetenv failed %m. Ignoring."); } else { *eq = 0; r = setenv(cenv, eq + 1, 1); if (r < 0) - log_warning("setenv failed %s. Ignoring.", strerror(errno)); + log_warning("setenv failed %m. Ignoring."); } free(cenv); @@ -495,14 +495,14 @@ static int config_parse_cpu_affinity2( unsigned cpu; if (!(t = strndup(w, l))) - return -ENOMEM; + return log_oom(); r = safe_atou(t, &cpu); free(t); if (!c) if (!(c = cpu_set_malloc(&ncpus))) - return -ENOMEM; + return log_oom(); if (r < 0 || cpu >= ncpus) { log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue); @@ -568,7 +568,7 @@ static int config_parse_join_controllers( s = strndup(w, length); if (!s) - return -ENOMEM; + return log_oom(); l = strv_split(s, ","); free(s); @@ -584,7 +584,7 @@ static int config_parse_join_controllers( arg_join_controllers = new(char**, 2); if (!arg_join_controllers) { strv_free(l); - return -ENOMEM; + return log_oom(); } arg_join_controllers[0] = l; @@ -598,7 +598,7 @@ static int config_parse_join_controllers( t = new0(char**, n+2); if (!t) { strv_free(l); - return -ENOMEM; + return log_oom(); } n = 0; @@ -612,7 +612,7 @@ static int config_parse_join_controllers( if (!c) { strv_free(l); strv_free_free(t); - return -ENOMEM; + return log_oom(); } strv_free(l); @@ -624,7 +624,7 @@ static int config_parse_join_controllers( if (!c) { strv_free(l); strv_free_free(t); - return -ENOMEM; + return log_oom(); } t[n++] = c; @@ -729,8 +729,10 @@ static int parse_proc_cmdline(void) { r = parse_proc_cmdline_word(word); free(word); - if (r < 0) + if (r < 0) { + log_error("Failed on cmdline argument %s: %s", word, strerror(-r)); goto finish; + } } r = 0; @@ -1017,8 +1019,10 @@ static int parse_argv(int argc, char *argv[]) { * instead. */ for (a = argv; a < argv + argc; a++) - if ((r = parse_proc_cmdline_word(*a)) < 0) + if ((r = parse_proc_cmdline_word(*a)) < 0) { + log_error("Failed on cmdline argument %s: %s", *a, strerror(-r)); return r; + } } return 0; @@ -1293,8 +1297,10 @@ int main(int argc, char *argv[]) { } /* Initialize default unit */ - if (set_default_unit(SPECIAL_DEFAULT_TARGET) < 0) + if (r == set_default_unit(SPECIAL_DEFAULT_TARGET) < 0) { + log_error("Failed to set default unit %s: %s", SPECIAL_DEFAULT_TARGET, strerror(-r)); goto finish; + } /* By default, mount "cpu" and "cpuacct" together */ arg_join_controllers = new(char**, 2); diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 07794df049..c10c6dad1c 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -190,8 +190,7 @@ int mount_cgroup_controllers(char ***join_controllers) { controllers = set_new(string_hash_func, string_compare_func); if (!controllers) { - r = -ENOMEM; - log_error("Failed to allocate controller set."); + r = log_oom(); goto finish; } @@ -262,9 +261,8 @@ int mount_cgroup_controllers(char ***join_controllers) { options = strv_join(*k, ","); if (!options) { - log_error("Failed to join options"); free(controller); - r = -ENOMEM; + r = log_oom(); goto finish; } @@ -275,9 +273,8 @@ int mount_cgroup_controllers(char ***join_controllers) { where = strappend("/sys/fs/cgroup/", options); if (!where) { - log_error("Failed to build path"); free(options); - r = -ENOMEM; + r = log_oom(); goto finish; } @@ -306,8 +303,7 @@ int mount_cgroup_controllers(char ***join_controllers) { t = strappend("/sys/fs/cgroup/", *i); if (!t) { - log_error("Failed to build path"); - r = -ENOMEM; + r = log_oom(); free(options); goto finish; } -- cgit v1.2.3-54-g00ecf From 2f29c419b01c104475f04d58a873b181273cfd8b Mon Sep 17 00:00:00 2001 From: Václav Pavlín Date: Fri, 21 Sep 2012 12:04:02 +0200 Subject: cgtop: missing '-' Return codes in systemd are negated and if (r < 0) if (r == ENOENT) was never true. --- src/cgtop/cgtop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 3756328fa7..9eb2d2fdeb 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -300,7 +300,7 @@ static int refresh_one( r = cg_enumerate_subgroups(controller, path, &d); if (r < 0) { - if (r == ENOENT) + if (r == -ENOENT) return 0; return r; -- cgit v1.2.3-54-g00ecf From 28917d7dc711746795f7e6468c06c1983a5cdf53 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 18 Oct 2012 23:50:26 +0200 Subject: util: simplify column caching logic --- src/cgtop/cgtop.c | 4 +++- src/shared/util.c | 47 ++++++++++++++++------------------------------- src/shared/util.h | 1 - 3 files changed, 19 insertions(+), 33 deletions(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 9eb2d2fdeb..ee421e383b 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -447,7 +447,7 @@ static int display(Hashmap *a) { if (rows <= 0) rows = 25; - path_columns = columns_uncached() - 42; + path_columns = columns() - 42; if (path_columns < 10) path_columns = 10; @@ -653,6 +653,8 @@ int main(int argc, char *argv[]) { goto finish; } + signal(SIGWINCH, columns_cache_reset); + while (!quit) { Hashmap *c; usec_t t; diff --git a/src/shared/util.c b/src/shared/util.c index 1c97a8a94a..462b541b41 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -72,7 +72,7 @@ int saved_argc = 0; char **saved_argv = NULL; -static int parsed_columns = 0; +static volatile unsigned cached_columns = 0; size_t page_size(void) { static __thread size_t pgsz = 0; @@ -3793,46 +3793,31 @@ int fd_columns(int fd) { return ws.ws_col; } -static unsigned columns_cached(bool cached) { - static __thread int env_columns = -1; +unsigned columns(void) { const char *e; + unsigned c; - if (_likely_(parsed_columns > 0 && cached)) - return parsed_columns; - - if (_unlikely_(env_columns == -1)) { - e = getenv("COLUMNS"); - if (e) - env_columns = atoi(e); - else - env_columns = 0; - } - - if (env_columns > 0) { - parsed_columns = env_columns; - return parsed_columns; - } + if (_likely_(cached_columns > 0)) + return cached_columns; - if (parsed_columns <= 0 || !cached) - parsed_columns = fd_columns(STDOUT_FILENO); - - if (parsed_columns <= 0) - parsed_columns = 80; + c = 0; + e = getenv("COLUMNS"); + if (e) + safe_atou(e, &c); - return parsed_columns; -} + if (c <= 0) + c = fd_columns(STDOUT_FILENO); -unsigned columns(void) { - return columns_cached(true); -} + if (c <= 0) + c = 80; -unsigned columns_uncached(void) { - return columns_cached(false); + cached_columns = c; + return c; } /* intended to be used as a SIGWINCH sighandler */ void columns_cache_reset(int signum) { - parsed_columns = 0; + cached_columns = 0; } int fd_lines(int fd) { diff --git a/src/shared/util.h b/src/shared/util.h index 50911ebb34..662c3d1f39 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -384,7 +384,6 @@ int status_welcome(void); int fd_columns(int fd); unsigned columns(void); -unsigned columns_uncached(void); void columns_cache_reset(int _unused_ signum); int fd_lines(int fd); -- cgit v1.2.3-54-g00ecf From ed757c0cb03eef50e8d9aeb4682401c3e9486f0b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 19 Oct 2012 00:06:47 +0200 Subject: util: unify line caching and column caching --- src/cgtop/cgtop.c | 8 ++++---- src/journal/journalctl.c | 3 ++- src/shared/util.c | 50 ++++++++++++++++++++++++++---------------------- src/shared/util.h | 6 +++--- 4 files changed, 36 insertions(+), 31 deletions(-) (limited to 'src/cgtop') diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index ee421e383b..f2e62761f1 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -443,9 +443,9 @@ static int display(Hashmap *a) { qsort(array, n, sizeof(Group*), group_compare); - rows = fd_lines(STDOUT_FILENO); - if (rows <= 0) - rows = 25; + rows = lines(); + if (rows <= 10) + rows = 10; path_columns = columns() - 42; if (path_columns < 10) @@ -653,7 +653,7 @@ int main(int argc, char *argv[]) { goto finish; } - signal(SIGWINCH, columns_cache_reset); + signal(SIGWINCH, columns_lines_cache_reset); while (!quit) { Hashmap *c; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index f4b6518557..d1338d2b7c 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -197,7 +197,6 @@ static int parse_argv(int argc, char *argv[]) { case 'f': arg_follow = true; - signal(SIGWINCH, columns_cache_reset); break; case 'o': @@ -834,6 +833,8 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; + signal(SIGWINCH, columns_lines_cache_reset); + if (arg_action == ACTION_NEW_ID128) { r = generate_new_id128(); goto finish; diff --git a/src/shared/util.c b/src/shared/util.c index 527a5800fe..ef30cb2dab 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -73,6 +73,7 @@ int saved_argc = 0; char **saved_argv = NULL; static volatile unsigned cached_columns = 0; +static volatile unsigned cached_lines = 0; size_t page_size(void) { static __thread size_t pgsz = 0; @@ -3812,20 +3813,6 @@ unsigned columns(void) { return c; } -/* intended to be used as a SIGWINCH sighandler */ -void columns_cache_reset(int signum) { - cached_columns = 0; -} - -bool on_tty(void) { - static int cached_on_tty = -1; - - if (_unlikely_(cached_on_tty < 0)) - cached_on_tty = isatty(STDOUT_FILENO) > 0; - - return cached_on_tty; -} - int fd_lines(int fd) { struct winsize ws; zero(ws); @@ -3840,23 +3827,40 @@ int fd_lines(int fd) { } unsigned lines(void) { - static __thread int parsed_lines = 0; const char *e; + unsigned l; - if (_likely_(parsed_lines > 0)) - return parsed_lines; + if (_likely_(cached_lines > 0)) + return cached_lines; + l = 0; e = getenv("LINES"); if (e) - parsed_lines = atoi(e); + safe_atou(e, &l); - if (parsed_lines <= 0) - parsed_lines = fd_lines(STDOUT_FILENO); + if (l <= 0) + l = fd_lines(STDOUT_FILENO); - if (parsed_lines <= 0) - parsed_lines = 25; + if (l <= 0) + l = 24; - return parsed_lines; + cached_lines = l; + return cached_lines; +} + +/* intended to be used as a SIGWINCH sighandler */ +void columns_lines_cache_reset(int signum) { + cached_columns = 0; + cached_lines = 0; +} + +bool on_tty(void) { + static int cached_on_tty = -1; + + if (_unlikely_(cached_on_tty < 0)) + cached_on_tty = isatty(STDOUT_FILENO) > 0; + + return cached_on_tty; } int running_in_chroot(void) { diff --git a/src/shared/util.h b/src/shared/util.h index e19f76c1ea..affb66998c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -384,11 +384,11 @@ int status_welcome(void); int fd_columns(int fd); unsigned columns(void); -void columns_cache_reset(int _unused_ signum); -bool on_tty(void); - int fd_lines(int fd); unsigned lines(void); +void columns_lines_cache_reset(int _unused_ signum); + +bool on_tty(void); int running_in_chroot(void); -- cgit v1.2.3-54-g00ecf