From 6bedfcbb2970e06a4d3280c8fb62083d252ede73 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 16:18:16 +0100 Subject: util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] --- src/journal/cat.c | 1 + src/journal/coredump.c | 1 + src/journal/coredumpctl.c | 3 ++- src/journal/journal-file.c | 1 + src/journal/journal-vacuum.c | 1 + src/journal/journalctl.c | 1 + src/journal/journald-console.c | 7 ++++--- src/journal/journald-kmsg.c | 1 + src/journal/journald-native.c | 1 + src/journal/journald-server.c | 1 + src/journal/journald-stream.c | 1 + src/journal/test-compress-benchmark.c | 1 + src/journal/test-journal-init.c | 1 + src/journal/test-journal-interleaving.c | 4 +++- src/journal/test-journal-stream.c | 10 ++++++---- 15 files changed, 26 insertions(+), 9 deletions(-) (limited to 'src/journal') diff --git a/src/journal/cat.c b/src/journal/cat.c index ff1887604a..95a1868b93 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -29,6 +29,7 @@ #include "sd-journal.h" #include "fd-util.h" +#include "parse-util.h" #include "string-util.h" #include "util.h" diff --git a/src/journal/coredump.c b/src/journal/coredump.c index 7336db219b..92f598464a 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -47,6 +47,7 @@ #include "log.h" #include "macro.h" #include "mkdir.h" +#include "parse-util.h" #include "process-util.h" #include "special.h" #include "stacktrace.h" diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index f891ddffc6..fecccd4eb9 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -34,6 +34,7 @@ #include "log.h" #include "macro.h" #include "pager.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "set.h" @@ -41,8 +42,8 @@ #include "signal-util.h" #include "string-util.h" #include "terminal-util.h" -#include "util.h" #include "user-util.h" +#include "util.h" static enum { ACTION_NONE, diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index f193cb90ce..c33e278cbe 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -35,6 +35,7 @@ #include "journal-def.h" #include "journal-file.h" #include "lookup3.h" +#include "parse-util.h" #include "random-util.h" #include "string-util.h" diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c index dca5bf5000..026dca4901 100644 --- a/src/journal/journal-vacuum.c +++ b/src/journal/journal-vacuum.c @@ -29,6 +29,7 @@ #include "journal-def.h" #include "journal-file.h" #include "journal-vacuum.h" +#include "parse-util.h" #include "string-util.h" #include "util.h" diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 6e452a4d51..c13b674e15 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -56,6 +56,7 @@ #include "logs-show.h" #include "mkdir.h" #include "pager.h" +#include "parse-util.h" #include "path-util.h" #include "set.h" #include "sigbus.h" diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index 5f3eb05275..4a5e07ec5d 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -23,13 +23,14 @@ #include #include +#include "fd-util.h" #include "fileio.h" -#include "journald-server.h" -#include "journald-console.h" #include "formats-util.h" +#include "journald-console.h" +#include "journald-server.h" +#include "parse-util.h" #include "process-util.h" #include "terminal-util.h" -#include "fd-util.h" static bool prefix_timestamp(void) { diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 5a05632e56..e680aafafe 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -34,6 +34,7 @@ #include "journald-kmsg.h" #include "journald-server.h" #include "journald-syslog.h" +#include "parse-util.h" #include "process-util.h" #include "string-util.h" diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index 7d4aac687e..ae229ecaf5 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -32,6 +32,7 @@ #include "journald-syslog.h" #include "journald-wall.h" #include "memfd-util.h" +#include "parse-util.h" #include "path-util.h" #include "selinux-util.h" #include "socket-util.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 7cefea323e..f286e3030f 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -54,6 +54,7 @@ #include "journald-syslog.h" #include "missing.h" #include "mkdir.h" +#include "parse-util.h" #include "process-util.h" #include "rm-rf.h" #include "selinux-util.h" diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 0dd511519c..6745864da1 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -39,6 +39,7 @@ #include "journald-syslog.h" #include "journald-wall.h" #include "mkdir.h" +#include "parse-util.h" #include "selinux-util.h" #include "socket-util.h" #include "string-util.h" diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c index 0a9ab7f52c..5a2f0564ca 100644 --- a/src/journal/test-compress-benchmark.c +++ b/src/journal/test-compress-benchmark.c @@ -21,6 +21,7 @@ #include "compress.h" #include "macro.h" +#include "parse-util.h" #include "random-util.h" #include "string-util.h" #include "util.h" diff --git a/src/journal/test-journal-init.c b/src/journal/test-journal-init.c index 717b703d19..142da85041 100644 --- a/src/journal/test-journal-init.c +++ b/src/journal/test-journal-init.c @@ -22,6 +22,7 @@ #include "sd-journal.h" #include "log.h" +#include "parse-util.h" #include "rm-rf.h" #include "util.h" diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c index 8069339c1f..3c8b0268a4 100644 --- a/src/journal/test-journal-interleaving.c +++ b/src/journal/test-journal-interleaving.c @@ -24,11 +24,13 @@ #include #include "sd-journal.h" + #include "journal-file.h" #include "journal-vacuum.h" -#include "util.h" #include "log.h" +#include "parse-util.h" #include "rm-rf.h" +#include "util.h" /* This program tests skipping around in a multi-file journal. */ diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c index b5ecf2f375..b8482743a2 100644 --- a/src/journal/test-journal-stream.c +++ b/src/journal/test-journal-stream.c @@ -19,16 +19,18 @@ along with systemd; If not, see . ***/ -#include #include +#include #include "sd-journal.h" -#include "util.h" + +#include "journal-file.h" +#include "journal-internal.h" #include "log.h" #include "macro.h" +#include "parse-util.h" #include "rm-rf.h" -#include "journal-file.h" -#include "journal-internal.h" +#include "util.h" #define N_ENTRIES 200 -- cgit v1.2.3-54-g00ecf From e4e73a632524c382139034d4271f53b6089ab4cb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 16:41:43 +0100 Subject: util-lib: split out hex/dec/oct encoding/decoding into its own file --- Makefile.am | 2 + src/basic/bus-label.c | 6 +- src/basic/escape.c | 4 +- src/basic/hexdecoct.c | 697 ++++++++++++++++++++++++++++++ src/basic/hexdecoct.h | 54 +++ src/basic/json.c | 3 +- src/basic/unit-name.c | 1 + src/basic/utf8.c | 1 + src/basic/util.c | 672 +--------------------------- src/basic/util.h | 22 - src/core/dbus-execute.c | 2 +- src/core/machine-id-setup.c | 1 + src/import/pull-job.c | 1 + src/journal/journal-authenticate.c | 1 + src/journal/journald-audit.c | 1 + src/libsystemd-network/network-internal.c | 1 + src/libsystemd-network/sd-dhcp-lease.c | 1 + src/libsystemd/sd-bus/bus-creds.c | 1 + src/libsystemd/sd-bus/bus-internal.c | 1 + src/libsystemd/sd-bus/bus-match.c | 1 + src/libsystemd/sd-bus/bus-socket.c | 1 + src/libsystemd/sd-bus/sd-bus.c | 1 + src/libsystemd/sd-bus/test-bus-marshal.c | 1 + src/libsystemd/sd-id128/sd-id128.c | 1 + src/resolve/resolved-dns-rr.c | 3 +- src/shared/dns-domain.c | 1 + src/sysv-generator/sysv-generator.c | 1 + src/test/test-util.c | 1 + 28 files changed, 782 insertions(+), 701 deletions(-) create mode 100644 src/basic/hexdecoct.c create mode 100644 src/basic/hexdecoct.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index 189d9c99ac..26d5587b11 100644 --- a/Makefile.am +++ b/Makefile.am @@ -791,6 +791,8 @@ libbasic_la_SOURCES = \ src/basic/parse-util.h \ src/basic/user-util.c \ src/basic/user-util.h \ + src/basic/hexdecoct.c \ + src/basic/hexdecoct.h \ src/basic/extract-word.c \ src/basic/extract-word.h \ src/basic/escape.c \ diff --git a/src/basic/bus-label.c b/src/basic/bus-label.c index ccc9f2bf8e..6f39528f13 100644 --- a/src/basic/bus-label.c +++ b/src/basic/bus-label.c @@ -21,10 +21,10 @@ #include -#include "util.h" -#include "macro.h" - #include "bus-label.h" +#include "macro.h" +#include "hexdecoct.h" +#include "util.h" char *bus_label_escape(const char *s) { char *r, *t; diff --git a/src/basic/escape.c b/src/basic/escape.c index cf05ce10ef..e763b5dac2 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -19,11 +19,11 @@ along with systemd; If not, see . ***/ +#include "escape.h" +#include "hexdecoct.h" #include "utf8.h" #include "util.h" -#include "escape.h" - size_t cescape_char(char c, char *buf) { char * buf_old = buf; diff --git a/src/basic/hexdecoct.c b/src/basic/hexdecoct.c new file mode 100644 index 0000000000..f958582e68 --- /dev/null +++ b/src/basic/hexdecoct.c @@ -0,0 +1,697 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "hexdecoct.h" +#include "util.h" + +char octchar(int x) { + return '0' + (x & 7); +} + +int unoctchar(char c) { + + if (c >= '0' && c <= '7') + return c - '0'; + + return -EINVAL; +} + +char decchar(int x) { + return '0' + (x % 10); +} + +int undecchar(char c) { + + if (c >= '0' && c <= '9') + return c - '0'; + + return -EINVAL; +} + +char hexchar(int x) { + static const char table[16] = "0123456789abcdef"; + + return table[x & 15]; +} + +int unhexchar(char c) { + + if (c >= '0' && c <= '9') + return c - '0'; + + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + + return -EINVAL; +} + +char *hexmem(const void *p, size_t l) { + char *r, *z; + const uint8_t *x; + + z = r = malloc(l * 2 + 1); + if (!r) + return NULL; + + for (x = p; x < (const uint8_t*) p + l; x++) { + *(z++) = hexchar(*x >> 4); + *(z++) = hexchar(*x & 15); + } + + *z = 0; + return r; +} + +int unhexmem(const char *p, size_t l, void **mem, size_t *len) { + _cleanup_free_ uint8_t *r = NULL; + uint8_t *z; + const char *x; + + assert(mem); + assert(len); + assert(p); + + z = r = malloc((l + 1) / 2 + 1); + if (!r) + return -ENOMEM; + + for (x = p; x < p + l; x += 2) { + int a, b; + + a = unhexchar(x[0]); + if (a < 0) + return a; + else if (x+1 < p + l) { + b = unhexchar(x[1]); + if (b < 0) + return b; + } else + b = 0; + + *(z++) = (uint8_t) a << 4 | (uint8_t) b; + } + + *z = 0; + + *mem = r; + r = NULL; + *len = (l + 1) / 2; + + return 0; +} + +/* https://tools.ietf.org/html/rfc4648#section-6 + * Notice that base32hex differs from base32 in the alphabet it uses. + * The distinction is that the base32hex representation preserves the + * order of the underlying data when compared as bytestrings, this is + * useful when representing NSEC3 hashes, as one can then verify the + * order of hashes directly from their representation. */ +char base32hexchar(int x) { + static const char table[32] = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUV"; + + return table[x & 31]; +} + +int unbase32hexchar(char c) { + unsigned offset; + + if (c >= '0' && c <= '9') + return c - '0'; + + offset = '9' - '0' + 1; + + if (c >= 'A' && c <= 'V') + return c - 'A' + offset; + + return -EINVAL; +} + +char *base32hexmem(const void *p, size_t l, bool padding) { + char *r, *z; + const uint8_t *x; + size_t len; + + if (padding) + /* five input bytes makes eight output bytes, padding is added so we must round up */ + len = 8 * (l + 4) / 5; + else { + /* same, but round down as there is no padding */ + len = 8 * l / 5; + + switch (l % 5) { + case 4: + len += 7; + break; + case 3: + len += 5; + break; + case 2: + len += 4; + break; + case 1: + len += 2; + break; + } + } + + z = r = malloc(len + 1); + if (!r) + return NULL; + + for (x = p; x < (const uint8_t*) p + (l / 5) * 5; x += 5) { + /* x[0] == XXXXXXXX; x[1] == YYYYYYYY; x[2] == ZZZZZZZZ + x[3] == QQQQQQQQ; x[4] == WWWWWWWW */ + *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ + *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ + *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ + *(z++) = base32hexchar((x[1] & 1) << 4 | x[2] >> 4); /* 000YZZZZ */ + *(z++) = base32hexchar((x[2] & 15) << 1 | x[3] >> 7); /* 000ZZZZQ */ + *(z++) = base32hexchar((x[3] & 127) >> 2); /* 000QQQQQ */ + *(z++) = base32hexchar((x[3] & 3) << 3 | x[4] >> 5); /* 000QQWWW */ + *(z++) = base32hexchar((x[4] & 31)); /* 000WWWWW */ + } + + switch (l % 5) { + case 4: + *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ + *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ + *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ + *(z++) = base32hexchar((x[1] & 1) << 4 | x[2] >> 4); /* 000YZZZZ */ + *(z++) = base32hexchar((x[2] & 15) << 1 | x[3] >> 7); /* 000ZZZZQ */ + *(z++) = base32hexchar((x[3] & 127) >> 2); /* 000QQQQQ */ + *(z++) = base32hexchar((x[3] & 3) << 3); /* 000QQ000 */ + if (padding) + *(z++) = '='; + + break; + + case 3: + *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ + *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ + *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ + *(z++) = base32hexchar((x[1] & 1) << 4 | x[2] >> 4); /* 000YZZZZ */ + *(z++) = base32hexchar((x[2] & 15) << 1); /* 000ZZZZ0 */ + if (padding) { + *(z++) = '='; + *(z++) = '='; + *(z++) = '='; + } + + break; + + case 2: + *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ + *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ + *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ + *(z++) = base32hexchar((x[1] & 1) << 4); /* 000Y0000 */ + if (padding) { + *(z++) = '='; + *(z++) = '='; + *(z++) = '='; + *(z++) = '='; + } + + break; + + case 1: + *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ + *(z++) = base32hexchar((x[0] & 7) << 2); /* 000XXX00 */ + if (padding) { + *(z++) = '='; + *(z++) = '='; + *(z++) = '='; + *(z++) = '='; + *(z++) = '='; + *(z++) = '='; + } + + break; + } + + *z = 0; + return r; +} + +int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_len) { + _cleanup_free_ uint8_t *r = NULL; + int a, b, c, d, e, f, g, h; + uint8_t *z; + const char *x; + size_t len; + unsigned pad = 0; + + assert(p); + + /* padding ensures any base32hex input has input divisible by 8 */ + if (padding && l % 8 != 0) + return -EINVAL; + + if (padding) { + /* strip the padding */ + while (l > 0 && p[l - 1] == '=' && pad < 7) { + pad ++; + l --; + } + } + + /* a group of eight input bytes needs five output bytes, in case of + padding we need to add some extra bytes */ + len = (l / 8) * 5; + + switch (l % 8) { + case 7: + len += 4; + break; + case 5: + len += 3; + break; + case 4: + len += 2; + break; + case 2: + len += 1; + break; + case 0: + break; + default: + return -EINVAL; + } + + z = r = malloc(len + 1); + if (!r) + return -ENOMEM; + + for (x = p; x < p + (l / 8) * 8; x += 8) { + /* a == 000XXXXX; b == 000YYYYY; c == 000ZZZZZ; d == 000WWWWW + e == 000SSSSS; f == 000QQQQQ; g == 000VVVVV; h == 000RRRRR */ + a = unbase32hexchar(x[0]); + if (a < 0) + return -EINVAL; + + b = unbase32hexchar(x[1]); + if (b < 0) + return -EINVAL; + + c = unbase32hexchar(x[2]); + if (c < 0) + return -EINVAL; + + d = unbase32hexchar(x[3]); + if (d < 0) + return -EINVAL; + + e = unbase32hexchar(x[4]); + if (e < 0) + return -EINVAL; + + f = unbase32hexchar(x[5]); + if (f < 0) + return -EINVAL; + + g = unbase32hexchar(x[6]); + if (g < 0) + return -EINVAL; + + h = unbase32hexchar(x[7]); + if (h < 0) + return -EINVAL; + + *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ + *(z++) = (uint8_t) b << 6 | (uint8_t) c << 1 | (uint8_t) d >> 4; /* YYZZZZZW */ + *(z++) = (uint8_t) d << 4 | (uint8_t) e >> 1; /* WWWWSSSS */ + *(z++) = (uint8_t) e << 7 | (uint8_t) f << 2 | (uint8_t) g >> 3; /* SQQQQQVV */ + *(z++) = (uint8_t) g << 5 | (uint8_t) h; /* VVVRRRRR */ + } + + switch (l % 8) { + case 7: + a = unbase32hexchar(x[0]); + if (a < 0) + return -EINVAL; + + b = unbase32hexchar(x[1]); + if (b < 0) + return -EINVAL; + + c = unbase32hexchar(x[2]); + if (c < 0) + return -EINVAL; + + d = unbase32hexchar(x[3]); + if (d < 0) + return -EINVAL; + + e = unbase32hexchar(x[4]); + if (e < 0) + return -EINVAL; + + f = unbase32hexchar(x[5]); + if (f < 0) + return -EINVAL; + + g = unbase32hexchar(x[6]); + if (g < 0) + return -EINVAL; + + /* g == 000VV000 */ + if (g & 7) + return -EINVAL; + + *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ + *(z++) = (uint8_t) b << 6 | (uint8_t) c << 1 | (uint8_t) d >> 4; /* YYZZZZZW */ + *(z++) = (uint8_t) d << 4 | (uint8_t) e >> 1; /* WWWWSSSS */ + *(z++) = (uint8_t) e << 7 | (uint8_t) f << 2 | (uint8_t) g >> 3; /* SQQQQQVV */ + + break; + case 5: + a = unbase32hexchar(x[0]); + if (a < 0) + return -EINVAL; + + b = unbase32hexchar(x[1]); + if (b < 0) + return -EINVAL; + + c = unbase32hexchar(x[2]); + if (c < 0) + return -EINVAL; + + d = unbase32hexchar(x[3]); + if (d < 0) + return -EINVAL; + + e = unbase32hexchar(x[4]); + if (e < 0) + return -EINVAL; + + /* e == 000SSSS0 */ + if (e & 1) + return -EINVAL; + + *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ + *(z++) = (uint8_t) b << 6 | (uint8_t) c << 1 | (uint8_t) d >> 4; /* YYZZZZZW */ + *(z++) = (uint8_t) d << 4 | (uint8_t) e >> 1; /* WWWWSSSS */ + + break; + case 4: + a = unbase32hexchar(x[0]); + if (a < 0) + return -EINVAL; + + b = unbase32hexchar(x[1]); + if (b < 0) + return -EINVAL; + + c = unbase32hexchar(x[2]); + if (c < 0) + return -EINVAL; + + d = unbase32hexchar(x[3]); + if (d < 0) + return -EINVAL; + + /* d == 000W0000 */ + if (d & 15) + return -EINVAL; + + *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ + *(z++) = (uint8_t) b << 6 | (uint8_t) c << 1 | (uint8_t) d >> 4; /* YYZZZZZW */ + + break; + case 2: + a = unbase32hexchar(x[0]); + if (a < 0) + return -EINVAL; + + b = unbase32hexchar(x[1]); + if (b < 0) + return -EINVAL; + + /* b == 000YYY00 */ + if (b & 3) + return -EINVAL; + + *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ + + break; + case 0: + break; + default: + return -EINVAL; + } + + *z = 0; + + *mem = r; + r = NULL; + *_len = len; + + return 0; +} + +/* https://tools.ietf.org/html/rfc4648#section-4 */ +char base64char(int x) { + static const char table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + return table[x & 63]; +} + +int unbase64char(char c) { + unsigned offset; + + if (c >= 'A' && c <= 'Z') + return c - 'A'; + + offset = 'Z' - 'A' + 1; + + if (c >= 'a' && c <= 'z') + return c - 'a' + offset; + + offset += 'z' - 'a' + 1; + + if (c >= '0' && c <= '9') + return c - '0' + offset; + + offset += '9' - '0' + 1; + + if (c == '+') + return offset; + + offset ++; + + if (c == '/') + return offset; + + return -EINVAL; +} + +char *base64mem(const void *p, size_t l) { + char *r, *z; + const uint8_t *x; + + /* three input bytes makes four output bytes, padding is added so we must round up */ + z = r = malloc(4 * (l + 2) / 3 + 1); + if (!r) + return NULL; + + for (x = p; x < (const uint8_t*) p + (l / 3) * 3; x += 3) { + /* x[0] == XXXXXXXX; x[1] == YYYYYYYY; x[2] == ZZZZZZZZ */ + *(z++) = base64char(x[0] >> 2); /* 00XXXXXX */ + *(z++) = base64char((x[0] & 3) << 4 | x[1] >> 4); /* 00XXYYYY */ + *(z++) = base64char((x[1] & 15) << 2 | x[2] >> 6); /* 00YYYYZZ */ + *(z++) = base64char(x[2] & 63); /* 00ZZZZZZ */ + } + + switch (l % 3) { + case 2: + *(z++) = base64char(x[0] >> 2); /* 00XXXXXX */ + *(z++) = base64char((x[0] & 3) << 4 | x[1] >> 4); /* 00XXYYYY */ + *(z++) = base64char((x[1] & 15) << 2); /* 00YYYY00 */ + *(z++) = '='; + + break; + case 1: + *(z++) = base64char(x[0] >> 2); /* 00XXXXXX */ + *(z++) = base64char((x[0] & 3) << 4); /* 00XX0000 */ + *(z++) = '='; + *(z++) = '='; + + break; + } + + *z = 0; + return r; +} + +int unbase64mem(const char *p, size_t l, void **mem, size_t *_len) { + _cleanup_free_ uint8_t *r = NULL; + int a, b, c, d; + uint8_t *z; + const char *x; + size_t len; + + assert(p); + + /* padding ensures any base63 input has input divisible by 4 */ + if (l % 4 != 0) + return -EINVAL; + + /* strip the padding */ + if (l > 0 && p[l - 1] == '=') + l --; + if (l > 0 && p[l - 1] == '=') + l --; + + /* a group of four input bytes needs three output bytes, in case of + padding we need to add two or three extra bytes */ + len = (l / 4) * 3 + (l % 4 ? (l % 4) - 1 : 0); + + z = r = malloc(len + 1); + if (!r) + return -ENOMEM; + + for (x = p; x < p + (l / 4) * 4; x += 4) { + /* a == 00XXXXXX; b == 00YYYYYY; c == 00ZZZZZZ; d == 00WWWWWW */ + a = unbase64char(x[0]); + if (a < 0) + return -EINVAL; + + b = unbase64char(x[1]); + if (b < 0) + return -EINVAL; + + c = unbase64char(x[2]); + if (c < 0) + return -EINVAL; + + d = unbase64char(x[3]); + if (d < 0) + return -EINVAL; + + *(z++) = (uint8_t) a << 2 | (uint8_t) b >> 4; /* XXXXXXYY */ + *(z++) = (uint8_t) b << 4 | (uint8_t) c >> 2; /* YYYYZZZZ */ + *(z++) = (uint8_t) c << 6 | (uint8_t) d; /* ZZWWWWWW */ + } + + switch (l % 4) { + case 3: + a = unbase64char(x[0]); + if (a < 0) + return -EINVAL; + + b = unbase64char(x[1]); + if (b < 0) + return -EINVAL; + + c = unbase64char(x[2]); + if (c < 0) + return -EINVAL; + + /* c == 00ZZZZ00 */ + if (c & 3) + return -EINVAL; + + *(z++) = (uint8_t) a << 2 | (uint8_t) b >> 4; /* XXXXXXYY */ + *(z++) = (uint8_t) b << 4 | (uint8_t) c >> 2; /* YYYYZZZZ */ + + break; + case 2: + a = unbase64char(x[0]); + if (a < 0) + return -EINVAL; + + b = unbase64char(x[1]); + if (b < 0) + return -EINVAL; + + /* b == 00YY0000 */ + if (b & 15) + return -EINVAL; + + *(z++) = (uint8_t) a << 2 | (uint8_t) (b >> 4); /* XXXXXXYY */ + + break; + case 0: + + break; + default: + return -EINVAL; + } + + *z = 0; + + *mem = r; + r = NULL; + *_len = len; + + return 0; +} + +void hexdump(FILE *f, const void *p, size_t s) { + const uint8_t *b = p; + unsigned n = 0; + + assert(s == 0 || b); + + while (s > 0) { + size_t i; + + fprintf(f, "%04x ", n); + + for (i = 0; i < 16; i++) { + + if (i >= s) + fputs(" ", f); + else + fprintf(f, "%02x ", b[i]); + + if (i == 7) + fputc(' ', f); + } + + fputc(' ', f); + + for (i = 0; i < 16; i++) { + + if (i >= s) + fputc(' ', f); + else + fputc(isprint(b[i]) ? (char) b[i] : '.', f); + } + + fputc('\n', f); + + if (s < 16) + break; + + n += 16; + b += 16; + s -= 16; + } +} diff --git a/src/basic/hexdecoct.h b/src/basic/hexdecoct.h new file mode 100644 index 0000000000..4aeb4c3bdc --- /dev/null +++ b/src/basic/hexdecoct.h @@ -0,0 +1,54 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "macro.h" + +char octchar(int x) _const_; +int unoctchar(char c) _const_; + +char decchar(int x) _const_; +int undecchar(char c) _const_; + +char hexchar(int x) _const_; +int unhexchar(char c) _const_; + +char *hexmem(const void *p, size_t l); +int unhexmem(const char *p, size_t l, void **mem, size_t *len); + +char base32hexchar(int x) _const_; +int unbase32hexchar(char c) _const_; + +char base64char(int x) _const_; +int unbase64char(char c) _const_; + +char *base32hexmem(const void *p, size_t l, bool padding); +int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *len); + +char *base64mem(const void *p, size_t l); +int unbase64mem(const char *p, size_t l, void **mem, size_t *len); + +void hexdump(FILE *f, const void *p, size_t s); diff --git a/src/basic/json.c b/src/basic/json.c index 2b634aa7f8..efe635e20e 100644 --- a/src/basic/json.c +++ b/src/basic/json.c @@ -22,10 +22,11 @@ #include #include +#include "json.h" #include "macro.h" +#include "hexdecoct.h" #include "string-util.h" #include "utf8.h" -#include "json.h" int json_variant_new(JsonVariant **ret, JsonVariantType type) { JsonVariant *v; diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c index 383c4ab871..c6ba9afb5a 100644 --- a/src/basic/unit-name.c +++ b/src/basic/unit-name.c @@ -29,6 +29,7 @@ #include "strv.h" #include "util.h" #include "unit-name.h" +#include "hexdecoct.h" #define VALID_CHARS \ DIGITS LETTERS \ diff --git a/src/basic/utf8.c b/src/basic/utf8.c index 800884ffee..de124abbde 100644 --- a/src/basic/utf8.c +++ b/src/basic/utf8.c @@ -49,6 +49,7 @@ #include #include +#include "hexdecoct.h" #include "utf8.h" #include "util.h" diff --git a/src/basic/util.c b/src/basic/util.c index 66b7978c60..5e3a363bb4 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -89,6 +89,7 @@ #include "macro.h" #include "missing.h" #include "mkdir.h" +#include "hexdecoct.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" @@ -320,634 +321,6 @@ int rmdir_parents(const char *path, const char *stop) { return 0; } -char hexchar(int x) { - static const char table[16] = "0123456789abcdef"; - - return table[x & 15]; -} - -int unhexchar(char c) { - - if (c >= '0' && c <= '9') - return c - '0'; - - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - - if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - - return -EINVAL; -} - -char *hexmem(const void *p, size_t l) { - char *r, *z; - const uint8_t *x; - - z = r = malloc(l * 2 + 1); - if (!r) - return NULL; - - for (x = p; x < (const uint8_t*) p + l; x++) { - *(z++) = hexchar(*x >> 4); - *(z++) = hexchar(*x & 15); - } - - *z = 0; - return r; -} - -int unhexmem(const char *p, size_t l, void **mem, size_t *len) { - _cleanup_free_ uint8_t *r = NULL; - uint8_t *z; - const char *x; - - assert(mem); - assert(len); - assert(p); - - z = r = malloc((l + 1) / 2 + 1); - if (!r) - return -ENOMEM; - - for (x = p; x < p + l; x += 2) { - int a, b; - - a = unhexchar(x[0]); - if (a < 0) - return a; - else if (x+1 < p + l) { - b = unhexchar(x[1]); - if (b < 0) - return b; - } else - b = 0; - - *(z++) = (uint8_t) a << 4 | (uint8_t) b; - } - - *z = 0; - - *mem = r; - r = NULL; - *len = (l + 1) / 2; - - return 0; -} - -/* https://tools.ietf.org/html/rfc4648#section-6 - * Notice that base32hex differs from base32 in the alphabet it uses. - * The distinction is that the base32hex representation preserves the - * order of the underlying data when compared as bytestrings, this is - * useful when representing NSEC3 hashes, as one can then verify the - * order of hashes directly from their representation. */ -char base32hexchar(int x) { - static const char table[32] = "0123456789" - "ABCDEFGHIJKLMNOPQRSTUV"; - - return table[x & 31]; -} - -int unbase32hexchar(char c) { - unsigned offset; - - if (c >= '0' && c <= '9') - return c - '0'; - - offset = '9' - '0' + 1; - - if (c >= 'A' && c <= 'V') - return c - 'A' + offset; - - return -EINVAL; -} - -char *base32hexmem(const void *p, size_t l, bool padding) { - char *r, *z; - const uint8_t *x; - size_t len; - - if (padding) - /* five input bytes makes eight output bytes, padding is added so we must round up */ - len = 8 * (l + 4) / 5; - else { - /* same, but round down as there is no padding */ - len = 8 * l / 5; - - switch (l % 5) { - case 4: - len += 7; - break; - case 3: - len += 5; - break; - case 2: - len += 4; - break; - case 1: - len += 2; - break; - } - } - - z = r = malloc(len + 1); - if (!r) - return NULL; - - for (x = p; x < (const uint8_t*) p + (l / 5) * 5; x += 5) { - /* x[0] == XXXXXXXX; x[1] == YYYYYYYY; x[2] == ZZZZZZZZ - x[3] == QQQQQQQQ; x[4] == WWWWWWWW */ - *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ - *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ - *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ - *(z++) = base32hexchar((x[1] & 1) << 4 | x[2] >> 4); /* 000YZZZZ */ - *(z++) = base32hexchar((x[2] & 15) << 1 | x[3] >> 7); /* 000ZZZZQ */ - *(z++) = base32hexchar((x[3] & 127) >> 2); /* 000QQQQQ */ - *(z++) = base32hexchar((x[3] & 3) << 3 | x[4] >> 5); /* 000QQWWW */ - *(z++) = base32hexchar((x[4] & 31)); /* 000WWWWW */ - } - - switch (l % 5) { - case 4: - *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ - *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ - *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ - *(z++) = base32hexchar((x[1] & 1) << 4 | x[2] >> 4); /* 000YZZZZ */ - *(z++) = base32hexchar((x[2] & 15) << 1 | x[3] >> 7); /* 000ZZZZQ */ - *(z++) = base32hexchar((x[3] & 127) >> 2); /* 000QQQQQ */ - *(z++) = base32hexchar((x[3] & 3) << 3); /* 000QQ000 */ - if (padding) - *(z++) = '='; - - break; - - case 3: - *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ - *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ - *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ - *(z++) = base32hexchar((x[1] & 1) << 4 | x[2] >> 4); /* 000YZZZZ */ - *(z++) = base32hexchar((x[2] & 15) << 1); /* 000ZZZZ0 */ - if (padding) { - *(z++) = '='; - *(z++) = '='; - *(z++) = '='; - } - - break; - - case 2: - *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ - *(z++) = base32hexchar((x[0] & 7) << 2 | x[1] >> 6); /* 000XXXYY */ - *(z++) = base32hexchar((x[1] & 63) >> 1); /* 000YYYYY */ - *(z++) = base32hexchar((x[1] & 1) << 4); /* 000Y0000 */ - if (padding) { - *(z++) = '='; - *(z++) = '='; - *(z++) = '='; - *(z++) = '='; - } - - break; - - case 1: - *(z++) = base32hexchar(x[0] >> 3); /* 000XXXXX */ - *(z++) = base32hexchar((x[0] & 7) << 2); /* 000XXX00 */ - if (padding) { - *(z++) = '='; - *(z++) = '='; - *(z++) = '='; - *(z++) = '='; - *(z++) = '='; - *(z++) = '='; - } - - break; - } - - *z = 0; - return r; -} - -int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *_len) { - _cleanup_free_ uint8_t *r = NULL; - int a, b, c, d, e, f, g, h; - uint8_t *z; - const char *x; - size_t len; - unsigned pad = 0; - - assert(p); - - /* padding ensures any base32hex input has input divisible by 8 */ - if (padding && l % 8 != 0) - return -EINVAL; - - if (padding) { - /* strip the padding */ - while (l > 0 && p[l - 1] == '=' && pad < 7) { - pad ++; - l --; - } - } - - /* a group of eight input bytes needs five output bytes, in case of - padding we need to add some extra bytes */ - len = (l / 8) * 5; - - switch (l % 8) { - case 7: - len += 4; - break; - case 5: - len += 3; - break; - case 4: - len += 2; - break; - case 2: - len += 1; - break; - case 0: - break; - default: - return -EINVAL; - } - - z = r = malloc(len + 1); - if (!r) - return -ENOMEM; - - for (x = p; x < p + (l / 8) * 8; x += 8) { - /* a == 000XXXXX; b == 000YYYYY; c == 000ZZZZZ; d == 000WWWWW - e == 000SSSSS; f == 000QQQQQ; g == 000VVVVV; h == 000RRRRR */ - a = unbase32hexchar(x[0]); - if (a < 0) - return -EINVAL; - - b = unbase32hexchar(x[1]); - if (b < 0) - return -EINVAL; - - c = unbase32hexchar(x[2]); - if (c < 0) - return -EINVAL; - - d = unbase32hexchar(x[3]); - if (d < 0) - return -EINVAL; - - e = unbase32hexchar(x[4]); - if (e < 0) - return -EINVAL; - - f = unbase32hexchar(x[5]); - if (f < 0) - return -EINVAL; - - g = unbase32hexchar(x[6]); - if (g < 0) - return -EINVAL; - - h = unbase32hexchar(x[7]); - if (h < 0) - return -EINVAL; - - *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ - *(z++) = (uint8_t) b << 6 | (uint8_t) c << 1 | (uint8_t) d >> 4; /* YYZZZZZW */ - *(z++) = (uint8_t) d << 4 | (uint8_t) e >> 1; /* WWWWSSSS */ - *(z++) = (uint8_t) e << 7 | (uint8_t) f << 2 | (uint8_t) g >> 3; /* SQQQQQVV */ - *(z++) = (uint8_t) g << 5 | (uint8_t) h; /* VVVRRRRR */ - } - - switch (l % 8) { - case 7: - a = unbase32hexchar(x[0]); - if (a < 0) - return -EINVAL; - - b = unbase32hexchar(x[1]); - if (b < 0) - return -EINVAL; - - c = unbase32hexchar(x[2]); - if (c < 0) - return -EINVAL; - - d = unbase32hexchar(x[3]); - if (d < 0) - return -EINVAL; - - e = unbase32hexchar(x[4]); - if (e < 0) - return -EINVAL; - - f = unbase32hexchar(x[5]); - if (f < 0) - return -EINVAL; - - g = unbase32hexchar(x[6]); - if (g < 0) - return -EINVAL; - - /* g == 000VV000 */ - if (g & 7) - return -EINVAL; - - *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ - *(z++) = (uint8_t) b << 6 | (uint8_t) c << 1 | (uint8_t) d >> 4; /* YYZZZZZW */ - *(z++) = (uint8_t) d << 4 | (uint8_t) e >> 1; /* WWWWSSSS */ - *(z++) = (uint8_t) e << 7 | (uint8_t) f << 2 | (uint8_t) g >> 3; /* SQQQQQVV */ - - break; - case 5: - a = unbase32hexchar(x[0]); - if (a < 0) - return -EINVAL; - - b = unbase32hexchar(x[1]); - if (b < 0) - return -EINVAL; - - c = unbase32hexchar(x[2]); - if (c < 0) - return -EINVAL; - - d = unbase32hexchar(x[3]); - if (d < 0) - return -EINVAL; - - e = unbase32hexchar(x[4]); - if (e < 0) - return -EINVAL; - - /* e == 000SSSS0 */ - if (e & 1) - return -EINVAL; - - *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ - *(z++) = (uint8_t) b << 6 | (uint8_t) c << 1 | (uint8_t) d >> 4; /* YYZZZZZW */ - *(z++) = (uint8_t) d << 4 | (uint8_t) e >> 1; /* WWWWSSSS */ - - break; - case 4: - a = unbase32hexchar(x[0]); - if (a < 0) - return -EINVAL; - - b = unbase32hexchar(x[1]); - if (b < 0) - return -EINVAL; - - c = unbase32hexchar(x[2]); - if (c < 0) - return -EINVAL; - - d = unbase32hexchar(x[3]); - if (d < 0) - return -EINVAL; - - /* d == 000W0000 */ - if (d & 15) - return -EINVAL; - - *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ - *(z++) = (uint8_t) b << 6 | (uint8_t) c << 1 | (uint8_t) d >> 4; /* YYZZZZZW */ - - break; - case 2: - a = unbase32hexchar(x[0]); - if (a < 0) - return -EINVAL; - - b = unbase32hexchar(x[1]); - if (b < 0) - return -EINVAL; - - /* b == 000YYY00 */ - if (b & 3) - return -EINVAL; - - *(z++) = (uint8_t) a << 3 | (uint8_t) b >> 2; /* XXXXXYYY */ - - break; - case 0: - break; - default: - return -EINVAL; - } - - *z = 0; - - *mem = r; - r = NULL; - *_len = len; - - return 0; -} - -/* https://tools.ietf.org/html/rfc4648#section-4 */ -char base64char(int x) { - static const char table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - return table[x & 63]; -} - -int unbase64char(char c) { - unsigned offset; - - if (c >= 'A' && c <= 'Z') - return c - 'A'; - - offset = 'Z' - 'A' + 1; - - if (c >= 'a' && c <= 'z') - return c - 'a' + offset; - - offset += 'z' - 'a' + 1; - - if (c >= '0' && c <= '9') - return c - '0' + offset; - - offset += '9' - '0' + 1; - - if (c == '+') - return offset; - - offset ++; - - if (c == '/') - return offset; - - return -EINVAL; -} - -char *base64mem(const void *p, size_t l) { - char *r, *z; - const uint8_t *x; - - /* three input bytes makes four output bytes, padding is added so we must round up */ - z = r = malloc(4 * (l + 2) / 3 + 1); - if (!r) - return NULL; - - for (x = p; x < (const uint8_t*) p + (l / 3) * 3; x += 3) { - /* x[0] == XXXXXXXX; x[1] == YYYYYYYY; x[2] == ZZZZZZZZ */ - *(z++) = base64char(x[0] >> 2); /* 00XXXXXX */ - *(z++) = base64char((x[0] & 3) << 4 | x[1] >> 4); /* 00XXYYYY */ - *(z++) = base64char((x[1] & 15) << 2 | x[2] >> 6); /* 00YYYYZZ */ - *(z++) = base64char(x[2] & 63); /* 00ZZZZZZ */ - } - - switch (l % 3) { - case 2: - *(z++) = base64char(x[0] >> 2); /* 00XXXXXX */ - *(z++) = base64char((x[0] & 3) << 4 | x[1] >> 4); /* 00XXYYYY */ - *(z++) = base64char((x[1] & 15) << 2); /* 00YYYY00 */ - *(z++) = '='; - - break; - case 1: - *(z++) = base64char(x[0] >> 2); /* 00XXXXXX */ - *(z++) = base64char((x[0] & 3) << 4); /* 00XX0000 */ - *(z++) = '='; - *(z++) = '='; - - break; - } - - *z = 0; - return r; -} - -int unbase64mem(const char *p, size_t l, void **mem, size_t *_len) { - _cleanup_free_ uint8_t *r = NULL; - int a, b, c, d; - uint8_t *z; - const char *x; - size_t len; - - assert(p); - - /* padding ensures any base63 input has input divisible by 4 */ - if (l % 4 != 0) - return -EINVAL; - - /* strip the padding */ - if (l > 0 && p[l - 1] == '=') - l --; - if (l > 0 && p[l - 1] == '=') - l --; - - /* a group of four input bytes needs three output bytes, in case of - padding we need to add two or three extra bytes */ - len = (l / 4) * 3 + (l % 4 ? (l % 4) - 1 : 0); - - z = r = malloc(len + 1); - if (!r) - return -ENOMEM; - - for (x = p; x < p + (l / 4) * 4; x += 4) { - /* a == 00XXXXXX; b == 00YYYYYY; c == 00ZZZZZZ; d == 00WWWWWW */ - a = unbase64char(x[0]); - if (a < 0) - return -EINVAL; - - b = unbase64char(x[1]); - if (b < 0) - return -EINVAL; - - c = unbase64char(x[2]); - if (c < 0) - return -EINVAL; - - d = unbase64char(x[3]); - if (d < 0) - return -EINVAL; - - *(z++) = (uint8_t) a << 2 | (uint8_t) b >> 4; /* XXXXXXYY */ - *(z++) = (uint8_t) b << 4 | (uint8_t) c >> 2; /* YYYYZZZZ */ - *(z++) = (uint8_t) c << 6 | (uint8_t) d; /* ZZWWWWWW */ - } - - switch (l % 4) { - case 3: - a = unbase64char(x[0]); - if (a < 0) - return -EINVAL; - - b = unbase64char(x[1]); - if (b < 0) - return -EINVAL; - - c = unbase64char(x[2]); - if (c < 0) - return -EINVAL; - - /* c == 00ZZZZ00 */ - if (c & 3) - return -EINVAL; - - *(z++) = (uint8_t) a << 2 | (uint8_t) b >> 4; /* XXXXXXYY */ - *(z++) = (uint8_t) b << 4 | (uint8_t) c >> 2; /* YYYYZZZZ */ - - break; - case 2: - a = unbase64char(x[0]); - if (a < 0) - return -EINVAL; - - b = unbase64char(x[1]); - if (b < 0) - return -EINVAL; - - /* b == 00YY0000 */ - if (b & 15) - return -EINVAL; - - *(z++) = (uint8_t) a << 2 | (uint8_t) (b >> 4); /* XXXXXXYY */ - - break; - case 0: - - break; - default: - return -EINVAL; - } - - *z = 0; - - *mem = r; - r = NULL; - *_len = len; - - return 0; -} - -char octchar(int x) { - return '0' + (x & 7); -} - -int unoctchar(char c) { - - if (c >= '0' && c <= '7') - return c - '0'; - - return -EINVAL; -} - -char decchar(int x) { - return '0' + (x % 10); -} - -int undecchar(char c) { - - if (c >= '0' && c <= '9') - return c - '0'; - - return -EINVAL; -} - _pure_ static bool hidden_file_allow_backup(const char *filename) { assert(filename); @@ -3000,49 +2373,6 @@ uint64_t physical_memory(void) { return (uint64_t) mem * (uint64_t) page_size(); } -void hexdump(FILE *f, const void *p, size_t s) { - const uint8_t *b = p; - unsigned n = 0; - - assert(s == 0 || b); - - while (s > 0) { - size_t i; - - fprintf(f, "%04x ", n); - - for (i = 0; i < 16; i++) { - - if (i >= s) - fputs(" ", f); - else - fprintf(f, "%02x ", b[i]); - - if (i == 7) - fputc(' ', f); - } - - fputc(' ', f); - - for (i = 0; i < 16; i++) { - - if (i >= s) - fputc(' ', f); - else - fputc(isprint(b[i]) ? (char) b[i] : '.', f); - } - - fputc('\n', f); - - if (s < 16) - break; - - n += 16; - b += 16; - s -= 16; - } -} - int update_reboot_param_file(const char *param) { int r = 0; diff --git a/src/basic/util.h b/src/basic/util.h index d51b824294..6c3449a706 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -95,17 +95,6 @@ char *file_in_same_dir(const char *path, const char *filename); int rmdir_parents(const char *path, const char *stop); -char hexchar(int x) _const_; -int unhexchar(char c) _const_; -char octchar(int x) _const_; -int unoctchar(char c) _const_; -char decchar(int x) _const_; -int undecchar(char c) _const_; -char base32hexchar(int x) _const_; -int unbase32hexchar(char c) _const_; -char base64char(int x) _const_; -int unbase64char(char c) _const_; - bool dirent_is_file(const struct dirent *de) _pure_; bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_; @@ -398,15 +387,6 @@ static inline void *mempset(void *s, int c, size_t n) { return (uint8_t*)s + n; } -char *hexmem(const void *p, size_t l); -int unhexmem(const char *p, size_t l, void **mem, size_t *len); - -char *base32hexmem(const void *p, size_t l, bool padding); -int unbase32hexmem(const char *p, size_t l, bool padding, void **mem, size_t *len); - -char *base64mem(const void *p, size_t l); -int unbase64mem(const char *p, size_t l, void **mem, size_t *len); - void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size); void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size); #define GREEDY_REALLOC(array, allocated, need) \ @@ -559,8 +539,6 @@ const char *personality_to_string(unsigned long); uint64_t physical_memory(void); -void hexdump(FILE *f, const void *p, size_t s); - union file_handle_union { struct file_handle handle; char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ]; diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index a7fbd71144..238fc8efdd 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -109,7 +109,7 @@ static int property_get_oom_score_adjust( n = 0; if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0) - safe_atoi(t, &n); + safe_atoi32(t, &n); } return sd_bus_message_append(reply, "i", n); diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c index c72892b343..ea4bdc5414 100644 --- a/src/core/machine-id-setup.c +++ b/src/core/machine-id-setup.c @@ -36,6 +36,7 @@ #include "machine-id-setup.h" #include "macro.h" #include "mkdir.h" +#include "hexdecoct.h" #include "path-util.h" #include "process-util.h" #include "string-util.h" diff --git a/src/import/pull-job.c b/src/import/pull-job.c index fd05877705..0910901375 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -24,6 +24,7 @@ #include "fd-util.h" #include "io-util.h" #include "machine-pool.h" +#include "hexdecoct.h" #include "parse-util.h" #include "pull-job.h" #include "string-util.h" diff --git a/src/journal/journal-authenticate.c b/src/journal/journal-authenticate.c index dc51a5ab2f..0c4ac5cdc3 100644 --- a/src/journal/journal-authenticate.c +++ b/src/journal/journal-authenticate.c @@ -27,6 +27,7 @@ #include "journal-authenticate.h" #include "journal-def.h" #include "journal-file.h" +#include "hexdecoct.h" static uint64_t journal_file_tag_seqnum(JournalFile *f) { uint64_t r; diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index 4c102fd530..289f9bf78d 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -23,6 +23,7 @@ #include "fd-util.h" #include "journald-audit.h" #include "missing.h" +#include "hexdecoct.h" #include "string-util.h" typedef struct MapField { diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index 926ad0b02f..d86977be17 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -30,6 +30,7 @@ #include "dhcp-lease-internal.h" #include "log.h" #include "network-internal.h" +#include "hexdecoct.h" #include "parse-util.h" #include "siphash24.h" #include "string-util.h" diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index 94a276fb28..3411f6ec91 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -34,6 +34,7 @@ #include "hostname-util.h" #include "in-addr-util.h" #include "network-internal.h" +#include "hexdecoct.h" #include "parse-util.h" #include "unaligned.h" diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index eee53b6407..d7a7b6e5bb 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -32,6 +32,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "hexdecoct.h" #include "parse-util.h" #include "process-util.h" #include "string-util.h" diff --git a/src/libsystemd/sd-bus/bus-internal.c b/src/libsystemd/sd-bus/bus-internal.c index 486a8cf8de..8cab1bf219 100644 --- a/src/libsystemd/sd-bus/bus-internal.c +++ b/src/libsystemd/sd-bus/bus-internal.c @@ -21,6 +21,7 @@ #include "bus-internal.h" #include "bus-message.h" +#include "hexdecoct.h" #include "string-util.h" bool object_path_is_valid(const char *p) { diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index 58b19fbdc7..fca3ebd394 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -24,6 +24,7 @@ #include "bus-message.h" #include "bus-util.h" #include "fd-util.h" +#include "hexdecoct.h" #include "string-util.h" #include "strv.h" diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 42d7f80461..7ca544f6fd 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -34,6 +34,7 @@ #include "formats-util.h" #include "macro.h" #include "missing.h" +#include "hexdecoct.h" #include "signal-util.h" #include "string-util.h" #include "user-util.h" diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 36370e79e3..0d92a0d461 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -48,6 +48,7 @@ #include "hostname-util.h" #include "macro.h" #include "missing.h" +#include "hexdecoct.h" #include "parse-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c index c0daa451ec..7da1dacd81 100644 --- a/src/libsystemd/sd-bus/test-bus-marshal.c +++ b/src/libsystemd/sd-bus/test-bus-marshal.c @@ -38,6 +38,7 @@ #include "bus-util.h" #include "fd-util.h" #include "log.h" +#include "hexdecoct.h" #include "util.h" static void test_bus_path_encode_unique(void) { diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index 335ad3b1b4..1e17ea6a06 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -28,6 +28,7 @@ #include "fd-util.h" #include "io-util.h" #include "macro.h" +#include "hexdecoct.h" #include "random-util.h" #include "util.h" diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index c8f591d005..63edee1fd1 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -23,10 +23,11 @@ #include "dns-domain.h" #include "dns-type.h" +#include "hexdecoct.h" #include "resolved-dns-packet.h" +#include "resolved-dns-rr.h" #include "string-util.h" #include "strv.h" -#include "resolved-dns-rr.h" DnsResourceKey* dns_resource_key_new(uint16_t class, uint16_t type, const char *name) { DnsResourceKey *k; diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index a8176af840..b6587306a5 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -25,6 +25,7 @@ #endif #include "dns-domain.h" +#include "hexdecoct.h" #include "parse-util.h" #include "string-util.h" diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 3374456973..109732d74e 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -30,6 +30,7 @@ #include "install.h" #include "log.h" #include "mkdir.h" +#include "hexdecoct.h" #include "path-lookup.h" #include "path-util.h" #include "set.h" diff --git a/src/test/test-util.c b/src/test/test-util.c index f42d8f19bb..848ebe69f4 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -39,6 +39,7 @@ #include "fileio.h" #include "io-util.h" #include "mkdir.h" +#include "hexdecoct.h" #include "parse-util.h" #include "process-util.h" #include "rm-rf.h" -- cgit v1.2.3-54-g00ecf From 5f311f8c0e51e2f13773823feb6a71f7c6f2838c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 17:30:56 +0100 Subject: util: remove path_get_parent(), in favour of dirname_malloc() We don't need two functions that do essentialy the same, hence drop path_get_parent(), and stick to dirname_malloc(), but move it to path-util.[ch]. --- src/analyze/analyze-verify.c | 7 +++-- src/basic/btrfs-util.c | 8 ++--- src/basic/path-util.c | 75 ++++++++++++++++++-------------------------- src/basic/path-util.h | 3 +- src/basic/util.c | 18 ----------- src/basic/util.h | 1 - src/core/automount.c | 7 ++--- src/core/mount.c | 7 +++-- src/core/socket.c | 6 ++-- src/core/unit.c | 5 ++- src/import/pull-dkr.c | 8 ++--- src/journal/catalog.c | 1 + src/shared/install.c | 7 ++--- src/systemctl/systemctl.c | 3 +- src/test/test-path-util.c | 14 --------- 15 files changed, 62 insertions(+), 108 deletions(-) (limited to 'src/journal') diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c index f4255f979e..2b6240232c 100644 --- a/src/analyze/analyze-verify.c +++ b/src/analyze/analyze-verify.c @@ -21,12 +21,13 @@ #include -#include "manager.h" +#include "analyze-verify.h" #include "bus-util.h" #include "log.h" -#include "strv.h" +#include "manager.h" #include "pager.h" -#include "analyze-verify.h" +#include "path-util.h" +#include "strv.h" static int generate_path(char **var, char **filenames) { char **filename; diff --git a/src/basic/btrfs-util.c b/src/basic/btrfs-util.c index f799f8dcc2..7b49a1a516 100644 --- a/src/basic/btrfs-util.c +++ b/src/basic/btrfs-util.c @@ -60,13 +60,13 @@ static int validate_subvolume_name(const char *name) { static int open_parent(const char *path, int flags) { _cleanup_free_ char *parent = NULL; - int r, fd; + int fd; assert(path); - r = path_get_parent(path, &parent); - if (r < 0) - return r; + parent = dirname_malloc(path); + if (!parent) + return -ENOMEM; fd = open(parent, flags); if (fd < 0) diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 0015667ac0..7abb3a7b9e 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -27,6 +27,12 @@ #include #include +/* When we include libgen.h because we need dirname() we immediately + * undefine basename() since libgen.h defines it as a macro to the + * POSIX version which is really broken. We prefer GNU basename(). */ +#include +#undef basename + #include "fd-util.h" #include "fileio.h" #include "log.h" @@ -46,47 +52,6 @@ bool is_path(const char *p) { return !!strchr(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; -} - int path_split_and_make_absolute(const char *p, char ***ret) { char **l; int r; @@ -659,7 +624,6 @@ fallback_fstat: int path_is_mount_point(const char *t, int flags) { _cleanup_close_ int fd = -1; _cleanup_free_ char *canonical = NULL, *parent = NULL; - int r; assert(t); @@ -678,9 +642,9 @@ int path_is_mount_point(const char *t, int flags) { t = canonical; } - r = path_get_parent(t, &parent); - if (r < 0) - return r; + parent = dirname_malloc(t); + if (!parent) + return -ENOMEM; fd = openat(AT_FDCWD, parent, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_PATH); if (fd < 0) @@ -937,3 +901,24 @@ int parse_path_argument_and_warn(const char *path, bool suppress_root, char **ar *arg = p; return 0; } + +char* dirname_malloc(const char *path) { + char *d, *dir, *dir2; + + assert(path); + + d = strdup(path); + if (!d) + return NULL; + + dir = dirname(d); + assert(dir); + + if (dir == d) + return d; + + dir2 = strdup(dir); + free(d); + + return dir2; +} diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 9d4522c8eb..708cdc1707 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -37,7 +37,6 @@ bool is_path(const char *p) _pure_; int path_split_and_make_absolute(const char *p, char ***ret); -int path_get_parent(const char *path, char **parent); bool path_is_absolute(const char *p) _pure_; char* path_make_absolute(const char *p, const char *prefix); int path_make_absolute_cwd(const char *p, char **ret); @@ -103,3 +102,5 @@ char *prefix_root(const char *root, const char *path); }) int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg); + +char* dirname_malloc(const char *path); diff --git a/src/basic/util.c b/src/basic/util.c index 5e3a363bb4..f403dca10e 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -398,24 +398,6 @@ int dir_is_empty(const char *path) { return 1; } -char* dirname_malloc(const char *path) { - char *d, *dir, *dir2; - - d = strdup(path); - if (!d) - return NULL; - dir = dirname(d); - assert(dir); - - if (dir != d) { - dir2 = strdup(dir); - free(d); - return dir2; - } - - return dir; -} - void rename_process(const char name[8]) { assert(name); diff --git a/src/basic/util.h b/src/basic/util.h index 6c3449a706..ec95c53130 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -163,7 +163,6 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path); bool is_device_path(const char *path); int dir_is_empty(const char *path); -char* dirname_malloc(const char *path); static inline int dir_is_populated(const char *path) { int r; diff --git a/src/core/automount.c b/src/core/automount.c index 2ee32312fb..df98711d96 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -141,13 +141,12 @@ static void automount_done(Unit *u) { static int automount_add_mount_links(Automount *a) { _cleanup_free_ char *parent = NULL; - int r; assert(a); - r = path_get_parent(a->where, &parent); - if (r < 0) - return r; + parent = dirname_malloc(a->where); + if (!parent) + return -ENOMEM; return unit_require_mounts_for(UNIT(a), parent); } diff --git a/src/core/mount.c b/src/core/mount.c index 59f56bdefa..9d8b55da58 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -252,9 +252,10 @@ static int mount_add_mount_links(Mount *m) { if (!path_equal(m->where, "/")) { /* Adds in links to other mount points that might lie further * up in the hierarchy */ - r = path_get_parent(m->where, &parent); - if (r < 0) - return r; + + parent = dirname_malloc(m->where); + if (!parent) + return -ENOMEM; r = unit_require_mounts_for(UNIT(m), parent); if (r < 0) diff --git a/src/core/socket.c b/src/core/socket.c index 49cef210dc..8ea7bd9af4 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1169,9 +1169,9 @@ static int usbffs_dispatch_eps(SocketPort *p) { _cleanup_free_ char *path = NULL; int r, i, n, k; - r = path_get_parent(p->path, &path); - if (r < 0) - return r; + path = dirname_malloc(p->path); + if (!path) + return -ENOMEM; r = scandir(path, &ent, usbffs_select_ep, alphasort); if (r < 0) diff --git a/src/core/unit.c b/src/core/unit.c index 17c135cf3f..b44a2a5e2d 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -417,12 +417,11 @@ static void unit_remove_transient(Unit *u) { STRV_FOREACH(i, u->dropin_paths) { _cleanup_free_ char *p = NULL; - int r; (void) unlink(*i); - r = path_get_parent(*i, &p); - if (r >= 0) + p = dirname_malloc(*i); + if (p) (void) rmdir(p); } } diff --git a/src/import/pull-dkr.c b/src/import/pull-dkr.c index 1cd9e7b0bd..448dbafa9f 100644 --- a/src/import/pull-dkr.c +++ b/src/import/pull-dkr.c @@ -479,13 +479,13 @@ static int dkr_pull_make_local_copy(DkrPull *i, DkrPullVersion version) { if (!i->final_path) { i->final_path = strjoin(i->image_root, "/.dkr-", i->id, NULL); if (!i->final_path) - return log_oom(); + return -ENOMEM; } if (version == DKR_PULL_V2) { - r = path_get_parent(i->image_root, &p); - if (r < 0) - return r; + p = dirname_malloc(i->image_root); + if (!p) + return -ENOMEM; } r = pull_make_local_copy(i->final_path, p ?: i->image_root, i->local, i->force_local); diff --git a/src/journal/catalog.c b/src/journal/catalog.c index d5bc17b4b6..fe3975b7b8 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -35,6 +35,7 @@ #include "hashmap.h" #include "log.h" #include "mkdir.h" +#include "path-util.h" #include "siphash24.h" #include "sparse-endian.h" #include "strbuf.h" diff --git a/src/shared/install.c b/src/shared/install.c index 9b72f76662..a1720488e8 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -48,13 +48,12 @@ typedef struct { static int in_search_path(const char *path, char **search) { _cleanup_free_ char *parent = NULL; - int r; assert(path); - r = path_get_parent(path, &parent); - if (r < 0) - return r; + parent = dirname_malloc(path); + if (!parent) + return -ENOMEM; return strv_contains(search, parent); } diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 49a4b46fd4..054e9eaa13 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3479,7 +3479,8 @@ static void print_status_info( dir = mfree(dir); - if (path_get_parent(*dropin, &dir) < 0) { + dir = dirname_malloc(*dropin); + if (!dir) { log_oom(); return; } diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 89129c9894..86d61b2efb 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -77,20 +77,6 @@ static void test_path(void) { assert_se(streq(basename("/aa///file..."), "file...")); assert_se(streq(basename("file.../"), "")); -#define test_parent(x, y) { \ - _cleanup_free_ char *z = NULL; \ - int r = path_get_parent(x, &z); \ - printf("expected: %s\n", y ? y : "error"); \ - printf("actual: %s\n", r<0 ? "error" : z); \ - assert_se((y==NULL) ^ (r==0)); \ - assert_se(y==NULL || path_equal(z, y)); \ - } - - test_parent("./aa/bb/../file.da.", "./aa/bb/.."); - test_parent("/aa///.file", "/aa///"); - test_parent("/aa///file...", "/aa///"); - test_parent("file.../", NULL); - fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY); assert_se(fd >= 0); assert_se(fd_is_mount_point(fd, "/", 0) > 0); -- cgit v1.2.3-54-g00ecf From 0d39fa9c69b97a2ceb156053deef69c0866c2b97 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 18:05:03 +0100 Subject: util-lib: move more file I/O related calls into fileio.[ch] --- src/basic/calendarspec.c | 1 + src/basic/copy.c | 1 + src/basic/fileio.c | 302 ++++++++++++++++++++++++++++++++- src/basic/fileio.h | 28 +++ src/basic/hostname-util.c | 1 + src/basic/time-util.c | 1 + src/basic/util.c | 295 -------------------------------- src/basic/util.h | 25 --- src/boot/bootctl.c | 1 + src/core/cgroup.c | 1 + src/core/dbus-cgroup.c | 1 + src/core/dbus-manager.c | 1 + src/core/dbus-service.c | 1 + src/core/ima-setup.c | 1 + src/core/manager.c | 1 + src/cryptsetup/cryptsetup-generator.c | 1 + src/dbus1-generator/dbus1-generator.c | 1 + src/fstab-generator/fstab-generator.c | 1 + src/hwdb/hwdb.c | 3 +- src/import/export-raw.c | 1 + src/import/export-tar.c | 1 + src/import/import-raw.c | 1 + src/import/import-tar.c | 1 + src/import/pull-dkr.c | 1 + src/import/pull-raw.c | 1 + src/import/pull-tar.c | 1 + src/journal/catalog.c | 1 + src/journal/coredumpctl.c | 1 + src/journal/journal-send.c | 1 + src/journal/journal-verify.c | 1 + src/journal/test-catalog.c | 1 + src/journal/test-compress.c | 1 + src/journal/test-mmap-cache.c | 3 +- src/libsystemd-network/sd-lldp.c | 1 + src/libsystemd/sd-bus/bus-dump.c | 3 +- src/libsystemd/sd-bus/bus-introspect.c | 1 + src/libsystemd/sd-bus/bus-match.c | 1 + src/libsystemd/sd-path/sd-path.c | 1 + src/libudev/libudev-monitor.c | 1 + src/login/logind-seat.c | 1 + src/modules-load/modules-load.c | 1 + src/network/networkd-manager.c | 1 + src/shared/ask-password-api.c | 1 + src/shared/clean-ipc.c | 1 + src/shared/machine-pool.c | 1 + src/test/test-async.c | 3 +- src/test/test-fdset.c | 1 + src/test/test-terminal-util.c | 7 +- src/test/test-tmpfiles.c | 1 + src/tmpfiles/tmpfiles.c | 1 + src/udev/udevadm-hwdb.c | 1 + 51 files changed, 382 insertions(+), 329 deletions(-) (limited to 'src/journal') diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 50328e4187..62b03a913c 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -24,6 +24,7 @@ #include "string-util.h" #include "calendarspec.h" +#include "fileio.h" #define BITS_WEEKDAYS 127 diff --git a/src/basic/copy.c b/src/basic/copy.c index 9f274c4d51..4b410a74e5 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -25,6 +25,7 @@ #include "btrfs-util.h" #include "copy.h" #include "fd-util.h" +#include "fileio.h" #include "io-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 5d33309ab2..b7e447f6b6 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -25,6 +25,9 @@ #include "escape.h" #include "fd-util.h" #include "fileio.h" +#include "hexdecoct.h" +#include "path-util.h" +#include "random-util.h" #include "string-util.h" #include "strv.h" #include "utf8.h" @@ -54,7 +57,7 @@ static int write_string_file_atomic(const char *fn, const char *line, bool enfor if (r < 0) return r; - fchmod_umask(fileno(f), 0644); + (void) fchmod_umask(fileno(f), 0644); r = write_string_stream(f, line, enforce_newline); if (r >= 0) { @@ -63,7 +66,7 @@ static int write_string_file_atomic(const char *fn, const char *line, bool enfor } if (r < 0) - unlink(p); + (void) unlink(p); return r; } @@ -848,3 +851,298 @@ int get_proc_field(const char *filename, const char *pattern, const char *termin *field = f; return 0; } + +DIR *xopendirat(int fd, const char *name, int flags) { + int nfd; + DIR *d; + + assert(!(flags & O_CREAT)); + + nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags, 0); + if (nfd < 0) + return NULL; + + d = fdopendir(nfd); + if (!d) { + safe_close(nfd); + return NULL; + } + + return d; +} + +static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) { + char **i; + + assert(path); + assert(mode); + assert(_f); + + if (!path_strv_resolve_uniq(search, root)) + return -ENOMEM; + + STRV_FOREACH(i, search) { + _cleanup_free_ char *p = NULL; + FILE *f; + + if (root) + p = strjoin(root, *i, "/", path, NULL); + else + p = strjoin(*i, "/", path, NULL); + if (!p) + return -ENOMEM; + + f = fopen(p, mode); + if (f) { + *_f = f; + return 0; + } + + if (errno != ENOENT) + return -errno; + } + + return -ENOENT; +} + +int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) { + _cleanup_strv_free_ char **copy = NULL; + + assert(path); + assert(mode); + assert(_f); + + if (path_is_absolute(path)) { + FILE *f; + + f = fopen(path, mode); + if (f) { + *_f = f; + return 0; + } + + return -errno; + } + + copy = strv_copy((char**) search); + if (!copy) + return -ENOMEM; + + return search_and_fopen_internal(path, mode, root, copy, _f); +} + +int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) { + _cleanup_strv_free_ char **s = NULL; + + if (path_is_absolute(path)) { + FILE *f; + + f = fopen(path, mode); + if (f) { + *_f = f; + return 0; + } + + return -errno; + } + + s = strv_split_nulstr(search); + if (!s) + return -ENOMEM; + + return search_and_fopen_internal(path, mode, root, s, _f); +} + +int fopen_temporary(const char *path, FILE **_f, char **_temp_path) { + FILE *f; + char *t; + int r, fd; + + assert(path); + assert(_f); + assert(_temp_path); + + r = tempfn_xxxxxx(path, NULL, &t); + if (r < 0) + return r; + + fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC); + if (fd < 0) { + free(t); + return -errno; + } + + f = fdopen(fd, "we"); + if (!f) { + unlink_noerrno(t); + free(t); + safe_close(fd); + return -errno; + } + + *_f = f; + *_temp_path = t; + + return 0; +} + +int fflush_and_check(FILE *f) { + assert(f); + + errno = 0; + fflush(f); + + if (ferror(f)) + return errno ? -errno : -EIO; + + return 0; +} + +/* This is much like like mkostemp() but is subject to umask(). */ +int mkostemp_safe(char *pattern, int flags) { + _cleanup_umask_ mode_t u; + int fd; + + assert(pattern); + + u = umask(077); + + fd = mkostemp(pattern, flags); + if (fd < 0) + return -errno; + + return fd; +} + +int open_tmpfile(const char *path, int flags) { + char *p; + int fd; + + assert(path); + +#ifdef O_TMPFILE + /* Try O_TMPFILE first, if it is supported */ + fd = open(path, flags|O_TMPFILE|O_EXCL, S_IRUSR|S_IWUSR); + if (fd >= 0) + return fd; +#endif + + /* Fall back to unguessable name + unlinking */ + p = strjoina(path, "/systemd-tmp-XXXXXX"); + + fd = mkostemp_safe(p, flags); + if (fd < 0) + return fd; + + unlink(p); + return fd; +} + +int tempfn_xxxxxx(const char *p, const char *extra, char **ret) { + const char *fn; + char *t; + + assert(p); + assert(ret); + + /* + * Turns this: + * /foo/bar/waldo + * + * Into this: + * /foo/bar/.#waldoXXXXXX + */ + + fn = basename(p); + if (!filename_is_valid(fn)) + return -EINVAL; + + if (extra == NULL) + extra = ""; + + t = new(char, strlen(p) + 2 + strlen(extra) + 6 + 1); + if (!t) + return -ENOMEM; + + strcpy(stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn), "XXXXXX"); + + *ret = path_kill_slashes(t); + return 0; +} + +int tempfn_random(const char *p, const char *extra, char **ret) { + const char *fn; + char *t, *x; + uint64_t u; + unsigned i; + + assert(p); + assert(ret); + + /* + * Turns this: + * /foo/bar/waldo + * + * Into this: + * /foo/bar/.#waldobaa2a261115984a9 + */ + + fn = basename(p); + if (!filename_is_valid(fn)) + return -EINVAL; + + if (!extra) + extra = ""; + + t = new(char, strlen(p) + 2 + strlen(extra) + 16 + 1); + if (!t) + return -ENOMEM; + + x = stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn); + + u = random_u64(); + for (i = 0; i < 16; i++) { + *(x++) = hexchar(u & 0xF); + u >>= 4; + } + + *x = 0; + + *ret = path_kill_slashes(t); + return 0; +} + +int tempfn_random_child(const char *p, const char *extra, char **ret) { + char *t, *x; + uint64_t u; + unsigned i; + + assert(p); + assert(ret); + + /* Turns this: + * /foo/bar/waldo + * Into this: + * /foo/bar/waldo/.#3c2b6219aa75d7d0 + */ + + if (!extra) + extra = ""; + + t = new(char, strlen(p) + 3 + strlen(extra) + 16 + 1); + if (!t) + return -ENOMEM; + + x = stpcpy(stpcpy(stpcpy(t, p), "/.#"), extra); + + u = random_u64(); + for (i = 0; i < 16; i++) { + *(x++) = hexchar(u & 0xF); + u >>= 4; + } + + *x = 0; + + *ret = path_kill_slashes(t); + return 0; +} diff --git a/src/basic/fileio.h b/src/basic/fileio.h index 4998d4d042..fa7f192331 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -20,8 +20,12 @@ 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 "macro.h" @@ -49,3 +53,27 @@ int write_env_file(const char *fname, char **l); int executable_is_script(const char *path, char **interpreter); int get_proc_field(const char *filename, const char *pattern, const char *terminator, char **field); + +DIR *xopendirat(int dirfd, const char *name, int flags); + +int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f); +int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f); + +#define FOREACH_LINE(line, f, on_error) \ + for (;;) \ + if (!fgets(line, sizeof(line), f)) { \ + if (ferror(f)) { \ + on_error; \ + } \ + break; \ + } else + +int fflush_and_check(FILE *f); + +int fopen_temporary(const char *path, FILE **_f, char **_temp_path); +int mkostemp_safe(char *pattern, int flags); +int open_tmpfile(const char *path, int flags); + +int tempfn_xxxxxx(const char *p, const char *extra, char **ret); +int tempfn_random(const char *p, const char *extra, char **ret); +int tempfn_random_child(const char *p, const char *extra, char **ret); diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c index 7d058416e5..ea0528c6fc 100644 --- a/src/basic/hostname-util.c +++ b/src/basic/hostname-util.c @@ -23,6 +23,7 @@ #include #include "fd-util.h" +#include "fileio.h" #include "hostname-util.h" #include "string-util.h" #include "util.h" diff --git a/src/basic/time-util.c b/src/basic/time-util.c index b348ed4204..b7d92cbad8 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -24,6 +24,7 @@ #include #include "fd-util.h" +#include "fileio.h" #include "path-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/basic/util.c b/src/basic/util.c index f403dca10e..25ba59505d 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -636,25 +636,6 @@ int null_or_empty_fd(int fd) { return null_or_empty(&st); } -DIR *xopendirat(int fd, const char *name, int flags) { - int nfd; - DIR *d; - - assert(!(flags & O_CREAT)); - - nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags, 0); - if (nfd < 0) - return NULL; - - d = fdopendir(nfd); - if (!d) { - safe_close(nfd); - return NULL; - } - - return d; -} - static char *tag_to_udev_node(const char *tagvalue, const char *by) { _cleanup_free_ char *t = NULL, *u = NULL; size_t enc_len; @@ -864,39 +845,6 @@ bool plymouth_running(void) { return access("/run/plymouth/pid", F_OK) >= 0; } -int fopen_temporary(const char *path, FILE **_f, char **_temp_path) { - FILE *f; - char *t; - int r, fd; - - assert(path); - assert(_f); - assert(_temp_path); - - r = tempfn_xxxxxx(path, NULL, &t); - if (r < 0) - return r; - - fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC); - if (fd < 0) { - free(t); - return -errno; - } - - f = fdopen(fd, "we"); - if (!f) { - unlink_noerrno(t); - free(t); - safe_close(fd); - return -errno; - } - - *_f = f; - *_temp_path = t; - - return 0; -} - int symlink_atomic(const char *from, const char *to) { _cleanup_free_ char *t = NULL; int r; @@ -1782,88 +1730,6 @@ int on_ac_power(void) { return found_online || !found_offline; } -static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) { - char **i; - - assert(path); - assert(mode); - assert(_f); - - if (!path_strv_resolve_uniq(search, root)) - return -ENOMEM; - - STRV_FOREACH(i, search) { - _cleanup_free_ char *p = NULL; - FILE *f; - - if (root) - p = strjoin(root, *i, "/", path, NULL); - else - p = strjoin(*i, "/", path, NULL); - if (!p) - return -ENOMEM; - - f = fopen(p, mode); - if (f) { - *_f = f; - return 0; - } - - if (errno != ENOENT) - return -errno; - } - - return -ENOENT; -} - -int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) { - _cleanup_strv_free_ char **copy = NULL; - - assert(path); - assert(mode); - assert(_f); - - if (path_is_absolute(path)) { - FILE *f; - - f = fopen(path, mode); - if (f) { - *_f = f; - return 0; - } - - return -errno; - } - - copy = strv_copy((char**) search); - if (!copy) - return -ENOMEM; - - return search_and_fopen_internal(path, mode, root, copy, _f); -} - -int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) { - _cleanup_strv_free_ char **s = NULL; - - if (path_is_absolute(path)) { - FILE *f; - - f = fopen(path, mode); - if (f) { - *_f = f; - return 0; - } - - return -errno; - } - - s = strv_split_nulstr(search); - if (!s) - return -ENOMEM; - - return search_and_fopen_internal(path, mode, root, s, _f); -} - void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) { size_t a, newalloc; void *q; @@ -2213,46 +2079,6 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int return reset_uid_gid(); } -/* This is much like like mkostemp() but is subject to umask(). */ -int mkostemp_safe(char *pattern, int flags) { - _cleanup_umask_ mode_t u; - int fd; - - assert(pattern); - - u = umask(077); - - fd = mkostemp(pattern, flags); - if (fd < 0) - return -errno; - - return fd; -} - -int open_tmpfile(const char *path, int flags) { - char *p; - int fd; - - assert(path); - -#ifdef O_TMPFILE - /* Try O_TMPFILE first, if it is supported */ - fd = open(path, flags|O_TMPFILE|O_EXCL, S_IRUSR|S_IWUSR); - if (fd >= 0) - return fd; -#endif - - /* Fall back to unguessable name + unlinking */ - p = strjoina(path, "/systemd-tmp-XXXXXX"); - - fd = mkostemp_safe(p, flags); - if (fd < 0) - return fd; - - unlink(p); - return fd; -} - int fd_warn_permissions(const char *path, int fd) { struct stat st; @@ -2599,127 +2425,6 @@ int bind_remount_recursive(const char *prefix, bool ro) { } } -int fflush_and_check(FILE *f) { - assert(f); - - errno = 0; - fflush(f); - - if (ferror(f)) - return errno ? -errno : -EIO; - - return 0; -} - -int tempfn_xxxxxx(const char *p, const char *extra, char **ret) { - const char *fn; - char *t; - - assert(p); - assert(ret); - - /* - * Turns this: - * /foo/bar/waldo - * - * Into this: - * /foo/bar/.#waldoXXXXXX - */ - - fn = basename(p); - if (!filename_is_valid(fn)) - return -EINVAL; - - if (extra == NULL) - extra = ""; - - t = new(char, strlen(p) + 2 + strlen(extra) + 6 + 1); - if (!t) - return -ENOMEM; - - strcpy(stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn), "XXXXXX"); - - *ret = path_kill_slashes(t); - return 0; -} - -int tempfn_random(const char *p, const char *extra, char **ret) { - const char *fn; - char *t, *x; - uint64_t u; - unsigned i; - - assert(p); - assert(ret); - - /* - * Turns this: - * /foo/bar/waldo - * - * Into this: - * /foo/bar/.#waldobaa2a261115984a9 - */ - - fn = basename(p); - if (!filename_is_valid(fn)) - return -EINVAL; - - if (!extra) - extra = ""; - - t = new(char, strlen(p) + 2 + strlen(extra) + 16 + 1); - if (!t) - return -ENOMEM; - - x = stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn); - - u = random_u64(); - for (i = 0; i < 16; i++) { - *(x++) = hexchar(u & 0xF); - u >>= 4; - } - - *x = 0; - - *ret = path_kill_slashes(t); - return 0; -} - -int tempfn_random_child(const char *p, const char *extra, char **ret) { - char *t, *x; - uint64_t u; - unsigned i; - - assert(p); - assert(ret); - - /* Turns this: - * /foo/bar/waldo - * Into this: - * /foo/bar/waldo/.#3c2b6219aa75d7d0 - */ - - if (!extra) - extra = ""; - - t = new(char, strlen(p) + 3 + strlen(extra) + 16 + 1); - if (!t) - return -ENOMEM; - - x = stpcpy(stpcpy(stpcpy(t, p), "/.#"), extra); - - u = random_u64(); - for (i = 0; i < 16; i++) { - *(x++) = hexchar(u & 0xF); - u >>= 4; - } - - *x = 0; - - *ret = path_kill_slashes(t); - return 0; -} - int take_password_lock(const char *root) { struct flock flock = { diff --git a/src/basic/util.h b/src/basic/util.h index ec95c53130..9393140c72 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -158,8 +158,6 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k bool fstype_is_network(const char *fstype); -int fopen_temporary(const char *path, FILE **_f, char **_temp_path); - bool is_device_path(const char *path); int dir_is_empty(const char *path); @@ -201,8 +199,6 @@ bool null_or_empty(struct stat *st) _pure_; int null_or_empty_path(const char *fn); int null_or_empty_fd(int fd); -DIR *xopendirat(int dirfd, const char *name, int flags); - char *fstab_node_to_udev_node(const char *p); void execute_directories(const char* const* directories, usec_t timeout, char *argv[]); @@ -349,18 +345,6 @@ const char *draw_special_char(DrawSpecialChar ch); int on_ac_power(void); -int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f); -int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f); - -#define FOREACH_LINE(line, f, on_error) \ - for (;;) \ - if (!fgets(line, sizeof(line), f)) { \ - if (ferror(f)) { \ - on_error; \ - } \ - break; \ - } else - #define FOREACH_DIRENT(de, d, on_error) \ for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ if (!de) { \ @@ -521,9 +505,6 @@ int container_get_leader(const char *machine, pid_t *pid); int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd); int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd); -int mkostemp_safe(char *pattern, int flags); -int open_tmpfile(const char *path, int flags); - int fd_warn_permissions(const char *path, int fd); #ifndef PERSONALITY_INVALID @@ -550,12 +531,6 @@ int umount_recursive(const char *target, int flags); int bind_remount_recursive(const char *prefix, bool ro); -int fflush_and_check(FILE *f); - -int tempfn_xxxxxx(const char *p, const char *extra, char **ret); -int tempfn_random(const char *p, const char *extra, char **ret); -int tempfn_random_child(const char *p, const char *extra, char **ret); - int take_password_lock(const char *root); int is_symlink(const char *path); diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index a167f8086c..7e06abd3bf 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -40,6 +40,7 @@ #include "blkid-util.h" #include "efivars.h" #include "fd-util.h" +#include "fileio.h" #include "rm-rf.h" #include "string-util.h" #include "util.h" diff --git a/src/core/cgroup.c b/src/core/cgroup.c index a33eaa8d42..6ef0580fad 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -25,6 +25,7 @@ #include "cgroup-util.h" #include "cgroup.h" #include "fd-util.h" +#include "fileio.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 6a43be873a..f424909b46 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -24,6 +24,7 @@ #include "cgroup.h" #include "dbus-cgroup.h" #include "fd-util.h" +#include "fileio.h" #include "path-util.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 1ef259ec7a..77a64dfd57 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -35,6 +35,7 @@ #include "dbus.h" #include "env-util.h" #include "fd-util.h" +#include "fileio.h" #include "formats-util.h" #include "install.h" #include "log.h" diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 22b8690c54..91cdeb1f30 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -26,6 +26,7 @@ #include "dbus-kill.h" #include "dbus-service.h" #include "fd-util.h" +#include "fileio.h" #include "path-util.h" #include "service.h" #include "string-util.h" diff --git a/src/core/ima-setup.c b/src/core/ima-setup.c index 0c0982b0b4..9572fa17d9 100644 --- a/src/core/ima-setup.c +++ b/src/core/ima-setup.c @@ -25,6 +25,7 @@ #include #include "fd-util.h" +#include "fileio.h" #include "ima-setup.h" #include "log.h" #include "util.h" diff --git a/src/core/manager.c b/src/core/manager.c index 9ad8a136ab..589501519a 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -54,6 +54,7 @@ #include "escape.h" #include "exit-status.h" #include "fd-util.h" +#include "fileio.h" #include "hashmap.h" #include "io-util.h" #include "locale-setup.h" diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 51a2c6dfd7..768d59c8df 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -23,6 +23,7 @@ #include "dropin.h" #include "fd-util.h" +#include "fileio.h" #include "fstab-util.h" #include "generator.h" #include "hashmap.h" diff --git a/src/dbus1-generator/dbus1-generator.c b/src/dbus1-generator/dbus1-generator.c index 8dd75f3324..b9683a7ee1 100644 --- a/src/dbus1-generator/dbus1-generator.c +++ b/src/dbus1-generator/dbus1-generator.c @@ -24,6 +24,7 @@ #include "cgroup-util.h" #include "conf-parser.h" #include "fd-util.h" +#include "fileio.h" #include "mkdir.h" #include "special.h" #include "unit-name.h" diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 18baf6cc7d..732b3d1704 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -26,6 +26,7 @@ #include #include "fd-util.h" +#include "fileio.h" #include "fstab-util.h" #include "generator.h" #include "log.h" diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c index 3b800e99d3..b4118828a9 100644 --- a/src/hwdb/hwdb.c +++ b/src/hwdb/hwdb.c @@ -23,6 +23,8 @@ #include #include "conf-files.h" +#include "fd-util.h" +#include "fileio.h" #include "hwdb-internal.h" #include "hwdb-util.h" #include "mkdir.h" @@ -31,7 +33,6 @@ #include "strv.h" #include "util.h" #include "verbs.h" -#include "fd-util.h" /* * Generic udev properties, key/value database based on modalias strings. diff --git a/src/import/export-raw.c b/src/import/export-raw.c index 24c0ec9309..85e781a308 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -29,6 +29,7 @@ #include "copy.h" #include "export-raw.h" #include "fd-util.h" +#include "fileio.h" #include "import-common.h" #include "ratelimit.h" #include "string-util.h" diff --git a/src/import/export-tar.c b/src/import/export-tar.c index aa9b7f1a91..38e659a517 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -24,6 +24,7 @@ #include "btrfs-util.h" #include "export-tar.h" #include "fd-util.h" +#include "fileio.h" #include "import-common.h" #include "process-util.h" #include "ratelimit.h" diff --git a/src/import/import-raw.c b/src/import/import-raw.c index a34f30abfc..d94d8ab4ae 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -27,6 +27,7 @@ #include "btrfs-util.h" #include "copy.h" #include "fd-util.h" +#include "fileio.h" #include "hostname-util.h" #include "import-common.h" #include "import-compress.h" diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 9aade0f430..d88eae1973 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -27,6 +27,7 @@ #include "btrfs-util.h" #include "copy.h" #include "fd-util.h" +#include "fileio.h" #include "hostname-util.h" #include "import-common.h" #include "import-compress.h" diff --git a/src/import/pull-dkr.c b/src/import/pull-dkr.c index 448dbafa9f..700462bfd2 100644 --- a/src/import/pull-dkr.c +++ b/src/import/pull-dkr.c @@ -28,6 +28,7 @@ #include "btrfs-util.h" #include "curl-util.h" #include "fd-util.h" +#include "fileio.h" #include "hostname-util.h" #include "import-common.h" #include "import-util.h" diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index 848a4fcd44..4d0ac770aa 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -29,6 +29,7 @@ #include "copy.h" #include "curl-util.h" #include "fd-util.h" +#include "fileio.h" #include "hostname-util.h" #include "import-common.h" #include "import-util.h" diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index 3540bbff41..3e21d72157 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -28,6 +28,7 @@ #include "copy.h" #include "curl-util.h" #include "fd-util.h" +#include "fileio.h" #include "hostname-util.h" #include "import-common.h" #include "import-util.h" diff --git a/src/journal/catalog.c b/src/journal/catalog.c index fe3975b7b8..72d2bedc26 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -32,6 +32,7 @@ #include "catalog.h" #include "conf-files.h" #include "fd-util.h" +#include "fileio.h" #include "hashmap.h" #include "log.h" #include "mkdir.h" diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index fecccd4eb9..07ca8dde0a 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -30,6 +30,7 @@ #include "compress.h" #include "fd-util.h" +#include "fileio.h" #include "journal-internal.h" #include "log.h" #include "macro.h" diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index f388c30d2e..dddd5703f4 100644 --- a/src/journal/journal-send.c +++ b/src/journal/journal-send.c @@ -32,6 +32,7 @@ #include "sd-journal.h" #include "fd-util.h" +#include "fileio.h" #include "io-util.h" #include "memfd-util.h" #include "socket-util.h" diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index de4f73a471..5d000aedbb 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -26,6 +26,7 @@ #include "compress.h" #include "fd-util.h" +#include "fileio.h" #include "journal-authenticate.h" #include "journal-def.h" #include "journal-file.h" diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c index 72c1f60f02..c942df46a8 100644 --- a/src/journal/test-catalog.c +++ b/src/journal/test-catalog.c @@ -29,6 +29,7 @@ #include "catalog.h" #include "fd-util.h" +#include "fileio.h" #include "log.h" #include "macro.h" #include "string-util.h" diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c index e562fa1948..db4fa15554 100644 --- a/src/journal/test-compress.c +++ b/src/journal/test-compress.c @@ -19,6 +19,7 @@ #include "compress.h" #include "fd-util.h" +#include "fileio.h" #include "macro.h" #include "random-util.h" #include "util.h" diff --git a/src/journal/test-mmap-cache.c b/src/journal/test-mmap-cache.c index ac1239acc4..fdd48e531c 100644 --- a/src/journal/test-mmap-cache.c +++ b/src/journal/test-mmap-cache.c @@ -19,12 +19,13 @@ along with systemd; If not, see . ***/ +#include #include #include #include -#include #include "fd-util.h" +#include "fileio.h" #include "macro.h" #include "mmap-cache.h" #include "util.h" diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c index b2b85e56e8..bc06f48386 100644 --- a/src/libsystemd-network/sd-lldp.c +++ b/src/libsystemd-network/sd-lldp.c @@ -25,6 +25,7 @@ #include "sd-lldp.h" #include "fd-util.h" +#include "fileio.h" #include "hashmap.h" #include "lldp-internal.h" #include "lldp-port.h" diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c index cd7fcc7c80..9ddd059072 100644 --- a/src/libsystemd/sd-bus/bus-dump.c +++ b/src/libsystemd/sd-bus/bus-dump.c @@ -19,18 +19,19 @@ along with systemd; If not, see . ***/ +#include "bus-dump.h" #include "bus-internal.h" #include "bus-message.h" #include "bus-type.h" #include "cap-list.h" #include "capability.h" +#include "fileio.h" #include "formats-util.h" #include "macro.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" #include "util.h" -#include "bus-dump.h" static char *indent(unsigned level, unsigned flags) { char *p; diff --git a/src/libsystemd/sd-bus/bus-introspect.c b/src/libsystemd/sd-bus/bus-introspect.c index f5a8885332..a90536bac9 100644 --- a/src/libsystemd/sd-bus/bus-introspect.c +++ b/src/libsystemd/sd-bus/bus-introspect.c @@ -24,6 +24,7 @@ #include "bus-protocol.h" #include "bus-signature.h" #include "fd-util.h" +#include "fileio.h" #include "string-util.h" #include "util.h" diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index fca3ebd394..6a37f22c1f 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -24,6 +24,7 @@ #include "bus-message.h" #include "bus-util.h" #include "fd-util.h" +#include "fileio.h" #include "hexdecoct.h" #include "string-util.h" #include "strv.h" diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index 8e3eeb15d8..c1d42e96e5 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -21,6 +21,7 @@ #include "architecture.h" #include "fd-util.h" +#include "fileio.h" #include "missing.h" #include "path-util.h" #include "string-util.h" diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index 5590aec2b7..0059c09e77 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -31,6 +31,7 @@ #include "libudev.h" #include "fd-util.h" +#include "fileio.h" #include "formats-util.h" #include "libudev-private.h" #include "missing.h" diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 2566894d05..2dcf8ddc62 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -27,6 +27,7 @@ #include "sd-messages.h" #include "fd-util.h" +#include "fileio.h" #include "formats-util.h" #include "logind-acl.h" #include "logind-seat.h" diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c index 34bd65cb11..5627e63938 100644 --- a/src/modules-load/modules-load.c +++ b/src/modules-load/modules-load.c @@ -28,6 +28,7 @@ #include "conf-files.h" #include "fd-util.h" +#include "fileio.h" #include "log.h" #include "string-util.h" #include "strv.h" diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index febfe2ff81..af243c9a70 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -29,6 +29,7 @@ #include "conf-parser.h" #include "def.h" #include "fd-util.h" +#include "fileio.h" #include "libudev-private.h" #include "local-addresses.h" #include "netlink-util.h" diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 15203d21ea..9e8025d615 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -34,6 +34,7 @@ #include "ask-password-api.h" #include "fd-util.h" +#include "fileio.h" #include "formats-util.h" #include "io-util.h" #include "missing.h" diff --git a/src/shared/clean-ipc.c b/src/shared/clean-ipc.c index fe3187384f..2be1bc3fc0 100644 --- a/src/shared/clean-ipc.c +++ b/src/shared/clean-ipc.c @@ -30,6 +30,7 @@ #include "clean-ipc.h" #include "fd-util.h" +#include "fileio.h" #include "formats-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c index c576242b59..6d726a687a 100644 --- a/src/shared/machine-pool.c +++ b/src/shared/machine-pool.c @@ -26,6 +26,7 @@ #include "btrfs-util.h" #include "fd-util.h" +#include "fileio.h" #include "lockfile-util.h" #include "machine-pool.h" #include "mkdir.h" diff --git a/src/test/test-async.c b/src/test/test-async.c index abd36d693c..ada6d67c42 100644 --- a/src/test/test-async.c +++ b/src/test/test-async.c @@ -20,8 +20,9 @@ #include #include "async.h" -#include "util.h" +#include "fileio.h" #include "macro.h" +#include "util.h" static bool test_async = false; diff --git a/src/test/test-fdset.c b/src/test/test-fdset.c index 96d5e38177..282aab1246 100644 --- a/src/test/test-fdset.c +++ b/src/test/test-fdset.c @@ -22,6 +22,7 @@ #include "fd-util.h" #include "fdset.h" +#include "fileio.h" #include "macro.h" #include "util.h" diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c index a41de59719..e940b5a204 100644 --- a/src/test/test-terminal-util.c +++ b/src/test/test-terminal-util.c @@ -21,11 +21,12 @@ #include #include -#include "terminal-util.h" +#include "fd-util.h" +#include "fileio.h" +#include "log.h" #include "macro.h" +#include "terminal-util.h" #include "util.h" -#include "log.h" -#include "fd-util.h" static void test_default_term_for_tty(void) { puts(default_term_for_tty("/dev/tty23")); diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c index 6aa9cc8473..683fbe217c 100644 --- a/src/test/test-tmpfiles.c +++ b/src/test/test-tmpfiles.c @@ -25,6 +25,7 @@ #include #include "fd-util.h" +#include "fileio.h" #include "formats-util.h" #include "string-util.h" #include "util.h" diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 57cca17e80..85a2d6c2f5 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -45,6 +45,7 @@ #include "copy.h" #include "escape.h" #include "fd-util.h" +#include "fileio.h" #include "formats-util.h" #include "io-util.h" #include "label.h" diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index f9509ad640..69aff7b579 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -23,6 +23,7 @@ #include #include "conf-files.h" +#include "fileio.h" #include "hwdb-internal.h" #include "hwdb-util.h" #include "strbuf.h" -- cgit v1.2.3-54-g00ecf From 78f22b973fa2c9b09bd974680836df17163d9ee0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 19:40:43 +0100 Subject: util-lib: split out resource limits related calls into rlimit-util.[ch] --- Makefile.am | 2 ++ src/basic/rlimit-util.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ src/basic/rlimit-util.h | 33 +++++++++++++++++++++++ src/basic/util.c | 46 ------------------------------- src/basic/util.h | 7 ----- src/core/dbus-execute.c | 1 + src/core/execute.c | 1 + src/core/main.c | 1 + src/journal/journalctl.c | 1 + src/shared/bus-util.c | 1 + src/systemctl/systemctl.c | 1 + src/test/test-tables.c | 13 ++++----- 12 files changed, 117 insertions(+), 59 deletions(-) create mode 100644 src/basic/rlimit-util.c create mode 100644 src/basic/rlimit-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index 275b856191..efd1329ade 100644 --- a/Makefile.am +++ b/Makefile.am @@ -791,6 +791,8 @@ libbasic_la_SOURCES = \ src/basic/parse-util.h \ src/basic/user-util.c \ src/basic/user-util.h \ + src/basic/rlimit-util.c \ + src/basic/rlimit-util.h \ src/basic/mount-util.c \ src/basic/mount-util.h \ src/basic/hexdecoct.c \ diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c new file mode 100644 index 0000000000..7f9d63224d --- /dev/null +++ b/src/basic/rlimit-util.c @@ -0,0 +1,69 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "missing.h" +#include "rlimit-util.h" +#include "util.h" + +int setrlimit_closest(int resource, const struct rlimit *rlim) { + struct rlimit highest, fixed; + + assert(rlim); + + if (setrlimit(resource, rlim) >= 0) + return 0; + + if (errno != EPERM) + return -errno; + + /* So we failed to set the desired setrlimit, then let's try + * to get as close as we can */ + assert_se(getrlimit(resource, &highest) == 0); + + fixed.rlim_cur = MIN(rlim->rlim_cur, highest.rlim_max); + fixed.rlim_max = MIN(rlim->rlim_max, highest.rlim_max); + + if (setrlimit(resource, &fixed) < 0) + return -errno; + + return 0; +} + +static const char* const rlimit_table[_RLIMIT_MAX] = { + [RLIMIT_CPU] = "LimitCPU", + [RLIMIT_FSIZE] = "LimitFSIZE", + [RLIMIT_DATA] = "LimitDATA", + [RLIMIT_STACK] = "LimitSTACK", + [RLIMIT_CORE] = "LimitCORE", + [RLIMIT_RSS] = "LimitRSS", + [RLIMIT_NOFILE] = "LimitNOFILE", + [RLIMIT_AS] = "LimitAS", + [RLIMIT_NPROC] = "LimitNPROC", + [RLIMIT_MEMLOCK] = "LimitMEMLOCK", + [RLIMIT_LOCKS] = "LimitLOCKS", + [RLIMIT_SIGPENDING] = "LimitSIGPENDING", + [RLIMIT_MSGQUEUE] = "LimitMSGQUEUE", + [RLIMIT_NICE] = "LimitNICE", + [RLIMIT_RTPRIO] = "LimitRTPRIO", + [RLIMIT_RTTIME] = "LimitRTTIME" +}; + +DEFINE_STRING_TABLE_LOOKUP(rlimit, int); diff --git a/src/basic/rlimit-util.h b/src/basic/rlimit-util.h new file mode 100644 index 0000000000..262f86dd04 --- /dev/null +++ b/src/basic/rlimit-util.h @@ -0,0 +1,33 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "macro.h" + +const char *rlimit_to_string(int i) _const_; +int rlimit_from_string(const char *s) _pure_; + +int setrlimit_closest(int resource, const struct rlimit *rlim); + +#define RLIMIT_MAKE_CONST(lim) ((struct rlimit) { lim, lim }) diff --git a/src/basic/util.c b/src/basic/util.c index 2ee5de9cd0..121ca3376e 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -1173,27 +1172,6 @@ static const char* const sched_policy_table[] = { DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX); -static const char* const rlimit_table[_RLIMIT_MAX] = { - [RLIMIT_CPU] = "LimitCPU", - [RLIMIT_FSIZE] = "LimitFSIZE", - [RLIMIT_DATA] = "LimitDATA", - [RLIMIT_STACK] = "LimitSTACK", - [RLIMIT_CORE] = "LimitCORE", - [RLIMIT_RSS] = "LimitRSS", - [RLIMIT_NOFILE] = "LimitNOFILE", - [RLIMIT_AS] = "LimitAS", - [RLIMIT_NPROC] = "LimitNPROC", - [RLIMIT_MEMLOCK] = "LimitMEMLOCK", - [RLIMIT_LOCKS] = "LimitLOCKS", - [RLIMIT_SIGPENDING] = "LimitSIGPENDING", - [RLIMIT_MSGQUEUE] = "LimitMSGQUEUE", - [RLIMIT_NICE] = "LimitNICE", - [RLIMIT_RTPRIO] = "LimitRTPRIO", - [RLIMIT_RTTIME] = "LimitRTTIME" -}; - -DEFINE_STRING_TABLE_LOOKUP(rlimit, int); - bool kexec_loaded(void) { bool loaded = false; char *s; @@ -1339,30 +1317,6 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa _exit(EXIT_FAILURE); } -int setrlimit_closest(int resource, const struct rlimit *rlim) { - struct rlimit highest, fixed; - - assert(rlim); - - if (setrlimit(resource, rlim) >= 0) - return 0; - - if (errno != EPERM) - return -errno; - - /* So we failed to set the desired setrlimit, then let's try - * to get as close as we can */ - assert_se(getrlimit(resource, &highest) == 0); - - fixed.rlim_cur = MIN(rlim->rlim_cur, highest.rlim_max); - fixed.rlim_max = MIN(rlim->rlim_max, highest.rlim_max); - - if (setrlimit(resource, &fixed) < 0) - return -errno; - - return 0; -} - bool http_etag_is_valid(const char *etag) { if (isempty(etag)) return false; diff --git a/src/basic/util.h b/src/basic/util.h index 76d0784d36..6e5df01450 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -247,9 +247,6 @@ bool log_level_is_valid(int level); int sched_policy_to_string_alloc(int i, char **s); int sched_policy_from_string(const char *s); -const char *rlimit_to_string(int i) _const_; -int rlimit_from_string(const char *s) _pure_; - extern int saved_argc; extern char **saved_argv; @@ -261,8 +258,6 @@ void* memdup(const void *p, size_t l) _alloc_(2); int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...); -int setrlimit_closest(int resource, const struct rlimit *rlim); - bool http_url_is_valid(const char *url) _pure_; bool documentation_url_is_valid(const char *url) _pure_; @@ -550,8 +545,6 @@ int chattr_path(const char *p, unsigned value, unsigned mask); int read_attr_fd(int fd, unsigned *ret); int read_attr_path(const char *p, unsigned *ret); -#define RLIMIT_MAKE_CONST(lim) ((struct rlimit) { lim, lim }) - int syslog_parse_priority(const char **p, int *priority, bool with_facility); int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 238fc8efdd..950e463bc5 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -38,6 +38,7 @@ #include "namespace.h" #include "parse-util.h" #include "path-util.h" +#include "rlimit-util.h" #ifdef HAVE_SECCOMP #include "seccomp-util.h" #endif diff --git a/src/core/execute.c b/src/core/execute.c index 24a8e646ad..ad0e6be4b7 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -79,6 +79,7 @@ #include "parse-util.h" #include "path-util.h" #include "process-util.h" +#include "rlimit-util.h" #include "rm-rf.h" #ifdef HAVE_SECCOMP #include "seccomp-util.h" diff --git a/src/core/main.c b/src/core/main.c index a8834b6f0b..dfd17694c9 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -69,6 +69,7 @@ #include "pager.h" #include "parse-util.h" #include "process-util.h" +#include "rlimit-util.h" #include "selinux-setup.h" #include "selinux-util.h" #include "signal-util.h" diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index c13b674e15..5b3b6cd143 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -58,6 +58,7 @@ #include "pager.h" #include "parse-util.h" #include "path-util.h" +#include "rlimit-util.h" #include "set.h" #include "sigbus.h" #include "strv.h" diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 53b9752af0..724103fc3f 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -39,6 +39,7 @@ #include "missing.h" #include "parse-util.h" #include "path-util.h" +#include "rlimit-util.h" #include "set.h" #include "signal-util.h" #include "string-util.h" diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 054e9eaa13..77a05ca346 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -65,6 +65,7 @@ #include "path-lookup.h" #include "path-util.h" #include "process-util.h" +#include "rlimit-util.h" #include "set.h" #include "signal-util.h" #include "socket-util.h" diff --git a/src/test/test-tables.c b/src/test/test-tables.c index 0e5ab1645f..ed4abdbf12 100644 --- a/src/test/test-tables.c +++ b/src/test/test-tables.c @@ -17,7 +17,10 @@ along with systemd; If not, see . ***/ +#include "architecture.h" #include "automount.h" +#include "bus-xml-policy.h" +#include "busname.h" #include "cgroup.h" #include "compress.h" #include "condition.h" @@ -25,7 +28,10 @@ #include "execute.h" #include "install.h" #include "job.h" +#include "journald-server.h" #include "kill.h" +#include "link-config.h" +#include "locale-util.h" #include "log.h" #include "logs-show.h" #include "mount.h" @@ -42,12 +48,7 @@ #include "unit-name.h" #include "unit.h" #include "util.h" -#include "architecture.h" -#include "link-config.h" -#include "bus-xml-policy.h" -#include "busname.h" -#include "journald-server.h" -#include "locale-util.h" +#include "rlimit-util.h" #include "test-tables.h" -- cgit v1.2.3-54-g00ecf From a09561746f15b84da9471b5c4be74e53d19e4f3f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 20:07:55 +0100 Subject: util-lib: introduce dirent-util.[ch] for directory entry calls Also, move a couple of more path-related functions to path-util.c. --- Makefile.am | 2 + src/basic/cgroup-util.c | 1 + src/basic/conf-files.c | 1 + src/basic/copy.c | 1 + src/basic/dirent-util.c | 81 ++++++++++++++ src/basic/dirent-util.h | 51 +++++++++ src/basic/fd-util.c | 1 + src/basic/fdset.c | 1 + src/basic/locale-util.c | 1 + src/basic/path-util.c | 67 ++++++++++++ src/basic/path-util.h | 7 ++ src/basic/util.c | 121 +-------------------- src/basic/util.h | 32 ------ src/bootchart/store.c | 1 + src/core/smack-setup.c | 1 + src/dbus1-generator/dbus1-generator.c | 1 + src/delta/delta.c | 1 + src/gpt-auto-generator/gpt-auto-generator.c | 1 + src/import/pull-common.c | 1 + src/journal/coredump-vacuum.c | 1 + src/journal/coredump.c | 1 + src/journal/journal-vacuum.c | 1 + src/journal/journald-server.c | 1 + src/journal/journald-stream.c | 1 + src/journal/sd-journal.c | 1 + src/libsystemd/sd-device/device-enumerator.c | 1 + src/libsystemd/sd-login/sd-login.c | 1 + src/login/logind-acl.c | 1 + src/login/logind-dbus.c | 1 + src/login/logind.c | 1 + src/machine/machined.c | 1 + src/shared/clean-ipc.c | 1 + src/shared/efivars.c | 1 + src/shared/install.c | 5 +- src/shared/machine-image.c | 1 + src/test/test-cgroup-util.c | 1 + .../tty-ask-password-agent.c | 1 + 37 files changed, 241 insertions(+), 154 deletions(-) create mode 100644 src/basic/dirent-util.c create mode 100644 src/basic/dirent-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index efd1329ade..563e2cc4ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -793,6 +793,8 @@ libbasic_la_SOURCES = \ src/basic/user-util.h \ src/basic/rlimit-util.c \ src/basic/rlimit-util.h \ + src/basic/dirent-util.c \ + src/basic/dirent-util.h \ src/basic/mount-util.c \ src/basic/mount-util.h \ src/basic/hexdecoct.c \ diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 232d6e8fe2..67dc291192 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -30,6 +30,7 @@ #include #include "cgroup-util.h" +#include "dirent-util.h" #include "extract-word.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 3af3fe392c..be9972ffff 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -26,6 +26,7 @@ #include #include "conf-files.h" +#include "dirent-util.h" #include "fd-util.h" #include "hashmap.h" #include "log.h" diff --git a/src/basic/copy.c b/src/basic/copy.c index 4b410a74e5..2d2d7ade34 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -24,6 +24,7 @@ #include "btrfs-util.h" #include "copy.h" +#include "dirent-util.h" #include "fd-util.h" #include "fileio.h" #include "io-util.h" diff --git a/src/basic/dirent-util.c b/src/basic/dirent-util.c new file mode 100644 index 0000000000..c433d5844a --- /dev/null +++ b/src/basic/dirent-util.c @@ -0,0 +1,81 @@ +/*-*- 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 "dirent-util.h" +#include "string-util.h" + +int dirent_ensure_type(DIR *d, struct dirent *de) { + struct stat st; + + assert(d); + assert(de); + + if (de->d_type != DT_UNKNOWN) + return 0; + + if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) + return -errno; + + de->d_type = + S_ISREG(st.st_mode) ? DT_REG : + S_ISDIR(st.st_mode) ? DT_DIR : + S_ISLNK(st.st_mode) ? DT_LNK : + S_ISFIFO(st.st_mode) ? DT_FIFO : + S_ISSOCK(st.st_mode) ? DT_SOCK : + S_ISCHR(st.st_mode) ? DT_CHR : + S_ISBLK(st.st_mode) ? DT_BLK : + DT_UNKNOWN; + + return 0; +} + +bool dirent_is_file(const struct dirent *de) { + assert(de); + + if (hidden_file(de->d_name)) + return false; + + if (de->d_type != DT_REG && + de->d_type != DT_LNK && + de->d_type != DT_UNKNOWN) + return false; + + return true; +} + +bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) { + assert(de); + + if (de->d_type != DT_REG && + de->d_type != DT_LNK && + de->d_type != DT_UNKNOWN) + return false; + + if (hidden_file_allow_backup(de->d_name)) + return false; + + return endswith(de->d_name, suffix); +} diff --git a/src/basic/dirent-util.h b/src/basic/dirent-util.h new file mode 100644 index 0000000000..5866a755f4 --- /dev/null +++ b/src/basic/dirent-util.h @@ -0,0 +1,51 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "path-util.h" + +int dirent_ensure_type(DIR *d, struct dirent *de); + +bool dirent_is_file(const struct dirent *de) _pure_; +bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_; + +#define FOREACH_DIRENT(de, d, on_error) \ + for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ + if (!de) { \ + if (errno > 0) { \ + on_error; \ + } \ + break; \ + } else if (hidden_file((de)->d_name)) \ + continue; \ + else + +#define FOREACH_DIRENT_ALL(de, d, on_error) \ + for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ + if (!de) { \ + if (errno > 0) { \ + on_error; \ + } \ + break; \ + } else diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 76d7e32bfa..f40365ce97 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -22,6 +22,7 @@ #include "fd-util.h" #include "parse-util.h" #include "util.h" +#include "dirent-util.h" int close_nointr(int fd) { assert(fd >= 0); diff --git a/src/basic/fdset.c b/src/basic/fdset.c index ef60f66431..4b11e4ea09 100644 --- a/src/basic/fdset.c +++ b/src/basic/fdset.c @@ -25,6 +25,7 @@ #include "sd-daemon.h" +#include "dirent-util.h" #include "fd-util.h" #include "fdset.h" #include "macro.h" diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index ccbc147931..08da4b98c5 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -21,6 +21,7 @@ #include +#include "dirent-util.h" #include "fd-util.h" #include "locale-util.h" #include "path-util.h" diff --git a/src/basic/path-util.c b/src/basic/path-util.c index d581f85707..ed30c3d92d 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -766,3 +766,70 @@ bool path_is_safe(const char *p) { return true; } + +char *file_in_same_dir(const char *path, const char *filename) { + char *e, *ret; + size_t k; + + assert(path); + assert(filename); + + /* This removes the last component of path and appends + * filename, unless the latter is absolute anyway or the + * former isn't */ + + if (path_is_absolute(filename)) + return strdup(filename); + + e = strrchr(path, '/'); + if (!e) + return strdup(filename); + + k = strlen(filename); + ret = new(char, (e + 1 - path) + k + 1); + if (!ret) + return NULL; + + memcpy(mempcpy(ret, path, e + 1 - path), filename, k + 1); + return ret; +} + +bool hidden_file_allow_backup(const char *filename) { + assert(filename); + + return + filename[0] == '.' || + streq(filename, "lost+found") || + streq(filename, "aquota.user") || + streq(filename, "aquota.group") || + endswith(filename, ".rpmnew") || + endswith(filename, ".rpmsave") || + endswith(filename, ".rpmorig") || + endswith(filename, ".dpkg-old") || + endswith(filename, ".dpkg-new") || + endswith(filename, ".dpkg-tmp") || + endswith(filename, ".dpkg-dist") || + endswith(filename, ".dpkg-bak") || + endswith(filename, ".dpkg-backup") || + endswith(filename, ".dpkg-remove") || + endswith(filename, ".swp"); +} + +bool hidden_file(const char *filename) { + assert(filename); + + if (endswith(filename, "~")) + return true; + + return hidden_file_allow_backup(filename); +} + +bool is_device_path(const char *path) { + + /* Returns true on paths that refer to a device, either in + * sysfs or in /dev */ + + return + path_startswith(path, "/dev/") || + path_startswith(path, "/sys/"); +} diff --git a/src/basic/path-util.h b/src/basic/path-util.h index b2acca05fe..193bf72468 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -105,3 +105,10 @@ char* dirname_malloc(const char *path); bool filename_is_valid(const char *p) _pure_; bool path_is_safe(const char *p) _pure_; + +char *file_in_same_dir(const char *path, const char *filename); + +bool hidden_file_allow_backup(const char *filename); +bool hidden_file(const char *filename) _pure_; + +bool is_device_path(const char *path); diff --git a/src/basic/util.c b/src/basic/util.c index 121ca3376e..e214c6f3dc 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -102,6 +102,7 @@ #include "utf8.h" #include "util.h" #include "virt.h" +#include "dirent-util.h" /* Put this test here for a lack of better place */ assert_cc(EAGAIN == EWOULDBLOCK); @@ -247,33 +248,6 @@ int readlink_and_canonicalize(const char *p, char **r) { return 0; } -char *file_in_same_dir(const char *path, const char *filename) { - char *e, *ret; - size_t k; - - assert(path); - assert(filename); - - /* This removes the last component of path and appends - * filename, unless the latter is absolute anyway or the - * former isn't */ - - if (path_is_absolute(filename)) - return strdup(filename); - - e = strrchr(path, '/'); - if (!e) - return strdup(filename); - - k = strlen(filename); - ret = new(char, (e + 1 - path) + k + 1); - if (!ret) - return NULL; - - memcpy(mempcpy(ret, path, e + 1 - path), filename, k + 1); - return ret; -} - int rmdir_parents(const char *path, const char *stop) { size_t l; int r = 0; @@ -320,36 +294,6 @@ int rmdir_parents(const char *path, const char *stop) { return 0; } -_pure_ static bool hidden_file_allow_backup(const char *filename) { - assert(filename); - - return - filename[0] == '.' || - streq(filename, "lost+found") || - streq(filename, "aquota.user") || - streq(filename, "aquota.group") || - endswith(filename, ".rpmnew") || - endswith(filename, ".rpmsave") || - endswith(filename, ".rpmorig") || - endswith(filename, ".dpkg-old") || - endswith(filename, ".dpkg-new") || - endswith(filename, ".dpkg-tmp") || - endswith(filename, ".dpkg-dist") || - endswith(filename, ".dpkg-bak") || - endswith(filename, ".dpkg-backup") || - endswith(filename, ".dpkg-remove") || - endswith(filename, ".swp"); -} - -bool hidden_file(const char *filename) { - assert(filename); - - if (endswith(filename, "~")) - return true; - - return hidden_file_allow_backup(filename); -} - bool fstype_is_network(const char *fstype) { static const char table[] = "afs\0" @@ -373,16 +317,6 @@ bool fstype_is_network(const char *fstype) { return nulstr_contains(table, fstype); } -bool is_device_path(const char *path) { - - /* Returns true on paths that refer to a device, either in - * sysfs or in /dev */ - - return - path_startswith(path, "/dev/") || - path_startswith(path, "/sys/"); -} - int dir_is_empty(const char *path) { _cleanup_closedir_ DIR *d; struct dirent *de; @@ -615,34 +549,6 @@ int null_or_empty_fd(int fd) { return null_or_empty(&st); } -bool dirent_is_file(const struct dirent *de) { - assert(de); - - if (hidden_file(de->d_name)) - return false; - - if (de->d_type != DT_REG && - de->d_type != DT_LNK && - de->d_type != DT_UNKNOWN) - return false; - - return true; -} - -bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) { - assert(de); - - if (de->d_type != DT_REG && - de->d_type != DT_LNK && - de->d_type != DT_UNKNOWN) - return false; - - if (hidden_file_allow_backup(de->d_name)) - return false; - - return endswith(de->d_name, suffix); -} - static int do_execute(char **directories, usec_t timeout, char *argv[]) { _cleanup_hashmap_free_free_ Hashmap *pids = NULL; _cleanup_set_free_free_ Set *seen = NULL; @@ -950,31 +856,6 @@ int glob_extend(char ***strv, const char *path) { return k; } -int dirent_ensure_type(DIR *d, struct dirent *de) { - struct stat st; - - assert(d); - assert(de); - - if (de->d_type != DT_UNKNOWN) - return 0; - - if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) - return -errno; - - de->d_type = - S_ISREG(st.st_mode) ? DT_REG : - S_ISDIR(st.st_mode) ? DT_DIR : - S_ISLNK(st.st_mode) ? DT_LNK : - S_ISFIFO(st.st_mode) ? DT_FIFO : - S_ISSOCK(st.st_mode) ? DT_SOCK : - S_ISCHR(st.st_mode) ? DT_CHR : - S_ISBLK(st.st_mode) ? DT_BLK : - DT_UNKNOWN; - - return 0; -} - int get_files_in_directory(const char *path, char ***list) { _cleanup_closedir_ DIR *d = NULL; size_t bufsize = 0, n = 0; diff --git a/src/basic/util.h b/src/basic/util.h index 6e5df01450..190d4f5edb 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -22,7 +22,6 @@ ***/ #include -#include #include #include #include @@ -90,15 +89,8 @@ int readlink_value(const char *p, char **ret); int readlink_and_make_absolute(const char *p, char **r); int readlink_and_canonicalize(const char *p, char **r); -char *file_in_same_dir(const char *path, const char *filename); - int rmdir_parents(const char *path, const char *stop); -bool dirent_is_file(const struct dirent *de) _pure_; -bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_; - -bool hidden_file(const char *filename) _pure_; - /* For basic lookup tables with strictly enumerated entries */ #define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ scope const char *name##_to_string(type i) { \ @@ -157,8 +149,6 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k bool fstype_is_network(const char *fstype); -bool is_device_path(const char *path); - int dir_is_empty(const char *path); static inline int dir_is_populated(const char *path) { @@ -216,8 +206,6 @@ int socket_from_display(const char *display, char **path); int glob_exists(const char *path); int glob_extend(char ***strv, const char *path); -int dirent_ensure_type(DIR *d, struct dirent *de); - int get_files_in_directory(const char *path, char ***list); bool is_main_thread(void); @@ -332,26 +320,6 @@ const char *draw_special_char(DrawSpecialChar ch); int on_ac_power(void); -#define FOREACH_DIRENT(de, d, on_error) \ - for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ - if (!de) { \ - if (errno > 0) { \ - on_error; \ - } \ - break; \ - } else if (hidden_file((de)->d_name)) \ - continue; \ - else - -#define FOREACH_DIRENT_ALL(de, d, on_error) \ - for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ - if (!de) { \ - if (errno > 0) { \ - on_error; \ - } \ - break; \ - } else - static inline void *mempset(void *s, int c, size_t n) { memset(s, c, n); return (uint8_t*)s + n; diff --git a/src/bootchart/store.c b/src/bootchart/store.c index 50b69637ef..e488c94b3b 100644 --- a/src/bootchart/store.c +++ b/src/bootchart/store.c @@ -33,6 +33,7 @@ #include "bootchart.h" #include "cgroup-util.h" +#include "dirent-util.h" #include "fd-util.h" #include "fileio.h" #include "parse-util.h" diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index 34df392184..b8cb9964a6 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -28,6 +28,7 @@ #include #include +#include "dirent-util.h" #include "fd-util.h" #include "fileio.h" #include "log.h" diff --git a/src/dbus1-generator/dbus1-generator.c b/src/dbus1-generator/dbus1-generator.c index b9683a7ee1..66a0fe9ea2 100644 --- a/src/dbus1-generator/dbus1-generator.c +++ b/src/dbus1-generator/dbus1-generator.c @@ -23,6 +23,7 @@ #include "bus-util.h" #include "cgroup-util.h" #include "conf-parser.h" +#include "dirent-util.h" #include "fd-util.h" #include "fileio.h" #include "mkdir.h" diff --git a/src/delta/delta.c b/src/delta/delta.c index bb2e6195b9..590ab86515 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -26,6 +26,7 @@ #include #include +#include "dirent-util.h" #include "fd-util.h" #include "hashmap.h" #include "log.h" diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 6440fd654e..f315d5ff6e 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -29,6 +29,7 @@ #include "blkid-util.h" #include "btrfs-util.h" +#include "dirent-util.h" #include "efivars.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/import/pull-common.c b/src/import/pull-common.c index 0e918d6416..17283a4a24 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -24,6 +24,7 @@ #include "btrfs-util.h" #include "capability.h" #include "copy.h" +#include "dirent-util.h" #include "escape.h" #include "fd-util.h" #include "io-util.h" diff --git a/src/journal/coredump-vacuum.c b/src/journal/coredump-vacuum.c index bad6ea4242..9635db19e1 100644 --- a/src/journal/coredump-vacuum.c +++ b/src/journal/coredump-vacuum.c @@ -22,6 +22,7 @@ #include #include "coredump-vacuum.h" +#include "dirent-util.h" #include "fd-util.h" #include "hashmap.h" #include "macro.h" diff --git a/src/journal/coredump.c b/src/journal/coredump.c index 92f598464a..ec57920d2e 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -40,6 +40,7 @@ #include "conf-parser.h" #include "copy.h" #include "coredump-vacuum.h" +#include "dirent-util.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c index 026dca4901..d3add065d2 100644 --- a/src/journal/journal-vacuum.c +++ b/src/journal/journal-vacuum.c @@ -25,6 +25,7 @@ #include "sd-id128.h" +#include "dirent-util.h" #include "fd-util.h" #include "journal-def.h" #include "journal-file.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index f286e3030f..6e6d9c1c4a 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -36,6 +36,7 @@ #include "acl-util.h" #include "cgroup-util.h" #include "conf-parser.h" +#include "dirent-util.h" #include "extract-word.h" #include "fd-util.h" #include "formats-util.h" diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 6745864da1..a9c940690f 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -29,6 +29,7 @@ #include "sd-daemon.h" #include "sd-event.h" +#include "dirent-util.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 9dcfc726ea..cfe1623e5b 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -32,6 +32,7 @@ #include "catalog.h" #include "compress.h" +#include "dirent-util.h" #include "fd-util.h" #include "fileio.h" #include "formats-util.h" diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index c98053220c..e1eb5b26b3 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -22,6 +22,7 @@ #include "device-enumerator-private.h" #include "device-util.h" +#include "dirent-util.h" #include "fd-util.h" #include "prioq.h" #include "set.h" diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 879838601c..90ee263079 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -43,6 +43,7 @@ #include "strv.h" #include "user-util.h" #include "util.h" +#include "dirent-util.h" /* Error codes: * diff --git a/src/login/logind-acl.c b/src/login/logind-acl.c index 4d7bda3ee0..acb2bd5765 100644 --- a/src/login/logind-acl.c +++ b/src/login/logind-acl.c @@ -23,6 +23,7 @@ #include #include "acl-util.h" +#include "dirent-util.h" #include "escape.h" #include "fd-util.h" #include "formats-util.h" diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 61c2c9ba40..2fcf4900d3 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -30,6 +30,7 @@ #include "bus-common-errors.h" #include "bus-error.h" #include "bus-util.h" +#include "dirent-util.h" #include "efivars.h" #include "escape.h" #include "fd-util.h" diff --git a/src/login/logind.c b/src/login/logind.c index 02c87ca58e..957ea1fd7e 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -30,6 +30,7 @@ #include "bus-error.h" #include "bus-util.h" #include "conf-parser.h" +#include "dirent-util.h" #include "fd-util.h" #include "formats-util.h" #include "logind.h" diff --git a/src/machine/machined.c b/src/machine/machined.c index fe229c88a8..1a61da041d 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -28,6 +28,7 @@ #include "bus-error.h" #include "bus-util.h" #include "cgroup-util.h" +#include "dirent-util.h" #include "fd-util.h" #include "formats-util.h" #include "hostname-util.h" diff --git a/src/shared/clean-ipc.c b/src/shared/clean-ipc.c index 2be1bc3fc0..c60f605997 100644 --- a/src/shared/clean-ipc.c +++ b/src/shared/clean-ipc.c @@ -35,6 +35,7 @@ #include "string-util.h" #include "strv.h" #include "util.h" +#include "dirent-util.h" static int clean_sysvipc_shm(uid_t delete_uid) { _cleanup_fclose_ FILE *f = NULL; diff --git a/src/shared/efivars.c b/src/shared/efivars.c index 771bc9458c..6e8f156a68 100644 --- a/src/shared/efivars.c +++ b/src/shared/efivars.c @@ -23,6 +23,7 @@ #include #include +#include "dirent-util.h" #include "efivars.h" #include "fd-util.h" #include "io-util.h" diff --git a/src/shared/install.c b/src/shared/install.c index a1720488e8..bfafb59008 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -27,8 +27,11 @@ #include "conf-files.h" #include "conf-parser.h" +#include "dirent-util.h" +#include "fd-util.h" #include "hashmap.h" #include "install-printf.h" +#include "install.h" #include "mkdir.h" #include "path-lookup.h" #include "path-util.h" @@ -38,8 +41,6 @@ #include "strv.h" #include "unit-name.h" #include "util.h" -#include "install.h" -#include "fd-util.h" typedef struct { OrderedHashmap *will_install; diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 415d939fc6..485793ed5d 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -25,6 +25,7 @@ #include "btrfs-util.h" #include "copy.h" +#include "dirent-util.h" #include "fd-util.h" #include "machine-image.h" #include "mkdir.h" diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index af8d478fa9..104f6327be 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -20,6 +20,7 @@ ***/ #include "cgroup-util.h" +#include "dirent-util.h" #include "fd-util.h" #include "formats-util.h" #include "parse-util.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 33419f6962..a6240ae89a 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -35,6 +35,7 @@ #include "ask-password-api.h" #include "conf-parser.h" #include "def.h" +#include "dirent-util.h" #include "fd-util.h" #include "io-util.h" #include "mkdir.h" -- cgit v1.2.3-54-g00ecf From 89a5a90cb0935cdad84a0b98d41789ad879d0d83 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 20:26:23 +0100 Subject: util-lib: split xattr-related calls into xattr-util.[ch] --- Makefile.am | 2 + src/basic/copy.c | 1 + src/basic/smack-util.c | 7 +- src/basic/util.c | 167 ------------------------------------- src/basic/util.h | 10 --- src/basic/xattr-util.c | 193 +++++++++++++++++++++++++++++++++++++++++++ src/basic/xattr-util.h | 38 +++++++++ src/import/pull-job.c | 3 +- src/journal/journal-file.c | 1 + src/journal/journal-vacuum.c | 1 + src/shared/machine-image.c | 1 + src/test/test-util.c | 3 +- 12 files changed, 245 insertions(+), 182 deletions(-) create mode 100644 src/basic/xattr-util.c create mode 100644 src/basic/xattr-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index 563e2cc4ea..33d66d4dd0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -795,6 +795,8 @@ libbasic_la_SOURCES = \ src/basic/rlimit-util.h \ src/basic/dirent-util.c \ src/basic/dirent-util.h \ + src/basic/xattr-util.c \ + src/basic/xattr-util.h \ src/basic/mount-util.c \ src/basic/mount-util.h \ src/basic/hexdecoct.c \ diff --git a/src/basic/copy.c b/src/basic/copy.c index 2d2d7ade34..60a4bee0fe 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -31,6 +31,7 @@ #include "string-util.h" #include "strv.h" #include "util.h" +#include "xattr-util.h" #define COPY_BUFFER_SIZE (16*1024) diff --git a/src/basic/smack-util.c b/src/basic/smack-util.c index 5f570ff02a..5ada621ca3 100644 --- a/src/basic/smack-util.c +++ b/src/basic/smack-util.c @@ -23,11 +23,12 @@ #include -#include "util.h" -#include "process-util.h" -#include "path-util.h" #include "fileio.h" +#include "path-util.h" +#include "process-util.h" #include "smack-util.h" +#include "util.h" +#include "xattr-util.h" #ifdef HAVE_SMACK bool mac_smack_use(void) { diff --git a/src/basic/util.c b/src/basic/util.c index e214c6f3dc..dfebff7ec1 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include @@ -1963,102 +1962,6 @@ int is_device_node(const char *path) { return !!(S_ISBLK(info.st_mode) || S_ISCHR(info.st_mode)); } -ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags) { - char fn[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; - _cleanup_close_ int fd = -1; - ssize_t l; - - /* The kernel doesn't have a fgetxattrat() command, hence let's emulate one */ - - fd = openat(dirfd, filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_PATH|(flags & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW : 0)); - if (fd < 0) - return -errno; - - xsprintf(fn, "/proc/self/fd/%i", fd); - - l = getxattr(fn, attribute, value, size); - if (l < 0) - return -errno; - - return l; -} - -static int parse_crtime(le64_t le, usec_t *usec) { - uint64_t u; - - assert(usec); - - u = le64toh(le); - if (u == 0 || u == (uint64_t) -1) - return -EIO; - - *usec = (usec_t) u; - return 0; -} - -int fd_getcrtime(int fd, usec_t *usec) { - le64_t le; - ssize_t n; - - assert(fd >= 0); - assert(usec); - - /* Until Linux gets a real concept of birthtime/creation time, - * let's fake one with xattrs */ - - n = fgetxattr(fd, "user.crtime_usec", &le, sizeof(le)); - if (n < 0) - return -errno; - if (n != sizeof(le)) - return -EIO; - - return parse_crtime(le, usec); -} - -int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags) { - le64_t le; - ssize_t n; - - n = fgetxattrat_fake(dirfd, name, "user.crtime_usec", &le, sizeof(le), flags); - if (n < 0) - return -errno; - if (n != sizeof(le)) - return -EIO; - - return parse_crtime(le, usec); -} - -int path_getcrtime(const char *p, usec_t *usec) { - le64_t le; - ssize_t n; - - assert(p); - assert(usec); - - n = getxattr(p, "user.crtime_usec", &le, sizeof(le)); - if (n < 0) - return -errno; - if (n != sizeof(le)) - return -EIO; - - return parse_crtime(le, usec); -} - -int fd_setcrtime(int fd, usec_t usec) { - le64_t le; - - assert(fd >= 0); - - if (usec <= 0) - usec = now(CLOCK_REALTIME); - - le = htole64((uint64_t) usec); - if (fsetxattr(fd, "user.crtime_usec", &le, sizeof(le), 0) < 0) - return -errno; - - return 0; -} - int chattr_fd(int fd, unsigned value, unsigned mask) { unsigned old_attr, new_attr; struct stat st; @@ -2233,76 +2136,6 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char return 0; } -int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink) { - char *v; - size_t l; - ssize_t n; - - assert(path); - assert(name); - assert(value); - - for (l = 100; ; l = (size_t) n + 1) { - v = new0(char, l); - if (!v) - return -ENOMEM; - - if (allow_symlink) - n = lgetxattr(path, name, v, l); - else - n = getxattr(path, name, v, l); - - if (n >= 0 && (size_t) n < l) { - *value = v; - return n; - } - - free(v); - - if (n < 0 && errno != ERANGE) - return -errno; - - if (allow_symlink) - n = lgetxattr(path, name, NULL, 0); - else - n = getxattr(path, name, NULL, 0); - if (n < 0) - return -errno; - } -} - -int fgetxattr_malloc(int fd, const char *name, char **value) { - char *v; - size_t l; - ssize_t n; - - assert(fd >= 0); - assert(name); - assert(value); - - for (l = 100; ; l = (size_t) n + 1) { - v = new0(char, l); - if (!v) - return -ENOMEM; - - n = fgetxattr(fd, name, v, l); - - if (n >= 0 && (size_t) n < l) { - *value = v; - return n; - } - - free(v); - - if (n < 0 && errno != ERANGE) - return -errno; - - n = fgetxattr(fd, name, NULL, 0); - if (n < 0) - return -errno; - } -} - int version(void) { puts(PACKAGE_STRING "\n" SYSTEMD_FEATURES); diff --git a/src/basic/util.h b/src/basic/util.h index 190d4f5edb..8f9f3f8fe6 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -500,13 +500,6 @@ union inotify_event_buffer { #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) -ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags); - -int fd_setcrtime(int fd, usec_t usec); -int fd_getcrtime(int fd, usec_t *usec); -int path_getcrtime(const char *p, usec_t *usec); -int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags); - int chattr_fd(int fd, unsigned value, unsigned mask); int chattr_path(const char *p, unsigned value, unsigned mask); @@ -517,9 +510,6 @@ int syslog_parse_priority(const char **p, int *priority, bool with_facility); int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); -int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink); -int fgetxattr_malloc(int fd, const char *name, char **value); - int version(void); bool fdname_is_valid(const char *s); diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c new file mode 100644 index 0000000000..35fd1c1616 --- /dev/null +++ b/src/basic/xattr-util.c @@ -0,0 +1,193 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "fd-util.h" +#include "sparse-endian.h" +#include "util.h" +#include "xattr-util.h" + +int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink) { + char *v; + size_t l; + ssize_t n; + + assert(path); + assert(name); + assert(value); + + for (l = 100; ; l = (size_t) n + 1) { + v = new0(char, l); + if (!v) + return -ENOMEM; + + if (allow_symlink) + n = lgetxattr(path, name, v, l); + else + n = getxattr(path, name, v, l); + + if (n >= 0 && (size_t) n < l) { + *value = v; + return n; + } + + free(v); + + if (n < 0 && errno != ERANGE) + return -errno; + + if (allow_symlink) + n = lgetxattr(path, name, NULL, 0); + else + n = getxattr(path, name, NULL, 0); + if (n < 0) + return -errno; + } +} + +int fgetxattr_malloc(int fd, const char *name, char **value) { + char *v; + size_t l; + ssize_t n; + + assert(fd >= 0); + assert(name); + assert(value); + + for (l = 100; ; l = (size_t) n + 1) { + v = new0(char, l); + if (!v) + return -ENOMEM; + + n = fgetxattr(fd, name, v, l); + + if (n >= 0 && (size_t) n < l) { + *value = v; + return n; + } + + free(v); + + if (n < 0 && errno != ERANGE) + return -errno; + + n = fgetxattr(fd, name, NULL, 0); + if (n < 0) + return -errno; + } +} + +ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags) { + char fn[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; + _cleanup_close_ int fd = -1; + ssize_t l; + + /* The kernel doesn't have a fgetxattrat() command, hence let's emulate one */ + + fd = openat(dirfd, filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_PATH|(flags & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW : 0)); + if (fd < 0) + return -errno; + + xsprintf(fn, "/proc/self/fd/%i", fd); + + l = getxattr(fn, attribute, value, size); + if (l < 0) + return -errno; + + return l; +} + +static int parse_crtime(le64_t le, usec_t *usec) { + uint64_t u; + + assert(usec); + + u = le64toh(le); + if (u == 0 || u == (uint64_t) -1) + return -EIO; + + *usec = (usec_t) u; + return 0; +} + +int fd_getcrtime(int fd, usec_t *usec) { + le64_t le; + ssize_t n; + + assert(fd >= 0); + assert(usec); + + /* Until Linux gets a real concept of birthtime/creation time, + * let's fake one with xattrs */ + + n = fgetxattr(fd, "user.crtime_usec", &le, sizeof(le)); + if (n < 0) + return -errno; + if (n != sizeof(le)) + return -EIO; + + return parse_crtime(le, usec); +} + +int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags) { + le64_t le; + ssize_t n; + + n = fgetxattrat_fake(dirfd, name, "user.crtime_usec", &le, sizeof(le), flags); + if (n < 0) + return -errno; + if (n != sizeof(le)) + return -EIO; + + return parse_crtime(le, usec); +} + +int path_getcrtime(const char *p, usec_t *usec) { + le64_t le; + ssize_t n; + + assert(p); + assert(usec); + + n = getxattr(p, "user.crtime_usec", &le, sizeof(le)); + if (n < 0) + return -errno; + if (n != sizeof(le)) + return -EIO; + + return parse_crtime(le, usec); +} + +int fd_setcrtime(int fd, usec_t usec) { + le64_t le; + + assert(fd >= 0); + + if (usec <= 0) + usec = now(CLOCK_REALTIME); + + le = htole64((uint64_t) usec); + if (fsetxattr(fd, "user.crtime_usec", &le, sizeof(le), 0) < 0) + return -errno; + + return 0; +} diff --git a/src/basic/xattr-util.h b/src/basic/xattr-util.h new file mode 100644 index 0000000000..cf4cb12a25 --- /dev/null +++ b/src/basic/xattr-util.h @@ -0,0 +1,38 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "time-util.h" + +int getxattr_malloc(const char *path, const char *name, char **value, bool allow_symlink); +int fgetxattr_malloc(int fd, const char *name, char **value); + +ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags); + +int fd_setcrtime(int fd, usec_t usec); + +int fd_getcrtime(int fd, usec_t *usec); +int path_getcrtime(const char *p, usec_t *usec); +int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags); diff --git a/src/import/pull-job.c b/src/import/pull-job.c index 0910901375..3cc7ea10b7 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -22,13 +22,14 @@ #include #include "fd-util.h" +#include "hexdecoct.h" #include "io-util.h" #include "machine-pool.h" -#include "hexdecoct.h" #include "parse-util.h" #include "pull-job.h" #include "string-util.h" #include "strv.h" +#include "xattr-util.h" PullJob* pull_job_unref(PullJob *j) { if (!j) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index c33e278cbe..a3b09dddff 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -38,6 +38,7 @@ #include "parse-util.h" #include "random-util.h" #include "string-util.h" +#include "xattr-util.h" #define DEFAULT_DATA_HASH_TABLE_SIZE (2047ULL*sizeof(HashItem)) #define DEFAULT_FIELD_HASH_TABLE_SIZE (333ULL*sizeof(HashItem)) diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c index d3add065d2..87646922fb 100644 --- a/src/journal/journal-vacuum.c +++ b/src/journal/journal-vacuum.c @@ -33,6 +33,7 @@ #include "parse-util.h" #include "string-util.h" #include "util.h" +#include "xattr-util.h" struct vacuum_info { uint64_t usage; diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 485793ed5d..ca85e26095 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -34,6 +34,7 @@ #include "string-util.h" #include "strv.h" #include "utf8.h" +#include "xattr-util.h" static const char image_search_path[] = "/var/lib/machines\0" diff --git a/src/test/test-util.c b/src/test/test-util.c index 109791163f..2e266bb047 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -42,6 +42,7 @@ #include "io-util.h" #include "mkdir.h" #include "parse-util.h" +#include "path-util.h" #include "process-util.h" #include "rm-rf.h" #include "signal-util.h" @@ -50,7 +51,7 @@ #include "user-util.h" #include "util.h" #include "virt.h" -#include "path-util.h" +#include "xattr-util.h" static void test_streq_ptr(void) { assert_se(streq_ptr(NULL, NULL)); -- cgit v1.2.3-54-g00ecf From c8b3094de58e3b1e37d06f3d56c9346cffbe320a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 20:39:23 +0100 Subject: util-lib: split out file attribute calls to chattr-util.[ch] --- Makefile.am | 2 + src/basic/chattr-util.c | 107 +++++++++++++++++++++++++++++++++++++++++++++ src/basic/chattr-util.h | 28 ++++++++++++ src/basic/copy.c | 1 + src/basic/util.c | 79 --------------------------------- src/basic/util.h | 6 --- src/import/import-raw.c | 1 + src/import/pull-raw.c | 1 + src/journal/journal-file.c | 1 + src/journal/journalctl.c | 1 + src/shared/machine-image.c | 1 + src/tmpfiles/tmpfiles.c | 1 + 12 files changed, 144 insertions(+), 85 deletions(-) create mode 100644 src/basic/chattr-util.c create mode 100644 src/basic/chattr-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index 33d66d4dd0..15aace196a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -797,6 +797,8 @@ libbasic_la_SOURCES = \ src/basic/dirent-util.h \ src/basic/xattr-util.c \ src/basic/xattr-util.h \ + src/basic/chattr-util.c \ + src/basic/chattr-util.h \ src/basic/mount-util.c \ src/basic/mount-util.h \ src/basic/hexdecoct.c \ diff --git a/src/basic/chattr-util.c b/src/basic/chattr-util.c new file mode 100644 index 0000000000..d49ca0537a --- /dev/null +++ b/src/basic/chattr-util.c @@ -0,0 +1,107 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "chattr-util.h" +#include "fd-util.h" +#include "util.h" + +int chattr_fd(int fd, unsigned value, unsigned mask) { + unsigned old_attr, new_attr; + struct stat st; + + assert(fd >= 0); + + if (fstat(fd, &st) < 0) + return -errno; + + /* Explicitly check whether this is a regular file or + * directory. If it is anything else (such as a device node or + * fifo), then the ioctl will not hit the file systems but + * possibly drivers, where the ioctl might have different + * effects. Notably, DRM is using the same ioctl() number. */ + + if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) + return -ENOTTY; + + if (mask == 0) + return 0; + + if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0) + return -errno; + + new_attr = (old_attr & ~mask) | (value & mask); + if (new_attr == old_attr) + return 0; + + if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0) + return -errno; + + return 1; +} + +int chattr_path(const char *p, unsigned value, unsigned mask) { + _cleanup_close_ int fd = -1; + + assert(p); + + if (mask == 0) + return 0; + + fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); + if (fd < 0) + return -errno; + + return chattr_fd(fd, value, mask); +} + +int read_attr_fd(int fd, unsigned *ret) { + struct stat st; + + assert(fd >= 0); + + if (fstat(fd, &st) < 0) + return -errno; + + if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) + return -ENOTTY; + + if (ioctl(fd, FS_IOC_GETFLAGS, ret) < 0) + return -errno; + + return 0; +} + +int read_attr_path(const char *p, unsigned *ret) { + _cleanup_close_ int fd = -1; + + assert(p); + assert(ret); + + fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); + if (fd < 0) + return -errno; + + return read_attr_fd(fd, ret); +} diff --git a/src/basic/chattr-util.h b/src/basic/chattr-util.h new file mode 100644 index 0000000000..ba6b8eb5c1 --- /dev/null +++ b/src/basic/chattr-util.h @@ -0,0 +1,28 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 . +***/ + +int chattr_fd(int fd, unsigned value, unsigned mask); +int chattr_path(const char *p, unsigned value, unsigned mask); + +int read_attr_fd(int fd, unsigned *ret); +int read_attr_path(const char *p, unsigned *ret); diff --git a/src/basic/copy.c b/src/basic/copy.c index 60a4bee0fe..8910052116 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -23,6 +23,7 @@ #include #include "btrfs-util.h" +#include "chattr-util.h" #include "copy.h" #include "dirent-util.h" #include "fd-util.h" diff --git a/src/basic/util.c b/src/basic/util.c index dfebff7ec1..889ca288fc 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -1962,85 +1962,6 @@ int is_device_node(const char *path) { return !!(S_ISBLK(info.st_mode) || S_ISCHR(info.st_mode)); } -int chattr_fd(int fd, unsigned value, unsigned mask) { - unsigned old_attr, new_attr; - struct stat st; - - assert(fd >= 0); - - if (fstat(fd, &st) < 0) - return -errno; - - /* Explicitly check whether this is a regular file or - * directory. If it is anything else (such as a device node or - * fifo), then the ioctl will not hit the file systems but - * possibly drivers, where the ioctl might have different - * effects. Notably, DRM is using the same ioctl() number. */ - - if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) - return -ENOTTY; - - if (mask == 0) - return 0; - - if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0) - return -errno; - - new_attr = (old_attr & ~mask) | (value & mask); - if (new_attr == old_attr) - return 0; - - if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0) - return -errno; - - return 1; -} - -int chattr_path(const char *p, unsigned value, unsigned mask) { - _cleanup_close_ int fd = -1; - - assert(p); - - if (mask == 0) - return 0; - - fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); - if (fd < 0) - return -errno; - - return chattr_fd(fd, value, mask); -} - -int read_attr_fd(int fd, unsigned *ret) { - struct stat st; - - assert(fd >= 0); - - if (fstat(fd, &st) < 0) - return -errno; - - if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) - return -ENOTTY; - - if (ioctl(fd, FS_IOC_GETFLAGS, ret) < 0) - return -errno; - - return 0; -} - -int read_attr_path(const char *p, unsigned *ret) { - _cleanup_close_ int fd = -1; - - assert(p); - assert(ret); - - fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW); - if (fd < 0) - return -errno; - - return read_attr_fd(fd, ret); -} - int syslog_parse_priority(const char **p, int *priority, bool with_facility) { int a = 0, b = 0, c = 0; int k; diff --git a/src/basic/util.h b/src/basic/util.h index 8f9f3f8fe6..30c88d38ad 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -500,12 +500,6 @@ union inotify_event_buffer { #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) -int chattr_fd(int fd, unsigned value, unsigned mask); -int chattr_path(const char *p, unsigned value, unsigned mask); - -int read_attr_fd(int fd, unsigned *ret); -int read_attr_path(const char *p, unsigned *ret); - int syslog_parse_priority(const char **p, int *priority, bool with_facility); int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); diff --git a/src/import/import-raw.c b/src/import/import-raw.c index d94d8ab4ae..0c81001dbe 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -25,6 +25,7 @@ #include "sd-event.h" #include "btrfs-util.h" +#include "chattr-util.h" #include "copy.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index 4d0ac770aa..39759b50b0 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -26,6 +26,7 @@ #include "sd-daemon.h" #include "btrfs-util.h" +#include "chattr-util.h" #include "copy.h" #include "curl-util.h" #include "fd-util.h" diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index a3b09dddff..6f9b8a2915 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -29,6 +29,7 @@ #include #include "btrfs-util.h" +#include "chattr-util.h" #include "compress.h" #include "fd-util.h" #include "journal-authenticate.h" diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 5b3b6cd143..ef5518136a 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -42,6 +42,7 @@ #include "bus-error.h" #include "bus-util.h" #include "catalog.h" +#include "chattr-util.h" #include "fd-util.h" #include "fileio.h" #include "fsprg.h" diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index ca85e26095..c5444ee010 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -24,6 +24,7 @@ #include #include "btrfs-util.h" +#include "chattr-util.h" #include "copy.h" #include "dirent-util.h" #include "fd-util.h" diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 85a2d6c2f5..8cf327a15f 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -41,6 +41,7 @@ #include "acl-util.h" #include "btrfs-util.h" #include "capability.h" +#include "chattr-util.h" #include "conf-files.h" #include "copy.h" #include "escape.h" -- cgit v1.2.3-54-g00ecf From f4f15635ec05293ffcc83a5b39f624bbabbd8fd0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 21:16:26 +0100 Subject: util-lib: move a number of fs operations into fs-util.[ch] --- Makefile.am | 2 + src/basic/cgroup-util.c | 1 + src/basic/copy.c | 1 + src/basic/fileio.c | 1 + src/basic/fs-util.c | 477 +++++++++++++++++++++ src/basic/fs-util.h | 60 +++ src/basic/lockfile-util.c | 1 + src/basic/mkdir.c | 5 +- src/basic/path-util.c | 1 + src/basic/process-util.c | 1 + src/basic/terminal-util.c | 1 + src/basic/time-util.c | 1 + src/basic/util.c | 445 ------------------- src/basic/util.h | 32 -- src/core/execute.c | 1 + src/core/load-fragment.c | 1 + src/core/machine-id-setup.c | 1 + src/core/main.c | 1 + src/core/manager.c | 1 + src/core/service.c | 1 + src/core/timer.c | 1 + src/delta/delta.c | 1 + src/firstboot/firstboot.c | 1 + src/fsck/fsck.c | 1 + src/hwdb/hwdb.c | 1 + src/import/export.c | 1 + src/import/import-raw.c | 1 + src/import/import-tar.c | 1 + src/import/import.c | 1 + src/import/pull-dkr.c | 1 + src/import/pull-raw.c | 1 + src/import/pull-tar.c | 1 + src/journal/coredump.c | 1 + src/journal/journalctl.c | 1 + src/journal/journald-native.c | 1 + src/journal/journald-server.c | 1 + src/libsystemd/sd-daemon/sd-daemon.c | 1 + src/libsystemd/sd-device/device-private.c | 1 + src/libsystemd/sd-device/sd-device.c | 1 + src/libsystemd/sd-login/sd-login.c | 3 +- src/login/logind-dbus.c | 1 + src/login/logind-user.c | 1 + src/machine/machine-dbus.c | 1 + src/nspawn/nspawn-mount.c | 1 + src/nspawn/nspawn.c | 1 + src/shared/conf-parser.c | 1 + src/shared/install.c | 1 + src/shared/machine-image.c | 1 + src/shared/machine-pool.c | 3 +- .../system-update-generator.c | 1 + src/systemctl/systemctl.c | 1 + src/test/test-conf-files.c | 1 + src/test/test-copy.c | 1 + src/test/test-execute.c | 7 +- src/test/test-path.c | 3 +- src/test/test-udev.c | 1 + src/test/test-util.c | 1 + src/timedate/timedated.c | 21 +- src/timesync/timesyncd-manager.c | 1 + src/timesync/timesyncd.c | 1 + src/tmpfiles/tmpfiles.c | 1 + src/udev/udev-node.c | 1 + src/udev/udevadm-hwdb.c | 1 + src/udev/udevd.c | 1 + 64 files changed, 616 insertions(+), 495 deletions(-) create mode 100644 src/basic/fs-util.c create mode 100644 src/basic/fs-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index 15aace196a..810ced3326 100644 --- a/Makefile.am +++ b/Makefile.am @@ -799,6 +799,8 @@ libbasic_la_SOURCES = \ src/basic/xattr-util.h \ src/basic/chattr-util.c \ src/basic/chattr-util.h \ + src/basic/fs-util.c \ + src/basic/fs-util.h \ src/basic/mount-util.c \ src/basic/mount-util.h \ src/basic/hexdecoct.c \ diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 67dc291192..84aea8afb8 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -35,6 +35,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "login-util.h" #include "macro.h" #include "mkdir.h" diff --git a/src/basic/copy.c b/src/basic/copy.c index 8910052116..f1413f74b0 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -28,6 +28,7 @@ #include "dirent-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "io-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/basic/fileio.c b/src/basic/fileio.c index b7e447f6b6..2c4d70aa1c 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -25,6 +25,7 @@ #include "escape.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hexdecoct.h" #include "path-util.h" #include "random-util.h" diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c new file mode 100644 index 0000000000..bd775b7b6f --- /dev/null +++ b/src/basic/fs-util.c @@ -0,0 +1,477 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "dirent-util.h" +#include "fd-util.h" +#include "fileio.h" +#include "fs-util.h" +#include "mkdir.h" +#include "path-util.h" +#include "string-util.h" +#include "strv.h" +#include "util.h" + +int unlink_noerrno(const char *path) { + PROTECT_ERRNO; + int r; + + r = unlink(path); + if (r < 0) + return -errno; + + return 0; +} + +int rmdir_parents(const char *path, const char *stop) { + size_t l; + int r = 0; + + assert(path); + assert(stop); + + l = strlen(path); + + /* Skip trailing slashes */ + while (l > 0 && path[l-1] == '/') + l--; + + while (l > 0) { + char *t; + + /* Skip last component */ + while (l > 0 && path[l-1] != '/') + l--; + + /* Skip trailing slashes */ + while (l > 0 && path[l-1] == '/') + l--; + + if (l <= 0) + break; + + t = strndup(path, l); + if (!t) + return -ENOMEM; + + if (path_startswith(stop, t)) { + free(t); + return 0; + } + + r = rmdir(t); + free(t); + + if (r < 0) + if (errno != ENOENT) + return -errno; + } + + return 0; +} + + +int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { + struct stat buf; + int ret; + + ret = renameat2(olddirfd, oldpath, newdirfd, newpath, RENAME_NOREPLACE); + if (ret >= 0) + return 0; + + /* renameat2() exists since Linux 3.15, btrfs added support for it later. + * If it is not implemented, fallback to another method. */ + if (!IN_SET(errno, EINVAL, ENOSYS)) + return -errno; + + /* The link()/unlink() fallback does not work on directories. But + * renameat() without RENAME_NOREPLACE gives the same semantics on + * directories, except when newpath is an *empty* directory. This is + * good enough. */ + ret = fstatat(olddirfd, oldpath, &buf, AT_SYMLINK_NOFOLLOW); + if (ret >= 0 && S_ISDIR(buf.st_mode)) { + ret = renameat(olddirfd, oldpath, newdirfd, newpath); + return ret >= 0 ? 0 : -errno; + } + + /* If it is not a directory, use the link()/unlink() fallback. */ + ret = linkat(olddirfd, oldpath, newdirfd, newpath, 0); + if (ret < 0) + return -errno; + + ret = unlinkat(olddirfd, oldpath, 0); + if (ret < 0) { + /* backup errno before the following unlinkat() alters it */ + ret = errno; + (void) unlinkat(newdirfd, newpath, 0); + errno = ret; + return -errno; + } + + return 0; +} + +int readlinkat_malloc(int fd, const char *p, char **ret) { + size_t l = 100; + int r; + + assert(p); + assert(ret); + + for (;;) { + char *c; + ssize_t n; + + c = new(char, l); + if (!c) + return -ENOMEM; + + n = readlinkat(fd, p, c, l-1); + if (n < 0) { + r = -errno; + free(c); + return r; + } + + if ((size_t) n < l-1) { + c[n] = 0; + *ret = c; + return 0; + } + + free(c); + l *= 2; + } +} + +int readlink_malloc(const char *p, char **ret) { + return readlinkat_malloc(AT_FDCWD, p, ret); +} + +int readlink_value(const char *p, char **ret) { + _cleanup_free_ char *link = NULL; + char *value; + int r; + + r = readlink_malloc(p, &link); + if (r < 0) + return r; + + value = basename(link); + if (!value) + return -ENOENT; + + value = strdup(value); + if (!value) + return -ENOMEM; + + *ret = value; + + return 0; +} + +int readlink_and_make_absolute(const char *p, char **r) { + _cleanup_free_ char *target = NULL; + char *k; + int j; + + assert(p); + assert(r); + + j = readlink_malloc(p, &target); + if (j < 0) + return j; + + k = file_in_same_dir(p, target); + if (!k) + return -ENOMEM; + + *r = k; + return 0; +} + +int readlink_and_canonicalize(const char *p, char **r) { + char *t, *s; + int j; + + assert(p); + assert(r); + + j = readlink_and_make_absolute(p, &t); + if (j < 0) + return j; + + s = canonicalize_file_name(t); + if (s) { + free(t); + *r = s; + } else + *r = t; + + path_kill_slashes(*r); + + return 0; +} + +int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) { + assert(path); + + /* Under the assumption that we are running privileged we + * first change the access mode and only then hand out + * ownership to avoid a window where access is too open. */ + + if (mode != MODE_INVALID) + if (chmod(path, mode) < 0) + return -errno; + + if (uid != UID_INVALID || gid != GID_INVALID) + if (chown(path, uid, gid) < 0) + return -errno; + + return 0; +} + +int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid) { + assert(fd >= 0); + + /* Under the assumption that we are running privileged we + * first change the access mode and only then hand out + * ownership to avoid a window where access is too open. */ + + if (mode != MODE_INVALID) + if (fchmod(fd, mode) < 0) + return -errno; + + if (uid != UID_INVALID || gid != GID_INVALID) + if (fchown(fd, uid, gid) < 0) + return -errno; + + return 0; +} + +int fchmod_umask(int fd, mode_t m) { + mode_t u; + int r; + + u = umask(0777); + r = fchmod(fd, m & (~u)) < 0 ? -errno : 0; + umask(u); + + return r; +} + +int fd_warn_permissions(const char *path, int fd) { + struct stat st; + + if (fstat(fd, &st) < 0) + return -errno; + + if (st.st_mode & 0111) + log_warning("Configuration file %s is marked executable. Please remove executable permission bits. Proceeding anyway.", path); + + if (st.st_mode & 0002) + log_warning("Configuration file %s is marked world-writable. Please remove world writability permission bits. Proceeding anyway.", path); + + if (getpid() == 1 && (st.st_mode & 0044) != 0044) + log_warning("Configuration file %s is marked world-inaccessible. This has no effect as configuration data is accessible via APIs without restrictions. Proceeding anyway.", path); + + return 0; +} + +int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode) { + _cleanup_close_ int fd; + int r; + + assert(path); + + if (parents) + mkdir_parents(path, 0755); + + fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, mode > 0 ? mode : 0644); + if (fd < 0) + return -errno; + + if (mode > 0) { + r = fchmod(fd, mode); + if (r < 0) + return -errno; + } + + if (uid != UID_INVALID || gid != GID_INVALID) { + r = fchown(fd, uid, gid); + if (r < 0) + return -errno; + } + + if (stamp != USEC_INFINITY) { + struct timespec ts[2]; + + timespec_store(&ts[0], stamp); + ts[1] = ts[0]; + r = futimens(fd, ts); + } else + r = futimens(fd, NULL); + if (r < 0) + return -errno; + + return 0; +} + +int touch(const char *path) { + return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, 0); +} + +int symlink_idempotent(const char *from, const char *to) { + _cleanup_free_ char *p = NULL; + int r; + + assert(from); + assert(to); + + if (symlink(from, to) < 0) { + if (errno != EEXIST) + return -errno; + + r = readlink_malloc(to, &p); + if (r < 0) + return r; + + if (!streq(p, from)) + return -EINVAL; + } + + return 0; +} + +int symlink_atomic(const char *from, const char *to) { + _cleanup_free_ char *t = NULL; + int r; + + assert(from); + assert(to); + + r = tempfn_random(to, NULL, &t); + if (r < 0) + return r; + + if (symlink(from, t) < 0) + return -errno; + + if (rename(t, to) < 0) { + unlink_noerrno(t); + return -errno; + } + + return 0; +} + +int mknod_atomic(const char *path, mode_t mode, dev_t dev) { + _cleanup_free_ char *t = NULL; + int r; + + assert(path); + + r = tempfn_random(path, NULL, &t); + if (r < 0) + return r; + + if (mknod(t, mode, dev) < 0) + return -errno; + + if (rename(t, path) < 0) { + unlink_noerrno(t); + return -errno; + } + + return 0; +} + +int mkfifo_atomic(const char *path, mode_t mode) { + _cleanup_free_ char *t = NULL; + int r; + + assert(path); + + r = tempfn_random(path, NULL, &t); + if (r < 0) + return r; + + if (mkfifo(t, mode) < 0) + return -errno; + + if (rename(t, path) < 0) { + unlink_noerrno(t); + return -errno; + } + + return 0; +} + +int get_files_in_directory(const char *path, char ***list) { + _cleanup_closedir_ DIR *d = NULL; + size_t bufsize = 0, n = 0; + _cleanup_strv_free_ char **l = NULL; + + assert(path); + + /* Returns all files in a directory in *list, and the number + * of files as return value. If list is NULL returns only the + * number. */ + + d = opendir(path); + if (!d) + return -errno; + + for (;;) { + struct dirent *de; + + errno = 0; + de = readdir(d); + if (!de && errno != 0) + return -errno; + if (!de) + break; + + dirent_ensure_type(d, de); + + if (!dirent_is_file(de)) + continue; + + if (list) { + /* one extra slot is needed for the terminating NULL */ + if (!GREEDY_REALLOC(l, bufsize, n + 2)) + return -ENOMEM; + + l[n] = strdup(de->d_name); + if (!l[n]) + return -ENOMEM; + + l[++n] = NULL; + } else + n++; + } + + if (list) { + *list = l; + l = NULL; /* avoid freeing */ + } + + return n; +} diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h new file mode 100644 index 0000000000..0e1906ba3f --- /dev/null +++ b/src/basic/fs-util.h @@ -0,0 +1,60 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "time-util.h" + +int unlink_noerrno(const char *path); + +int rmdir_parents(const char *path, const char *stop); + +int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); + +int readlinkat_malloc(int fd, const char *p, char **ret); +int readlink_malloc(const char *p, char **r); +int readlink_value(const char *p, char **ret); +int readlink_and_make_absolute(const char *p, char **r); +int readlink_and_canonicalize(const char *p, char **r); + +int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); +int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid); + +int fchmod_umask(int fd, mode_t mode); + +int fd_warn_permissions(const char *path, int fd); + +#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) + +int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode); +int touch(const char *path); + +int symlink_idempotent(const char *from, const char *to); + +int symlink_atomic(const char *from, const char *to); +int mknod_atomic(const char *path, mode_t mode, dev_t dev); +int mkfifo_atomic(const char *path, mode_t mode); + +int get_files_in_directory(const char *path, char ***list); diff --git a/src/basic/lockfile-util.c b/src/basic/lockfile-util.c index 6eee3009d8..60235cc972 100644 --- a/src/basic/lockfile-util.c +++ b/src/basic/lockfile-util.c @@ -29,6 +29,7 @@ #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "lockfile-util.h" #include "path-util.h" #include "util.h" diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c index 7ee4546988..4fe90b2bb7 100644 --- a/src/basic/mkdir.c +++ b/src/basic/mkdir.c @@ -22,9 +22,10 @@ #include #include -#include "util.h" -#include "path-util.h" +#include "fs-util.h" #include "mkdir.h" +#include "path-util.h" +#include "util.h" int mkdir_safe_internal(const char *path, mode_t mode, uid_t uid, gid_t gid, mkdir_func_t _mkdir) { struct stat st; diff --git a/src/basic/path-util.c b/src/basic/path-util.c index ed30c3d92d..256a98f3e6 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -35,6 +35,7 @@ #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "log.h" #include "macro.h" #include "missing.h" diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 72fc82e7cb..e0061d15b3 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -31,6 +31,7 @@ #include "escape.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "log.h" #include "process-util.h" #include "signal-util.h" diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 2fe5c26a67..1edceacfa2 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -33,6 +33,7 @@ #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "io-util.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/basic/time-util.c b/src/basic/time-util.c index b7d92cbad8..867e7b2430 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -25,6 +25,7 @@ #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "path-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/basic/util.c b/src/basic/util.c index 889ca288fc..92ce009620 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -123,176 +123,6 @@ size_t page_size(void) { return pgsz; } -int unlink_noerrno(const char *path) { - PROTECT_ERRNO; - int r; - - r = unlink(path); - if (r < 0) - return -errno; - - return 0; -} - -int fchmod_umask(int fd, mode_t m) { - mode_t u; - int r; - - u = umask(0777); - r = fchmod(fd, m & (~u)) < 0 ? -errno : 0; - umask(u); - - return r; -} - -int readlinkat_malloc(int fd, const char *p, char **ret) { - size_t l = 100; - int r; - - assert(p); - assert(ret); - - for (;;) { - char *c; - ssize_t n; - - c = new(char, l); - if (!c) - return -ENOMEM; - - n = readlinkat(fd, p, c, l-1); - if (n < 0) { - r = -errno; - free(c); - return r; - } - - if ((size_t) n < l-1) { - c[n] = 0; - *ret = c; - return 0; - } - - free(c); - l *= 2; - } -} - -int readlink_malloc(const char *p, char **ret) { - return readlinkat_malloc(AT_FDCWD, p, ret); -} - -int readlink_value(const char *p, char **ret) { - _cleanup_free_ char *link = NULL; - char *value; - int r; - - r = readlink_malloc(p, &link); - if (r < 0) - return r; - - value = basename(link); - if (!value) - return -ENOENT; - - value = strdup(value); - if (!value) - return -ENOMEM; - - *ret = value; - - return 0; -} - -int readlink_and_make_absolute(const char *p, char **r) { - _cleanup_free_ char *target = NULL; - char *k; - int j; - - assert(p); - assert(r); - - j = readlink_malloc(p, &target); - if (j < 0) - return j; - - k = file_in_same_dir(p, target); - if (!k) - return -ENOMEM; - - *r = k; - return 0; -} - -int readlink_and_canonicalize(const char *p, char **r) { - char *t, *s; - int j; - - assert(p); - assert(r); - - j = readlink_and_make_absolute(p, &t); - if (j < 0) - return j; - - s = canonicalize_file_name(t); - if (s) { - free(t); - *r = s; - } else - *r = t; - - path_kill_slashes(*r); - - return 0; -} - -int rmdir_parents(const char *path, const char *stop) { - size_t l; - int r = 0; - - assert(path); - assert(stop); - - l = strlen(path); - - /* Skip trailing slashes */ - while (l > 0 && path[l-1] == '/') - l--; - - while (l > 0) { - char *t; - - /* Skip last component */ - while (l > 0 && path[l-1] != '/') - l--; - - /* Skip trailing slashes */ - while (l > 0 && path[l-1] == '/') - l--; - - if (l <= 0) - break; - - if (!(t = strndup(path, l))) - return -ENOMEM; - - if (path_startswith(stop, t)) { - free(t); - return 0; - } - - r = rmdir(t); - free(t); - - if (r < 0) - if (errno != ENOENT) - return -errno; - } - - return 0; -} - bool fstype_is_network(const char *fstype) { static const char table[] = "afs\0" @@ -401,42 +231,6 @@ int fd_is_temporary_fs(int fd) { return is_temporary_fs(&s); } -int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid) { - assert(path); - - /* Under the assumption that we are running privileged we - * first change the access mode and only then hand out - * ownership to avoid a window where access is too open. */ - - if (mode != MODE_INVALID) - if (chmod(path, mode) < 0) - return -errno; - - if (uid != UID_INVALID || gid != GID_INVALID) - if (chown(path, uid, gid) < 0) - return -errno; - - return 0; -} - -int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid) { - assert(fd >= 0); - - /* Under the assumption that we are running privileged we - * first change the access mode and only then hand out - * ownership to avoid a window where access is too open. */ - - if (mode != MODE_INVALID) - if (fchmod(fd, mode) < 0) - return -errno; - - if (uid != UID_INVALID || gid != GID_INVALID) - if (fchown(fd, uid, gid) < 0) - return -errno; - - return 0; -} - int files_same(const char *filea, const char *fileb) { struct stat a, b; @@ -460,49 +254,6 @@ int running_in_chroot(void) { return ret == 0; } -int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode) { - _cleanup_close_ int fd; - int r; - - assert(path); - - if (parents) - mkdir_parents(path, 0755); - - fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, mode > 0 ? mode : 0644); - if (fd < 0) - return -errno; - - if (mode > 0) { - r = fchmod(fd, mode); - if (r < 0) - return -errno; - } - - if (uid != UID_INVALID || gid != GID_INVALID) { - r = fchown(fd, uid, gid); - if (r < 0) - return -errno; - } - - if (stamp != USEC_INFINITY) { - struct timespec ts[2]; - - timespec_store(&ts[0], stamp); - ts[1] = ts[0]; - r = futimens(fd, ts); - } else - r = futimens(fd, NULL); - if (r < 0) - return -errno; - - return 0; -} - -int touch(const char *path) { - return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, 0); -} - noreturn void freeze(void) { /* Make sure nobody waits for us on a socket anymore */ @@ -692,92 +443,6 @@ bool plymouth_running(void) { return access("/run/plymouth/pid", F_OK) >= 0; } -int symlink_atomic(const char *from, const char *to) { - _cleanup_free_ char *t = NULL; - int r; - - assert(from); - assert(to); - - r = tempfn_random(to, NULL, &t); - if (r < 0) - return r; - - if (symlink(from, t) < 0) - return -errno; - - if (rename(t, to) < 0) { - unlink_noerrno(t); - return -errno; - } - - return 0; -} - -int symlink_idempotent(const char *from, const char *to) { - _cleanup_free_ char *p = NULL; - int r; - - assert(from); - assert(to); - - if (symlink(from, to) < 0) { - if (errno != EEXIST) - return -errno; - - r = readlink_malloc(to, &p); - if (r < 0) - return r; - - if (!streq(p, from)) - return -EINVAL; - } - - return 0; -} - -int mknod_atomic(const char *path, mode_t mode, dev_t dev) { - _cleanup_free_ char *t = NULL; - int r; - - assert(path); - - r = tempfn_random(path, NULL, &t); - if (r < 0) - return r; - - if (mknod(t, mode, dev) < 0) - return -errno; - - if (rename(t, path) < 0) { - unlink_noerrno(t); - return -errno; - } - - return 0; -} - -int mkfifo_atomic(const char *path, mode_t mode) { - _cleanup_free_ char *t = NULL; - int r; - - assert(path); - - r = tempfn_random(path, NULL, &t); - if (r < 0) - return r; - - if (mkfifo(t, mode) < 0) - return -errno; - - if (rename(t, path) < 0) { - unlink_noerrno(t); - return -errno; - } - - return 0; -} - bool display_is_local(const char *display) { assert(display); @@ -855,58 +520,6 @@ int glob_extend(char ***strv, const char *path) { return k; } -int get_files_in_directory(const char *path, char ***list) { - _cleanup_closedir_ DIR *d = NULL; - size_t bufsize = 0, n = 0; - _cleanup_strv_free_ char **l = NULL; - - assert(path); - - /* Returns all files in a directory in *list, and the number - * of files as return value. If list is NULL returns only the - * number. */ - - d = opendir(path); - if (!d) - return -errno; - - for (;;) { - struct dirent *de; - - errno = 0; - de = readdir(d); - if (!de && errno != 0) - return -errno; - if (!de) - break; - - dirent_ensure_type(d, de); - - if (!dirent_is_file(de)) - continue; - - if (list) { - /* one extra slot is needed for the terminating NULL */ - if (!GREEDY_REALLOC(l, bufsize, n + 2)) - return -ENOMEM; - - l[n] = strdup(de->d_name); - if (!l[n]) - return -ENOMEM; - - l[++n] = NULL; - } else - n++; - } - - if (list) { - *list = l; - l = NULL; /* avoid freeing */ - } - - return n; -} - bool is_main_thread(void) { static thread_local int cached = 0; @@ -1815,24 +1428,6 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int return reset_uid_gid(); } -int fd_warn_permissions(const char *path, int fd) { - struct stat st; - - if (fstat(fd, &st) < 0) - return -errno; - - if (st.st_mode & 0111) - log_warning("Configuration file %s is marked executable. Please remove executable permission bits. Proceeding anyway.", path); - - if (st.st_mode & 0002) - log_warning("Configuration file %s is marked world-writable. Please remove world writability permission bits. Proceeding anyway.", path); - - if (getpid() == 1 && (st.st_mode & 0044) != 0044) - log_warning("Configuration file %s is marked world-inaccessible. This has no effect as configuration data is accessible via APIs without restrictions. Proceeding anyway.", path); - - return 0; -} - unsigned long personality_from_string(const char *p) { /* Parse a personality specifier. We introduce our own @@ -2017,46 +1612,6 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k return -1; } -int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { - struct stat buf; - int ret; - - ret = renameat2(olddirfd, oldpath, newdirfd, newpath, RENAME_NOREPLACE); - if (ret >= 0) - return 0; - - /* renameat2() exists since Linux 3.15, btrfs added support for it later. - * If it is not implemented, fallback to another method. */ - if (!IN_SET(errno, EINVAL, ENOSYS)) - return -errno; - - /* The link()/unlink() fallback does not work on directories. But - * renameat() without RENAME_NOREPLACE gives the same semantics on - * directories, except when newpath is an *empty* directory. This is - * good enough. */ - ret = fstatat(olddirfd, oldpath, &buf, AT_SYMLINK_NOFOLLOW); - if (ret >= 0 && S_ISDIR(buf.st_mode)) { - ret = renameat(olddirfd, oldpath, newdirfd, newpath); - return ret >= 0 ? 0 : -errno; - } - - /* If it is not a directory, use the link()/unlink() fallback. */ - ret = linkat(olddirfd, oldpath, newdirfd, newpath, 0); - if (ret < 0) - return -errno; - - ret = unlinkat(olddirfd, oldpath, 0); - if (ret < 0) { - /* backup errno before the following unlinkat() alters it */ - ret = errno; - (void) unlinkat(newdirfd, newpath, 0); - errno = ret; - return -errno; - } - - return 0; -} - int version(void) { puts(PACKAGE_STRING "\n" SYSTEMD_FEATURES); diff --git a/src/basic/util.h b/src/basic/util.h index 30c88d38ad..7608e49689 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -83,14 +83,6 @@ static inline const char* one_zero(bool b) { return b ? "1" : "0"; } -int readlinkat_malloc(int fd, const char *p, char **ret); -int readlink_malloc(const char *p, char **r); -int readlink_value(const char *p, char **ret); -int readlink_and_make_absolute(const char *p, char **r); -int readlink_and_canonicalize(const char *p, char **r); - -int rmdir_parents(const char *path, const char *stop); - /* For basic lookup tables with strictly enumerated entries */ #define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ scope const char *name##_to_string(type i) { \ @@ -159,9 +151,6 @@ static inline int dir_is_populated(const char *path) { return !r; } -int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); -int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid); - typedef long statfs_f_type_t; bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_; @@ -179,9 +168,6 @@ int files_same(const char *filea, const char *fileb); int running_in_chroot(void); -int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode); -int touch(const char *path); - noreturn void freeze(void); bool null_or_empty(struct stat *st) _pure_; @@ -192,22 +178,12 @@ void execute_directories(const char* const* directories, usec_t timeout, char *a bool plymouth_running(void); -int symlink_idempotent(const char *from, const char *to); - -int symlink_atomic(const char *from, const char *to); -int mknod_atomic(const char *path, mode_t mode, dev_t dev); -int mkfifo_atomic(const char *path, mode_t mode); - -int fchmod_umask(int fd, mode_t mode); - bool display_is_local(const char *display) _pure_; int socket_from_display(const char *display, char **path); int glob_exists(const char *path); int glob_extend(char ***strv, const char *path); -int get_files_in_directory(const char *path, char ***list); - bool is_main_thread(void); int block_get_whole_disk(dev_t d, dev_t *ret); @@ -408,8 +384,6 @@ static inline unsigned log2u_round_up(unsigned x) { ans; \ }) -int unlink_noerrno(const char *path); - #define alloca0(n) \ ({ \ char *_new_; \ @@ -460,8 +434,6 @@ int container_get_leader(const char *machine, pid_t *pid); int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd); int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd); -int fd_warn_permissions(const char *path, int fd); - #ifndef PERSONALITY_INVALID /* personality(7) documents that 0xffffffffUL is used for querying the * current personality, hence let's use that here as error @@ -498,12 +470,8 @@ union inotify_event_buffer { uint8_t raw[INOTIFY_EVENT_MAX]; }; -#define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW) - int syslog_parse_priority(const char **p, int *priority, bool with_facility); -int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); - int version(void); bool fdname_is_valid(const char *s); diff --git a/src/core/execute.c b/src/core/execute.c index ad0e6be4b7..a9564386ba 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -69,6 +69,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "io-util.h" #include "ioprio.h" #include "log.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index f5c28e514f..688c4c7e0c 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -44,6 +44,7 @@ #include "errno-list.h" #include "escape.h" #include "fd-util.h" +#include "fs-util.h" #include "ioprio.h" #include "load-fragment.h" #include "log.h" diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c index 764728c804..921f071068 100644 --- a/src/core/machine-id-setup.c +++ b/src/core/machine-id-setup.c @@ -31,6 +31,7 @@ #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hexdecoct.h" #include "io-util.h" #include "log.h" diff --git a/src/core/main.c b/src/core/main.c index dfd17694c9..a931b10b9f 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -55,6 +55,7 @@ #include "fdset.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "hostname-setup.h" #include "ima-setup.h" #include "killall.h" diff --git a/src/core/manager.c b/src/core/manager.c index 589501519a..a56162ab5b 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -55,6 +55,7 @@ #include "exit-status.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hashmap.h" #include "io-util.h" #include "locale-setup.h" diff --git a/src/core/service.c b/src/core/service.c index d5bd8869da..bb77f4502d 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -35,6 +35,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "load-dropin.h" #include "load-fragment.h" #include "log.h" diff --git a/src/core/timer.c b/src/core/timer.c index 3ece2e056d..26d94eb521 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -24,6 +24,7 @@ #include "bus-error.h" #include "bus-util.h" #include "dbus-timer.h" +#include "fs-util.h" #include "parse-util.h" #include "special.h" #include "string-util.h" diff --git a/src/delta/delta.c b/src/delta/delta.c index 590ab86515..a40a92b5cb 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -28,6 +28,7 @@ #include "dirent-util.h" #include "fd-util.h" +#include "fs-util.h" #include "hashmap.h" #include "log.h" #include "pager.h" diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 564bd50f9b..8faed594c6 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -28,6 +28,7 @@ #include "copy.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hostname-util.h" #include "locale-util.h" #include "mkdir.h" diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 7415be1529..590ffafef6 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -37,6 +37,7 @@ #include "bus-util.h" #include "device-util.h" #include "fd-util.h" +#include "fs-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c index b4118828a9..48d0883a3a 100644 --- a/src/hwdb/hwdb.c +++ b/src/hwdb/hwdb.c @@ -25,6 +25,7 @@ #include "conf-files.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hwdb-internal.h" #include "hwdb-util.h" #include "mkdir.h" diff --git a/src/import/export.c b/src/import/export.c index 1ecd1e4e10..6ff732d73f 100644 --- a/src/import/export.c +++ b/src/import/export.c @@ -27,6 +27,7 @@ #include "export-raw.h" #include "export-tar.h" #include "fd-util.h" +#include "fs-util.h" #include "hostname-util.h" #include "import-util.h" #include "machine-image.h" diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 0c81001dbe..87f4a3935d 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -29,6 +29,7 @@ #include "copy.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hostname-util.h" #include "import-common.h" #include "import-compress.h" diff --git a/src/import/import-tar.c b/src/import/import-tar.c index d88eae1973..64eb5ccd83 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -28,6 +28,7 @@ #include "copy.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hostname-util.h" #include "import-common.h" #include "import-compress.h" diff --git a/src/import/import.c b/src/import/import.c index e50ded9219..76b38e4903 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -25,6 +25,7 @@ #include "event-util.h" #include "fd-util.h" +#include "fs-util.h" #include "hostname-util.h" #include "import-raw.h" #include "import-tar.h" diff --git a/src/import/pull-dkr.c b/src/import/pull-dkr.c index 700462bfd2..2420b9a5f4 100644 --- a/src/import/pull-dkr.c +++ b/src/import/pull-dkr.c @@ -29,6 +29,7 @@ #include "curl-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hostname-util.h" #include "import-common.h" #include "import-util.h" diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index 39759b50b0..0e9b5ca2b2 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -31,6 +31,7 @@ #include "curl-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hostname-util.h" #include "import-common.h" #include "import-util.h" diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index 3e21d72157..306fbe720a 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -29,6 +29,7 @@ #include "curl-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hostname-util.h" #include "import-common.h" #include "import-util.h" diff --git a/src/journal/coredump.c b/src/journal/coredump.c index ec57920d2e..1756a823a9 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -44,6 +44,7 @@ #include "escape.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "journald-native.h" #include "log.h" #include "macro.h" diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index ef5518136a..61d502f0a1 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -45,6 +45,7 @@ #include "chattr-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "fsprg.h" #include "hostname-util.h" #include "io-util.h" diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index ae229ecaf5..e427f20e69 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -25,6 +25,7 @@ #include #include "fd-util.h" +#include "fs-util.h" #include "journald-console.h" #include "journald-kmsg.h" #include "journald-native.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 6e6d9c1c4a..a474293a87 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -40,6 +40,7 @@ #include "extract-word.h" #include "fd-util.h" #include "formats-util.h" +#include "fs-util.h" #include "hashmap.h" #include "hostname-util.h" #include "journal-authenticate.h" diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c index a125be7cb8..49fac7bdcc 100644 --- a/src/libsystemd/sd-daemon/sd-daemon.c +++ b/src/libsystemd/sd-daemon/sd-daemon.c @@ -36,6 +36,7 @@ #include "sd-daemon.h" #include "fd-util.h" +#include "fs-util.h" #include "parse-util.h" #include "path-util.h" #include "socket-util.h" diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 91690d83f6..da325c9d28 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -29,6 +29,7 @@ #include "device-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hashmap.h" #include "macro.h" #include "mkdir.h" diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 0e7a26523d..13d1baa41d 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -29,6 +29,7 @@ #include "device-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "hashmap.h" #include "macro.h" #include "parse-util.h" diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 90ee263079..6b98a7c178 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -28,10 +28,12 @@ #include "sd-login.h" #include "cgroup-util.h" +#include "dirent-util.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "hostname-util.h" #include "io-util.h" #include "login-util.h" @@ -43,7 +45,6 @@ #include "strv.h" #include "user-util.h" #include "util.h" -#include "dirent-util.h" /* Error codes: * diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 2fcf4900d3..284ec42138 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -36,6 +36,7 @@ #include "fd-util.h" #include "fileio-label.h" #include "formats-util.h" +#include "fs-util.h" #include "logind.h" #include "mkdir.h" #include "path-util.h" diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 5a7ae11ec1..925190b603 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -32,6 +32,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "hashmap.h" #include "label.h" #include "logind-user.h" diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index c17a98e90f..0003b84dd5 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -38,6 +38,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "in-addr-util.h" #include "local-addresses.h" #include "machine-dbus.h" diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index ac9c31b931..01e9a67d76 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -24,6 +24,7 @@ #include "cgroup-util.h" #include "escape.h" +#include "fs-util.h" #include "label.h" #include "mkdir.h" #include "mount-util.h" diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index c34d52293d..c7ec511cca 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -61,6 +61,7 @@ #include "fdset.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "gpt.h" #include "hostname-util.h" #include "log.h" diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 8bb33add72..4235e95d92 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -29,6 +29,7 @@ #include "conf-files.h" #include "conf-parser.h" #include "fd-util.h" +#include "fs-util.h" #include "log.h" #include "macro.h" #include "parse-util.h" diff --git a/src/shared/install.c b/src/shared/install.c index bfafb59008..454fe79aa1 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -29,6 +29,7 @@ #include "conf-parser.h" #include "dirent-util.h" #include "fd-util.h" +#include "fs-util.h" #include "hashmap.h" #include "install-printf.h" #include "install.h" diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index c5444ee010..3f12a67b54 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -28,6 +28,7 @@ #include "copy.h" #include "dirent-util.h" #include "fd-util.h" +#include "fs-util.h" #include "machine-image.h" #include "mkdir.h" #include "path-util.h" diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c index 9270f22479..6be1b7b264 100644 --- a/src/shared/machine-pool.c +++ b/src/shared/machine-pool.c @@ -27,16 +27,17 @@ #include "btrfs-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "lockfile-util.h" #include "machine-pool.h" #include "mkdir.h" +#include "mount-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "signal-util.h" #include "string-util.h" #include "util.h" -#include "mount-util.h" #define VAR_LIB_MACHINES_SIZE_START (1024UL*1024UL*500UL) #define VAR_LIB_MACHINES_FREE_MIN (1024UL*1024UL*750UL) diff --git a/src/system-update-generator/system-update-generator.c b/src/system-update-generator/system-update-generator.c index 794aa1a0c7..6c2f53774d 100644 --- a/src/system-update-generator/system-update-generator.c +++ b/src/system-update-generator/system-update-generator.c @@ -22,6 +22,7 @@ #include #include +#include "fs-util.h" #include "log.h" #include "string-util.h" #include "util.h" diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 77a05ca346..2b1caa6199 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -51,6 +51,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "hostname-util.h" #include "initreq.h" #include "install.h" diff --git a/src/test/test-conf-files.c b/src/test/test-conf-files.c index 30ba5364c4..d00517e929 100644 --- a/src/test/test-conf-files.c +++ b/src/test/test-conf-files.c @@ -23,6 +23,7 @@ #include #include "conf-files.h" +#include "fs-util.h" #include "macro.h" #include "rm-rf.h" #include "string-util.h" diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 1bd50edca2..4ccf729e80 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -22,6 +22,7 @@ #include "copy.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "macro.h" #include "mkdir.h" #include "path-util.h" diff --git a/src/test/test-execute.c b/src/test/test-execute.c index fa6336f1fb..cdbfe6698e 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -19,12 +19,13 @@ #include -#include "unit.h" -#include "manager.h" -#include "util.h" +#include "fs-util.h" #include "macro.h" +#include "manager.h" #include "mkdir.h" #include "rm-rf.h" +#include "unit.h" +#include "util.h" typedef void (*test_function_t)(Manager *m); diff --git a/src/test/test-path.c b/src/test/test-path.c index e9e0bfd41d..405434c1ff 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -20,6 +20,8 @@ #include #include +#include "fd-util.h" +#include "fs-util.h" #include "macro.h" #include "manager.h" #include "mkdir.h" @@ -28,7 +30,6 @@ #include "strv.h" #include "unit.h" #include "util.h" -#include "fd-util.h" typedef void (*test_function_t)(Manager *m); diff --git a/src/test/test-udev.c b/src/test/test-udev.c index 3b9f71e3a2..219d659b41 100644 --- a/src/test/test-udev.c +++ b/src/test/test-udev.c @@ -26,6 +26,7 @@ #include #include +#include "fs-util.h" #include "missing.h" #include "selinux-util.h" #include "signal-util.h" diff --git a/src/test/test-util.c b/src/test/test-util.c index 2e266bb047..d6fe7cd997 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -37,6 +37,7 @@ #include "escape.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "fstab-util.h" #include "hexdecoct.h" #include "io-util.h" diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 6de9e246f6..e97dc97ae1 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -23,21 +23,22 @@ #include #include -#include "sd-messages.h" -#include "sd-event.h" #include "sd-bus.h" +#include "sd-event.h" +#include "sd-messages.h" -#include "util.h" -#include "strv.h" -#include "def.h" -#include "clock-util.h" -#include "path-util.h" -#include "fileio-label.h" -#include "bus-util.h" -#include "bus-error.h" #include "bus-common-errors.h" +#include "bus-error.h" +#include "bus-util.h" +#include "clock-util.h" +#include "def.h" #include "event-util.h" +#include "fileio-label.h" +#include "fs-util.h" +#include "path-util.h" #include "selinux-util.h" +#include "strv.h" +#include "util.h" #define NULL_ADJTIME_UTC "0.0 0 0\n0\nUTC\n" #define NULL_ADJTIME_LOCAL "0.0 0 0\n0\nLOCAL\n" diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index d44cf0a80b..15ca006deb 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -34,6 +34,7 @@ #include "sd-daemon.h" #include "fd-util.h" +#include "fs-util.h" #include "list.h" #include "log.h" #include "missing.h" diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c index 7a0ab18ca0..59d348c356 100644 --- a/src/timesync/timesyncd.c +++ b/src/timesync/timesyncd.c @@ -25,6 +25,7 @@ #include "capability.h" #include "clock-util.h" #include "fd-util.h" +#include "fs-util.h" #include "network-util.h" #include "signal-util.h" #include "timesyncd-conf.h" diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 8cf327a15f..090864becd 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -48,6 +48,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "io-util.h" #include "label.h" #include "log.h" diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 4ed6416ecd..afdeb0a21b 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -26,6 +26,7 @@ #include #include "formats-util.h" +#include "fs-util.h" #include "selinux-util.h" #include "smack-util.h" #include "string-util.h" diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 69aff7b579..87468c43ae 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -24,6 +24,7 @@ #include "conf-files.h" #include "fileio.h" +#include "fs-util.h" #include "hwdb-internal.h" #include "hwdb-util.h" #include "strbuf.h" diff --git a/src/udev/udevd.c b/src/udev/udevd.c index f1fc1cd082..90e1de7b7a 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -50,6 +50,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "hashmap.h" #include "io-util.h" #include "netlink-util.h" -- cgit v1.2.3-54-g00ecf From 8b43440b7ef4b81c69c31de7ff820dc07a780254 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 22:31:05 +0100 Subject: util-lib: move string table stuff into its own string-table.[ch] --- Makefile.am | 2 + src/basic/cgroup-util.c | 1 + src/basic/locale-util.c | 1 + src/basic/log.c | 1 + src/basic/rlimit-util.c | 1 + src/basic/signal-util.c | 1 + src/basic/smack-util.c | 1 + src/basic/socket-util.c | 1 + src/basic/string-table.c | 35 ++++++++++++ src/basic/string-table.h | 88 +++++++++++++++++++++++++++++++ src/basic/unit-name.c | 5 +- src/basic/util.c | 14 +---- src/basic/util.h | 56 -------------------- src/basic/virt.c | 1 + src/bus-proxyd/bus-xml-policy.c | 1 + src/core/automount.c | 1 + src/core/bus-policy.c | 1 + src/core/busname.c | 1 + src/core/cgroup.c | 1 + src/core/execute.c | 1 + src/core/failure-action.c | 5 +- src/core/job.c | 1 + src/core/kill.c | 5 +- src/core/manager.c | 1 + src/core/mount.c | 1 + src/core/namespace.c | 1 + src/core/path.c | 1 + src/core/scope.c | 1 + src/core/service.c | 1 + src/core/show-status.c | 2 + src/core/socket.c | 1 + src/core/swap.c | 1 + src/core/timer.c | 1 + src/import/import-compress.c | 3 +- src/import/importd.c | 1 + src/journal-remote/journal-remote.c | 1 + src/journal/compress.c | 1 + src/journal/coredump.c | 1 + src/journal/journald-server.c | 1 + src/libsystemd-network/sd-dhcp6-client.c | 1 + src/libsystemd/sd-device/device-private.c | 1 + src/libsystemd/sd-netlink/netlink-types.c | 7 ++- src/login/logind-action.c | 11 ++-- src/login/logind-inhibit.c | 1 + src/login/logind-session.c | 1 + src/login/logind-user.c | 1 + src/machine/machine.c | 1 + src/network/networkctl.c | 1 + src/network/networkd-link.c | 1 + src/network/networkd-netdev-bond.c | 3 +- src/network/networkd-netdev-ipvlan.c | 3 +- src/network/networkd-netdev-macvlan.c | 3 +- src/network/networkd-netdev-tunnel.c | 1 + src/network/networkd-netdev.c | 1 + src/network/networkd-network.c | 1 + src/network/networkd-util.c | 1 + src/resolve/resolved-dns-packet.c | 9 ++-- src/resolve/resolved-dns-transaction.c | 1 + src/resolve/resolved-manager.c | 1 + src/rfkill/rfkill.c | 1 + src/shared/architecture.c | 1 + src/shared/condition.c | 1 + src/shared/import-util.c | 1 + src/shared/install.c | 1 + src/shared/logs-show.c | 1 + src/shared/machine-image.c | 1 + src/tmpfiles/tmpfiles.c | 1 + src/udev/net/ethtool-util.c | 8 +-- src/udev/net/link-config.c | 1 + 69 files changed, 215 insertions(+), 96 deletions(-) create mode 100644 src/basic/string-table.c create mode 100644 src/basic/string-table.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index 6f819cb9f2..56715f6351 100644 --- a/Makefile.am +++ b/Makefile.am @@ -823,6 +823,8 @@ libbasic_la_SOURCES = \ src/basic/locale-util.h \ src/basic/signal-util.c \ src/basic/signal-util.h \ + src/basic/string-table.c \ + src/basic/string-table.h \ src/basic/mempool.c \ src/basic/mempool.h \ src/basic/hashmap.c \ diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 84aea8afb8..d416b0b41e 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -44,6 +44,7 @@ #include "process-util.h" #include "set.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "unit-name.h" #include "user-util.h" diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 08da4b98c5..9db906316b 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -26,6 +26,7 @@ #include "locale-util.h" #include "path-util.h" #include "set.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "utf8.h" diff --git a/src/basic/log.c b/src/basic/log.c index 2c0abdc0bd..dcb24cfab7 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -39,6 +39,7 @@ #include "process-util.h" #include "signal-util.h" #include "socket-util.h" +#include "string-table.h" #include "string-util.h" #include "terminal-util.h" #include "util.h" diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c index 7f9d63224d..2627c813fc 100644 --- a/src/basic/rlimit-util.c +++ b/src/basic/rlimit-util.c @@ -21,6 +21,7 @@ #include "missing.h" #include "rlimit-util.h" +#include "string-table.h" #include "util.h" int setrlimit_closest(int resource, const struct rlimit *rlim) { diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index e5ac6317d4..8038bc891d 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -21,6 +21,7 @@ #include "parse-util.h" #include "signal-util.h" +#include "string-table.h" #include "string-util.h" #include "util.h" diff --git a/src/basic/smack-util.c b/src/basic/smack-util.c index 5ada621ca3..a96fb5b594 100644 --- a/src/basic/smack-util.c +++ b/src/basic/smack-util.c @@ -27,6 +27,7 @@ #include "path-util.h" #include "process-util.h" #include "smack-util.h" +#include "string-table.h" #include "util.h" #include "xattr-util.h" diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index c4af6aa941..71a52a840a 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -38,6 +38,7 @@ #include "parse-util.h" #include "path-util.h" #include "socket-util.h" +#include "string-table.h" #include "string-util.h" #include "util.h" diff --git a/src/basic/string-table.c b/src/basic/string-table.c new file mode 100644 index 0000000000..a860324fc9 --- /dev/null +++ b/src/basic/string-table.c @@ -0,0 +1,35 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "string-table.h" + +ssize_t string_table_lookup(const char * const *table, size_t len, const char *key) { + size_t i; + + if (!key) + return -1; + + for (i = 0; i < len; ++i) + if (streq_ptr(table[i], key)) + return (ssize_t) i; + + return -1; +} diff --git a/src/basic/string-table.h b/src/basic/string-table.h new file mode 100644 index 0000000000..51b6007214 --- /dev/null +++ b/src/basic/string-table.h @@ -0,0 +1,88 @@ + +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "macro.h" +#include "parse-util.h" +#include "string-util.h" + +ssize_t string_table_lookup(const char * const *table, size_t len, const char *key); + +/* For basic lookup tables with strictly enumerated entries */ +#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ + scope const char *name##_to_string(type i) { \ + if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \ + return NULL; \ + return name##_table[i]; \ + } + +#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ + scope type name##_from_string(const char *s) { \ + return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \ + } + +#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \ + _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ + _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ + struct __useless_struct_to_allow_trailing_semicolon__ + +#define DEFINE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,static) + +/* For string conversions where numbers are also acceptable */ +#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \ + int name##_to_string_alloc(type i, char **str) { \ + char *s; \ + if (i < 0 || i > max) \ + return -ERANGE; \ + if (i < (type) ELEMENTSOF(name##_table)) { \ + s = strdup(name##_table[i]); \ + if (!s) \ + return -ENOMEM; \ + } else { \ + if (asprintf(&s, "%i", i) < 0) \ + return -ENOMEM; \ + } \ + *str = s; \ + return 0; \ + } \ + type name##_from_string(const char *s) { \ + type i; \ + unsigned u = 0; \ + if (!s) \ + return (type) -1; \ + for (i = 0; i < (type) ELEMENTSOF(name##_table); i++) \ + if (streq_ptr(name##_table[i], s)) \ + return i; \ + if (safe_atou(s, &u) >= 0 && u <= max) \ + return (type) u; \ + return (type) -1; \ + } \ + struct __useless_struct_to_allow_trailing_semicolon__ diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c index c6ba9afb5a..43f52ce7c8 100644 --- a/src/basic/unit-name.c +++ b/src/basic/unit-name.c @@ -24,12 +24,13 @@ #include "bus-label.h" #include "def.h" +#include "hexdecoct.h" #include "path-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" -#include "util.h" #include "unit-name.h" -#include "hexdecoct.h" +#include "util.h" #define VALID_CHARS \ DIGITS LETTERS \ diff --git a/src/basic/util.c b/src/basic/util.c index 30691dea6b..0878adbfac 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -94,6 +94,7 @@ #include "random-util.h" #include "signal-util.h" #include "sparse-endian.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" @@ -1450,19 +1451,6 @@ int syslog_parse_priority(const char **p, int *priority, bool with_facility) { return 1; } -ssize_t string_table_lookup(const char * const *table, size_t len, const char *key) { - size_t i; - - if (!key) - return -1; - - for (i = 0; i < len; ++i) - if (streq_ptr(table[i], key)) - return (ssize_t) i; - - return -1; -} - int version(void) { puts(PACKAGE_STRING "\n" SYSTEMD_FEATURES); diff --git a/src/basic/util.h b/src/basic/util.h index 6c6920c2a4..d18b151d88 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -83,62 +83,6 @@ static inline const char* one_zero(bool b) { return b ? "1" : "0"; } -/* For basic lookup tables with strictly enumerated entries */ -#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ - scope const char *name##_to_string(type i) { \ - if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \ - return NULL; \ - return name##_table[i]; \ - } - -ssize_t string_table_lookup(const char * const *table, size_t len, const char *key); - -#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ - scope type name##_from_string(const char *s) { \ - return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \ - } - -#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \ - _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ - _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ - struct __useless_struct_to_allow_trailing_semicolon__ - -#define DEFINE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,static) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,static) - -/* For string conversions where numbers are also acceptable */ -#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \ - int name##_to_string_alloc(type i, char **str) { \ - char *s; \ - if (i < 0 || i > max) \ - return -ERANGE; \ - if (i < (type) ELEMENTSOF(name##_table)) { \ - s = strdup(name##_table[i]); \ - if (!s) \ - return -ENOMEM; \ - } else { \ - if (asprintf(&s, "%i", i) < 0) \ - return -ENOMEM; \ - } \ - *str = s; \ - return 0; \ - } \ - type name##_from_string(const char *s) { \ - type i; \ - unsigned u = 0; \ - if (!s) \ - return (type) -1; \ - for (i = 0; i < (type) ELEMENTSOF(name##_table); i++) \ - if (streq_ptr(name##_table[i], s)) \ - return i; \ - if (safe_atou(s, &u) >= 0 && u <= max) \ - return (type) u; \ - return (type) -1; \ - } \ - struct __useless_struct_to_allow_trailing_semicolon__ - bool fstype_is_network(const char *fstype); #define xsprintf(buf, fmt, ...) \ diff --git a/src/basic/virt.c b/src/basic/virt.c index 9267a2730b..9076cf618f 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -25,6 +25,7 @@ #include "fileio.h" #include "process-util.h" +#include "string-table.h" #include "string-util.h" #include "util.h" #include "virt.h" diff --git a/src/bus-proxyd/bus-xml-policy.c b/src/bus-proxyd/bus-xml-policy.c index 56dcfeab62..cf922ef02f 100644 --- a/src/bus-proxyd/bus-xml-policy.c +++ b/src/bus-proxyd/bus-xml-policy.c @@ -27,6 +27,7 @@ #include "fileio.h" #include "formats-util.h" #include "set.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "user-util.h" diff --git a/src/core/automount.c b/src/core/automount.c index 00911118e6..379f71f74a 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -45,6 +45,7 @@ #include "path-util.h" #include "process-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "unit-name.h" #include "unit.h" diff --git a/src/core/bus-policy.c b/src/core/bus-policy.c index 2490903a8c..7ad18fb28c 100644 --- a/src/core/bus-policy.c +++ b/src/core/bus-policy.c @@ -22,6 +22,7 @@ #include "bus-kernel.h" #include "bus-policy.h" #include "kdbus.h" +#include "string-table.h" #include "user-util.h" #include "util.h" diff --git a/src/core/busname.c b/src/core/busname.c index df4a8bef52..94674c99fa 100644 --- a/src/core/busname.c +++ b/src/core/busname.c @@ -34,6 +34,7 @@ #include "service.h" #include "signal-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" static const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = { diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 6ef0580fad..0d37e69cd9 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -30,6 +30,7 @@ #include "path-util.h" #include "process-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #define CGROUP_CPU_QUOTA_PERIOD_USEC ((usec_t) 100 * USEC_PER_MSEC) diff --git a/src/core/execute.c b/src/core/execute.c index a9564386ba..f354216325 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -89,6 +89,7 @@ #include "selinux-util.h" #include "signal-util.h" #include "smack-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" diff --git a/src/core/failure-action.c b/src/core/failure-action.c index 3412accf3e..c7c95984b7 100644 --- a/src/core/failure-action.c +++ b/src/core/failure-action.c @@ -23,10 +23,11 @@ #include #include -#include "bus-util.h" #include "bus-error.h" -#include "special.h" +#include "bus-util.h" #include "failure-action.h" +#include "special.h" +#include "string-table.h" #include "terminal-util.h" static void log_and_status(Manager *m, const char *message) { diff --git a/src/core/job.c b/src/core/job.c index 7fde88f5fe..44532d0d5a 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -34,6 +34,7 @@ #include "parse-util.h" #include "set.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" diff --git a/src/core/kill.c b/src/core/kill.c index bddfa4460f..1466d5ce64 100644 --- a/src/core/kill.c +++ b/src/core/kill.c @@ -19,9 +19,10 @@ along with systemd; If not, see . ***/ -#include "util.h" -#include "signal-util.h" #include "kill.h" +#include "signal-util.h" +#include "string-table.h" +#include "util.h" void kill_context_init(KillContext *c) { assert(c); diff --git a/src/core/manager.c b/src/core/manager.c index 51e8b0566f..83068af77e 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -73,6 +73,7 @@ #include "signal-util.h" #include "special.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" diff --git a/src/core/mount.c b/src/core/mount.c index 9d8b55da58..f04f386930 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -41,6 +41,7 @@ #include "smack-util.h" #include "special.h" #include "string-util.h" +#include "string-table.h" #include "strv.h" #include "unit-name.h" #include "unit.h" diff --git a/src/core/namespace.c b/src/core/namespace.c index e6c381800b..ec7180ebdc 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -38,6 +38,7 @@ #include "path-util.h" #include "selinux-util.h" #include "socket-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "util.h" diff --git a/src/core/path.c b/src/core/path.c index efd97d44eb..761ec265b4 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -33,6 +33,7 @@ #include "path.h" #include "special.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "unit-name.h" #include "unit.h" diff --git a/src/core/scope.c b/src/core/scope.c index 9f72851382..13de02cf16 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -26,6 +26,7 @@ #include "load-dropin.h" #include "log.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" diff --git a/src/core/service.c b/src/core/service.c index bb77f4502d..54a420d6f0 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -46,6 +46,7 @@ #include "service.h" #include "signal-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" diff --git a/src/core/show-status.c b/src/core/show-status.c index 9e4c9f563e..9509b21ccb 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -19,9 +19,11 @@ along with systemd; If not, see . ***/ +#include "fd-util.h" #include "parse-util.h" #include "show-status.h" #include "string-util.h" +#include "terminal-util.h" #include "util.h" int parse_show_status(const char *v, ShowStatus *ret) { diff --git a/src/core/socket.c b/src/core/socket.c index 8ea7bd9af4..c145aa6081 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -50,6 +50,7 @@ #include "smack-util.h" #include "socket.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" diff --git a/src/core/swap.c b/src/core/swap.c index c4151c6afd..cb2da1cb5c 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -35,6 +35,7 @@ #include "parse-util.h" #include "path-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "swap.h" #include "udev-util.h" diff --git a/src/core/timer.c b/src/core/timer.c index 26d94eb521..47e501815a 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -27,6 +27,7 @@ #include "fs-util.h" #include "parse-util.h" #include "special.h" +#include "string-table.h" #include "string-util.h" #include "timer.h" #include "unit-name.h" diff --git a/src/import/import-compress.c b/src/import/import-compress.c index d6b8133036..d4ff178f60 100644 --- a/src/import/import-compress.c +++ b/src/import/import-compress.c @@ -19,8 +19,9 @@ along with systemd; If not, see . ***/ -#include "util.h" #include "import-compress.h" +#include "string-table.h" +#include "util.h" void import_compress_free(ImportCompress *c) { assert(c); diff --git a/src/import/importd.c b/src/import/importd.c index 975907e3c9..2a03507d3a 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -37,6 +37,7 @@ #include "process-util.h" #include "signal-util.h" #include "socket-util.h" +#include "string-table.h" #include "strv.h" #include "util.h" diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index b53b2abd76..dc87b21020 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -48,6 +48,7 @@ #include "signal-util.h" #include "socket-util.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" diff --git a/src/journal/compress.c b/src/journal/compress.c index 9308e8b789..196d6ff425 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -39,6 +39,7 @@ #include "journal-def.h" #include "macro.h" #include "sparse-endian.h" +#include "string-table.h" #include "string-util.h" #include "util.h" diff --git a/src/journal/coredump.c b/src/journal/coredump.c index 1756a823a9..257a665819 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -53,6 +53,7 @@ #include "process-util.h" #include "special.h" #include "stacktrace.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "user-util.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index a474293a87..ab213f705d 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -62,6 +62,7 @@ #include "selinux-util.h" #include "signal-util.h" #include "socket-util.h" +#include "string-table.h" #include "string-util.h" #define USER_JOURNALS_MAX 1024 diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index ade1b470d4..559c5e4df4 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -33,6 +33,7 @@ #include "fd-util.h" #include "network-internal.h" #include "random-util.h" +#include "string-table.h" #include "util.h" #define MAX_MAC_ADDR_LEN INFINIBAND_ALEN diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index da325c9d28..daed321bd8 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -37,6 +37,7 @@ #include "path-util.h" #include "refcnt.h" #include "set.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "strxcpyx.h" diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c index 4a5340e659..cf0a6248d6 100644 --- a/src/libsystemd/sd-netlink/netlink-types.c +++ b/src/libsystemd/sd-netlink/netlink-types.c @@ -28,16 +28,15 @@ #include #include #include - #include #include #include #include "macro.h" -#include "util.h" - -#include "netlink-types.h" #include "missing.h" +#include "netlink-types.h" +#include "string-table.h" +#include "util.h" /* Maximum ARP IP target defined in kernel */ #define BOND_MAX_ARP_TARGETS 16 diff --git a/src/login/logind-action.c b/src/login/logind-action.c index f06f8edc07..8c452456a0 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -21,14 +21,15 @@ #include -#include "conf-parser.h" -#include "special.h" -#include "sleep-config.h" -#include "bus-util.h" #include "bus-error.h" -#include "logind-action.h" +#include "bus-util.h" +#include "conf-parser.h" #include "formats-util.h" +#include "logind-action.h" #include "process-util.h" +#include "sleep-config.h" +#include "special.h" +#include "string-table.h" #include "terminal-util.h" #include "user-util.h" diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 460c2f0bd8..92b5807094 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -31,6 +31,7 @@ #include "logind-inhibit.h" #include "mkdir.h" #include "parse-util.h" +#include "string-table.h" #include "string-util.h" #include "user-util.h" #include "util.h" diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 9651d3e24a..829b614509 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -43,6 +43,7 @@ #include "mkdir.h" #include "parse-util.h" #include "path-util.h" +#include "string-table.h" #include "terminal-util.h" #include "user-util.h" #include "util.h" diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 925190b603..9692a86709 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -43,6 +43,7 @@ #include "rm-rf.h" #include "smack-util.h" #include "special.h" +#include "string-table.h" #include "unit-name.h" #include "util.h" diff --git a/src/machine/machine.c b/src/machine/machine.c index 7aff55b761..2889cb3205 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -37,6 +37,7 @@ #include "mkdir.h" #include "parse-util.h" #include "special.h" +#include "string-table.h" #include "terminal-util.h" #include "unit-name.h" #include "util.h" diff --git a/src/network/networkctl.c b/src/network/networkctl.c index be679acca0..6ea9563fcf 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -39,6 +39,7 @@ #include "parse-util.h" #include "socket-util.h" #include "string-util.h" +#include "string-table.h" #include "strv.h" #include "terminal-util.h" #include "util.h" diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 1144c82c17..de49fd5c22 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -33,6 +33,7 @@ #include "networkd-netdev.h" #include "set.h" #include "socket-util.h" +#include "string-table.h" #include "udev-util.h" #include "util.h" #include "virt.h" diff --git a/src/network/networkd-netdev-bond.c b/src/network/networkd-netdev-bond.c index afc1efdcf7..ce9c18d654 100644 --- a/src/network/networkd-netdev-bond.c +++ b/src/network/networkd-netdev-bond.c @@ -27,8 +27,9 @@ #include "conf-parser.h" #include "missing.h" -#include "string-util.h" #include "networkd-netdev-bond.h" +#include "string-util.h" +#include "string-table.h" /* * Number of seconds between instances where the bonding diff --git a/src/network/networkd-netdev-ipvlan.c b/src/network/networkd-netdev-ipvlan.c index fb0aed0dcb..27cb7d1bf0 100644 --- a/src/network/networkd-netdev-ipvlan.c +++ b/src/network/networkd-netdev-ipvlan.c @@ -21,8 +21,9 @@ #include -#include "networkd-netdev-ipvlan.h" #include "conf-parser.h" +#include "networkd-netdev-ipvlan.h" +#include "string-table.h" static const char* const ipvlan_mode_table[_NETDEV_IPVLAN_MODE_MAX] = { [NETDEV_IPVLAN_MODE_L2] = "L2", diff --git a/src/network/networkd-netdev-macvlan.c b/src/network/networkd-netdev-macvlan.c index e17de793ce..7144823b2d 100644 --- a/src/network/networkd-netdev-macvlan.c +++ b/src/network/networkd-netdev-macvlan.c @@ -21,8 +21,9 @@ #include -#include "networkd-netdev-macvlan.h" #include "conf-parser.h" +#include "networkd-netdev-macvlan.h" +#include "string-table.h" static const char* const macvlan_mode_table[_NETDEV_MACVLAN_MODE_MAX] = { [NETDEV_MACVLAN_MODE_PRIVATE] = "private", diff --git a/src/network/networkd-netdev-tunnel.c b/src/network/networkd-netdev-tunnel.c index 2dd16be381..385338849f 100644 --- a/src/network/networkd-netdev-tunnel.c +++ b/src/network/networkd-netdev-tunnel.c @@ -32,6 +32,7 @@ #include "networkd-link.h" #include "networkd-netdev-tunnel.h" #include "parse-util.h" +#include "string-table.h" #include "string-util.h" #include "util.h" diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index 0ed52a8d68..5060888a2f 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -31,6 +31,7 @@ #include "networkd.h" #include "siphash24.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = { diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index eeb03df517..c8c6f5df11 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -32,6 +32,7 @@ #include "networkd.h" #include "parse-util.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "util.h" diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c index 3ada0ce32b..17165266ef 100644 --- a/src/network/networkd-util.c +++ b/src/network/networkd-util.c @@ -22,6 +22,7 @@ #include "conf-parser.h" #include "networkd-util.h" #include "parse-util.h" +#include "string-table.h" #include "string-util.h" #include "util.h" diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index bebd1ee4a6..f7f936d343 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -19,12 +19,13 @@ along with systemd; If not, see . ***/ -#include "utf8.h" -#include "util.h" -#include "strv.h" -#include "unaligned.h" #include "dns-domain.h" #include "resolved-dns-packet.h" +#include "string-table.h" +#include "strv.h" +#include "unaligned.h" +#include "utf8.h" +#include "util.h" int dns_packet_new(DnsPacket **ret, DnsProtocol protocol, size_t mtu) { DnsPacket *p; diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 84472ca1bc..1e38547e23 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -26,6 +26,7 @@ #include "random-util.h" #include "resolved-dns-transaction.h" #include "resolved-llmnr.h" +#include "string-table.h" DnsTransaction* dns_transaction_free(DnsTransaction *t) { DnsQuery *q; diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index a6aac196db..b9c625b9cf 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -40,6 +40,7 @@ #include "resolved-llmnr.h" #include "resolved-manager.h" #include "socket-util.h" +#include "string-table.h" #include "string-util.h" #include "utf8.h" diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index 559a176535..c08b746f2c 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -31,6 +31,7 @@ #include "io-util.h" #include "mkdir.h" #include "parse-util.h" +#include "string-table.h" #include "string-util.h" #include "udev-util.h" #include "util.h" diff --git a/src/shared/architecture.c b/src/shared/architecture.c index e5efcd77b6..e2efa4272b 100644 --- a/src/shared/architecture.c +++ b/src/shared/architecture.c @@ -21,6 +21,7 @@ #include +#include "string-table.h" #include "string-util.h" #include "architecture.h" diff --git a/src/shared/condition.c b/src/shared/condition.c index 1c4c9419d0..a79a74eaa5 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -42,6 +42,7 @@ #include "selinux-util.h" #include "smack-util.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "util.h" #include "virt.h" diff --git a/src/shared/import-util.c b/src/shared/import-util.c index b50e86b944..bf5395dee8 100644 --- a/src/shared/import-util.c +++ b/src/shared/import-util.c @@ -22,6 +22,7 @@ #include "btrfs-util.h" #include "import-util.h" #include "path-util.h" +#include "string-table.h" #include "string-util.h" #include "util.h" diff --git a/src/shared/install.c b/src/shared/install.c index df381358f8..1f63ae9ce0 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -39,6 +39,7 @@ #include "set.h" #include "special.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 3519323b7a..5b4a220e5f 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -35,6 +35,7 @@ #include "logs-show.h" #include "parse-util.h" #include "process-util.h" +#include "string-table.h" #include "string-util.h" #include "terminal-util.h" #include "utf8.h" diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 3f12a67b54..a4e77fb8d8 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -33,6 +33,7 @@ #include "mkdir.h" #include "path-util.h" #include "rm-rf.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "utf8.h" diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 3b9fdf4378..9440ce7bb6 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -62,6 +62,7 @@ #include "set.h" #include "specifier.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "user-util.h" diff --git a/src/udev/net/ethtool-util.c b/src/udev/net/ethtool-util.c index a4b05d1bec..0647008d90 100644 --- a/src/udev/net/ethtool-util.c +++ b/src/udev/net/ethtool-util.c @@ -19,17 +19,17 @@ along with systemd; If not, see . ***/ -#include #include +#include #include #include +#include "conf-parser.h" #include "ethtool-util.h" - +#include "log.h" +#include "string-table.h" #include "strxcpyx.h" #include "util.h" -#include "log.h" -#include "conf-parser.h" static const char* const duplex_table[_DUP_MAX] = { [DUP_FULL] = "full", diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index b4807dc0f7..db4fe0c855 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -38,6 +38,7 @@ #include "path-util.h" #include "random-util.h" #include "stat-util.h" +#include "string-table.h" #include "string-util.h" #include "strv.h" #include "util.h" -- cgit v1.2.3-54-g00ecf From 8752c5752f3b9023f9ce96a55d70c6e5fc31118f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 23:01:30 +0100 Subject: util-lib: move more locale-related calls to locale-util.[ch] --- src/analyze/analyze.c | 1 + src/basic/locale-util.c | 84 ++++++++++++++++++++++++++++++++++ src/basic/locale-util.h | 21 +++++++++ src/basic/util.c | 77 ------------------------------- src/basic/util.h | 19 -------- src/boot/bootctl.c | 1 + src/bus-proxyd/bus-xml-policy.c | 1 + src/core/dbus-unit.c | 3 +- src/delta/delta.c | 1 + src/journal/journalctl.c | 1 + src/libsystemd/sd-bus/bus-dump.c | 1 + src/libsystemd/sd-bus/busctl.c | 1 + src/login/sysfs-show.c | 1 + src/network/networkctl.c | 4 +- src/resolve/resolved-dns-transaction.c | 1 - src/shared/cgroup-show.c | 1 + src/shared/pager.c | 1 + src/systemctl/systemctl.c | 1 + src/vconsole/vconsole-setup.c | 1 + 19 files changed, 122 insertions(+), 99 deletions(-) (limited to 'src/journal') diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 6ba16d8b65..a165152cb2 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -31,6 +31,7 @@ #include "bus-error.h" #include "bus-util.h" #include "hashmap.h" +#include "locale-util.h" #include "log.h" #include "pager.h" #include "parse-util.h" diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index 9db906316b..b87fd7670b 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -19,6 +19,8 @@ along with systemd; If not, see . ***/ +#include +#include #include #include "dirent-util.h" @@ -208,6 +210,88 @@ bool locale_is_valid(const char *name) { return true; } +void init_gettext(void) { + setlocale(LC_ALL, ""); + textdomain(GETTEXT_PACKAGE); +} + +bool is_locale_utf8(void) { + const char *set; + static int cached_answer = -1; + + /* Note that we default to 'true' here, since today UTF8 is + * pretty much supported everywhere. */ + + if (cached_answer >= 0) + goto out; + + if (!setlocale(LC_ALL, "")) { + cached_answer = true; + goto out; + } + + set = nl_langinfo(CODESET); + if (!set) { + cached_answer = true; + goto out; + } + + if (streq(set, "UTF-8")) { + cached_answer = true; + goto out; + } + + /* For LC_CTYPE=="C" return true, because CTYPE is effectly + * unset and everything can do to UTF-8 nowadays. */ + set = setlocale(LC_CTYPE, NULL); + if (!set) { + cached_answer = true; + goto out; + } + + /* Check result, but ignore the result if C was set + * explicitly. */ + cached_answer = + STR_IN_SET(set, "C", "POSIX") && + !getenv("LC_ALL") && + !getenv("LC_CTYPE") && + !getenv("LANG"); + +out: + return (bool) cached_answer; +} + + +const char *draw_special_char(DrawSpecialChar ch) { + + static const char *draw_table[2][_DRAW_SPECIAL_CHAR_MAX] = { + + /* UTF-8 */ { + [DRAW_TREE_VERTICAL] = "\342\224\202 ", /* │ */ + [DRAW_TREE_BRANCH] = "\342\224\234\342\224\200", /* ├─ */ + [DRAW_TREE_RIGHT] = "\342\224\224\342\224\200", /* └─ */ + [DRAW_TREE_SPACE] = " ", /* */ + [DRAW_TRIANGULAR_BULLET] = "\342\200\243", /* ‣ */ + [DRAW_BLACK_CIRCLE] = "\342\227\217", /* ● */ + [DRAW_ARROW] = "\342\206\222", /* → */ + [DRAW_DASH] = "\342\200\223", /* – */ + }, + + /* ASCII fallback */ { + [DRAW_TREE_VERTICAL] = "| ", + [DRAW_TREE_BRANCH] = "|-", + [DRAW_TREE_RIGHT] = "`-", + [DRAW_TREE_SPACE] = " ", + [DRAW_TRIANGULAR_BULLET] = ">", + [DRAW_BLACK_CIRCLE] = "*", + [DRAW_ARROW] = "->", + [DRAW_DASH] = "-", + } + }; + + return draw_table[!is_locale_utf8()][ch]; +} + static const char * const locale_variable_table[_VARIABLE_LC_MAX] = { [VARIABLE_LANG] = "LANG", [VARIABLE_LANGUAGE] = "LANGUAGE", diff --git a/src/basic/locale-util.h b/src/basic/locale-util.h index e48aa3d9af..c71d145139 100644 --- a/src/basic/locale-util.h +++ b/src/basic/locale-util.h @@ -21,6 +21,7 @@ along with systemd; If not, see . ***/ +#include #include #include "macro.h" @@ -50,5 +51,25 @@ typedef enum LocaleVariable { int get_locales(char ***l); bool locale_is_valid(const char *name); +#define _(String) gettext(String) +#define N_(String) String +void init_gettext(void); + +bool is_locale_utf8(void); + +typedef enum DrawSpecialChar { + DRAW_TREE_VERTICAL, + DRAW_TREE_BRANCH, + DRAW_TREE_RIGHT, + DRAW_TREE_SPACE, + DRAW_TRIANGULAR_BULLET, + DRAW_BLACK_CIRCLE, + DRAW_ARROW, + DRAW_DASH, + _DRAW_SPECIAL_CHAR_MAX +} DrawSpecialChar; + +const char *draw_special_char(DrawSpecialChar ch); + const char* locale_variable_to_string(LocaleVariable i) _const_; LocaleVariable locale_variable_from_string(const char *s) _pure_; diff --git a/src/basic/util.c b/src/basic/util.c index 0878adbfac..b079e8af16 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -810,83 +810,6 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, return NULL; } -void init_gettext(void) { - setlocale(LC_ALL, ""); - textdomain(GETTEXT_PACKAGE); -} - -bool is_locale_utf8(void) { - const char *set; - static int cached_answer = -1; - - if (cached_answer >= 0) - goto out; - - if (!setlocale(LC_ALL, "")) { - cached_answer = true; - goto out; - } - - set = nl_langinfo(CODESET); - if (!set) { - cached_answer = true; - goto out; - } - - if (streq(set, "UTF-8")) { - cached_answer = true; - goto out; - } - - /* For LC_CTYPE=="C" return true, because CTYPE is effectly - * unset and everything can do to UTF-8 nowadays. */ - set = setlocale(LC_CTYPE, NULL); - if (!set) { - cached_answer = true; - goto out; - } - - /* Check result, but ignore the result if C was set - * explicitly. */ - cached_answer = - STR_IN_SET(set, "C", "POSIX") && - !getenv("LC_ALL") && - !getenv("LC_CTYPE") && - !getenv("LANG"); - -out: - return (bool) cached_answer; -} - -const char *draw_special_char(DrawSpecialChar ch) { - static const char *draw_table[2][_DRAW_SPECIAL_CHAR_MAX] = { - - /* UTF-8 */ { - [DRAW_TREE_VERTICAL] = "\342\224\202 ", /* │ */ - [DRAW_TREE_BRANCH] = "\342\224\234\342\224\200", /* ├─ */ - [DRAW_TREE_RIGHT] = "\342\224\224\342\224\200", /* └─ */ - [DRAW_TREE_SPACE] = " ", /* */ - [DRAW_TRIANGULAR_BULLET] = "\342\200\243", /* ‣ */ - [DRAW_BLACK_CIRCLE] = "\342\227\217", /* ● */ - [DRAW_ARROW] = "\342\206\222", /* → */ - [DRAW_DASH] = "\342\200\223", /* – */ - }, - - /* ASCII fallback */ { - [DRAW_TREE_VERTICAL] = "| ", - [DRAW_TREE_BRANCH] = "|-", - [DRAW_TREE_RIGHT] = "`-", - [DRAW_TREE_SPACE] = " ", - [DRAW_TRIANGULAR_BULLET] = ">", - [DRAW_BLACK_CIRCLE] = "*", - [DRAW_ARROW] = "->", - [DRAW_DASH] = "-", - } - }; - - return draw_table[!is_locale_utf8()][ch]; -} - int on_ac_power(void) { bool found_offline = false, found_online = false; _cleanup_closedir_ DIR *d = NULL; diff --git a/src/basic/util.h b/src/basic/util.h index d18b151d88..680317909d 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -192,25 +192,6 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); -#define _(String) gettext (String) -#define N_(String) String -void init_gettext(void); -bool is_locale_utf8(void); - -typedef enum DrawSpecialChar { - DRAW_TREE_VERTICAL, - DRAW_TREE_BRANCH, - DRAW_TREE_RIGHT, - DRAW_TREE_SPACE, - DRAW_TRIANGULAR_BULLET, - DRAW_BLACK_CIRCLE, - DRAW_ARROW, - DRAW_DASH, - _DRAW_SPECIAL_CHAR_MAX -} DrawSpecialChar; - -const char *draw_special_char(DrawSpecialChar ch); - int on_ac_power(void); static inline void *mempset(void *s, int c, size_t n) { diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index 7e06abd3bf..332bb33545 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -41,6 +41,7 @@ #include "efivars.h" #include "fd-util.h" #include "fileio.h" +#include "locale-util.h" #include "rm-rf.h" #include "string-util.h" #include "util.h" diff --git a/src/bus-proxyd/bus-xml-policy.c b/src/bus-proxyd/bus-xml-policy.c index cf922ef02f..1b9fdedca3 100644 --- a/src/bus-proxyd/bus-xml-policy.c +++ b/src/bus-proxyd/bus-xml-policy.c @@ -26,6 +26,7 @@ #include "conf-files.h" #include "fileio.h" #include "formats-util.h" +#include "locale-util.h" #include "set.h" #include "string-table.h" #include "string-util.h" diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 7220fe688f..62086a7fde 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -23,13 +23,14 @@ #include "bus-common-errors.h" #include "cgroup-util.h" +#include "dbus-unit.h" #include "dbus.h" +#include "locale-util.h" #include "log.h" #include "selinux-access.h" #include "special.h" #include "string-util.h" #include "strv.h" -#include "dbus-unit.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_load_state, unit_load_state, UnitLoadState); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_job_mode, job_mode, JobMode); diff --git a/src/delta/delta.c b/src/delta/delta.c index e5e0be476f..4ade23ffab 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -30,6 +30,7 @@ #include "fd-util.h" #include "fs-util.h" #include "hashmap.h" +#include "locale-util.h" #include "log.h" #include "pager.h" #include "parse-util.h" diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 61d502f0a1..8b8c50b436 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -54,6 +54,7 @@ #include "journal-qrcode.h" #include "journal-vacuum.h" #include "journal-verify.h" +#include "locale-util.h" #include "log.h" #include "logs-show.h" #include "mkdir.h" diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c index 9ddd059072..02c9ff8f2f 100644 --- a/src/libsystemd/sd-bus/bus-dump.c +++ b/src/libsystemd/sd-bus/bus-dump.c @@ -27,6 +27,7 @@ #include "capability.h" #include "fileio.h" #include "formats-util.h" +#include "locale-util.h" #include "macro.h" #include "string-util.h" #include "strv.h" diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c index 4b121e849a..4fa60bb185 100644 --- a/src/libsystemd/sd-bus/busctl.c +++ b/src/libsystemd/sd-bus/busctl.c @@ -31,6 +31,7 @@ #include "busctl-introspect.h" #include "escape.h" #include "fd-util.h" +#include "locale-util.h" #include "log.h" #include "pager.h" #include "parse-util.h" diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index 32e53c0a11..0f671ac90e 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -24,6 +24,7 @@ #include "libudev.h" +#include "locale-util.h" #include "path-util.h" #include "string-util.h" #include "sysfs-show.h" diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 6ea9563fcf..d0d7669c87 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -34,12 +34,14 @@ #include "hwdb-util.h" #include "lldp.h" #include "local-addresses.h" +#include "locale-util.h" +#include "locale-util.h" #include "netlink-util.h" #include "pager.h" #include "parse-util.h" #include "socket-util.h" -#include "string-util.h" #include "string-table.h" +#include "string-util.h" #include "strv.h" #include "terminal-util.h" #include "util.h" diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 1e38547e23..c60197cf8d 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -20,7 +20,6 @@ ***/ #include "af-list.h" - #include "dns-domain.h" #include "fd-util.h" #include "random-util.h" diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index 395e41930c..9e70713ce8 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -28,6 +28,7 @@ #include "cgroup-util.h" #include "fd-util.h" #include "formats-util.h" +#include "locale-util.h" #include "macro.h" #include "path-util.h" #include "process-util.h" diff --git a/src/shared/pager.c b/src/shared/pager.c index 7029d6b2e2..d149bc1722 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -27,6 +27,7 @@ #include "copy.h" #include "fd-util.h" +#include "locale-util.h" #include "macro.h" #include "pager.h" #include "process-util.h" diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 9156760027..48d17cb52a 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -57,6 +57,7 @@ #include "install.h" #include "io-util.h" #include "list.h" +#include "locale-util.h" #include "log.h" #include "logs-show.h" #include "macro.h" diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 49523a0a67..2da28f8be0 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -34,6 +34,7 @@ #include "fd-util.h" #include "fileio.h" #include "io-util.h" +#include "locale-util.h" #include "log.h" #include "process-util.h" #include "signal-util.h" -- cgit v1.2.3-54-g00ecf From 430f0182b72373145c839dbfe99d2382855cb8f8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 26 Oct 2015 23:32:16 +0100 Subject: src/basic: rename audit.[ch] → audit-util.[ch] and capability.[ch] → capability-util.[ch] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The files are named too generically, so that they might conflict with the upstream project headers. Hence, let's add a "-util" suffix, to clarify that this are just our utility headers and not any official upstream headers. --- Makefile.am | 8 +- src/basic/audit-util.c | 104 ++++++++++++ src/basic/audit-util.h | 33 ++++ src/basic/audit.c | 104 ------------ src/basic/audit.h | 33 ---- src/basic/capability-util.c | 308 ++++++++++++++++++++++++++++++++++++ src/basic/capability-util.h | 45 ++++++ src/basic/capability.c | 308 ------------------------------------ src/basic/capability.h | 45 ------ src/bus-proxyd/bus-proxyd.c | 2 +- src/core/dbus-execute.c | 2 +- src/core/execute.c | 2 +- src/core/kmod-setup.c | 2 +- src/core/main.c | 2 +- src/import/import-common.c | 2 +- src/import/pull-common.c | 2 +- src/journal/coredump.c | 2 +- src/journal/journald-server.c | 1 + src/journal/journald-server.h | 4 +- src/libsystemd/sd-bus/bus-control.c | 2 +- src/libsystemd/sd-bus/bus-creds.c | 4 +- src/libsystemd/sd-bus/bus-dump.c | 2 +- src/libsystemd/sd-bus/bus-kernel.c | 2 +- src/login/logind-dbus.c | 2 +- src/login/logind-session.c | 2 +- src/login/logind-utmp.c | 2 +- src/login/pam_systemd.c | 2 +- src/network/networkd.c | 2 +- src/nspawn/nspawn.c | 2 +- src/resolve/resolved.c | 2 +- src/shared/condition.c | 2 +- src/test/test-cap-list.c | 2 +- src/test/test-capability.c | 2 +- src/test/test-condition.c | 2 +- src/timesync/timesyncd.c | 2 +- src/tmpfiles/tmpfiles.c | 2 +- 36 files changed, 523 insertions(+), 522 deletions(-) create mode 100644 src/basic/audit-util.c create mode 100644 src/basic/audit-util.h delete mode 100644 src/basic/audit.c delete mode 100644 src/basic/audit.h create mode 100644 src/basic/capability-util.c create mode 100644 src/basic/capability-util.h delete mode 100644 src/basic/capability.c delete mode 100644 src/basic/capability.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index dada6cd85f..d435141492 100644 --- a/Makefile.am +++ b/Makefile.am @@ -762,8 +762,8 @@ noinst_LTLIBRARIES += \ libbasic_la_SOURCES = \ src/basic/missing.h \ - src/basic/capability.c \ - src/basic/capability.h \ + src/basic/capability-util.c \ + src/basic/capability-util.h \ src/basic/conf-files.c \ src/basic/conf-files.h \ src/basic/hostname-util.h \ @@ -898,8 +898,8 @@ libbasic_la_SOURCES = \ src/basic/login-util.c \ src/basic/cap-list.c \ src/basic/cap-list.h \ - src/basic/audit.c \ - src/basic/audit.h \ + src/basic/audit-util.c \ + src/basic/audit-util.h \ src/basic/xml.c \ src/basic/xml.h \ src/basic/json.c \ diff --git a/src/basic/audit-util.c b/src/basic/audit-util.c new file mode 100644 index 0000000000..93d1adaf99 --- /dev/null +++ b/src/basic/audit-util.c @@ -0,0 +1,104 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "audit-util.h" +#include "fd-util.h" +#include "fileio.h" +#include "macro.h" +#include "parse-util.h" +#include "process-util.h" +#include "user-util.h" +#include "util.h" + +int audit_session_from_pid(pid_t pid, uint32_t *id) { + _cleanup_free_ char *s = NULL; + const char *p; + uint32_t u; + int r; + + assert(id); + + /* We don't convert ENOENT to ESRCH here, since we can't + * really distuingish between "audit is not available in the + * kernel" and "the process does not exist", both which will + * result in ENOENT. */ + + p = procfs_file_alloca(pid, "sessionid"); + + r = read_one_line_file(p, &s); + if (r < 0) + return r; + + r = safe_atou32(s, &u); + if (r < 0) + return r; + + if (u == AUDIT_SESSION_INVALID || u <= 0) + return -ENODATA; + + *id = u; + return 0; +} + +int audit_loginuid_from_pid(pid_t pid, uid_t *uid) { + _cleanup_free_ char *s = NULL; + const char *p; + uid_t u; + int r; + + assert(uid); + + p = procfs_file_alloca(pid, "loginuid"); + + r = read_one_line_file(p, &s); + if (r < 0) + return r; + + r = parse_uid(s, &u); + if (r == -ENXIO) /* the UID was -1 */ + return -ENODATA; + if (r < 0) + return r; + + *uid = (uid_t) u; + return 0; +} + +bool use_audit(void) { + static int cached_use = -1; + + if (cached_use < 0) { + int fd; + + fd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_AUDIT); + if (fd < 0) + cached_use = errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT; + else { + cached_use = true; + safe_close(fd); + } + } + + return cached_use; +} diff --git a/src/basic/audit-util.h b/src/basic/audit-util.h new file mode 100644 index 0000000000..6de331c73e --- /dev/null +++ b/src/basic/audit-util.h @@ -0,0 +1,33 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 + +#define AUDIT_SESSION_INVALID ((uint32_t) -1) + +int audit_session_from_pid(pid_t pid, uint32_t *id); +int audit_loginuid_from_pid(pid_t pid, uid_t *uid); + +bool use_audit(void); diff --git a/src/basic/audit.c b/src/basic/audit.c deleted file mode 100644 index 4957fc1bec..0000000000 --- a/src/basic/audit.c +++ /dev/null @@ -1,104 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2010 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 "audit.h" -#include "fd-util.h" -#include "fileio.h" -#include "macro.h" -#include "parse-util.h" -#include "process-util.h" -#include "user-util.h" -#include "util.h" - -int audit_session_from_pid(pid_t pid, uint32_t *id) { - _cleanup_free_ char *s = NULL; - const char *p; - uint32_t u; - int r; - - assert(id); - - /* We don't convert ENOENT to ESRCH here, since we can't - * really distuingish between "audit is not available in the - * kernel" and "the process does not exist", both which will - * result in ENOENT. */ - - p = procfs_file_alloca(pid, "sessionid"); - - r = read_one_line_file(p, &s); - if (r < 0) - return r; - - r = safe_atou32(s, &u); - if (r < 0) - return r; - - if (u == AUDIT_SESSION_INVALID || u <= 0) - return -ENODATA; - - *id = u; - return 0; -} - -int audit_loginuid_from_pid(pid_t pid, uid_t *uid) { - _cleanup_free_ char *s = NULL; - const char *p; - uid_t u; - int r; - - assert(uid); - - p = procfs_file_alloca(pid, "loginuid"); - - r = read_one_line_file(p, &s); - if (r < 0) - return r; - - r = parse_uid(s, &u); - if (r == -ENXIO) /* the UID was -1 */ - return -ENODATA; - if (r < 0) - return r; - - *uid = (uid_t) u; - return 0; -} - -bool use_audit(void) { - static int cached_use = -1; - - if (cached_use < 0) { - int fd; - - fd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_AUDIT); - if (fd < 0) - cached_use = errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT; - else { - cached_use = true; - safe_close(fd); - } - } - - return cached_use; -} diff --git a/src/basic/audit.h b/src/basic/audit.h deleted file mode 100644 index 6de331c73e..0000000000 --- a/src/basic/audit.h +++ /dev/null @@ -1,33 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -#pragma once - -/*** - This file is part of systemd. - - Copyright 2010 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 - -#define AUDIT_SESSION_INVALID ((uint32_t) -1) - -int audit_session_from_pid(pid_t pid, uint32_t *id); -int audit_loginuid_from_pid(pid_t pid, uid_t *uid); - -bool use_audit(void); diff --git a/src/basic/capability-util.c b/src/basic/capability-util.c new file mode 100644 index 0000000000..3a6ceed6f5 --- /dev/null +++ b/src/basic/capability-util.c @@ -0,0 +1,308 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "capability-util.h" +#include "fileio.h" +#include "log.h" +#include "macro.h" +#include "parse-util.h" +#include "util.h" + +int have_effective_cap(int value) { + _cleanup_cap_free_ cap_t cap; + cap_flag_value_t fv; + + cap = cap_get_proc(); + if (!cap) + return -errno; + + if (cap_get_flag(cap, value, CAP_EFFECTIVE, &fv) < 0) + return -errno; + else + return fv == CAP_SET; +} + +unsigned long cap_last_cap(void) { + static thread_local unsigned long saved; + static thread_local bool valid = false; + _cleanup_free_ char *content = NULL; + unsigned long p = 0; + int r; + + if (valid) + return saved; + + /* available since linux-3.2 */ + r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content); + if (r >= 0) { + r = safe_atolu(content, &p); + if (r >= 0) { + saved = p; + valid = true; + return p; + } + } + + /* fall back to syscall-probing for pre linux-3.2 */ + p = (unsigned long) CAP_LAST_CAP; + + if (prctl(PR_CAPBSET_READ, p) < 0) { + + /* Hmm, look downwards, until we find one that + * works */ + for (p--; p > 0; p --) + if (prctl(PR_CAPBSET_READ, p) >= 0) + break; + + } else { + + /* Hmm, look upwards, until we find one that doesn't + * work */ + for (;; p++) + if (prctl(PR_CAPBSET_READ, p+1) < 0) + break; + } + + saved = p; + valid = true; + + return p; +} + +int capability_bounding_set_drop(uint64_t drop, bool right_now) { + _cleanup_cap_free_ cap_t after_cap = NULL; + cap_flag_value_t fv; + unsigned long i; + int r; + + /* If we are run as PID 1 we will lack CAP_SETPCAP by default + * in the effective set (yes, the kernel drops that when + * executing init!), so get it back temporarily so that we can + * call PR_CAPBSET_DROP. */ + + after_cap = cap_get_proc(); + if (!after_cap) + return -errno; + + if (cap_get_flag(after_cap, CAP_SETPCAP, CAP_EFFECTIVE, &fv) < 0) + return -errno; + + if (fv != CAP_SET) { + _cleanup_cap_free_ cap_t temp_cap = NULL; + static const cap_value_t v = CAP_SETPCAP; + + temp_cap = cap_dup(after_cap); + if (!temp_cap) { + r = -errno; + goto finish; + } + + if (cap_set_flag(temp_cap, CAP_EFFECTIVE, 1, &v, CAP_SET) < 0) { + r = -errno; + goto finish; + } + + if (cap_set_proc(temp_cap) < 0) { + r = -errno; + goto finish; + } + } + + for (i = 0; i <= cap_last_cap(); i++) { + + if (drop & ((uint64_t) 1ULL << (uint64_t) i)) { + cap_value_t v; + + /* Drop it from the bounding set */ + if (prctl(PR_CAPBSET_DROP, i) < 0) { + r = -errno; + goto finish; + } + v = (cap_value_t) i; + + /* Also drop it from the inheritable set, so + * that anything we exec() loses the + * capability for good. */ + if (cap_set_flag(after_cap, CAP_INHERITABLE, 1, &v, CAP_CLEAR) < 0) { + r = -errno; + goto finish; + } + + /* If we shall apply this right now drop it + * also from our own capability sets. */ + if (right_now) { + if (cap_set_flag(after_cap, CAP_PERMITTED, 1, &v, CAP_CLEAR) < 0 || + cap_set_flag(after_cap, CAP_EFFECTIVE, 1, &v, CAP_CLEAR) < 0) { + r = -errno; + goto finish; + } + } + } + } + + r = 0; + +finish: + if (cap_set_proc(after_cap) < 0) + return -errno; + + return r; +} + +static int drop_from_file(const char *fn, uint64_t drop) { + int r, k; + uint32_t hi, lo; + uint64_t current, after; + char *p; + + r = read_one_line_file(fn, &p); + if (r < 0) + return r; + + assert_cc(sizeof(hi) == sizeof(unsigned)); + assert_cc(sizeof(lo) == sizeof(unsigned)); + + k = sscanf(p, "%u %u", &lo, &hi); + free(p); + + if (k != 2) + return -EIO; + + current = (uint64_t) lo | ((uint64_t) hi << 32ULL); + after = current & ~drop; + + if (current == after) + return 0; + + lo = (unsigned) (after & 0xFFFFFFFFULL); + hi = (unsigned) ((after >> 32ULL) & 0xFFFFFFFFULL); + + if (asprintf(&p, "%u %u", lo, hi) < 0) + return -ENOMEM; + + r = write_string_file(fn, p, WRITE_STRING_FILE_CREATE); + free(p); + + return r; +} + +int capability_bounding_set_drop_usermode(uint64_t drop) { + int r; + + r = drop_from_file("/proc/sys/kernel/usermodehelper/inheritable", drop); + if (r < 0) + return r; + + r = drop_from_file("/proc/sys/kernel/usermodehelper/bset", drop); + if (r < 0) + return r; + + return r; +} + +int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) { + _cleanup_cap_free_ cap_t d = NULL; + unsigned i, j = 0; + int r; + + /* Unfortunately we cannot leave privilege dropping to PID 1 + * here, since we want to run as user but want to keep some + * capabilities. Since file capabilities have been introduced + * this cannot be done across exec() anymore, unless our + * binary has the capability configured in the file system, + * which we want to avoid. */ + + if (setresgid(gid, gid, gid) < 0) + return log_error_errno(errno, "Failed to change group ID: %m"); + + if (setgroups(0, NULL) < 0) + return log_error_errno(errno, "Failed to drop auxiliary groups list: %m"); + + /* Ensure we keep the permitted caps across the setresuid() */ + if (prctl(PR_SET_KEEPCAPS, 1) < 0) + return log_error_errno(errno, "Failed to enable keep capabilities flag: %m"); + + r = setresuid(uid, uid, uid); + if (r < 0) + return log_error_errno(errno, "Failed to change user ID: %m"); + + if (prctl(PR_SET_KEEPCAPS, 0) < 0) + return log_error_errno(errno, "Failed to disable keep capabilities flag: %m"); + + /* Drop all caps from the bounding set, except the ones we want */ + r = capability_bounding_set_drop(~keep_capabilities, true); + if (r < 0) + return log_error_errno(r, "Failed to drop capabilities: %m"); + + /* Now upgrade the permitted caps we still kept to effective caps */ + d = cap_init(); + if (!d) + return log_oom(); + + if (keep_capabilities) { + cap_value_t bits[u64log2(keep_capabilities) + 1]; + + for (i = 0; i < ELEMENTSOF(bits); i++) + if (keep_capabilities & (1ULL << i)) + bits[j++] = i; + + /* use enough bits */ + assert(i == 64 || (keep_capabilities >> i) == 0); + /* don't use too many bits */ + assert(keep_capabilities & (1ULL << (i - 1))); + + if (cap_set_flag(d, CAP_EFFECTIVE, j, bits, CAP_SET) < 0 || + cap_set_flag(d, CAP_PERMITTED, j, bits, CAP_SET) < 0) { + log_error_errno(errno, "Failed to enable capabilities bits: %m"); + return -errno; + } + + if (cap_set_proc(d) < 0) + return log_error_errno(errno, "Failed to increase capabilities: %m"); + } + + return 0; +} + +int drop_capability(cap_value_t cv) { + _cleanup_cap_free_ cap_t tmp_cap = NULL; + + tmp_cap = cap_get_proc(); + if (!tmp_cap) + return -errno; + + if ((cap_set_flag(tmp_cap, CAP_INHERITABLE, 1, &cv, CAP_CLEAR) < 0) || + (cap_set_flag(tmp_cap, CAP_PERMITTED, 1, &cv, CAP_CLEAR) < 0) || + (cap_set_flag(tmp_cap, CAP_EFFECTIVE, 1, &cv, CAP_CLEAR) < 0)) + return -errno; + + if (cap_set_proc(tmp_cap) < 0) + return -errno; + + return 0; +} diff --git a/src/basic/capability-util.h b/src/basic/capability-util.h new file mode 100644 index 0000000000..4eb5c2a835 --- /dev/null +++ b/src/basic/capability-util.h @@ -0,0 +1,45 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "util.h" + +unsigned long cap_last_cap(void); +int have_effective_cap(int value); +int capability_bounding_set_drop(uint64_t drop, bool right_now); +int capability_bounding_set_drop_usermode(uint64_t drop); + +int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities); + +int drop_capability(cap_value_t cv); + +DEFINE_TRIVIAL_CLEANUP_FUNC(cap_t, cap_free); +#define _cleanup_cap_free_ _cleanup_(cap_freep) + +static inline void cap_free_charpp(char **p) { + if (*p) + cap_free(*p); +} +#define _cleanup_cap_free_charp_ _cleanup_(cap_free_charpp) diff --git a/src/basic/capability.c b/src/basic/capability.c deleted file mode 100644 index 04c7047a6a..0000000000 --- a/src/basic/capability.c +++ /dev/null @@ -1,308 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2010 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 "capability.h" -#include "fileio.h" -#include "log.h" -#include "macro.h" -#include "parse-util.h" -#include "util.h" - -int have_effective_cap(int value) { - _cleanup_cap_free_ cap_t cap; - cap_flag_value_t fv; - - cap = cap_get_proc(); - if (!cap) - return -errno; - - if (cap_get_flag(cap, value, CAP_EFFECTIVE, &fv) < 0) - return -errno; - else - return fv == CAP_SET; -} - -unsigned long cap_last_cap(void) { - static thread_local unsigned long saved; - static thread_local bool valid = false; - _cleanup_free_ char *content = NULL; - unsigned long p = 0; - int r; - - if (valid) - return saved; - - /* available since linux-3.2 */ - r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content); - if (r >= 0) { - r = safe_atolu(content, &p); - if (r >= 0) { - saved = p; - valid = true; - return p; - } - } - - /* fall back to syscall-probing for pre linux-3.2 */ - p = (unsigned long) CAP_LAST_CAP; - - if (prctl(PR_CAPBSET_READ, p) < 0) { - - /* Hmm, look downwards, until we find one that - * works */ - for (p--; p > 0; p --) - if (prctl(PR_CAPBSET_READ, p) >= 0) - break; - - } else { - - /* Hmm, look upwards, until we find one that doesn't - * work */ - for (;; p++) - if (prctl(PR_CAPBSET_READ, p+1) < 0) - break; - } - - saved = p; - valid = true; - - return p; -} - -int capability_bounding_set_drop(uint64_t drop, bool right_now) { - _cleanup_cap_free_ cap_t after_cap = NULL; - cap_flag_value_t fv; - unsigned long i; - int r; - - /* If we are run as PID 1 we will lack CAP_SETPCAP by default - * in the effective set (yes, the kernel drops that when - * executing init!), so get it back temporarily so that we can - * call PR_CAPBSET_DROP. */ - - after_cap = cap_get_proc(); - if (!after_cap) - return -errno; - - if (cap_get_flag(after_cap, CAP_SETPCAP, CAP_EFFECTIVE, &fv) < 0) - return -errno; - - if (fv != CAP_SET) { - _cleanup_cap_free_ cap_t temp_cap = NULL; - static const cap_value_t v = CAP_SETPCAP; - - temp_cap = cap_dup(after_cap); - if (!temp_cap) { - r = -errno; - goto finish; - } - - if (cap_set_flag(temp_cap, CAP_EFFECTIVE, 1, &v, CAP_SET) < 0) { - r = -errno; - goto finish; - } - - if (cap_set_proc(temp_cap) < 0) { - r = -errno; - goto finish; - } - } - - for (i = 0; i <= cap_last_cap(); i++) { - - if (drop & ((uint64_t) 1ULL << (uint64_t) i)) { - cap_value_t v; - - /* Drop it from the bounding set */ - if (prctl(PR_CAPBSET_DROP, i) < 0) { - r = -errno; - goto finish; - } - v = (cap_value_t) i; - - /* Also drop it from the inheritable set, so - * that anything we exec() loses the - * capability for good. */ - if (cap_set_flag(after_cap, CAP_INHERITABLE, 1, &v, CAP_CLEAR) < 0) { - r = -errno; - goto finish; - } - - /* If we shall apply this right now drop it - * also from our own capability sets. */ - if (right_now) { - if (cap_set_flag(after_cap, CAP_PERMITTED, 1, &v, CAP_CLEAR) < 0 || - cap_set_flag(after_cap, CAP_EFFECTIVE, 1, &v, CAP_CLEAR) < 0) { - r = -errno; - goto finish; - } - } - } - } - - r = 0; - -finish: - if (cap_set_proc(after_cap) < 0) - return -errno; - - return r; -} - -static int drop_from_file(const char *fn, uint64_t drop) { - int r, k; - uint32_t hi, lo; - uint64_t current, after; - char *p; - - r = read_one_line_file(fn, &p); - if (r < 0) - return r; - - assert_cc(sizeof(hi) == sizeof(unsigned)); - assert_cc(sizeof(lo) == sizeof(unsigned)); - - k = sscanf(p, "%u %u", &lo, &hi); - free(p); - - if (k != 2) - return -EIO; - - current = (uint64_t) lo | ((uint64_t) hi << 32ULL); - after = current & ~drop; - - if (current == after) - return 0; - - lo = (unsigned) (after & 0xFFFFFFFFULL); - hi = (unsigned) ((after >> 32ULL) & 0xFFFFFFFFULL); - - if (asprintf(&p, "%u %u", lo, hi) < 0) - return -ENOMEM; - - r = write_string_file(fn, p, WRITE_STRING_FILE_CREATE); - free(p); - - return r; -} - -int capability_bounding_set_drop_usermode(uint64_t drop) { - int r; - - r = drop_from_file("/proc/sys/kernel/usermodehelper/inheritable", drop); - if (r < 0) - return r; - - r = drop_from_file("/proc/sys/kernel/usermodehelper/bset", drop); - if (r < 0) - return r; - - return r; -} - -int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) { - _cleanup_cap_free_ cap_t d = NULL; - unsigned i, j = 0; - int r; - - /* Unfortunately we cannot leave privilege dropping to PID 1 - * here, since we want to run as user but want to keep some - * capabilities. Since file capabilities have been introduced - * this cannot be done across exec() anymore, unless our - * binary has the capability configured in the file system, - * which we want to avoid. */ - - if (setresgid(gid, gid, gid) < 0) - return log_error_errno(errno, "Failed to change group ID: %m"); - - if (setgroups(0, NULL) < 0) - return log_error_errno(errno, "Failed to drop auxiliary groups list: %m"); - - /* Ensure we keep the permitted caps across the setresuid() */ - if (prctl(PR_SET_KEEPCAPS, 1) < 0) - return log_error_errno(errno, "Failed to enable keep capabilities flag: %m"); - - r = setresuid(uid, uid, uid); - if (r < 0) - return log_error_errno(errno, "Failed to change user ID: %m"); - - if (prctl(PR_SET_KEEPCAPS, 0) < 0) - return log_error_errno(errno, "Failed to disable keep capabilities flag: %m"); - - /* Drop all caps from the bounding set, except the ones we want */ - r = capability_bounding_set_drop(~keep_capabilities, true); - if (r < 0) - return log_error_errno(r, "Failed to drop capabilities: %m"); - - /* Now upgrade the permitted caps we still kept to effective caps */ - d = cap_init(); - if (!d) - return log_oom(); - - if (keep_capabilities) { - cap_value_t bits[u64log2(keep_capabilities) + 1]; - - for (i = 0; i < ELEMENTSOF(bits); i++) - if (keep_capabilities & (1ULL << i)) - bits[j++] = i; - - /* use enough bits */ - assert(i == 64 || (keep_capabilities >> i) == 0); - /* don't use too many bits */ - assert(keep_capabilities & (1ULL << (i - 1))); - - if (cap_set_flag(d, CAP_EFFECTIVE, j, bits, CAP_SET) < 0 || - cap_set_flag(d, CAP_PERMITTED, j, bits, CAP_SET) < 0) { - log_error_errno(errno, "Failed to enable capabilities bits: %m"); - return -errno; - } - - if (cap_set_proc(d) < 0) - return log_error_errno(errno, "Failed to increase capabilities: %m"); - } - - return 0; -} - -int drop_capability(cap_value_t cv) { - _cleanup_cap_free_ cap_t tmp_cap = NULL; - - tmp_cap = cap_get_proc(); - if (!tmp_cap) - return -errno; - - if ((cap_set_flag(tmp_cap, CAP_INHERITABLE, 1, &cv, CAP_CLEAR) < 0) || - (cap_set_flag(tmp_cap, CAP_PERMITTED, 1, &cv, CAP_CLEAR) < 0) || - (cap_set_flag(tmp_cap, CAP_EFFECTIVE, 1, &cv, CAP_CLEAR) < 0)) - return -errno; - - if (cap_set_proc(tmp_cap) < 0) - return -errno; - - return 0; -} diff --git a/src/basic/capability.h b/src/basic/capability.h deleted file mode 100644 index 4eb5c2a835..0000000000 --- a/src/basic/capability.h +++ /dev/null @@ -1,45 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -#pragma once - -/*** - This file is part of systemd. - - Copyright 2010 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 "util.h" - -unsigned long cap_last_cap(void); -int have_effective_cap(int value); -int capability_bounding_set_drop(uint64_t drop, bool right_now); -int capability_bounding_set_drop_usermode(uint64_t drop); - -int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities); - -int drop_capability(cap_value_t cv); - -DEFINE_TRIVIAL_CLEANUP_FUNC(cap_t, cap_free); -#define _cleanup_cap_free_ _cleanup_(cap_freep) - -static inline void cap_free_charpp(char **p) { - if (*p) - cap_free(*p); -} -#define _cleanup_cap_free_charp_ _cleanup_(cap_free_charpp) diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c index 7e7574568c..fc8edaeb36 100644 --- a/src/bus-proxyd/bus-proxyd.c +++ b/src/bus-proxyd/bus-proxyd.c @@ -35,7 +35,7 @@ #include "bus-internal.h" #include "bus-xml-policy.h" -#include "capability.h" +#include "capability-util.h" #include "def.h" #include "fd-util.h" #include "formats-util.h" diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 950e463bc5..35f1b2913b 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -27,7 +27,7 @@ #include "af-list.h" #include "bus-util.h" -#include "capability.h" +#include "capability-util.h" #include "dbus-execute.h" #include "env-util.h" #include "execute.h" diff --git a/src/core/execute.c b/src/core/execute.c index f354216325..2982125b82 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -60,7 +60,7 @@ #include "barrier.h" #include "bus-endpoint.h" #include "cap-list.h" -#include "capability.h" +#include "capability-util.h" #include "def.h" #include "env-util.h" #include "errno-list.h" diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c index 2068ffd69b..651f79a1fe 100644 --- a/src/core/kmod-setup.c +++ b/src/core/kmod-setup.c @@ -27,7 +27,7 @@ #endif #include "macro.h" -#include "capability.h" +#include "capability-util.h" #include "bus-util.h" #include "kmod-setup.h" diff --git a/src/core/main.c b/src/core/main.c index 3e4e9199ed..fd8ad0c0ea 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -44,7 +44,7 @@ #include "build.h" #include "bus-error.h" #include "bus-util.h" -#include "capability.h" +#include "capability-util.h" #include "clock-util.h" #include "conf-parser.h" #include "cpu-set-util.h" diff --git a/src/import/import-common.c b/src/import/import-common.c index d96a000f81..a8551ca9e8 100644 --- a/src/import/import-common.c +++ b/src/import/import-common.c @@ -25,7 +25,7 @@ #include #include "btrfs-util.h" -#include "capability.h" +#include "capability-util.h" #include "fd-util.h" #include "import-common.h" #include "signal-util.h" diff --git a/src/import/pull-common.c b/src/import/pull-common.c index 17283a4a24..f9c168e374 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -22,7 +22,7 @@ #include #include "btrfs-util.h" -#include "capability.h" +#include "capability-util.h" #include "copy.h" #include "dirent-util.h" #include "escape.h" diff --git a/src/journal/coredump.c b/src/journal/coredump.c index 257a665819..b9ece73a81 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -34,7 +34,7 @@ #include "sd-login.h" #include "acl-util.h" -#include "capability.h" +#include "capability-util.h" #include "cgroup-util.h" #include "compress.h" #include "conf-parser.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index ab213f705d..442fbb8ecd 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -34,6 +34,7 @@ #include "sd-messages.h" #include "acl-util.h" +#include "audit-util.h" #include "cgroup-util.h" #include "conf-parser.h" #include "dirent-util.h" diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index 535c0ab9ab..a2631c6017 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -25,9 +25,9 @@ #include #include "sd-event.h" -#include "journal-file.h" + #include "hashmap.h" -#include "audit.h" +#include "journal-file.h" #include "journald-rate-limit.h" #include "list.h" diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c index e68207ae07..dc4ac88712 100644 --- a/src/libsystemd/sd-bus/bus-control.c +++ b/src/libsystemd/sd-bus/bus-control.c @@ -32,7 +32,7 @@ #include "bus-internal.h" #include "bus-message.h" #include "bus-util.h" -#include "capability.h" +#include "capability-util.h" #include "string-util.h" #include "strv.h" #include "bus-control.h" diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index d7a7b6e5bb..d291da8934 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -22,12 +22,12 @@ #include #include -#include "audit.h" +#include "audit-util.h" #include "bus-creds.h" #include "bus-label.h" #include "bus-message.h" #include "bus-util.h" -#include "capability.h" +#include "capability-util.h" #include "cgroup-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c index 02c9ff8f2f..ab4e9cbc06 100644 --- a/src/libsystemd/sd-bus/bus-dump.c +++ b/src/libsystemd/sd-bus/bus-dump.c @@ -24,7 +24,7 @@ #include "bus-message.h" #include "bus-type.h" #include "cap-list.h" -#include "capability.h" +#include "capability-util.h" #include "fileio.h" #include "formats-util.h" #include "locale-util.h" diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 6f396b7953..a455259007 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -40,7 +40,7 @@ #include "bus-label.h" #include "bus-message.h" #include "bus-util.h" -#include "capability.h" +#include "capability-util.h" #include "fd-util.h" #include "fileio.h" #include "formats-util.h" diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 284ec42138..4204732e7d 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -26,7 +26,7 @@ #include "sd-messages.h" -#include "audit.h" +#include "audit-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 829b614509..26c135b2ca 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -30,7 +30,7 @@ #include "sd-messages.h" -#include "audit.h" +#include "audit-util.h" #include "bus-error.h" #include "bus-util.h" #include "escape.h" diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index 9c766bcb25..3f4a629be3 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -26,7 +26,7 @@ #include "sd-messages.h" -#include "audit.h" +#include "audit-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 464da88bcc..c37cfdb68b 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -30,7 +30,7 @@ #include #include -#include "audit.h" +#include "audit-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/network/networkd.c b/src/network/networkd.c index 1a17847715..c03ac69e27 100644 --- a/src/network/networkd.c +++ b/src/network/networkd.c @@ -21,7 +21,7 @@ #include "sd-daemon.h" -#include "capability.h" +#include "capability-util.h" #include "networkd.h" #include "signal-util.h" #include "user-util.h" diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 4e9ac04094..28bca1f71e 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -51,7 +51,7 @@ #include "blkid-util.h" #include "btrfs-util.h" #include "cap-list.h" -#include "capability.h" +#include "capability-util.h" #include "cgroup-util.h" #include "copy.h" #include "dev-setup.h" diff --git a/src/resolve/resolved.c b/src/resolve/resolved.c index df4eb6f63e..7ba0546f4a 100644 --- a/src/resolve/resolved.c +++ b/src/resolve/resolved.c @@ -22,7 +22,7 @@ #include "sd-daemon.h" #include "sd-event.h" -#include "capability.h" +#include "capability-util.h" #include "mkdir.h" #include "resolved-conf.h" #include "resolved-manager.h" diff --git a/src/shared/condition.c b/src/shared/condition.c index a79a74eaa5..a11054e316 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -29,7 +29,7 @@ #include "apparmor-util.h" #include "architecture.h" -#include "audit.h" +#include "audit-util.h" #include "cap-list.h" #include "condition.h" #include "extract-word.h" diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c index 5f17868458..f43f737951 100644 --- a/src/test/test-cap-list.c +++ b/src/test/test-cap-list.c @@ -22,7 +22,7 @@ #include #include "cap-list.h" -#include "capability.h" +#include "capability-util.h" #include "fileio.h" #include "parse-util.h" #include "util.h" diff --git a/src/test/test-capability.c b/src/test/test-capability.c index 09d7e61e92..fc8d3ffe0d 100644 --- a/src/test/test-capability.c +++ b/src/test/test-capability.c @@ -24,7 +24,7 @@ #include #include -#include "capability.h" +#include "capability-util.h" #include "fd-util.h" #include "macro.h" #include "util.h" diff --git a/src/test/test-condition.c b/src/test/test-condition.c index 91a27138eb..365f5794d4 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -21,7 +21,7 @@ #include "apparmor-util.h" #include "architecture.h" -#include "audit.h" +#include "audit-util.h" #include "condition.h" #include "hostname-util.h" #include "ima-util.h" diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c index 59d348c356..7f70eaaea0 100644 --- a/src/timesync/timesyncd.c +++ b/src/timesync/timesyncd.c @@ -22,7 +22,7 @@ #include "sd-daemon.h" #include "sd-event.h" -#include "capability.h" +#include "capability-util.h" #include "clock-util.h" #include "fd-util.h" #include "fs-util.h" diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 9ac10db22a..7217f54611 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -40,7 +40,7 @@ #include "acl-util.h" #include "btrfs-util.h" -#include "capability.h" +#include "capability-util.h" #include "chattr-util.h" #include "conf-files.h" #include "copy.h" -- cgit v1.2.3-54-g00ecf From 4e731273edfe852a3eee2949cd20f49fd5b4f6d7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 00:06:29 +0100 Subject: util-lib: move /proc/cmdline parsing code to proc-cmdline.[ch] --- Makefile.am | 2 + src/backlight/backlight.c | 3 +- src/basic/cgroup-util.c | 1 + src/basic/log.c | 3 +- src/basic/proc-cmdline.c | 144 ++++++++++++++++++++++ src/basic/proc-cmdline.h | 28 +++++ src/basic/util.c | 114 ----------------- src/basic/util.h | 6 - src/core/main.c | 1 + src/cryptsetup/cryptsetup-generator.c | 1 + src/debug-generator/debug-generator.c | 9 +- src/fsck/fsck.c | 1 + src/fstab-generator/fstab-generator.c | 1 + src/gpt-auto-generator/gpt-auto-generator.c | 1 + src/hibernate-resume/hibernate-resume-generator.c | 1 + src/journal/journald-server.c | 1 + src/modules-load/modules-load.c | 1 + src/quotacheck/quotacheck.c | 1 + src/rfkill/rfkill.c | 1 + src/shared/bus-util.c | 1 + src/shared/condition.c | 1 + src/test/test-util.c | 1 + src/udev/net/link-config.c | 1 + src/udev/udevd.c | 1 + 24 files changed, 199 insertions(+), 126 deletions(-) create mode 100644 src/basic/proc-cmdline.c create mode 100644 src/basic/proc-cmdline.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index d435141492..549ac014e3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -799,6 +799,8 @@ libbasic_la_SOURCES = \ src/basic/xattr-util.h \ src/basic/chattr-util.c \ src/basic/chattr-util.h \ + src/basic/proc-cmdline.c \ + src/basic/proc-cmdline.h \ src/basic/fs-util.c \ src/basic/fs-util.h \ src/basic/stat-util.c \ diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 6a2d04ef13..9112ed328d 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -25,10 +25,11 @@ #include "escape.h" #include "fileio.h" #include "mkdir.h" +#include "parse-util.h" +#include "proc-cmdline.h" #include "string-util.h" #include "udev-util.h" #include "util.h" -#include "parse-util.h" static struct udev_device *find_pci_or_platform_parent(struct udev_device *device) { struct udev_device *parent; diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index d416b0b41e..cfbeab7411 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -49,6 +49,7 @@ #include "unit-name.h" #include "user-util.h" #include "util.h" +#include "proc-cmdline.h" int cg_enumerate_processes(const char *controller, const char *path, FILE **_f) { _cleanup_free_ char *fs = NULL; diff --git a/src/basic/log.c b/src/basic/log.c index dcb24cfab7..d0db77eca0 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -36,6 +36,8 @@ #include "log.h" #include "macro.h" #include "missing.h" +#include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "signal-util.h" #include "socket-util.h" @@ -43,7 +45,6 @@ #include "string-util.h" #include "terminal-util.h" #include "util.h" -#include "parse-util.h" #define SNDBUF_SIZE (8*1024*1024) diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c new file mode 100644 index 0000000000..dd0e18ed6e --- /dev/null +++ b/src/basic/proc-cmdline.c @@ -0,0 +1,144 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "extract-word.h" +#include "fileio.h" +#include "macro.h" +#include "parse-util.h" +#include "proc-cmdline.h" +#include "process-util.h" +#include "string-util.h" +#include "util.h" +#include "virt.h" + +int proc_cmdline(char **ret) { + assert(ret); + + if (detect_container() > 0) + return get_process_cmdline(1, 0, false, ret); + else + return read_one_line_file("/proc/cmdline", ret); +} + +int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) { + _cleanup_free_ char *line = NULL; + const char *p; + int r; + + assert(parse_item); + + r = proc_cmdline(&line); + if (r < 0) + return r; + + p = line; + for (;;) { + _cleanup_free_ char *word = NULL; + char *value = NULL; + + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); + if (r < 0) + return r; + if (r == 0) + break; + + /* Filter out arguments that are intended only for the + * initrd */ + if (!in_initrd() && startswith(word, "rd.")) + continue; + + value = strchr(word, '='); + if (value) + *(value++) = 0; + + r = parse_item(word, value); + if (r < 0) + return r; + } + + return 0; +} + +int get_proc_cmdline_key(const char *key, char **value) { + _cleanup_free_ char *line = NULL, *ret = NULL; + bool found = false; + const char *p; + int r; + + assert(key); + + r = proc_cmdline(&line); + if (r < 0) + return r; + + p = line; + for (;;) { + _cleanup_free_ char *word = NULL; + const char *e; + + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); + if (r < 0) + return r; + if (r == 0) + break; + + /* Filter out arguments that are intended only for the + * initrd */ + if (!in_initrd() && startswith(word, "rd.")) + continue; + + if (value) { + e = startswith(word, key); + if (!e) + continue; + + r = free_and_strdup(&ret, e); + if (r < 0) + return r; + + found = true; + } else { + if (streq(word, key)) + found = true; + } + } + + if (value) { + *value = ret; + ret = NULL; + } + + return found; + +} + +int shall_restore_state(void) { + _cleanup_free_ char *value = NULL; + int r; + + r = get_proc_cmdline_key("systemd.restore_state=", &value); + if (r < 0) + return r; + if (r == 0) + return true; + + return parse_boolean(value) != 0; +} diff --git a/src/basic/proc-cmdline.h b/src/basic/proc-cmdline.h new file mode 100644 index 0000000000..ea8277b053 --- /dev/null +++ b/src/basic/proc-cmdline.h @@ -0,0 +1,28 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 . +***/ + +int proc_cmdline(char **ret); +int parse_proc_cmdline(int (*parse_word)(const char *key, const char *value)); +int get_proc_cmdline_key(const char *parameter, char **value); + +int shall_restore_state(void); diff --git a/src/basic/util.c b/src/basic/util.c index 6fe4f47018..66bb00b982 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -963,120 +963,6 @@ bool id128_is_valid(const char *s) { return true; } -int shall_restore_state(void) { - _cleanup_free_ char *value = NULL; - int r; - - r = get_proc_cmdline_key("systemd.restore_state=", &value); - if (r < 0) - return r; - if (r == 0) - return true; - - return parse_boolean(value) != 0; -} - -int proc_cmdline(char **ret) { - assert(ret); - - if (detect_container() > 0) - return get_process_cmdline(1, 0, false, ret); - else - return read_one_line_file("/proc/cmdline", ret); -} - -int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) { - _cleanup_free_ char *line = NULL; - const char *p; - int r; - - assert(parse_item); - - r = proc_cmdline(&line); - if (r < 0) - return r; - - p = line; - for (;;) { - _cleanup_free_ char *word = NULL; - char *value = NULL; - - r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); - if (r < 0) - return r; - if (r == 0) - break; - - /* Filter out arguments that are intended only for the - * initrd */ - if (!in_initrd() && startswith(word, "rd.")) - continue; - - value = strchr(word, '='); - if (value) - *(value++) = 0; - - r = parse_item(word, value); - if (r < 0) - return r; - } - - return 0; -} - -int get_proc_cmdline_key(const char *key, char **value) { - _cleanup_free_ char *line = NULL, *ret = NULL; - bool found = false; - const char *p; - int r; - - assert(key); - - r = proc_cmdline(&line); - if (r < 0) - return r; - - p = line; - for (;;) { - _cleanup_free_ char *word = NULL; - const char *e; - - r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX); - if (r < 0) - return r; - if (r == 0) - break; - - /* Filter out arguments that are intended only for the - * initrd */ - if (!in_initrd() && startswith(word, "rd.")) - continue; - - if (value) { - e = startswith(word, key); - if (!e) - continue; - - r = free_and_strdup(&ret, e); - if (r < 0) - return r; - - found = true; - } else { - if (streq(word, key)) - found = true; - } - } - - if (value) { - *value = ret; - ret = NULL; - } - - return found; - -} - int container_get_leader(const char *machine, pid_t *pid) { _cleanup_free_ char *s = NULL, *class = NULL; const char *p; diff --git a/src/basic/util.h b/src/basic/util.h index 96be6ecaa8..2ebb275494 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -288,8 +288,6 @@ static inline unsigned log2u_round_up(unsigned x) { bool id128_is_valid(const char *s) _pure_; -int shall_restore_state(void); - /** * Normal qsort requires base to be nonnull. Here were require * that only if nmemb > 0. @@ -302,10 +300,6 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_ qsort(base, nmemb, size, compar); } -int proc_cmdline(char **ret); -int parse_proc_cmdline(int (*parse_word)(const char *key, const char *value)); -int get_proc_cmdline_key(const char *parameter, char **value); - int container_get_leader(const char *machine, pid_t *pid); int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd); diff --git a/src/core/main.c b/src/core/main.c index fd8ad0c0ea..dbe774b14d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -69,6 +69,7 @@ #include "mount-setup.h" #include "pager.h" #include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "rlimit-util.h" #include "selinux-setup.h" diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 768d59c8df..54a89452a3 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -31,6 +31,7 @@ #include "mkdir.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index 115f99e68c..1a98cbaef8 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -19,12 +19,13 @@ along with systemd; If not, see . ***/ -#include "util.h" -#include "strv.h" -#include "unit-name.h" #include "mkdir.h" -#include "string-util.h" #include "parse-util.h" +#include "proc-cmdline.h" +#include "string-util.h" +#include "strv.h" +#include "unit-name.h" +#include "util.h" static const char *arg_dest = "/tmp"; static char **arg_mask = NULL; diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 590ffafef6..45c24b2fcf 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -40,6 +40,7 @@ #include "fs-util.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "signal-util.h" #include "socket-util.h" diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 64aa6db01a..a51ecd9f7a 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -35,6 +35,7 @@ #include "mount-util.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "special.h" #include "stat-util.h" #include "string-util.h" diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 8bdb6c7548..cc1bd3f50e 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -41,6 +41,7 @@ #include "mount-util.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "special.h" #include "stat-util.h" #include "string-util.h" diff --git a/src/hibernate-resume/hibernate-resume-generator.c b/src/hibernate-resume/hibernate-resume-generator.c index da7d33508d..8c3a09501f 100644 --- a/src/hibernate-resume/hibernate-resume-generator.c +++ b/src/hibernate-resume/hibernate-resume-generator.c @@ -25,6 +25,7 @@ #include "fstab-util.h" #include "log.h" #include "mkdir.h" +#include "proc-cmdline.h" #include "special.h" #include "string-util.h" #include "unit-name.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 442fbb8ecd..32d1f36821 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -58,6 +58,7 @@ #include "missing.h" #include "mkdir.h" #include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "rm-rf.h" #include "selinux-util.h" diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c index 5627e63938..830ca7b89d 100644 --- a/src/modules-load/modules-load.c +++ b/src/modules-load/modules-load.c @@ -30,6 +30,7 @@ #include "fd-util.h" #include "fileio.h" #include "log.h" +#include "proc-cmdline.h" #include "string-util.h" #include "strv.h" #include "util.h" diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index a2a035f4f1..dc2911e4e8 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -29,6 +29,7 @@ #include "signal-util.h" #include "string-util.h" #include "util.h" +#include "proc-cmdline.h" static bool arg_skip = false; static bool arg_force = false; diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index c08b746f2c..5ba1e3d4a8 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -31,6 +31,7 @@ #include "io-util.h" #include "mkdir.h" #include "parse-util.h" +#include "proc-cmdline.h" #include "string-table.h" #include "string-util.h" #include "udev-util.h" diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 724103fc3f..9fcc61dbd2 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -47,6 +47,7 @@ #include "unit-name.h" #include "utf8.h" #include "util.h" +#include "proc-cmdline.h" static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { sd_event *e = userdata; diff --git a/src/shared/condition.c b/src/shared/condition.c index a11054e316..d06120f0d7 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -39,6 +39,7 @@ #include "mount-util.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "selinux-util.h" #include "smack-util.h" #include "stat-util.h" diff --git a/src/test/test-util.c b/src/test/test-util.c index d339bc686f..a020b33e75 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -44,6 +44,7 @@ #include "mkdir.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "rm-rf.h" #include "signal-util.h" diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index db4fe0c855..972841b6d9 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -36,6 +36,7 @@ #include "network-internal.h" #include "parse-util.h" #include "path-util.h" +#include "proc-cmdline.h" #include "random-util.h" #include "stat-util.h" #include "string-table.h" diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 90e1de7b7a..2dcdef9918 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -55,6 +55,7 @@ #include "io-util.h" #include "netlink-util.h" #include "parse-util.h" +#include "proc-cmdline.h" #include "process-util.h" #include "selinux-util.h" #include "signal-util.h" -- cgit v1.2.3-54-g00ecf From 7ccbd1ae843d77275f2c542582a9a80e5e058a70 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 00:40:25 +0100 Subject: util-lib: split out syslog-related calls into syslog-util.[ch] --- Makefile.am | 2 + src/basic/log.c | 1 + src/basic/syslog-util.c | 115 ++++++++++++++++++++++++++++++++++++++++++ src/basic/syslog-util.h | 34 +++++++++++++ src/basic/util.c | 88 -------------------------------- src/basic/util.h | 10 ---- src/core/dbus-execute.c | 1 + src/core/dbus-manager.c | 1 + src/core/execute.c | 1 + src/import/importd.c | 1 + src/journal/cat.c | 1 + src/journal/journalctl.c | 1 + src/journal/journald-stream.c | 1 + src/journal/journald-syslog.c | 1 + src/libudev/libudev-util.c | 1 + src/shared/bus-util.c | 1 + src/shared/conf-parser.c | 1 + 17 files changed, 163 insertions(+), 98 deletions(-) create mode 100644 src/basic/syslog-util.c create mode 100644 src/basic/syslog-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index 549ac014e3..78788f65e9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -803,6 +803,8 @@ libbasic_la_SOURCES = \ src/basic/proc-cmdline.h \ src/basic/fs-util.c \ src/basic/fs-util.h \ + src/basic/syslog-util.c \ + src/basic/syslog-util.h \ src/basic/stat-util.c \ src/basic/stat-util.h \ src/basic/mount-util.c \ diff --git a/src/basic/log.c b/src/basic/log.c index d0db77eca0..c99746f916 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -43,6 +43,7 @@ #include "socket-util.h" #include "string-table.h" #include "string-util.h" +#include "syslog-util.h" #include "terminal-util.h" #include "util.h" diff --git a/src/basic/syslog-util.c b/src/basic/syslog-util.c new file mode 100644 index 0000000000..01577941a0 --- /dev/null +++ b/src/basic/syslog-util.c @@ -0,0 +1,115 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "assert.h" +#include "hexdecoct.h" +#include "string-table.h" +#include "syslog-util.h" + +int syslog_parse_priority(const char **p, int *priority, bool with_facility) { + int a = 0, b = 0, c = 0; + int k; + + assert(p); + assert(*p); + assert(priority); + + if ((*p)[0] != '<') + return 0; + + if (!strchr(*p, '>')) + return 0; + + if ((*p)[2] == '>') { + c = undecchar((*p)[1]); + k = 3; + } else if ((*p)[3] == '>') { + b = undecchar((*p)[1]); + c = undecchar((*p)[2]); + k = 4; + } else if ((*p)[4] == '>') { + a = undecchar((*p)[1]); + b = undecchar((*p)[2]); + c = undecchar((*p)[3]); + k = 5; + } else + return 0; + + if (a < 0 || b < 0 || c < 0 || + (!with_facility && (a || b || c > 7))) + return 0; + + if (with_facility) + *priority = a*100 + b*10 + c; + else + *priority = (*priority & LOG_FACMASK) | c; + + *p += k; + return 1; +} + +static const char *const log_facility_unshifted_table[LOG_NFACILITIES] = { + [LOG_FAC(LOG_KERN)] = "kern", + [LOG_FAC(LOG_USER)] = "user", + [LOG_FAC(LOG_MAIL)] = "mail", + [LOG_FAC(LOG_DAEMON)] = "daemon", + [LOG_FAC(LOG_AUTH)] = "auth", + [LOG_FAC(LOG_SYSLOG)] = "syslog", + [LOG_FAC(LOG_LPR)] = "lpr", + [LOG_FAC(LOG_NEWS)] = "news", + [LOG_FAC(LOG_UUCP)] = "uucp", + [LOG_FAC(LOG_CRON)] = "cron", + [LOG_FAC(LOG_AUTHPRIV)] = "authpriv", + [LOG_FAC(LOG_FTP)] = "ftp", + [LOG_FAC(LOG_LOCAL0)] = "local0", + [LOG_FAC(LOG_LOCAL1)] = "local1", + [LOG_FAC(LOG_LOCAL2)] = "local2", + [LOG_FAC(LOG_LOCAL3)] = "local3", + [LOG_FAC(LOG_LOCAL4)] = "local4", + [LOG_FAC(LOG_LOCAL5)] = "local5", + [LOG_FAC(LOG_LOCAL6)] = "local6", + [LOG_FAC(LOG_LOCAL7)] = "local7" +}; + +DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int, LOG_FAC(~0)); + +bool log_facility_unshifted_is_valid(int facility) { + return facility >= 0 && facility <= LOG_FAC(~0); +} + +static const char *const log_level_table[] = { + [LOG_EMERG] = "emerg", + [LOG_ALERT] = "alert", + [LOG_CRIT] = "crit", + [LOG_ERR] = "err", + [LOG_WARNING] = "warning", + [LOG_NOTICE] = "notice", + [LOG_INFO] = "info", + [LOG_DEBUG] = "debug" +}; + +DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG); + +bool log_level_is_valid(int level) { + return level >= 0 && level <= LOG_DEBUG; +} diff --git a/src/basic/syslog-util.h b/src/basic/syslog-util.h new file mode 100644 index 0000000000..eb79c6dbd8 --- /dev/null +++ b/src/basic/syslog-util.h @@ -0,0 +1,34 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 + +int log_facility_unshifted_to_string_alloc(int i, char **s); +int log_facility_unshifted_from_string(const char *s); +bool log_facility_unshifted_is_valid(int faciliy); + +int log_level_to_string_alloc(int i, char **s); +int log_level_from_string(const char *s); +bool log_level_is_valid(int level); + +int syslog_parse_priority(const char **p, int *priority, bool with_facility); diff --git a/src/basic/util.c b/src/basic/util.c index 8c5e88f00c..55decc7eea 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -491,52 +491,6 @@ static const char *const sigchld_code_table[] = { DEFINE_STRING_TABLE_LOOKUP(sigchld_code, int); -static const char *const log_facility_unshifted_table[LOG_NFACILITIES] = { - [LOG_FAC(LOG_KERN)] = "kern", - [LOG_FAC(LOG_USER)] = "user", - [LOG_FAC(LOG_MAIL)] = "mail", - [LOG_FAC(LOG_DAEMON)] = "daemon", - [LOG_FAC(LOG_AUTH)] = "auth", - [LOG_FAC(LOG_SYSLOG)] = "syslog", - [LOG_FAC(LOG_LPR)] = "lpr", - [LOG_FAC(LOG_NEWS)] = "news", - [LOG_FAC(LOG_UUCP)] = "uucp", - [LOG_FAC(LOG_CRON)] = "cron", - [LOG_FAC(LOG_AUTHPRIV)] = "authpriv", - [LOG_FAC(LOG_FTP)] = "ftp", - [LOG_FAC(LOG_LOCAL0)] = "local0", - [LOG_FAC(LOG_LOCAL1)] = "local1", - [LOG_FAC(LOG_LOCAL2)] = "local2", - [LOG_FAC(LOG_LOCAL3)] = "local3", - [LOG_FAC(LOG_LOCAL4)] = "local4", - [LOG_FAC(LOG_LOCAL5)] = "local5", - [LOG_FAC(LOG_LOCAL6)] = "local6", - [LOG_FAC(LOG_LOCAL7)] = "local7" -}; - -DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int, LOG_FAC(~0)); - -bool log_facility_unshifted_is_valid(int facility) { - return facility >= 0 && facility <= LOG_FAC(~0); -} - -static const char *const log_level_table[] = { - [LOG_EMERG] = "emerg", - [LOG_ALERT] = "alert", - [LOG_CRIT] = "crit", - [LOG_ERR] = "err", - [LOG_WARNING] = "warning", - [LOG_NOTICE] = "notice", - [LOG_INFO] = "info", - [LOG_DEBUG] = "debug" -}; - -DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG); - -bool log_level_is_valid(int level) { - return level >= 0 && level <= LOG_DEBUG; -} - static const char* const sched_policy_table[] = { [SCHED_OTHER] = "other", [SCHED_BATCH] = "batch", @@ -1199,48 +1153,6 @@ int update_reboot_param_file(const char *param) { return 0; } -int syslog_parse_priority(const char **p, int *priority, bool with_facility) { - int a = 0, b = 0, c = 0; - int k; - - assert(p); - assert(*p); - assert(priority); - - if ((*p)[0] != '<') - return 0; - - if (!strchr(*p, '>')) - return 0; - - if ((*p)[2] == '>') { - c = undecchar((*p)[1]); - k = 3; - } else if ((*p)[3] == '>') { - b = undecchar((*p)[1]); - c = undecchar((*p)[2]); - k = 4; - } else if ((*p)[4] == '>') { - a = undecchar((*p)[1]); - b = undecchar((*p)[2]); - c = undecchar((*p)[3]); - k = 5; - } else - return 0; - - if (a < 0 || b < 0 || c < 0 || - (!with_facility && (a || b || c > 7))) - return 0; - - if (with_facility) - *priority = a*100 + b*10 + c; - else - *priority = (*priority & LOG_FACMASK) | c; - - *p += k; - return 1; -} - int version(void) { puts(PACKAGE_STRING "\n" SYSTEMD_FEATURES); diff --git a/src/basic/util.h b/src/basic/util.h index c3992349df..6c3434d15b 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -115,14 +115,6 @@ int ioprio_class_from_string(const char *s); const char *sigchld_code_to_string(int i) _const_; int sigchld_code_from_string(const char *s) _pure_; -int log_facility_unshifted_to_string_alloc(int i, char **s); -int log_facility_unshifted_from_string(const char *s); -bool log_facility_unshifted_is_valid(int faciliy); - -int log_level_to_string_alloc(int i, char **s); -int log_level_from_string(const char *s); -bool log_level_is_valid(int level); - int sched_policy_to_string_alloc(int i, char **s); int sched_policy_from_string(const char *s); @@ -335,8 +327,6 @@ union inotify_event_buffer { uint8_t raw[INOTIFY_EVENT_MAX]; }; -int syslog_parse_priority(const char **p, int *priority, bool with_facility); - int version(void); bool fdname_is_valid(const char *s); diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 35f1b2913b..67405a1672 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -43,6 +43,7 @@ #include "seccomp-util.h" #endif #include "strv.h" +#include "syslog-util.h" #include "utf8.h" BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index f737140363..3f631bd9a0 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -44,6 +44,7 @@ #include "stat-util.h" #include "string-util.h" #include "strv.h" +#include "syslog-util.h" #include "virt.h" #include "watchdog.h" diff --git a/src/core/execute.c b/src/core/execute.c index 2982125b82..3814fd4381 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -92,6 +92,7 @@ #include "string-table.h" #include "string-util.h" #include "strv.h" +#include "syslog-util.h" #include "terminal-util.h" #include "unit.h" #include "user-util.h" diff --git a/src/import/importd.c b/src/import/importd.c index 2a03507d3a..3c57713fa5 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -39,6 +39,7 @@ #include "socket-util.h" #include "string-table.h" #include "strv.h" +#include "syslog-util.h" #include "util.h" typedef struct Transfer Transfer; diff --git a/src/journal/cat.c b/src/journal/cat.c index 95a1868b93..7fd4198df8 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -31,6 +31,7 @@ #include "fd-util.h" #include "parse-util.h" #include "string-util.h" +#include "syslog-util.h" #include "util.h" static char *arg_identifier = NULL; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 8b8c50b436..1965522dfd 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -65,6 +65,7 @@ #include "set.h" #include "sigbus.h" #include "strv.h" +#include "syslog-util.h" #include "terminal-util.h" #include "unit-name.h" #include "user-util.h" diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index a9c940690f..8d9c416bc9 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -44,6 +44,7 @@ #include "selinux-util.h" #include "socket-util.h" #include "string-util.h" +#include "syslog-util.h" #define STDOUT_STREAMS_MAX 4096 diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 7e9ba12560..488cccb6d9 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -36,6 +36,7 @@ #include "selinux-util.h" #include "socket-util.h" #include "string-util.h" +#include "syslog-util.h" /* Warn once every 30s if we missed syslog message */ #define WARN_FORWARD_SYSLOG_MISSED_USEC (30 * USEC_PER_SEC) diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c index a614230df4..574cfeac85 100644 --- a/src/libudev/libudev-util.c +++ b/src/libudev/libudev-util.c @@ -29,6 +29,7 @@ #include "MurmurHash2.h" #include "device-nodes.h" #include "libudev-private.h" +#include "syslog-util.h" #include "utf8.h" /** diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 9fcc61dbd2..c854ff4344 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -44,6 +44,7 @@ #include "signal-util.h" #include "string-util.h" #include "strv.h" +#include "syslog-util.h" #include "unit-name.h" #include "utf8.h" #include "util.h" diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 4235e95d92..fa13eb8075 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -39,6 +39,7 @@ #include "strv.h" #include "utf8.h" #include "util.h" +#include "syslog-util.h" int config_item_table_lookup( const void *table, -- cgit v1.2.3-54-g00ecf From afc5dbf37fd2399d37976388d9dd9ab470ecf446 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 01:02:30 +0100 Subject: io-util.h: move iovec stuff from macro.h to io-util.h --- src/basic/io-util.h | 39 ++++++++++++++++++++++++++++++++++- src/basic/log.c | 1 + src/basic/macro.h | 41 ++----------------------------------- src/core/show-status.c | 1 + src/journal/coredump.c | 1 + src/journal/journald-audit.c | 3 ++- src/journal/journald-console.c | 1 + src/journal/journald-kmsg.c | 1 + src/journal/journald-native.c | 1 + src/journal/journald-server.c | 1 + src/journal/journald-stream.c | 1 + src/journal/journald-syslog.c | 1 + src/libsystemd/sd-bus/bus-message.c | 1 + src/resolve/resolved-dns-stream.c | 1 + 14 files changed, 53 insertions(+), 41 deletions(-) (limited to 'src/journal') diff --git a/src/basic/io-util.h b/src/basic/io-util.h index ff7c2a9ac4..cd2aa75ad2 100644 --- a/src/basic/io-util.h +++ b/src/basic/io-util.h @@ -21,8 +21,9 @@ along with systemd; If not, see . ***/ -#include #include +#include +#include #include "time-util.h" @@ -37,3 +38,39 @@ int pipe_eof(int fd); int fd_wait_for_event(int fd, int event, usec_t timeout); ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length); + +#define IOVEC_SET_STRING(i, s) \ + do { \ + struct iovec *_i = &(i); \ + char *_s = (char *)(s); \ + _i->iov_base = _s; \ + _i->iov_len = strlen(_s); \ + } while(false) + +static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n) { + unsigned j; + size_t r = 0; + + for (j = 0; j < n; j++) + r += i[j].iov_len; + + return r; +} + +static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) { + unsigned j; + + for (j = 0; j < n; j++) { + size_t sub; + + if (_unlikely_(k <= 0)) + break; + + sub = MIN(i[j].iov_len, k); + i[j].iov_len -= sub; + i[j].iov_base = (uint8_t*) i[j].iov_base + sub; + k -= sub; + } + + return k; +} diff --git a/src/basic/log.c b/src/basic/log.c index c99746f916..4583cb840f 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -33,6 +33,7 @@ #include "fd-util.h" #include "formats-util.h" +#include "io-util.h" #include "log.h" #include "macro.h" #include "missing.h" diff --git a/src/basic/macro.h b/src/basic/macro.h index 44ae1f157a..c9bbe8df4b 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -22,11 +22,10 @@ ***/ #include -#include -#include -#include #include #include +#include +#include #define _printf_(a,b) __attribute__ ((format (printf, a, b))) #define _alloc_(...) __attribute__ ((alloc_size(__VA_ARGS__))) @@ -302,42 +301,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { #define char_array_0(x) x[sizeof(x)-1] = 0; -#define IOVEC_SET_STRING(i, s) \ - do { \ - struct iovec *_i = &(i); \ - char *_s = (char *)(s); \ - _i->iov_base = _s; \ - _i->iov_len = strlen(_s); \ - } while(false) - -static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, unsigned n) { - unsigned j; - size_t r = 0; - - for (j = 0; j < n; j++) - r += i[j].iov_len; - - return r; -} - -static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) { - unsigned j; - - for (j = 0; j < n; j++) { - size_t sub; - - if (_unlikely_(k <= 0)) - break; - - sub = MIN(i[j].iov_len, k); - i[j].iov_len -= sub; - i[j].iov_base = (uint8_t*) i[j].iov_base + sub; - k -= sub; - } - - return k; -} - #define VA_FORMAT_ADVANCE(format, ap) \ do { \ int _argtypes[128]; \ diff --git a/src/core/show-status.c b/src/core/show-status.c index 91f8f8e5ad..81166abf23 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -20,6 +20,7 @@ ***/ #include "fd-util.h" +#include "io-util.h" #include "parse-util.h" #include "show-status.h" #include "string-util.h" diff --git a/src/journal/coredump.c b/src/journal/coredump.c index b9ece73a81..f32e2d4a9f 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -45,6 +45,7 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "io-util.h" #include "journald-native.h" #include "log.h" #include "macro.h" diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index 289f9bf78d..6a8ef7dd40 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -21,9 +21,10 @@ #include "audit-type.h" #include "fd-util.h" +#include "hexdecoct.h" +#include "io-util.h" #include "journald-audit.h" #include "missing.h" -#include "hexdecoct.h" #include "string-util.h" typedef struct MapField { diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index 4a5e07ec5d..9acc324bc5 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -26,6 +26,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "io-util.h" #include "journald-console.h" #include "journald-server.h" #include "parse-util.h" diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index e680aafafe..52e1fbeb3d 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -31,6 +31,7 @@ #include "escape.h" #include "fd-util.h" #include "formats-util.h" +#include "io-util.h" #include "journald-kmsg.h" #include "journald-server.h" #include "journald-syslog.h" diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index e427f20e69..9f3b1e3b16 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -26,6 +26,7 @@ #include "fd-util.h" #include "fs-util.h" +#include "io-util.h" #include "journald-console.h" #include "journald-kmsg.h" #include "journald-native.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 32d1f36821..03cc074e7a 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -44,6 +44,7 @@ #include "fs-util.h" #include "hashmap.h" #include "hostname-util.h" +#include "io-util.h" #include "journal-authenticate.h" #include "journal-file.h" #include "journal-internal.h" diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 8d9c416bc9..de4f4d97fe 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -33,6 +33,7 @@ #include "escape.h" #include "fd-util.h" #include "fileio.h" +#include "io-util.h" #include "journald-console.h" #include "journald-kmsg.h" #include "journald-server.h" diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 488cccb6d9..d0c4a41b9d 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -27,6 +27,7 @@ #include "fd-util.h" #include "formats-util.h" +#include "io-util.h" #include "journald-console.h" #include "journald-kmsg.h" #include "journald-server.h" diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 447e25db8a..d5a6ad581f 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -32,6 +32,7 @@ #include "bus-type.h" #include "bus-util.h" #include "fd-util.h" +#include "io-util.h" #include "memfd-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index b2eebe09a2..1150c30677 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -22,6 +22,7 @@ #include #include "fd-util.h" +#include "io-util.h" #include "missing.h" #include "resolved-dns-stream.h" -- cgit v1.2.3-54-g00ecf From 15a5e95075a7f6007dd97b2a165c8ed16fe683df Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 01:26:31 +0100 Subject: util-lib: split out printf() helpers to stdio-util.h --- Makefile.am | 1 + src/basic/log.c | 1 + src/basic/macro.h | 45 --------------------- src/basic/mount-util.c | 1 + src/basic/stdio-util.h | 78 +++++++++++++++++++++++++++++++++++++ src/basic/util.h | 4 -- src/basic/xattr-util.c | 1 + src/core/automount.c | 1 + src/core/main.c | 1 + src/core/selinux-access.c | 8 ++-- src/fsck/fsck.c | 1 + src/journal-remote/journal-remote.c | 1 + src/journal/journal-send.c | 1 + src/journal/journald-console.c | 1 + src/journal/journald-kmsg.c | 1 + src/journal/journald-stream.c | 1 + src/journal/journald-syslog.c | 1 + src/journal/sd-journal.c | 2 + src/libsystemd/sd-bus/bus-control.c | 1 + src/libsystemd/sd-bus/bus-socket.c | 3 +- src/machine/machined-dbus.c | 1 + src/network/networkd-link.c | 1 + src/nspawn/nspawn.c | 1 + src/shared/bus-util.c | 1 + src/shared/efivars.c | 1 + src/shared/spawn-polkit-agent.c | 6 ++- src/tmpfiles/tmpfiles.c | 1 + src/udev/udev-builtin-keyboard.c | 1 + 28 files changed, 112 insertions(+), 55 deletions(-) create mode 100644 src/basic/stdio-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index d851e96f38..c47ad240ab 100644 --- a/Makefile.am +++ b/Makefile.am @@ -766,6 +766,7 @@ libbasic_la_SOURCES = \ src/basic/capability-util.h \ src/basic/conf-files.c \ src/basic/conf-files.h \ + src/basic/stdio-util.h \ src/basic/hostname-util.h \ src/basic/hostname-util.c \ src/basic/unit-name.c \ diff --git a/src/basic/log.c b/src/basic/log.c index 4583cb840f..505c0d072c 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -42,6 +42,7 @@ #include "process-util.h" #include "signal-util.h" #include "socket-util.h" +#include "stdio-util.h" #include "string-table.h" #include "string-util.h" #include "syslog-util.h" diff --git a/src/basic/macro.h b/src/basic/macro.h index 156c16b1c3..acd67feabb 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -301,51 +301,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { #define char_array_0(x) x[sizeof(x)-1] = 0; -#define VA_FORMAT_ADVANCE(format, ap) \ -do { \ - int _argtypes[128]; \ - size_t _i, _k; \ - _k = parse_printf_format((format), ELEMENTSOF(_argtypes), _argtypes); \ - assert(_k < ELEMENTSOF(_argtypes)); \ - for (_i = 0; _i < _k; _i++) { \ - if (_argtypes[_i] & PA_FLAG_PTR) { \ - (void) va_arg(ap, void*); \ - continue; \ - } \ - \ - switch (_argtypes[_i]) { \ - case PA_INT: \ - case PA_INT|PA_FLAG_SHORT: \ - case PA_CHAR: \ - (void) va_arg(ap, int); \ - break; \ - case PA_INT|PA_FLAG_LONG: \ - (void) va_arg(ap, long int); \ - break; \ - case PA_INT|PA_FLAG_LONG_LONG: \ - (void) va_arg(ap, long long int); \ - break; \ - case PA_WCHAR: \ - (void) va_arg(ap, wchar_t); \ - break; \ - case PA_WSTRING: \ - case PA_STRING: \ - case PA_POINTER: \ - (void) va_arg(ap, void*); \ - break; \ - case PA_FLOAT: \ - case PA_DOUBLE: \ - (void) va_arg(ap, double); \ - break; \ - case PA_DOUBLE|PA_FLAG_LONG_DOUBLE: \ - (void) va_arg(ap, long double); \ - break; \ - default: \ - assert_not_reached("Unknown format string argument."); \ - } \ - } \ -} while(false) - /* Because statfs.t_type can be int on some architectures, we have to cast * the const magic to the type, otherwise the compiler warns about * signed/unsigned comparison, because the magic can be 32 bit unsigned. diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c index 6b33d43024..24e88babcd 100644 --- a/src/basic/mount-util.c +++ b/src/basic/mount-util.c @@ -30,6 +30,7 @@ #include "parse-util.h" #include "path-util.h" #include "set.h" +#include "stdio-util.h" #include "string-util.h" #include "util.h" diff --git a/src/basic/stdio-util.h b/src/basic/stdio-util.h new file mode 100644 index 0000000000..b36e8a947e --- /dev/null +++ b/src/basic/stdio-util.h @@ -0,0 +1,78 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "macro.h" + +#define xsprintf(buf, fmt, ...) \ + assert_message_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf), "xsprintf: " #buf "[] must be big enough") + + +#define VA_FORMAT_ADVANCE(format, ap) \ +do { \ + int _argtypes[128]; \ + size_t _i, _k; \ + _k = parse_printf_format((format), ELEMENTSOF(_argtypes), _argtypes); \ + assert(_k < ELEMENTSOF(_argtypes)); \ + for (_i = 0; _i < _k; _i++) { \ + if (_argtypes[_i] & PA_FLAG_PTR) { \ + (void) va_arg(ap, void*); \ + continue; \ + } \ + \ + switch (_argtypes[_i]) { \ + case PA_INT: \ + case PA_INT|PA_FLAG_SHORT: \ + case PA_CHAR: \ + (void) va_arg(ap, int); \ + break; \ + case PA_INT|PA_FLAG_LONG: \ + (void) va_arg(ap, long int); \ + break; \ + case PA_INT|PA_FLAG_LONG_LONG: \ + (void) va_arg(ap, long long int); \ + break; \ + case PA_WCHAR: \ + (void) va_arg(ap, wchar_t); \ + break; \ + case PA_WSTRING: \ + case PA_STRING: \ + case PA_POINTER: \ + (void) va_arg(ap, void*); \ + break; \ + case PA_FLOAT: \ + case PA_DOUBLE: \ + (void) va_arg(ap, double); \ + break; \ + case PA_DOUBLE|PA_FLAG_LONG_DOUBLE: \ + (void) va_arg(ap, long double); \ + break; \ + default: \ + assert_not_reached("Unknown format string argument."); \ + } \ + } \ +} while(false) diff --git a/src/basic/util.h b/src/basic/util.h index fc73e13fe4..95c7c75b9c 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -85,10 +85,6 @@ static inline const char* one_zero(bool b) { bool fstype_is_network(const char *fstype); -#define xsprintf(buf, fmt, ...) \ - assert_message_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf), \ - "xsprintf: " #buf "[] must be big enough") - noreturn void freeze(void); void execute_directories(const char* const* directories, usec_t timeout, char *argv[]); diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 35fd1c1616..7351337c6b 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -23,6 +23,7 @@ #include "fd-util.h" #include "sparse-endian.h" +#include "stdio-util.h" #include "util.h" #include "xattr-util.h" diff --git a/src/core/automount.c b/src/core/automount.c index 379f71f74a..50a7772753 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -45,6 +45,7 @@ #include "path-util.h" #include "process-util.h" #include "special.h" +#include "stdio-util.h" #include "string-table.h" #include "string-util.h" #include "unit-name.h" diff --git a/src/core/main.c b/src/core/main.c index dbe774b14d..d9c888d747 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -78,6 +78,7 @@ #include "smack-setup.h" #include "special.h" #include "stat-util.h" +#include "stdio-util.h" #include "strv.h" #include "switch-root.h" #include "terminal-util.h" diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c index cf38fa0ebe..a9368ead22 100644 --- a/src/core/selinux-access.c +++ b/src/core/selinux-access.c @@ -32,13 +32,15 @@ #endif #include "sd-bus.h" + +#include "audit-fd.h" #include "bus-util.h" -#include "util.h" #include "log.h" +#include "path-util.h" #include "selinux-util.h" -#include "audit-fd.h" +#include "stdio-util.h" #include "strv.h" -#include "path-util.h" +#include "util.h" static bool initialized = false; diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 45c24b2fcf..4119edde30 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -45,6 +45,7 @@ #include "signal-util.h" #include "socket-util.h" #include "special.h" +#include "stdio-util.h" #include "util.h" /* exit codes as defined in fsck(8) */ diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index dc87b21020..f70d278e1c 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -48,6 +48,7 @@ #include "signal-util.h" #include "socket-util.h" #include "stat-util.h" +#include "stdio-util.h" #include "string-table.h" #include "string-util.h" #include "strv.h" diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index dddd5703f4..8fe99fae99 100644 --- a/src/journal/journal-send.c +++ b/src/journal/journal-send.c @@ -36,6 +36,7 @@ #include "io-util.h" #include "memfd-util.h" #include "socket-util.h" +#include "stdio-util.h" #include "string-util.h" #include "util.h" diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index 9acc324bc5..72c4ba5879 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -31,6 +31,7 @@ #include "journald-server.h" #include "parse-util.h" #include "process-util.h" +#include "stdio-util.h" #include "terminal-util.h" static bool prefix_timestamp(void) { diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 52e1fbeb3d..489f6f689c 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -37,6 +37,7 @@ #include "journald-syslog.h" #include "parse-util.h" #include "process-util.h" +#include "stdio-util.h" #include "string-util.h" void server_forward_kmsg( diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index de4f4d97fe..0dd6d54d68 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -44,6 +44,7 @@ #include "parse-util.h" #include "selinux-util.h" #include "socket-util.h" +#include "stdio-util.h" #include "string-util.h" #include "syslog-util.h" diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index d0c4a41b9d..3553e9cc1d 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -36,6 +36,7 @@ #include "process-util.h" #include "selinux-util.h" #include "socket-util.h" +#include "stdio-util.h" #include "string-util.h" #include "syslog-util.h" diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index cfe1623e5b..bd93d90776 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -47,6 +47,8 @@ #include "missing.h" #include "path-util.h" #include "replace-var.h" +#include "stat-util.h" +#include "stdio-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c index 7c9dcf5283..5951db483d 100644 --- a/src/libsystemd/sd-bus/bus-control.c +++ b/src/libsystemd/sd-bus/bus-control.c @@ -34,6 +34,7 @@ #include "bus-message.h" #include "bus-util.h" #include "capability-util.h" +#include "stdio-util.h" #include "string-util.h" #include "strv.h" #include "user-util.h" diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 7ca544f6fd..2c46d84cd0 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -32,10 +32,11 @@ #include "bus-socket.h" #include "fd-util.h" #include "formats-util.h" +#include "hexdecoct.h" #include "macro.h" #include "missing.h" -#include "hexdecoct.h" #include "signal-util.h" +#include "stdio-util.h" #include "string-util.h" #include "user-util.h" #include "utf8.h" diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 3c91fa8644..182dedda89 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -39,6 +39,7 @@ #include "machined.h" #include "path-util.h" #include "process-util.h" +#include "stdio-util.h" #include "strv.h" #include "unit-name.h" #include "user-util.h" diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index de49fd5c22..ab37c43dcb 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -33,6 +33,7 @@ #include "networkd-netdev.h" #include "set.h" #include "socket-util.h" +#include "stdio-util.h" #include "string-table.h" #include "udev-util.h" #include "util.h" diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 28bca1f71e..1ce219b844 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -91,6 +91,7 @@ #include "signal-util.h" #include "socket-util.h" #include "stat-util.h" +#include "stdio-util.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index b253eb95ee..8f6278191a 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -43,6 +43,7 @@ #include "rlimit-util.h" #include "set.h" #include "signal-util.h" +#include "stdio-util.h" #include "string-util.h" #include "strv.h" #include "syslog-util.h" diff --git a/src/shared/efivars.c b/src/shared/efivars.c index 6e8f156a68..e7972d1574 100644 --- a/src/shared/efivars.c +++ b/src/shared/efivars.c @@ -28,6 +28,7 @@ #include "fd-util.h" #include "io-util.h" #include "parse-util.h" +#include "stdio-util.h" #include "utf8.h" #include "util.h" #include "virt.h" diff --git a/src/shared/spawn-polkit-agent.c b/src/shared/spawn-polkit-agent.c index 7cc9e7ccc1..ec6e5a8312 100644 --- a/src/shared/spawn-polkit-agent.c +++ b/src/shared/spawn-polkit-agent.c @@ -30,6 +30,7 @@ #include "log.h" #include "process-util.h" #include "spawn-polkit-agent.h" +#include "stdio-util.h" #include "util.h" #ifdef ENABLE_POLKIT @@ -78,8 +79,9 @@ void polkit_agent_close(void) { return; /* Inform agent that we are done */ - kill(agent_pid, SIGTERM); - kill(agent_pid, SIGCONT); + (void) kill(agent_pid, SIGTERM); + (void) kill(agent_pid, SIGCONT); + (void) wait_for_terminate(agent_pid, NULL); agent_pid = 0; } diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 7217f54611..41deea70fb 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -62,6 +62,7 @@ #include "set.h" #include "specifier.h" #include "stat-util.h" +#include "stdio-util.h" #include "string-table.h" #include "string-util.h" #include "strv.h" diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c index 74df4cb0f4..aa10beafb0 100644 --- a/src/udev/udev-builtin-keyboard.c +++ b/src/udev/udev-builtin-keyboard.c @@ -25,6 +25,7 @@ #include "fd-util.h" #include "parse-util.h" +#include "stdio-util.h" #include "string-util.h" #include "udev.h" -- cgit v1.2.3-54-g00ecf From 7d50b32a129e781401cf897475f388f682de1368 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 01:48:17 +0100 Subject: util-lib: split out globbing related calls into glob-util.[ch] --- Makefile.am | 2 ++ src/analyze/analyze.c | 1 + src/basic/glob-util.c | 71 +++++++++++++++++++++++++++++++++++++ src/basic/glob-util.h | 37 +++++++++++++++++++ src/basic/macro.h | 3 -- src/basic/util.c | 44 ----------------------- src/basic/util.h | 14 ++------ src/core/execute.c | 1 + src/core/path.c | 1 + src/journal-remote/journal-upload.c | 1 + src/journal/fsprg.h | 1 + src/journal/journalctl.c | 1 + src/shared/condition.c | 1 + src/systemctl/systemctl.c | 1 + src/test/test-util.c | 3 +- src/tmpfiles/tmpfiles.c | 1 + src/udev/udev-rules.c | 1 + 17 files changed, 125 insertions(+), 59 deletions(-) create mode 100644 src/basic/glob-util.c create mode 100644 src/basic/glob-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index c47ad240ab..3c4250a144 100644 --- a/Makefile.am +++ b/Makefile.am @@ -812,6 +812,8 @@ libbasic_la_SOURCES = \ src/basic/mount-util.h \ src/basic/hexdecoct.c \ src/basic/hexdecoct.h \ + src/basic/glob-util.h \ + src/basic/glob-util.c \ src/basic/extract-word.c \ src/basic/extract-word.h \ src/basic/escape.c \ diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index a165152cb2..7e63bfa821 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -30,6 +30,7 @@ #include "analyze-verify.h" #include "bus-error.h" #include "bus-util.h" +#include "glob-util.h" #include "hashmap.h" #include "locale-util.h" #include "log.h" diff --git a/src/basic/glob-util.c b/src/basic/glob-util.c new file mode 100644 index 0000000000..112c6392e5 --- /dev/null +++ b/src/basic/glob-util.c @@ -0,0 +1,71 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "glob-util.h" +#include "strv.h" +#include "util.h" + +int glob_exists(const char *path) { + _cleanup_globfree_ glob_t g = {}; + int k; + + assert(path); + + errno = 0; + k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g); + + if (k == GLOB_NOMATCH) + return 0; + if (k == GLOB_NOSPACE) + return -ENOMEM; + if (k != 0) + return errno ? -errno : -EIO; + + return !strv_isempty(g.gl_pathv); +} + +int glob_extend(char ***strv, const char *path) { + _cleanup_globfree_ glob_t g = {}; + int k; + char **p; + + errno = 0; + k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g); + + if (k == GLOB_NOMATCH) + return -ENOENT; + if (k == GLOB_NOSPACE) + return -ENOMEM; + if (k != 0) + return errno ? -errno : -EIO; + if (strv_isempty(g.gl_pathv)) + return -ENOENT; + + STRV_FOREACH(p, g.gl_pathv) { + k = strv_extend(strv, *p); + if (k < 0) + return k; + } + + return 0; +} diff --git a/src/basic/glob-util.h b/src/basic/glob-util.h new file mode 100644 index 0000000000..8817df14b4 --- /dev/null +++ b/src/basic/glob-util.h @@ -0,0 +1,37 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "macro.h" +#include "util.h" + +int glob_exists(const char *path); +int glob_extend(char ***strv, const char *path); + +#define _cleanup_globfree_ _cleanup_(globfree) + +_pure_ static inline bool string_is_glob(const char *p) { + /* Check if a string contains any glob patterns. */ + return !!strpbrk(p, GLOB_CHARS); +} diff --git a/src/basic/macro.h b/src/basic/macro.h index 975714da2b..daa7c416f7 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -294,9 +294,6 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { #define PTR_TO_SIZE(p) ((size_t) ((uintptr_t) (p))) #define SIZE_TO_PTR(u) ((void *) ((uintptr_t) (u))) -#define memzero(x,l) (memset((x), 0, (l))) -#define zero(x) (memzero(&(x), sizeof(x))) - #define CHAR_TO_STR(x) ((char[2]) { x, 0 }) #define char_array_0(x) x[sizeof(x)-1] = 0; diff --git a/src/basic/util.c b/src/basic/util.c index 412ea50b96..6da311ad1e 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -368,49 +367,6 @@ int socket_from_display(const char *display, char **path) { return 0; } -int glob_exists(const char *path) { - _cleanup_globfree_ glob_t g = {}; - int k; - - assert(path); - - errno = 0; - k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g); - - if (k == GLOB_NOMATCH) - return 0; - else if (k == GLOB_NOSPACE) - return -ENOMEM; - else if (k == 0) - return !strv_isempty(g.gl_pathv); - else - return errno ? -errno : -EIO; -} - -int glob_extend(char ***strv, const char *path) { - _cleanup_globfree_ glob_t g = {}; - int k; - char **p; - - errno = 0; - k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g); - - if (k == GLOB_NOMATCH) - return -ENOENT; - else if (k == GLOB_NOSPACE) - return -ENOMEM; - else if (k != 0 || strv_isempty(g.gl_pathv)) - return errno ? -errno : -EIO; - - STRV_FOREACH(p, g.gl_pathv) { - k = strv_extend(strv, *p); - if (k < 0) - break; - } - - return k; -} - int block_get_whole_disk(dev_t d, dev_t *ret) { char *p, *s; int r; diff --git a/src/basic/util.h b/src/basic/util.h index 95c7c75b9c..3074029f38 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -94,9 +94,6 @@ bool plymouth_running(void); bool display_is_local(const char *display) _pure_; int socket_from_display(const char *display, char **path); -int glob_exists(const char *path); -int glob_extend(char ***strv, const char *path); - int block_get_whole_disk(dev_t d, dev_t *ret); #define NULSTR_FOREACH(i, l) \ @@ -132,7 +129,6 @@ static inline void freep(void *p) { } #define _cleanup_free_ _cleanup_(freep) -#define _cleanup_globfree_ _cleanup_(globfree) _malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) { if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) @@ -155,13 +151,6 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_ return memdup(p, a * b); } -/** - * Check if a string contains any glob patterns. - */ -_pure_ static inline bool string_is_glob(const char *p) { - return !!strpbrk(p, GLOB_CHARS); -} - void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); @@ -173,6 +162,9 @@ static inline void *mempset(void *s, int c, size_t n) { return (uint8_t*)s + n; } +#define memzero(x,l) (memset((x), 0, (l))) +#define zero(x) (memzero(&(x), sizeof(x))) + void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size); void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size); #define GREEDY_REALLOC(array, allocated, need) \ diff --git a/src/core/execute.c b/src/core/execute.c index 3814fd4381..bf13e29bd9 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -70,6 +70,7 @@ #include "fileio.h" #include "formats-util.h" #include "fs-util.h" +#include "glob-util.h" #include "io-util.h" #include "ioprio.h" #include "log.h" diff --git a/src/core/path.c b/src/core/path.c index 761ec265b4..9c5309a58a 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -28,6 +28,7 @@ #include "bus-util.h" #include "dbus-path.h" #include "fd-util.h" +#include "glob-util.h" #include "macro.h" #include "mkdir.h" #include "path.h" diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 20e2a2f73b..1925475db8 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -31,6 +31,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "glob-util.h" #include "journal-upload.h" #include "log.h" #include "mkdir.h" diff --git a/src/journal/fsprg.h b/src/journal/fsprg.h index 150d034828..5959b1fed2 100644 --- a/src/journal/fsprg.h +++ b/src/journal/fsprg.h @@ -29,6 +29,7 @@ #include #include "macro.h" +#include "util.h" #ifdef __cplusplus extern "C" { diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 1965522dfd..2782ac0329 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -47,6 +47,7 @@ #include "fileio.h" #include "fs-util.h" #include "fsprg.h" +#include "glob-util.h" #include "hostname-util.h" #include "io-util.h" #include "journal-def.h" diff --git a/src/shared/condition.c b/src/shared/condition.c index d06120f0d7..2929e3e821 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -34,6 +34,7 @@ #include "condition.h" #include "extract-word.h" #include "fd-util.h" +#include "glob-util.h" #include "hostname-util.h" #include "ima-util.h" #include "mount-util.h" diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 2166554f4d..2faa93ef88 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -52,6 +52,7 @@ #include "fileio.h" #include "formats-util.h" #include "fs-util.h" +#include "glob-util.h" #include "hostname-util.h" #include "initreq.h" #include "install.h" diff --git a/src/test/test-util.c b/src/test/test-util.c index 6c6fce2d6a..647eff0496 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -39,6 +39,7 @@ #include "fileio.h" #include "fs-util.h" #include "fstab-util.h" +#include "glob-util.h" #include "hexdecoct.h" #include "io-util.h" #include "mkdir.h" @@ -54,8 +55,8 @@ #include "user-util.h" #include "util.h" #include "virt.h" -#include "xattr-util.h" #include "web-util.h" +#include "xattr-util.h" static void test_streq_ptr(void) { assert_se(streq_ptr(NULL, NULL)); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 41deea70fb..5196447963 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -49,6 +49,7 @@ #include "fileio.h" #include "formats-util.h" #include "fs-util.h" +#include "glob-util.h" #include "io-util.h" #include "label.h" #include "log.h" diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index b87c14efb2..7d5f473d45 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -32,6 +32,7 @@ #include "conf-files.h" #include "escape.h" #include "fd-util.h" +#include "glob-util.h" #include "path-util.h" #include "stat-util.h" #include "strbuf.h" -- cgit v1.2.3-54-g00ecf From b5efdb8af40ea759a1ea584c1bc44ecc81dd00ce Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 03:01:06 +0100 Subject: util-lib: split out allocation calls into alloc-util.[ch] --- Makefile.am | 2 + src/activate/activate.c | 3 +- src/analyze/analyze-verify.c | 1 + src/analyze/analyze.c | 1 + src/backlight/backlight.c | 1 + src/basic/alloc-util.c | 81 +++++++++++++++ src/basic/alloc-util.h | 108 ++++++++++++++++++++ src/basic/audit-util.c | 1 + src/basic/bitmap.c | 4 +- src/basic/btrfs-util.c | 1 + src/basic/bus-label.c | 3 +- src/basic/calendarspec.c | 1 + src/basic/capability-util.c | 1 + src/basic/cgroup-util.c | 1 + src/basic/copy.c | 1 + src/basic/cpu-set-util.c | 1 + src/basic/env-util.c | 3 +- src/basic/escape.c | 1 + src/basic/extract-word.c | 1 + src/basic/fileio.c | 1 + src/basic/fs-util.c | 1 + src/basic/hashmap.c | 1 + src/basic/hexdecoct.c | 1 + src/basic/in-addr-util.c | 1 + src/basic/json.c | 1 + src/basic/lockfile-util.c | 1 + src/basic/log.c | 1 + src/basic/memfd-util.c | 1 + src/basic/mount-util.c | 1 + src/basic/path-util.c | 1 + src/basic/prioq.c | 3 +- src/basic/proc-cmdline.c | 1 + src/basic/process-util.c | 1 + src/basic/replace-var.c | 1 + src/basic/selinux-util.c | 1 + src/basic/smack-util.c | 1 + src/basic/socket-label.c | 1 + src/basic/socket-util.c | 1 + src/basic/strbuf.c | 3 +- src/basic/string-util.c | 1 + src/basic/strv.c | 1 + src/basic/terminal-util.c | 1 + src/basic/time-util.c | 1 + src/basic/unit-name.c | 1 + src/basic/user-util.c | 1 + src/basic/utf8.c | 1 + src/basic/util.c | 59 +---------- src/basic/util.h | 109 +++------------------ src/basic/virt.c | 3 +- src/basic/xattr-util.c | 1 + src/binfmt/binfmt.c | 1 + src/boot/bootctl.c | 1 + src/bootchart/bootchart.c | 1 + src/bootchart/store.c | 1 + src/bootchart/svg.c | 1 + src/bus-proxyd/bus-proxyd.c | 1 + src/bus-proxyd/bus-xml-policy.c | 1 + src/bus-proxyd/driver.c | 1 + src/bus-proxyd/proxy.c | 1 + src/bus-proxyd/stdio-bridge.c | 1 + src/bus-proxyd/test-bus-xml-policy.c | 1 + src/cgls/cgls.c | 1 + src/cgtop/cgtop.c | 1 + src/core/automount.c | 1 + src/core/bus-endpoint.c | 5 +- src/core/bus-policy.c | 1 + src/core/busname.c | 1 + src/core/cgroup.c | 1 + src/core/dbus-cgroup.c | 1 + src/core/dbus-execute.c | 1 + src/core/dbus-job.c | 3 +- src/core/dbus-manager.c | 1 + src/core/dbus-scope.c | 15 +-- src/core/dbus-service.c | 1 + src/core/dbus-socket.c | 3 +- src/core/dbus-timer.c | 7 +- src/core/dbus-unit.c | 1 + src/core/dbus.c | 1 + src/core/device.c | 1 + src/core/execute.c | 1 + src/core/hostname-setup.c | 1 + src/core/job.c | 1 + src/core/killall.c | 1 + src/core/load-fragment.c | 1 + src/core/machine-id-setup.c | 1 + src/core/main.c | 1 + src/core/manager.c | 1 + src/core/mount-setup.c | 1 + src/core/mount.c | 3 +- src/core/namespace.c | 1 + src/core/scope.c | 3 +- src/core/selinux-access.c | 1 + src/core/service.c | 1 + src/core/show-status.c | 1 + src/core/shutdown.c | 1 + src/core/slice.c | 1 + src/core/smack-setup.c | 1 + src/core/snapshot.c | 1 + src/core/socket.c | 1 + src/core/swap.c | 1 + src/core/timer.c | 1 + src/core/transaction.c | 3 +- src/core/umount.c | 1 + src/core/unit-printf.c | 1 + src/core/unit.c | 1 + src/cryptsetup/cryptsetup-generator.c | 1 + src/cryptsetup/cryptsetup.c | 1 + src/dbus1-generator/dbus1-generator.c | 1 + src/debug-generator/debug-generator.c | 1 + src/delta/delta.c | 1 + src/escape/escape.c | 1 + src/firstboot/firstboot.c | 1 + src/fsck/fsck.c | 1 + src/fstab-generator/fstab-generator.c | 1 + src/getty-generator/getty-generator.c | 1 + src/gpt-auto-generator/gpt-auto-generator.c | 1 + src/hibernate-resume/hibernate-resume-generator.c | 1 + src/hibernate-resume/hibernate-resume.c | 3 +- src/hostname/hostnamectl.c | 1 + src/hostname/hostnamed.c | 1 + src/hwdb/hwdb.c | 1 + src/import/curl-util.c | 1 + src/import/export-raw.c | 1 + src/import/export-tar.c | 1 + src/import/export.c | 1 + src/import/import-raw.c | 1 + src/import/import-tar.c | 1 + src/import/import.c | 1 + src/import/importd.c | 1 + src/import/pull-common.c | 1 + src/import/pull-dkr.c | 1 + src/import/pull-job.c | 1 + src/import/pull-raw.c | 1 + src/import/pull-tar.c | 1 + src/import/pull.c | 1 + src/import/qcow2-util.c | 7 +- src/initctl/initctl.c | 1 + src/journal-remote/journal-gatewayd.c | 1 + src/journal-remote/journal-remote-parse.c | 1 + src/journal-remote/journal-remote-write.c | 1 + src/journal-remote/journal-remote.c | 1 + src/journal-remote/journal-upload-journal.c | 26 ++++- src/journal-remote/journal-upload.c | 1 + src/journal-remote/microhttpd-util.c | 1 + src/journal/catalog.c | 1 + src/journal/compress.c | 1 + src/journal/coredump-vacuum.c | 1 + src/journal/coredump.c | 1 + src/journal/coredumpctl.c | 1 + src/journal/journal-file.c | 1 + src/journal/journal-send.c | 1 + src/journal/journal-vacuum.c | 1 + src/journal/journal-verify.c | 1 + src/journal/journalctl.c | 1 + src/journal/journald-audit.c | 1 + src/journal/journald-console.c | 1 + src/journal/journald-native.c | 1 + src/journal/journald-rate-limit.c | 1 + src/journal/journald-server.c | 1 + src/journal/journald-stream.c | 1 + src/journal/journald-syslog.c | 1 + src/journal/journald-wall.c | 1 + src/journal/mmap-cache.c | 1 + src/journal/sd-journal.c | 1 + src/journal/stacktrace.c | 1 + src/journal/test-catalog.c | 1 + src/journal/test-compress-benchmark.c | 1 + src/journal/test-compress.c | 1 + src/journal/test-journal-flush.c | 1 + src/journal/test-journal-interleaving.c | 1 + src/journal/test-journal-match.c | 1 + src/journal/test-journal-stream.c | 1 + src/journal/test-journal-syslog.c | 1 + src/libsystemd-network/dhcp6-option.c | 10 +- src/libsystemd-network/lldp-internal.c | 1 + src/libsystemd-network/lldp-port.c | 1 + src/libsystemd-network/lldp-tlv.c | 3 +- src/libsystemd-network/network-internal.c | 1 + src/libsystemd-network/sd-dhcp-client.c | 1 + src/libsystemd-network/sd-dhcp-lease.c | 1 + src/libsystemd-network/sd-dhcp-server.c | 1 + src/libsystemd-network/sd-dhcp6-client.c | 1 + src/libsystemd-network/sd-dhcp6-lease.c | 6 +- src/libsystemd-network/sd-ipv4acd.c | 1 + src/libsystemd-network/sd-ipv4ll.c | 1 + src/libsystemd-network/sd-lldp.c | 1 + src/libsystemd-network/sd-ndisc.c | 1 + src/libsystemd-network/sd-pppoe.c | 1 + src/libsystemd-network/test-dhcp-client.c | 1 + src/libsystemd-network/test-dhcp-option.c | 8 +- src/libsystemd-network/test-ipv4ll-manual.c | 1 + src/libsystemd-network/test-lldp.c | 1 + src/libsystemd/sd-bus/bus-control.c | 1 + src/libsystemd/sd-bus/bus-creds.c | 1 + src/libsystemd/sd-bus/bus-dump.c | 1 + src/libsystemd/sd-bus/bus-error.c | 1 + src/libsystemd/sd-bus/bus-internal.c | 1 + src/libsystemd/sd-bus/bus-kernel.c | 1 + src/libsystemd/sd-bus/bus-match.c | 1 + src/libsystemd/sd-bus/bus-message.c | 1 + src/libsystemd/sd-bus/bus-objects.c | 1 + src/libsystemd/sd-bus/bus-slot.c | 1 + src/libsystemd/sd-bus/bus-socket.c | 1 + src/libsystemd/sd-bus/bus-track.c | 1 + src/libsystemd/sd-bus/busctl-introspect.c | 3 +- src/libsystemd/sd-bus/busctl.c | 1 + src/libsystemd/sd-bus/sd-bus.c | 1 + src/libsystemd/sd-bus/test-bus-benchmark.c | 1 + src/libsystemd/sd-bus/test-bus-chat.c | 1 + src/libsystemd/sd-bus/test-bus-gvariant.c | 1 + src/libsystemd/sd-bus/test-bus-kernel-bloom.c | 1 + src/libsystemd/sd-bus/test-bus-kernel.c | 1 + src/libsystemd/sd-bus/test-bus-marshal.c | 1 + src/libsystemd/sd-bus/test-bus-objects.c | 1 + src/libsystemd/sd-bus/test-bus-proxy.c | 1 + src/libsystemd/sd-bus/test-bus-zero-copy.c | 1 + src/libsystemd/sd-daemon/sd-daemon.c | 1 + src/libsystemd/sd-device/device-enumerator.c | 1 + src/libsystemd/sd-device/device-private.c | 1 + src/libsystemd/sd-device/sd-device.c | 1 + src/libsystemd/sd-event/sd-event.c | 1 + src/libsystemd/sd-hwdb/sd-hwdb.c | 1 + src/libsystemd/sd-login/sd-login.c | 1 + src/libsystemd/sd-login/test-login.c | 1 + src/libsystemd/sd-netlink/local-addresses.c | 2 + src/libsystemd/sd-netlink/netlink-message.c | 1 + src/libsystemd/sd-netlink/netlink-socket.c | 1 + src/libsystemd/sd-netlink/sd-netlink.c | 1 + src/libsystemd/sd-netlink/test-local-addresses.c | 1 + src/libsystemd/sd-network/network-util.c | 1 + src/libsystemd/sd-network/sd-network.c | 1 + src/libsystemd/sd-path/sd-path.c | 1 + src/libsystemd/sd-resolve/sd-resolve.c | 1 + src/libsystemd/sd-resolve/test-resolve.c | 1 + src/libudev/libudev-device.c | 1 + src/libudev/libudev-enumerate.c | 1 + src/libudev/libudev-hwdb.c | 1 + src/libudev/libudev-list.c | 5 +- src/libudev/libudev-monitor.c | 1 + src/libudev/libudev-queue.c | 1 + src/libudev/libudev.c | 1 + src/locale/localed.c | 1 + src/login/inhibit.c | 1 + src/login/loginctl.c | 1 + src/login/logind-acl.c | 1 + src/login/logind-action.c | 1 + src/login/logind-button.c | 1 + src/login/logind-core.c | 1 + src/login/logind-dbus.c | 1 + src/login/logind-device.c | 3 +- src/login/logind-inhibit.c | 1 + src/login/logind-seat-dbus.c | 1 + src/login/logind-seat.c | 1 + src/login/logind-session-dbus.c | 1 + src/login/logind-session-device.c | 1 + src/login/logind-session.c | 1 + src/login/logind-user-dbus.c | 1 + src/login/logind-user.c | 1 + src/login/logind-utmp.c | 1 + src/login/logind.c | 1 + src/login/pam_systemd.c | 1 + src/login/sysfs-show.c | 1 + src/machine/image-dbus.c | 1 + src/machine/machine-dbus.c | 1 + src/machine/machine.c | 1 + src/machine/machinectl.c | 1 + src/machine/machined-dbus.c | 1 + src/machine/machined.c | 1 + src/network/networkctl.c | 1 + src/network/networkd-address-pool.c | 1 + src/network/networkd-address.c | 1 + src/network/networkd-dhcp4.c | 5 +- src/network/networkd-fdb.c | 6 +- src/network/networkd-link-bus.c | 1 + src/network/networkd-link.c | 1 + src/network/networkd-manager-bus.c | 2 +- src/network/networkd-manager.c | 1 + src/network/networkd-netdev-bond.c | 1 + src/network/networkd-netdev-tuntap.c | 1 + src/network/networkd-netdev.c | 1 + src/network/networkd-network-bus.c | 1 + src/network/networkd-network.c | 1 + src/network/networkd-route.c | 1 + src/network/networkd-wait-online-link.c | 1 + src/network/networkd-wait-online-manager.c | 5 +- src/network/test-network.c | 1 + src/notify/notify.c | 1 + src/nspawn/nspawn-cgroup.c | 1 + src/nspawn/nspawn-expose-ports.c | 1 + src/nspawn/nspawn-mount.c | 1 + src/nspawn/nspawn-network.c | 1 + src/nspawn/nspawn-settings.c | 1 + src/nspawn/nspawn-setuid.c | 1 + src/nspawn/nspawn.c | 1 + src/nss-myhostname/nss-myhostname.c | 1 + src/nss-mymachines/nss-mymachines.c | 1 + src/path/path.c | 1 + src/random-seed/random-seed.c | 1 + src/rc-local-generator/rc-local-generator.c | 1 + src/resolve-host/resolve-host.c | 1 + src/resolve/resolved-bus.c | 2 +- src/resolve/resolved-conf.c | 6 +- src/resolve/resolved-dns-answer.c | 1 + src/resolve/resolved-dns-cache.c | 1 + src/resolve/resolved-dns-packet.c | 1 + src/resolve/resolved-dns-query.c | 4 +- src/resolve/resolved-dns-question.c | 3 +- src/resolve/resolved-dns-rr.c | 1 + src/resolve/resolved-dns-scope.c | 1 + src/resolve/resolved-dns-server.c | 4 +- src/resolve/resolved-dns-stream.c | 1 + src/resolve/resolved-dns-transaction.c | 1 + src/resolve/resolved-dns-zone.c | 1 + src/resolve/resolved-link.c | 1 + src/resolve/resolved-manager.c | 1 + src/rfkill/rfkill.c | 1 + src/run/run.c | 1 + src/shared/acl-util.c | 1 + src/shared/acpi-fpdt.c | 1 + src/shared/apparmor-util.c | 1 + src/shared/ask-password-api.c | 1 + src/shared/base-filesystem.c | 1 + src/shared/bus-util.c | 1 + src/shared/cgroup-show.c | 1 + src/shared/condition.c | 1 + src/shared/conf-parser.c | 1 + src/shared/dev-setup.c | 1 + src/shared/dns-domain.c | 1 + src/shared/dropin.c | 1 + src/shared/efivars.c | 1 + src/shared/firewall-util.c | 3 +- src/shared/fstab-util.c | 1 + src/shared/generator.c | 1 + src/shared/import-util.c | 1 + src/shared/install-printf.c | 1 + src/shared/install.c | 1 + src/shared/logs-show.c | 1 + src/shared/machine-image.c | 1 + src/shared/machine-pool.c | 1 + src/shared/path-lookup.c | 1 + src/shared/ptyfwd.c | 1 + src/shared/sleep-config.c | 1 + src/shared/specifier.c | 3 +- src/shared/utmp-wtmp.c | 1 + src/socket-proxy/socket-proxyd.c | 1 + src/systemctl/systemctl.c | 1 + src/sysusers/sysusers.c | 1 + src/sysv-generator/sysv-generator.c | 1 + src/test/test-calendarspec.c | 1 + src/test/test-cap-list.c | 1 + src/test/test-cgroup-util.c | 1 + src/test/test-condition.c | 1 + src/test/test-conf-files.c | 1 + src/test/test-copy.c | 1 + src/test/test-date.c | 3 +- src/test/test-device-nodes.c | 1 + src/test/test-dns-domain.c | 1 + src/test/test-ellipsize.c | 1 + src/test/test-fileio.c | 1 + src/test/test-fstab-util.c | 1 + src/test/test-hashmap-plain.c | 1 + src/test/test-hostname-util.c | 3 +- src/test/test-id128.c | 1 + src/test/test-json.c | 1 + src/test/test-namespace.c | 1 + src/test/test-path-util.c | 1 + src/test/test-path.c | 1 + src/test/test-prioq.c | 5 +- src/test/test-process-util.c | 1 + src/test/test-socket-util.c | 1 + src/test/test-strv.c | 1 + src/test/test-tmpfiles.c | 1 + src/test/test-uid-range.c | 1 + src/test/test-unit-file.c | 1 + src/test/test-unit-name.c | 1 + src/test/test-user-util.c | 1 + src/test/test-utf8.c | 1 + src/test/test-util.c | 1 + src/test/test-xml.c | 1 + src/timedate/timedated.c | 1 + src/timesync/timesyncd-conf.c | 5 +- src/timesync/timesyncd-manager.c | 1 + src/timesync/timesyncd-server.c | 1 + src/tmpfiles/tmpfiles.c | 1 + .../tty-ask-password-agent.c | 1 + src/udev/collect/collect.c | 1 + src/udev/net/link-config.c | 1 + src/udev/udev-builtin-blkid.c | 1 + src/udev/udev-builtin-hwdb.c | 1 + src/udev/udev-builtin-net_setup_link.c | 3 +- src/udev/udev-builtin-path_id.c | 1 + src/udev/udev-builtin-usb_id.c | 1 + src/udev/udev-ctrl.c | 1 + src/udev/udev-event.c | 1 + src/udev/udev-rules.c | 1 + src/udev/udevadm-hwdb.c | 1 + src/udev/udevd.c | 1 + src/update-utmp/update-utmp.c | 11 ++- src/vconsole/vconsole-setup.c | 1 + 399 files changed, 691 insertions(+), 232 deletions(-) create mode 100644 src/basic/alloc-util.c create mode 100644 src/basic/alloc-util.h (limited to 'src/journal') diff --git a/Makefile.am b/Makefile.am index 3c4250a144..9250f8f2c5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -943,6 +943,8 @@ libbasic_la_SOURCES = \ src/basic/rm-rf.h \ src/basic/copy.c \ src/basic/copy.h \ + src/basic/alloc-util.h \ + src/basic/alloc-util.c \ src/basic/formats-util.h nodist_libbasic_la_SOURCES = \ diff --git a/src/activate/activate.c b/src/activate/activate.c index 0e6ead310e..b7e6255f49 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -28,13 +28,14 @@ #include "sd-daemon.h" +#include "alloc-util.h" +#include "fd-util.h" #include "log.h" #include "macro.h" #include "signal-util.h" #include "socket-util.h" #include "string-util.h" #include "strv.h" -#include "fd-util.h" static char** arg_listen = NULL; static bool arg_accept = false; diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c index 2b6240232c..a377996a37 100644 --- a/src/analyze/analyze-verify.c +++ b/src/analyze/analyze-verify.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "analyze-verify.h" #include "bus-util.h" #include "log.h" diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 7e63bfa821..27ead903e9 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -27,6 +27,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "analyze-verify.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index 9112ed328d..08980fba82 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -21,6 +21,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "def.h" #include "escape.h" #include "fileio.h" diff --git a/src/basic/alloc-util.c b/src/basic/alloc-util.c new file mode 100644 index 0000000000..48183e381f --- /dev/null +++ b/src/basic/alloc-util.c @@ -0,0 +1,81 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010 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 "alloc-util.h" +#include "util.h" + +void* memdup(const void *p, size_t l) { + void *r; + + assert(p); + + r = malloc(l); + if (!r) + return NULL; + + memcpy(r, p, l); + return r; +} + +void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) { + size_t a, newalloc; + void *q; + + assert(p); + assert(allocated); + + if (*allocated >= need) + return *p; + + newalloc = MAX(need * 2, 64u / size); + a = newalloc * size; + + /* check for overflows */ + if (a < size * need) + return NULL; + + q = realloc(*p, a); + if (!q) + return NULL; + + *p = q; + *allocated = newalloc; + return q; +} + +void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size) { + size_t prev; + uint8_t *q; + + assert(p); + assert(allocated); + + prev = *allocated; + + q = greedy_realloc(p, allocated, need, size); + if (!q) + return NULL; + + if (*allocated > prev) + memzero(q + prev * size, (*allocated - prev) * size); + + return q; +} diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h new file mode 100644 index 0000000000..12b602e185 --- /dev/null +++ b/src/basic/alloc-util.h @@ -0,0 +1,108 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010 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 "macro.h" + +#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n))) + +#define new0(t, n) ((t*) calloc((n), sizeof(t))) + +#define newa(t, n) ((t*) alloca(sizeof(t)*(n))) + +#define newa0(t, n) ((t*) alloca0(sizeof(t)*(n))) + +#define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n))) + +#define malloc0(n) (calloc(1, (n))) + +static inline void *mfree(void *memory) { + free(memory); + return NULL; +} + +void* memdup(const void *p, size_t l) _alloc_(2); + +static inline void freep(void *p) { + free(*(void**) p); +} + +#define _cleanup_free_ _cleanup_(freep) + +_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) { + if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) + return NULL; + + return malloc(a * b); +} + +_alloc_(2, 3) static inline void *realloc_multiply(void *p, size_t a, size_t b) { + if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) + return NULL; + + return realloc(p, a * b); +} + +_alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_t b) { + if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) + return NULL; + + return memdup(p, a * b); +} + +void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size); +void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size); + +#define GREEDY_REALLOC(array, allocated, need) \ + greedy_realloc((void**) &(array), &(allocated), (need), sizeof((array)[0])) + +#define GREEDY_REALLOC0(array, allocated, need) \ + greedy_realloc0((void**) &(array), &(allocated), (need), sizeof((array)[0])) + +#define alloca0(n) \ + ({ \ + char *_new_; \ + size_t _len_ = n; \ + _new_ = alloca(_len_); \ + (void *) memset(_new_, 0, _len_); \ + }) + +/* It's not clear what alignment glibc/gcc alloca() guarantee, hence provide a guaranteed safe version */ +#define alloca_align(size, align) \ + ({ \ + void *_ptr_; \ + size_t _mask_ = (align) - 1; \ + _ptr_ = alloca((size) + _mask_); \ + (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); \ + }) + +#define alloca0_align(size, align) \ + ({ \ + void *_new_; \ + size_t _size_ = (size); \ + _new_ = alloca_align(_size_, (align)); \ + (void*)memset(_new_, 0, _size_); \ + }) diff --git a/src/basic/audit-util.c b/src/basic/audit-util.c index 93d1adaf99..4612297334 100644 --- a/src/basic/audit-util.c +++ b/src/basic/audit-util.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "audit-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/basic/bitmap.c b/src/basic/bitmap.c index 2eabf3e1c1..1449e2ea85 100644 --- a/src/basic/bitmap.c +++ b/src/basic/bitmap.c @@ -19,9 +19,9 @@ along with systemd; If not, see . ***/ -#include "util.h" - +#include "alloc-util.h" #include "bitmap.h" +#include "util.h" struct Bitmap { uint64_t *bitmaps; diff --git a/src/basic/btrfs-util.c b/src/basic/btrfs-util.c index 7457e9f218..4c90bc0c80 100644 --- a/src/basic/btrfs-util.c +++ b/src/basic/btrfs-util.c @@ -26,6 +26,7 @@ #include #endif +#include "alloc-util.h" #include "btrfs-ctree.h" #include "btrfs-util.h" #include "copy.h" diff --git a/src/basic/bus-label.c b/src/basic/bus-label.c index 6f39528f13..c1534657ac 100644 --- a/src/basic/bus-label.c +++ b/src/basic/bus-label.c @@ -21,9 +21,10 @@ #include +#include "alloc-util.h" #include "bus-label.h" -#include "macro.h" #include "hexdecoct.h" +#include "macro.h" #include "util.h" char *bus_label_escape(const char *s) { diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 62b03a913c..a6a906f453 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "string-util.h" #include "calendarspec.h" #include "fileio.h" diff --git a/src/basic/capability-util.c b/src/basic/capability-util.c index 3a6ceed6f5..4479200306 100644 --- a/src/basic/capability-util.c +++ b/src/basic/capability-util.c @@ -26,6 +26,7 @@ #include #include +#include "alloc-util.h" #include "capability-util.h" #include "fileio.h" #include "log.h" diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 0f0e144b5e..f7fc2c2c97 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -29,6 +29,7 @@ #include #include +#include "alloc-util.h" #include "cgroup-util.h" #include "dirent-util.h" #include "extract-word.h" diff --git a/src/basic/copy.c b/src/basic/copy.c index a3a4099b4d..a187ae08fe 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "btrfs-util.h" #include "chattr-util.h" #include "copy.h" diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c index cbeae0bf20..9122ea5d48 100644 --- a/src/basic/cpu-set-util.c +++ b/src/basic/cpu-set-util.c @@ -20,6 +20,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "cpu-set-util.h" #include "extract-word.h" #include "parse-util.h" diff --git a/src/basic/env-util.c b/src/basic/env-util.c index a392af737c..94cb251698 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -22,12 +22,13 @@ #include #include +#include "alloc-util.h" #include "def.h" +#include "env-util.h" #include "string-util.h" #include "strv.h" #include "utf8.h" #include "util.h" -#include "env-util.h" #define VALID_CHARS_ENV_NAME \ DIGITS LETTERS \ diff --git a/src/basic/escape.c b/src/basic/escape.c index e763b5dac2..add0d7795b 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "escape.h" #include "hexdecoct.h" #include "utf8.h" diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c index f2b74802fa..c0f9394fad 100644 --- a/src/basic/extract-word.c +++ b/src/basic/extract-word.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "escape.h" #include "utf8.h" #include "util.h" diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 3dfd3af8af..619dafb517 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "ctype.h" #include "escape.h" #include "fd-util.h" diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 6ad381afb4..7aee404bfc 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "dirent-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 015cc629b1..4109a08c6c 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "hashmap.h" #include "macro.h" #include "mempool.h" diff --git a/src/basic/hexdecoct.c b/src/basic/hexdecoct.c index f958582e68..4eb566b15a 100644 --- a/src/basic/hexdecoct.c +++ b/src/basic/hexdecoct.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "hexdecoct.h" #include "util.h" diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c index d88864b598..f4e24121e7 100644 --- a/src/basic/in-addr-util.c +++ b/src/basic/in-addr-util.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "in-addr-util.h" int in_addr_is_null(int family, const union in_addr_union *u) { diff --git a/src/basic/json.c b/src/basic/json.c index efe635e20e..716705e5ff 100644 --- a/src/basic/json.c +++ b/src/basic/json.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "json.h" #include "macro.h" #include "hexdecoct.h" diff --git a/src/basic/lockfile-util.c b/src/basic/lockfile-util.c index 60235cc972..87c3aef7af 100644 --- a/src/basic/lockfile-util.c +++ b/src/basic/lockfile-util.c @@ -27,6 +27,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/basic/log.c b/src/basic/log.c index 505c0d072c..1582fce61c 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -31,6 +31,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "fd-util.h" #include "formats-util.h" #include "io-util.h" diff --git a/src/basic/memfd-util.c b/src/basic/memfd-util.c index 9d638b27f0..92630f6b25 100644 --- a/src/basic/memfd-util.c +++ b/src/basic/memfd-util.c @@ -27,6 +27,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "memfd-util.h" #include "missing.h" diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c index 24e88babcd..fefa50709c 100644 --- a/src/basic/mount-util.c +++ b/src/basic/mount-util.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 3783129f69..ec90c432a4 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -33,6 +33,7 @@ #include #undef basename +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/basic/prioq.c b/src/basic/prioq.c index d55b348c22..7590698911 100644 --- a/src/basic/prioq.c +++ b/src/basic/prioq.c @@ -29,8 +29,9 @@ * The underlying algorithm used in this implementation is a Heap. */ -#include "util.h" +#include "alloc-util.h" #include "prioq.h" +#include "util.h" struct prioq_item { void *data; diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c index dd0e18ed6e..dd91ce7dbc 100644 --- a/src/basic/proc-cmdline.c +++ b/src/basic/proc-cmdline.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "extract-word.h" #include "fileio.h" #include "macro.h" diff --git a/src/basic/process-util.c b/src/basic/process-util.c index c5d7dc3089..c534656c97 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -28,6 +28,7 @@ #include #include +#include "alloc-util.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/basic/replace-var.c b/src/basic/replace-var.c index 478fc43a38..18b49a9227 100644 --- a/src/basic/replace-var.c +++ b/src/basic/replace-var.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "macro.h" #include "util.h" #include "replace-var.h" diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c index 7a7dc90e3c..a821a3d5bb 100644 --- a/src/basic/selinux-util.c +++ b/src/basic/selinux-util.c @@ -29,6 +29,7 @@ #include #endif +#include "alloc-util.h" #include "strv.h" #include "path-util.h" #include "selinux-util.h" diff --git a/src/basic/smack-util.c b/src/basic/smack-util.c index a96fb5b594..fcc046098d 100644 --- a/src/basic/smack-util.c +++ b/src/basic/smack-util.c @@ -23,6 +23,7 @@ #include +#include "alloc-util.h" #include "fileio.h" #include "path-util.h" #include "process-util.h" diff --git a/src/basic/socket-label.c b/src/basic/socket-label.c index 4099ea6f9f..e5d4efc719 100644 --- a/src/basic/socket-label.c +++ b/src/basic/socket-label.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "macro.h" #include "missing.h" diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index ef5b764e60..1acab1ef95 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -30,6 +30,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "formats-util.h" diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c index 01a076c2ba..f4f702a05a 100644 --- a/src/basic/strbuf.c +++ b/src/basic/strbuf.c @@ -22,8 +22,9 @@ #include #include -#include "util.h" +#include "alloc-util.h" #include "strbuf.h" +#include "util.h" /* * Strbuf stores given strings in a single continuous allocated memory diff --git a/src/basic/string-util.c b/src/basic/string-util.c index a1781c505a..63b9b79df9 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "gunicode.h" #include "utf8.h" #include "util.h" diff --git a/src/basic/strv.c b/src/basic/strv.c index f5df269006..ba6df716a7 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "escape.h" #include "string-util.h" #include "util.h" diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 7d694e4664..b96bfcb8ef 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -31,6 +31,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 867e7b2430..9dc280efc6 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c index 43f52ce7c8..0775ae7c14 100644 --- a/src/basic/unit-name.c +++ b/src/basic/unit-name.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "bus-label.h" #include "def.h" #include "hexdecoct.h" diff --git a/src/basic/user-util.c b/src/basic/user-util.c index bdee77a7d2..d6c936db37 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "macro.h" #include "parse-util.h" diff --git a/src/basic/utf8.c b/src/basic/utf8.c index de124abbde..7600d99903 100644 --- a/src/basic/utf8.c +++ b/src/basic/utf8.c @@ -49,6 +49,7 @@ #include #include +#include "alloc-util.h" #include "hexdecoct.h" #include "utf8.h" #include "util.h" diff --git a/src/basic/util.c b/src/basic/util.c index 6da311ad1e..62d58c13fd 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -69,6 +69,7 @@ * otherwise conflicts with sys/mount.h. Yay, Linux is great! */ #include +#include "alloc-util.h" #include "build.h" #include "def.h" #include "device-nodes.h" @@ -487,19 +488,6 @@ int prot_from_flags(int flags) { } } -void* memdup(const void *p, size_t l) { - void *r; - - assert(p); - - r = malloc(l); - if (!r) - return NULL; - - memcpy(r, p, l); - return r; -} - int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...) { bool stdout_is_tty, stderr_is_tty; pid_t parent_pid, agent_pid; @@ -725,51 +713,6 @@ int on_ac_power(void) { return found_online || !found_offline; } -void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) { - size_t a, newalloc; - void *q; - - assert(p); - assert(allocated); - - if (*allocated >= need) - return *p; - - newalloc = MAX(need * 2, 64u / size); - a = newalloc * size; - - /* check for overflows */ - if (a < size * need) - return NULL; - - q = realloc(*p, a); - if (!q) - return NULL; - - *p = q; - *allocated = newalloc; - return q; -} - -void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size) { - size_t prev; - uint8_t *q; - - assert(p); - assert(allocated); - - prev = *allocated; - - q = greedy_realloc(p, allocated, need, size); - if (!q) - return NULL; - - if (*allocated > prev) - memzero(q + prev * size, (*allocated - prev) * size); - - return q; -} - bool id128_is_valid(const char *s) { size_t i, l; diff --git a/src/basic/util.h b/src/basic/util.h index 3074029f38..e2fceafd9a 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -54,23 +54,6 @@ size_t page_size(void) _pure_; #define PAGE_ALIGN(l) ALIGN_TO((l), page_size()) -#define new(t, n) ((t*) malloc_multiply(sizeof(t), (n))) - -#define new0(t, n) ((t*) calloc((n), sizeof(t))) - -#define newa(t, n) ((t*) alloca(sizeof(t)*(n))) - -#define newa0(t, n) ((t*) alloca0(sizeof(t)*(n))) - -#define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n))) - -#define malloc0(n) (calloc(1, (n))) - -static inline void *mfree(void *memory) { - free(memory); - return NULL; -} - static inline const char* yes_no(bool b) { return b ? "yes" : "no"; } @@ -118,60 +101,35 @@ bool kexec_loaded(void); int prot_from_flags(int flags) _const_; -void* memdup(const void *p, size_t l) _alloc_(2); - int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *path, ...); bool in_initrd(void); -static inline void freep(void *p) { - free(*(void**) p); -} - -#define _cleanup_free_ _cleanup_(freep) - -_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) { - if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) - return NULL; - - return malloc(a * b); -} - -_alloc_(2, 3) static inline void *realloc_multiply(void *p, size_t a, size_t b) { - if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) - return NULL; - - return realloc(p, a * b); -} - -_alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_t b) { - if (_unlikely_(b != 0 && a > ((size_t) -1) / b)) - return NULL; - - return memdup(p, a * b); -} - void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); -int on_ac_power(void); +/** + * Normal qsort requires base to be nonnull. Here were require + * that only if nmemb > 0. + */ +static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) { + if (nmemb <= 1) + return; -static inline void *mempset(void *s, int c, size_t n) { - memset(s, c, n); - return (uint8_t*)s + n; + assert(base); + qsort(base, nmemb, size, compar); } +int on_ac_power(void); + #define memzero(x,l) (memset((x), 0, (l))) #define zero(x) (memzero(&(x), sizeof(x))) -void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size); -void* greedy_realloc0(void **p, size_t *allocated, size_t need, size_t size); -#define GREEDY_REALLOC(array, allocated, need) \ - greedy_realloc((void**) &(array), &(allocated), (need), sizeof((array)[0])) - -#define GREEDY_REALLOC0(array, allocated, need) \ - greedy_realloc0((void**) &(array), &(allocated), (need), sizeof((array)[0])) +static inline void *mempset(void *s, int c, size_t n) { + memset(s, c, n); + return (uint8_t*)s + n; +} static inline void _reset_errno_(int *saved_errno) { errno = *saved_errno; @@ -225,45 +183,8 @@ static inline unsigned log2u_round_up(unsigned x) { return log2u(x - 1) + 1; } -#define alloca0(n) \ - ({ \ - char *_new_; \ - size_t _len_ = n; \ - _new_ = alloca(_len_); \ - (void *) memset(_new_, 0, _len_); \ - }) - -/* It's not clear what alignment glibc/gcc alloca() guarantee, hence provide a guaranteed safe version */ -#define alloca_align(size, align) \ - ({ \ - void *_ptr_; \ - size_t _mask_ = (align) - 1; \ - _ptr_ = alloca((size) + _mask_); \ - (void*)(((uintptr_t)_ptr_ + _mask_) & ~_mask_); \ - }) - -#define alloca0_align(size, align) \ - ({ \ - void *_new_; \ - size_t _size_ = (size); \ - _new_ = alloca_align(_size_, (align)); \ - (void*)memset(_new_, 0, _size_); \ - }) - bool id128_is_valid(const char *s) _pure_; -/** - * Normal qsort requires base to be nonnull. Here were require - * that only if nmemb > 0. - */ -static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) { - if (nmemb <= 1) - return; - - assert(base); - qsort(base, nmemb, size, compar); -} - int container_get_leader(const char *machine, pid_t *pid); int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd); diff --git a/src/basic/virt.c b/src/basic/virt.c index 19f93b95aa..fb181e5b55 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -23,9 +23,10 @@ #include #include +#include "alloc-util.h" #include "fileio.h" -#include "stat-util.h" #include "process-util.h" +#include "stat-util.h" #include "string-table.h" #include "string-util.h" #include "util.h" diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 7351337c6b..6abdaedc3e 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "fd-util.h" #include "sparse-endian.h" #include "stdio-util.h" diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index b96695c353..8e63153c92 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -27,6 +27,7 @@ #include #include +#include "alloc-util.h" #include "conf-files.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index 332bb33545..4cf42d17f3 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -37,6 +37,7 @@ #include #include +#include "alloc-util.h" #include "blkid-util.h" #include "efivars.h" #include "fd-util.h" diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index c0019174ab..6723fa5098 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -48,6 +48,7 @@ #include "sd-journal.h" +#include "alloc-util.h" #include "bootchart.h" #include "conf-parser.h" #include "fd-util.h" diff --git a/src/bootchart/store.c b/src/bootchart/store.c index e488c94b3b..c1b1e77e44 100644 --- a/src/bootchart/store.c +++ b/src/bootchart/store.c @@ -31,6 +31,7 @@ #include #include +#include "alloc-util.h" #include "bootchart.h" #include "cgroup-util.h" #include "dirent-util.h" diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index 43eca90618..05330c0577 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -30,6 +30,7 @@ #include #include +#include "alloc-util.h" #include "architecture.h" #include "util.h" #include "fileio.h" diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c index fc8edaeb36..6a7134644f 100644 --- a/src/bus-proxyd/bus-proxyd.c +++ b/src/bus-proxyd/bus-proxyd.c @@ -33,6 +33,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "bus-internal.h" #include "bus-xml-policy.h" #include "capability-util.h" diff --git a/src/bus-proxyd/bus-xml-policy.c b/src/bus-proxyd/bus-xml-policy.c index 1b9fdedca3..f0834e9525 100644 --- a/src/bus-proxyd/bus-xml-policy.c +++ b/src/bus-proxyd/bus-xml-policy.c @@ -21,6 +21,7 @@ #include "sd-login.h" +#include "alloc-util.h" #include "bus-internal.h" #include "bus-xml-policy.h" #include "conf-files.h" diff --git a/src/bus-proxyd/driver.c b/src/bus-proxyd/driver.c index 4e859412f8..2e8bd83efd 100644 --- a/src/bus-proxyd/driver.c +++ b/src/bus-proxyd/driver.c @@ -27,6 +27,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-internal.h" #include "bus-message.h" #include "bus-util.h" diff --git a/src/bus-proxyd/proxy.c b/src/bus-proxyd/proxy.c index 6c251b5244..db399b24f2 100644 --- a/src/bus-proxyd/proxy.c +++ b/src/bus-proxyd/proxy.c @@ -31,6 +31,7 @@ #include "sd-bus.h" #include "sd-daemon.h" +#include "alloc-util.h" #include "bus-control.h" #include "bus-internal.h" #include "bus-message.h" diff --git a/src/bus-proxyd/stdio-bridge.c b/src/bus-proxyd/stdio-bridge.c index a009ea76c4..6e47884209 100644 --- a/src/bus-proxyd/stdio-bridge.c +++ b/src/bus-proxyd/stdio-bridge.c @@ -30,6 +30,7 @@ #include "sd-daemon.h" #include "sd-bus.h" +#include "alloc-util.h" #include "bus-internal.h" #include "bus-util.h" #include "def.h" diff --git a/src/bus-proxyd/test-bus-xml-policy.c b/src/bus-proxyd/test-bus-xml-policy.c index cb7ff6b970..1f465edd91 100644 --- a/src/bus-proxyd/test-bus-xml-policy.c +++ b/src/bus-proxyd/test-bus-xml-policy.c @@ -25,6 +25,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-xml-policy.h" #include "log.h" #include "string-util.h" diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c index 41c539a1bc..4e9a76a100 100644 --- a/src/cgls/cgls.c +++ b/src/cgls/cgls.c @@ -27,6 +27,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-show.h" diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 43b8af4420..eea8aea76b 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -30,6 +30,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-util.h" diff --git a/src/core/automount.c b/src/core/automount.c index 50a7772753..715e52e794 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -29,6 +29,7 @@ #include #include +#include "alloc-util.h" #include "async.h" #include "automount.h" #include "bus-error.h" diff --git a/src/core/bus-endpoint.c b/src/core/bus-endpoint.c index 0c4b3e7c8b..d22a80c91f 100644 --- a/src/core/bus-endpoint.c +++ b/src/core/bus-endpoint.c @@ -19,10 +19,11 @@ #include -#include "kdbus.h" +#include "alloc-util.h" +#include "bus-endpoint.h" #include "bus-kernel.h" #include "bus-policy.h" -#include "bus-endpoint.h" +#include "kdbus.h" int bus_kernel_set_endpoint_policy(int fd, uid_t uid, BusEndpoint *ep) { diff --git a/src/core/bus-policy.c b/src/core/bus-policy.c index 7ad18fb28c..4907c268e8 100644 --- a/src/core/bus-policy.c +++ b/src/core/bus-policy.c @@ -19,6 +19,7 @@ #include +#include "alloc-util.h" #include "bus-kernel.h" #include "bus-policy.h" #include "kdbus.h" diff --git a/src/core/busname.c b/src/core/busname.c index 94674c99fa..9fed54ffc8 100644 --- a/src/core/busname.c +++ b/src/core/busname.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "bus-internal.h" #include "bus-kernel.h" #include "bus-policy.h" diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 0d37e69cd9..90cee12be7 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "cgroup-util.h" #include "cgroup.h" #include "fd-util.h" diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index f424909b46..3fd295baa9 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-util.h" #include "cgroup-util.h" #include "cgroup.h" diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 67405a1672..882a76e988 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -26,6 +26,7 @@ #endif #include "af-list.h" +#include "alloc-util.h" #include "bus-util.h" #include "capability-util.h" #include "dbus-execute.h" diff --git a/src/core/dbus-job.c b/src/core/dbus-job.c index e95ec5c0cb..8c30d66250 100644 --- a/src/core/dbus-job.c +++ b/src/core/dbus-job.c @@ -21,12 +21,13 @@ #include "sd-bus.h" +#include "alloc-util.h" +#include "dbus-job.h" #include "dbus.h" #include "job.h" #include "log.h" #include "selinux-access.h" #include "string-util.h" -#include "dbus-job.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, job_type, JobType); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_state, job_state, JobState); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 3f631bd9a0..1f9f25093d 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "architecture.h" #include "build.h" #include "bus-common-errors.h" diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c index f8fb373bf0..16375b2311 100644 --- a/src/core/dbus-scope.c +++ b/src/core/dbus-scope.c @@ -19,17 +19,18 @@ along with systemd; If not, see . ***/ -#include "selinux-access.h" -#include "unit.h" -#include "scope.h" -#include "dbus.h" -#include "bus-util.h" -#include "bus-internal.h" +#include "alloc-util.h" #include "bus-common-errors.h" -#include "dbus-unit.h" +#include "bus-internal.h" +#include "bus-util.h" #include "dbus-cgroup.h" #include "dbus-kill.h" #include "dbus-scope.h" +#include "dbus-unit.h" +#include "dbus.h" +#include "scope.h" +#include "selinux-access.h" +#include "unit.h" static int bus_scope_abandon(sd_bus_message *message, void *userdata, sd_bus_error *error) { Scope *s = userdata; diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 91cdeb1f30..c41b3e1723 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "async.h" #include "bus-util.h" #include "dbus-cgroup.h" diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c index 5941b72bc0..be5ef261a6 100644 --- a/src/core/dbus-socket.c +++ b/src/core/dbus-socket.c @@ -19,13 +19,14 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-util.h" #include "dbus-cgroup.h" #include "dbus-execute.h" +#include "dbus-socket.h" #include "socket.h" #include "string-util.h" #include "unit.h" -#include "dbus-socket.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, socket_result, SocketResult); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only); diff --git a/src/core/dbus-timer.c b/src/core/dbus-timer.c index 8ea2cf84a4..a8a280d961 100644 --- a/src/core/dbus-timer.c +++ b/src/core/dbus-timer.c @@ -19,11 +19,12 @@ along with systemd; If not, see . ***/ -#include "unit.h" -#include "timer.h" -#include "dbus-timer.h" +#include "alloc-util.h" #include "bus-util.h" +#include "dbus-timer.h" #include "strv.h" +#include "timer.h" +#include "unit.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, timer_result, TimerResult); diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 10cd80389b..6320cd1aa9 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -21,6 +21,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "cgroup-util.h" #include "dbus-unit.h" diff --git a/src/core/dbus.c b/src/core/dbus.c index bbab0aeddb..834745aeb5 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -25,6 +25,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-internal.h" diff --git a/src/core/device.c b/src/core/device.c index 90bb2c45fd..23ee7aee7e 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -24,6 +24,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "dbus-device.h" #include "device.h" #include "log.h" diff --git a/src/core/execute.c b/src/core/execute.c index bf13e29bd9..d751065af0 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -53,6 +53,7 @@ #include "sd-messages.h" #include "af-list.h" +#include "alloc-util.h" #ifdef HAVE_APPARMOR #include "apparmor-util.h" #endif diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c index f1563afff9..cc7515905d 100644 --- a/src/core/hostname-setup.c +++ b/src/core/hostname-setup.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "fileio.h" #include "hostname-util.h" #include "log.h" diff --git a/src/core/job.c b/src/core/job.c index 44532d0d5a..120381fc3b 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -24,6 +24,7 @@ #include "sd-id128.h" #include "sd-messages.h" +#include "alloc-util.h" #include "async.h" #include "dbus-job.h" #include "dbus.h" diff --git a/src/core/killall.c b/src/core/killall.c index dbfa90ebac..77f145b4d1 100644 --- a/src/core/killall.c +++ b/src/core/killall.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "formats-util.h" #include "killall.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 72e918ed54..c1d09e8e5a 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -32,6 +32,7 @@ #include #include +#include "alloc-util.h" #include "af-list.h" #include "bus-error.h" #include "bus-internal.h" diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c index d00d3e94bb..145ba2a28d 100644 --- a/src/core/machine-id-setup.c +++ b/src/core/machine-id-setup.c @@ -29,6 +29,7 @@ #include "sd-id128.h" +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/core/main.c b/src/core/main.c index d9c888d747..593b974566 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -40,6 +40,7 @@ #include "sd-daemon.h" #include "sd-bus.h" +#include "alloc-util.h" #include "architecture.h" #include "build.h" #include "bus-error.h" diff --git a/src/core/manager.c b/src/core/manager.c index bf0cf069ca..04111091e7 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -40,6 +40,7 @@ #include "sd-daemon.h" #include "sd-messages.h" +#include "alloc-util.h" #include "audit-fd.h" #include "boot-timestamps.h" #include "bus-common-errors.h" diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 1ab4ee5b1a..b2596d1cd1 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "bus-util.h" #include "cgroup-util.h" #include "dev-setup.h" diff --git a/src/core/mount.c b/src/core/mount.c index f04f386930..68cf312fca 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -26,6 +26,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "dbus-mount.h" #include "escape.h" #include "exit-status.h" @@ -40,8 +41,8 @@ #include "path-util.h" #include "smack-util.h" #include "special.h" -#include "string-util.h" #include "string-table.h" +#include "string-util.h" #include "strv.h" #include "unit-name.h" #include "unit.h" diff --git a/src/core/namespace.c b/src/core/namespace.c index 6c49ff32fe..81ba09ea5d 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -28,6 +28,7 @@ #include #include +#include "alloc-util.h" #include "dev-setup.h" #include "fd-util.h" #include "loopback-setup.h" diff --git a/src/core/scope.c b/src/core/scope.c index 13de02cf16..6bacb226e8 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -22,16 +22,17 @@ #include #include +#include "alloc-util.h" #include "dbus-scope.h" #include "load-dropin.h" #include "log.h" +#include "scope.h" #include "special.h" #include "string-table.h" #include "string-util.h" #include "strv.h" #include "unit-name.h" #include "unit.h" -#include "scope.h" static const UnitActiveState state_translation_table[_SCOPE_STATE_MAX] = { [SCOPE_DEAD] = UNIT_INACTIVE, diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c index a9368ead22..4bcdd27389 100644 --- a/src/core/selinux-access.c +++ b/src/core/selinux-access.c @@ -33,6 +33,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "audit-fd.h" #include "bus-util.h" #include "log.h" diff --git a/src/core/service.c b/src/core/service.c index 54a420d6f0..2d92799fec 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "async.h" #include "bus-error.h" #include "bus-kernel.h" diff --git a/src/core/show-status.c b/src/core/show-status.c index 81166abf23..e4e12a3365 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "fd-util.h" #include "io-util.h" #include "parse-util.h" diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 93bbc315d3..3a95b5fd72 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -31,6 +31,7 @@ #include #include +#include "alloc-util.h" #include "cgroup-util.h" #include "def.h" #include "fileio.h" diff --git a/src/core/slice.c b/src/core/slice.c index 8fb6d28a3c..4602144150 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "dbus-slice.h" #include "log.h" #include "special.h" diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index b8cb9964a6..0661ff9ecd 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -28,6 +28,7 @@ #include #include +#include "alloc-util.h" #include "dirent-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/core/snapshot.c b/src/core/snapshot.c index da1c99ad12..ba3135f401 100644 --- a/src/core/snapshot.c +++ b/src/core/snapshot.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "bus-common-errors.h" #include "dbus-snapshot.h" #include "parse-util.h" diff --git a/src/core/socket.c b/src/core/socket.c index c145aa6081..d8b8cf576a 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -31,6 +31,7 @@ #include "sd-event.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "copy.h" diff --git a/src/core/swap.c b/src/core/swap.c index cb2da1cb5c..5be3c709bf 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -26,6 +26,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "dbus-swap.h" #include "escape.h" #include "exit-status.h" diff --git a/src/core/timer.c b/src/core/timer.c index 47e501815a..cc2afedabf 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "dbus-timer.h" diff --git a/src/core/transaction.c b/src/core/transaction.c index d1c1b9a3cd..69f28c902f 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -22,10 +22,11 @@ #include #include +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" -#include "transaction.h" #include "terminal-util.h" +#include "transaction.h" static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies); diff --git a/src/core/umount.c b/src/core/umount.c index 8735bed7b1..9d1f7660db 100644 --- a/src/core/umount.c +++ b/src/core/umount.c @@ -29,6 +29,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "escape.h" #include "fd-util.h" #include "fstab-util.h" diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 4a5c7efdb0..721c8ccce9 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "cgroup-util.h" #include "formats-util.h" #include "macro.h" diff --git a/src/core/unit.c b/src/core/unit.c index 11d3bb9633..8d56401231 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -28,6 +28,7 @@ #include "sd-id128.h" #include "sd-messages.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-util.h" #include "cgroup-util.h" diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 54a89452a3..ae53bac600 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "dropin.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 8531b6b125..98fe52a81b 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -27,6 +27,7 @@ #include "sd-device.h" +#include "alloc-util.h" #include "ask-password-api.h" #include "device-util.h" #include "escape.h" diff --git a/src/dbus1-generator/dbus1-generator.c b/src/dbus1-generator/dbus1-generator.c index 66a0fe9ea2..b57bf9a57d 100644 --- a/src/dbus1-generator/dbus1-generator.c +++ b/src/dbus1-generator/dbus1-generator.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-internal.h" #include "bus-util.h" #include "cgroup-util.h" diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index 1a98cbaef8..e16c3b9453 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "mkdir.h" #include "parse-util.h" #include "proc-cmdline.h" diff --git a/src/delta/delta.c b/src/delta/delta.c index 4ade23ffab..6c25b185ed 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -26,6 +26,7 @@ #include #include +#include "alloc-util.h" #include "dirent-util.h" #include "fd-util.h" #include "fs-util.h" diff --git a/src/escape/escape.c b/src/escape/escape.c index 9390558554..e857affbc4 100644 --- a/src/escape/escape.c +++ b/src/escape/escape.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "log.h" #include "string-util.h" #include "strv.h" diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 30ea942d14..46cfe9f851 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "ask-password-api.h" #include "copy.h" #include "fd-util.h" diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 4119edde30..5b806a1e69 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -32,6 +32,7 @@ #include "sd-bus.h" #include "sd-device.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index a51ecd9f7a..f7c8d11ace 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "fstab-util.h" diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index 0997cc5fae..03df7365b5 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "log.h" diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index cc1bd3f50e..5ea6c86898 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -27,6 +27,7 @@ #include "libudev.h" #include "sd-id128.h" +#include "alloc-util.h" #include "blkid-util.h" #include "btrfs-util.h" #include "dirent-util.h" diff --git a/src/hibernate-resume/hibernate-resume-generator.c b/src/hibernate-resume/hibernate-resume-generator.c index 8c3a09501f..da719f2a30 100644 --- a/src/hibernate-resume/hibernate-resume-generator.c +++ b/src/hibernate-resume/hibernate-resume-generator.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "fstab-util.h" #include "log.h" #include "mkdir.h" diff --git a/src/hibernate-resume/hibernate-resume.c b/src/hibernate-resume/hibernate-resume.c index 1f3b169905..316a2803d3 100644 --- a/src/hibernate-resume/hibernate-resume.c +++ b/src/hibernate-resume/hibernate-resume.c @@ -23,9 +23,10 @@ #include #include +#include "alloc-util.h" +#include "fileio.h" #include "log.h" #include "util.h" -#include "fileio.h" int main(int argc, char *argv[]) { struct stat st; diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 0724fcc16d..bf09fb8fbb 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -28,6 +28,7 @@ #include "sd-bus.h" #include "sd-id128.h" +#include "alloc-util.h" #include "architecture.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 5c63a025a3..92061532b8 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "bus-util.h" #include "def.h" #include "env-util.h" diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c index 48d0883a3a..de59b797a6 100644 --- a/src/hwdb/hwdb.c +++ b/src/hwdb/hwdb.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "conf-files.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/import/curl-util.c b/src/import/curl-util.c index 455fa1e07d..4278466df1 100644 --- a/src/import/curl-util.c +++ b/src/import/curl-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "curl-util.h" #include "fd-util.h" #include "string-util.h" diff --git a/src/import/export-raw.c b/src/import/export-raw.c index 85e781a308..103d45bf21 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -25,6 +25,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "copy.h" #include "export-raw.h" diff --git a/src/import/export-tar.c b/src/import/export-tar.c index 38e659a517..2bbec661e6 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -21,6 +21,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "export-tar.h" #include "fd-util.h" diff --git a/src/import/export.c b/src/import/export.c index 6ff732d73f..2b33d778d3 100644 --- a/src/import/export.c +++ b/src/import/export.c @@ -23,6 +23,7 @@ #include "sd-event.h" +#include "alloc-util.h" #include "event-util.h" #include "export-raw.h" #include "export-tar.h" diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 87f4a3935d..2193d1d7f1 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -24,6 +24,7 @@ #include "sd-daemon.h" #include "sd-event.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "chattr-util.h" #include "copy.h" diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 64eb5ccd83..2ae1d88168 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -24,6 +24,7 @@ #include "sd-daemon.h" #include "sd-event.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "copy.h" #include "fd-util.h" diff --git a/src/import/import.c b/src/import/import.c index 76b38e4903..018b94d4c4 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -23,6 +23,7 @@ #include "sd-event.h" +#include "alloc-util.h" #include "event-util.h" #include "fd-util.h" #include "fs-util.h" diff --git a/src/import/importd.c b/src/import/importd.c index 65e2354640..4228681cea 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -23,6 +23,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-util.h" #include "def.h" diff --git a/src/import/pull-common.c b/src/import/pull-common.c index c235848821..d6567ba7ee 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "btrfs-util.h" #include "capability-util.h" #include "copy.h" diff --git a/src/import/pull-dkr.c b/src/import/pull-dkr.c index 786651d581..831470ff13 100644 --- a/src/import/pull-dkr.c +++ b/src/import/pull-dkr.c @@ -24,6 +24,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "aufs-util.h" #include "btrfs-util.h" #include "curl-util.h" diff --git a/src/import/pull-job.c b/src/import/pull-job.c index 3cc7ea10b7..824fa246ec 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "fd-util.h" #include "hexdecoct.h" #include "io-util.h" diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index c3476714c8..394131680d 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -25,6 +25,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "chattr-util.h" #include "copy.h" diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index 43b7b65586..26c0bc5866 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -24,6 +24,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "copy.h" #include "curl-util.h" diff --git a/src/import/pull.c b/src/import/pull.c index 5e6cd50688..39f5b2d8e4 100644 --- a/src/import/pull.c +++ b/src/import/pull.c @@ -23,6 +23,7 @@ #include "sd-event.h" +#include "alloc-util.h" #include "event-util.h" #include "hostname-util.h" #include "import-util.h" diff --git a/src/import/qcow2-util.c b/src/import/qcow2-util.c index fd3cf1b0e3..47dabaa86e 100644 --- a/src/import/qcow2-util.c +++ b/src/import/qcow2-util.c @@ -21,10 +21,11 @@ #include -#include "util.h" -#include "sparse-endian.h" -#include "qcow2-util.h" +#include "alloc-util.h" #include "btrfs-util.h" +#include "qcow2-util.h" +#include "sparse-endian.h" +#include "util.h" #define QCOW2_MAGIC 0x514649fb diff --git a/src/initctl/initctl.c b/src/initctl/initctl.c index 2b374c0288..f1cf31a4a8 100644 --- a/src/initctl/initctl.c +++ b/src/initctl/initctl.c @@ -28,6 +28,7 @@ #include "sd-bus.h" #include "sd-daemon.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "def.h" diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index b8a513bb74..6b93a758f6 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -33,6 +33,7 @@ #include "sd-daemon.h" #include "sd-journal.h" +#include "alloc-util.h" #include "bus-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c index db1636ac3e..3ff40228a0 100644 --- a/src/journal-remote/journal-remote-parse.c +++ b/src/journal-remote/journal-remote-parse.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "fd-util.h" #include "journal-remote-parse.h" #include "journald-native.h" diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c index 40f4ff8e58..d8250378b0 100644 --- a/src/journal-remote/journal-remote-write.c +++ b/src/journal-remote/journal-remote-write.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "journal-remote.h" int iovw_put(struct iovec_wrapper *iovw, void* data, size_t len) { diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index f70d278e1c..a2c49b8b4d 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -35,6 +35,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "conf-parser.h" #include "escape.h" #include "fd-util.h" diff --git a/src/journal-remote/journal-upload-journal.c b/src/journal-remote/journal-upload-journal.c index 6b3ad924a7..3ee6d32bf7 100644 --- a/src/journal-remote/journal-upload-journal.c +++ b/src/journal-remote/journal-upload-journal.c @@ -1,11 +1,33 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2014 Zbigniew Jędrzejewski-Szmek + + 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 "util.h" +#include "alloc-util.h" +#include "journal-upload.h" #include "log.h" #include "utf8.h" -#include "journal-upload.h" +#include "util.h" /** * Write up to size bytes to buf. Return negative on error, and number of diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 1925475db8..7d274d2fc9 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -27,6 +27,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "conf-parser.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c index df068a089c..b2c398a845 100644 --- a/src/journal-remote/microhttpd-util.c +++ b/src/journal-remote/microhttpd-util.c @@ -29,6 +29,7 @@ #include #endif +#include "alloc-util.h" #include "log.h" #include "macro.h" #include "string-util.h" diff --git a/src/journal/catalog.c b/src/journal/catalog.c index 72d2bedc26..95a6857472 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -29,6 +29,7 @@ #include "sd-id128.h" +#include "alloc-util.h" #include "catalog.h" #include "conf-files.h" #include "fd-util.h" diff --git a/src/journal/compress.c b/src/journal/compress.c index 196d6ff425..e1ca0a8818 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -33,6 +33,7 @@ #include #endif +#include "alloc-util.h" #include "compress.h" #include "fd-util.h" #include "io-util.h" diff --git a/src/journal/coredump-vacuum.c b/src/journal/coredump-vacuum.c index 9635db19e1..39bc2e4270 100644 --- a/src/journal/coredump-vacuum.c +++ b/src/journal/coredump-vacuum.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "coredump-vacuum.h" #include "dirent-util.h" #include "fd-util.h" diff --git a/src/journal/coredump.c b/src/journal/coredump.c index f32e2d4a9f..2e543537f6 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -34,6 +34,7 @@ #include "sd-login.h" #include "acl-util.h" +#include "alloc-util.h" #include "capability-util.h" #include "cgroup-util.h" #include "compress.h" diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index 07ca8dde0a..af4d051138 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -28,6 +28,7 @@ #include "sd-journal.h" +#include "alloc-util.h" #include "compress.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 6f9b8a2915..12b39dbb27 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -28,6 +28,7 @@ #include #include +#include "alloc-util.h" #include "btrfs-util.h" #include "chattr-util.h" #include "compress.h" diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index 8fe99fae99..fa5dee73c3 100644 --- a/src/journal/journal-send.c +++ b/src/journal/journal-send.c @@ -31,6 +31,7 @@ #include "sd-journal.h" +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "io-util.h" diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c index 87646922fb..4b5fc76eb1 100644 --- a/src/journal/journal-vacuum.c +++ b/src/journal/journal-vacuum.c @@ -25,6 +25,7 @@ #include "sd-id128.h" +#include "alloc-util.h" #include "dirent-util.h" #include "fd-util.h" #include "journal-def.h" diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index 5d000aedbb..b78ce98b17 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "compress.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 2782ac0329..a35783e3ff 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -39,6 +39,7 @@ #include "sd-journal.h" #include "acl-util.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "catalog.h" diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index 6a8ef7dd40..3c13fe0d67 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "audit-type.h" #include "fd-util.h" #include "hexdecoct.h" diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index 72c4ba5879..860832cfc8 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "formats-util.h" diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index 9f3b1e3b16..6fff4fe473 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fs-util.h" #include "io-util.h" diff --git a/src/journal/journald-rate-limit.c b/src/journal/journald-rate-limit.c index 6e9557c06e..434ddc8ac9 100644 --- a/src/journal/journald-rate-limit.c +++ b/src/journal/journald-rate-limit.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "hashmap.h" #include "list.h" #include "random-util.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 03cc074e7a..ecf7b7a476 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -34,6 +34,7 @@ #include "sd-messages.h" #include "acl-util.h" +#include "alloc-util.h" #include "audit-util.h" #include "cgroup-util.h" #include "conf-parser.h" diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 0dd6d54d68..5300c61c02 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -29,6 +29,7 @@ #include "sd-daemon.h" #include "sd-event.h" +#include "alloc-util.h" #include "dirent-util.h" #include "escape.h" #include "fd-util.h" diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c index 3553e9cc1d..f3ac1a7ae0 100644 --- a/src/journal/journald-syslog.c +++ b/src/journal/journald-syslog.c @@ -25,6 +25,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "fd-util.h" #include "formats-util.h" #include "io-util.h" diff --git a/src/journal/journald-wall.c b/src/journal/journald-wall.c index 5284914941..69540f1141 100644 --- a/src/journal/journald-wall.c +++ b/src/journal/journald-wall.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "formats-util.h" #include "journald-server.h" #include "process-util.h" diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c index 22f75540b8..3cb1dfa986 100644 --- a/src/journal/mmap-cache.c +++ b/src/journal/mmap-cache.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "hashmap.h" #include "list.h" #include "log.h" diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index bd93d90776..6eda5162c7 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -30,6 +30,7 @@ #include "sd-journal.h" +#include "alloc-util.h" #include "catalog.h" #include "compress.h" #include "dirent-util.h" diff --git a/src/journal/stacktrace.c b/src/journal/stacktrace.c index e32550d644..4305462f80 100644 --- a/src/journal/stacktrace.c +++ b/src/journal/stacktrace.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "formats-util.h" #include "macro.h" diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c index c942df46a8..aea8fd15e6 100644 --- a/src/journal/test-catalog.c +++ b/src/journal/test-catalog.c @@ -27,6 +27,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "catalog.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c index 5a2f0564ca..93ea9c6318 100644 --- a/src/journal/test-compress-benchmark.c +++ b/src/journal/test-compress-benchmark.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "compress.h" #include "macro.h" #include "parse-util.h" diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c index db4fa15554..b9d90a8988 100644 --- a/src/journal/test-compress.c +++ b/src/journal/test-compress.c @@ -17,6 +17,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "compress.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal/test-journal-flush.c b/src/journal/test-journal-flush.c index 6061623ae7..03d1522e23 100644 --- a/src/journal/test-journal-flush.c +++ b/src/journal/test-journal-flush.c @@ -23,6 +23,7 @@ #include "sd-journal.h" +#include "alloc-util.h" #include "journal-file.h" #include "journal-internal.h" #include "macro.h" diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c index 3c8b0268a4..4ad89fe4b6 100644 --- a/src/journal/test-journal-interleaving.c +++ b/src/journal/test-journal-interleaving.c @@ -25,6 +25,7 @@ #include "sd-journal.h" +#include "alloc-util.h" #include "journal-file.h" #include "journal-vacuum.h" #include "log.h" diff --git a/src/journal/test-journal-match.c b/src/journal/test-journal-match.c index 476477055a..abefedb992 100644 --- a/src/journal/test-journal-match.c +++ b/src/journal/test-journal-match.c @@ -23,6 +23,7 @@ #include "sd-journal.h" +#include "alloc-util.h" #include "journal-internal.h" #include "log.h" #include "string-util.h" diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c index b8482743a2..0cbef4b8c5 100644 --- a/src/journal/test-journal-stream.c +++ b/src/journal/test-journal-stream.c @@ -24,6 +24,7 @@ #include "sd-journal.h" +#include "alloc-util.h" #include "journal-file.h" #include "journal-internal.h" #include "log.h" diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c index de942c50cc..1784187fe9 100644 --- a/src/journal/test-journal-syslog.c +++ b/src/journal/test-journal-syslog.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "journald-syslog.h" #include "macro.h" #include "string-util.h" diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c index f41bebced0..076bb2dac0 100644 --- a/src/libsystemd-network/dhcp6-option.c +++ b/src/libsystemd-network/dhcp6-option.c @@ -23,14 +23,14 @@ #include #include -#include "sparse-endian.h" -#include "unaligned.h" -#include "util.h" -#include "strv.h" - +#include "alloc-util.h" #include "dhcp6-internal.h" #include "dhcp6-protocol.h" #include "dns-domain.h" +#include "sparse-endian.h" +#include "strv.h" +#include "unaligned.h" +#include "util.h" #define DHCP6_OPTION_IA_NA_LEN 12 #define DHCP6_OPTION_IA_TA_LEN 4 diff --git a/src/libsystemd-network/lldp-internal.c b/src/libsystemd-network/lldp-internal.c index 70061e914f..583be2f55d 100644 --- a/src/libsystemd-network/lldp-internal.c +++ b/src/libsystemd-network/lldp-internal.c @@ -22,6 +22,7 @@ #include "sd-lldp.h" +#include "alloc-util.h" #include "lldp-internal.h" /* We store maximum 1K chassis entries */ diff --git a/src/libsystemd-network/lldp-port.c b/src/libsystemd-network/lldp-port.c index 7486b4c38f..97b6b485d2 100644 --- a/src/libsystemd-network/lldp-port.c +++ b/src/libsystemd-network/lldp-port.c @@ -20,6 +20,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "async.h" #include "lldp-port.h" #include "lldp-network.h" diff --git a/src/libsystemd-network/lldp-tlv.c b/src/libsystemd-network/lldp-tlv.c index 66af22e37d..0851957ab4 100644 --- a/src/libsystemd-network/lldp-tlv.c +++ b/src/libsystemd-network/lldp-tlv.c @@ -23,8 +23,9 @@ #include #include -#include "macro.h" +#include "alloc-util.h" #include "lldp-tlv.h" +#include "macro.h" int tlv_section_new(tlv_section **ret) { tlv_section *s; diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index d86977be17..52d76e443e 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -25,6 +25,7 @@ #include "sd-ndisc.h" +#include "alloc-util.h" #include "condition.h" #include "conf-parser.h" #include "dhcp-lease-internal.h" diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index a6d6a176e4..57fc8216c3 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -28,6 +28,7 @@ #include "sd-dhcp-client.h" +#include "alloc-util.h" #include "async.h" #include "dhcp-identifier.h" #include "dhcp-internal.h" diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index 3411f6ec91..c850538d74 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -26,6 +26,7 @@ #include "sd-dhcp-lease.h" +#include "alloc-util.h" #include "dhcp-lease-internal.h" #include "dhcp-protocol.h" #include "dns-domain.h" diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index a2a8c16fc8..8d0d9955c3 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -24,6 +24,7 @@ #include "sd-dhcp-server.h" +#include "alloc-util.h" #include "dhcp-internal.h" #include "dhcp-server-internal.h" #include "fd-util.h" diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 559c5e4df4..e29de60d24 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -26,6 +26,7 @@ #include "sd-dhcp6-client.h" +#include "alloc-util.h" #include "dhcp-identifier.h" #include "dhcp6-internal.h" #include "dhcp6-lease-internal.h" diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c index f34af6eaba..3f32ba35e7 100644 --- a/src/libsystemd-network/sd-dhcp6-lease.c +++ b/src/libsystemd-network/sd-dhcp6-lease.c @@ -22,11 +22,11 @@ #include -#include "strv.h" -#include "util.h" - +#include "alloc-util.h" #include "dhcp6-lease-internal.h" #include "dhcp6-protocol.h" +#include "strv.h" +#include "util.h" int dhcp6_lease_clear_timers(DHCP6IA *ia) { assert_return(ia, -EINVAL); diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c index 3053724ea2..5340fdc0c1 100644 --- a/src/libsystemd-network/sd-ipv4acd.c +++ b/src/libsystemd-network/sd-ipv4acd.c @@ -26,6 +26,7 @@ #include "sd-ipv4acd.h" +#include "alloc-util.h" #include "arp-util.h" #include "event-util.h" #include "fd-util.h" diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 68ec58da90..0d915e20e7 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -27,6 +27,7 @@ #include "sd-ipv4acd.h" #include "sd-ipv4ll.h" +#include "alloc-util.h" #include "event-util.h" #include "in-addr-util.h" #include "list.h" diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c index bc06f48386..4ebe8053fa 100644 --- a/src/libsystemd-network/sd-lldp.c +++ b/src/libsystemd-network/sd-lldp.c @@ -24,6 +24,7 @@ #include "sd-lldp.h" +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "hashmap.h" diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c index ca4bb6325b..c494b9d6d8 100644 --- a/src/libsystemd-network/sd-ndisc.c +++ b/src/libsystemd-network/sd-ndisc.c @@ -26,6 +26,7 @@ #include "sd-ndisc.h" +#include "alloc-util.h" #include "async.h" #include "icmp6-util.h" #include "list.h" diff --git a/src/libsystemd-network/sd-pppoe.c b/src/libsystemd-network/sd-pppoe.c index 03a88973bf..045decc46c 100644 --- a/src/libsystemd-network/sd-pppoe.c +++ b/src/libsystemd-network/sd-pppoe.c @@ -30,6 +30,7 @@ #include "sd-pppoe.h" +#include "alloc-util.h" #include "async.h" #include "event-util.h" #include "fd-util.h" diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c index 40a85eb25e..5b52c1cbb9 100644 --- a/src/libsystemd-network/test-dhcp-client.c +++ b/src/libsystemd-network/test-dhcp-client.c @@ -27,6 +27,7 @@ #include "sd-dhcp-client.h" #include "sd-event.h" +#include "alloc-util.h" #include "dhcp-identifier.h" #include "dhcp-internal.h" #include "dhcp-protocol.h" diff --git a/src/libsystemd-network/test-dhcp-option.c b/src/libsystemd-network/test-dhcp-option.c index b1ef174849..2d29e28f16 100644 --- a/src/libsystemd-network/test-dhcp-option.c +++ b/src/libsystemd-network/test-dhcp-option.c @@ -5,11 +5,11 @@ #include #include -#include "util.h" -#include "macro.h" - -#include "dhcp-protocol.h" +#include "alloc-util.h" #include "dhcp-internal.h" +#include "dhcp-protocol.h" +#include "macro.h" +#include "util.h" struct option_desc { uint8_t sname[64]; diff --git a/src/libsystemd-network/test-ipv4ll-manual.c b/src/libsystemd-network/test-ipv4ll-manual.c index 9485a7df64..913a929069 100644 --- a/src/libsystemd-network/test-ipv4ll-manual.c +++ b/src/libsystemd-network/test-ipv4ll-manual.c @@ -29,6 +29,7 @@ #include "sd-ipv4ll.h" #include "sd-netlink.h" +#include "alloc-util.h" #include "event-util.h" #include "in-addr-util.h" #include "netlink-util.h" diff --git a/src/libsystemd-network/test-lldp.c b/src/libsystemd-network/test-lldp.c index 109462662f..931df7c170 100644 --- a/src/libsystemd-network/test-lldp.c +++ b/src/libsystemd-network/test-lldp.c @@ -28,6 +28,7 @@ #include "sd-event.h" #include "sd-lldp.h" +#include "alloc-util.h" #include "event-util.h" #include "fd-util.h" #include "lldp-network.h" diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c index 5951db483d..d5bc32e757 100644 --- a/src/libsystemd/sd-bus/bus-control.c +++ b/src/libsystemd/sd-bus/bus-control.c @@ -28,6 +28,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-bloom.h" #include "bus-control.h" #include "bus-internal.h" diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index 7c99904c64..2922da3763 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "audit-util.h" #include "bus-creds.h" #include "bus-label.h" diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c index ab4e9cbc06..43a7e67a6d 100644 --- a/src/libsystemd/sd-bus/bus-dump.c +++ b/src/libsystemd/sd-bus/bus-dump.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-dump.h" #include "bus-internal.h" #include "bus-message.h" diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c index 831ceb86b9..84229c2964 100644 --- a/src/libsystemd/sd-bus/bus-error.c +++ b/src/libsystemd/sd-bus/bus-error.c @@ -28,6 +28,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "errno-list.h" #include "string-util.h" #include "util.h" diff --git a/src/libsystemd/sd-bus/bus-internal.c b/src/libsystemd/sd-bus/bus-internal.c index 8cab1bf219..d9f9cd1c5e 100644 --- a/src/libsystemd/sd-bus/bus-internal.c +++ b/src/libsystemd/sd-bus/bus-internal.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-internal.h" #include "bus-message.h" #include "hexdecoct.h" diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index a32b0ef221..6716f6daca 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -34,6 +34,7 @@ #include #undef basename +#include "alloc-util.h" #include "bus-bloom.h" #include "bus-internal.h" #include "bus-kernel.h" diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index 6a37f22c1f..55dc7caa53 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-internal.h" #include "bus-match.h" #include "bus-message.h" diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index d5a6ad581f..5c80095bf0 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -25,6 +25,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-gvariant.h" #include "bus-internal.h" #include "bus-message.h" diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c index d3679800b5..8c472626a8 100644 --- a/src/libsystemd/sd-bus/bus-objects.c +++ b/src/libsystemd/sd-bus/bus-objects.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-internal.h" #include "bus-introspect.h" #include "bus-message.h" diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c index 63f10eba2c..550bad27ba 100644 --- a/src/libsystemd/sd-bus/bus-slot.c +++ b/src/libsystemd/sd-bus/bus-slot.c @@ -21,6 +21,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-control.h" #include "bus-objects.h" #include "string-util.h" diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index 2c46d84cd0..a5cb667630 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -27,6 +27,7 @@ #include "sd-bus.h" #include "sd-daemon.h" +#include "alloc-util.h" #include "bus-internal.h" #include "bus-message.h" #include "bus-socket.h" diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c index 0911156e19..fd7e58fcfa 100644 --- a/src/libsystemd/sd-bus/bus-track.c +++ b/src/libsystemd/sd-bus/bus-track.c @@ -21,6 +21,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-internal.h" #include "bus-track.h" #include "bus-util.h" diff --git a/src/libsystemd/sd-bus/busctl-introspect.c b/src/libsystemd/sd-bus/busctl-introspect.c index 5604db9716..71f962b00c 100644 --- a/src/libsystemd/sd-bus/busctl-introspect.c +++ b/src/libsystemd/sd-bus/busctl-introspect.c @@ -21,10 +21,11 @@ #include "sd-bus.h" +#include "alloc-util.h" +#include "busctl-introspect.h" #include "string-util.h" #include "util.h" #include "xml.h" -#include "busctl-introspect.h" #define NODE_DEPTH_MAX 16 diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c index 4fa60bb185..452ac7c407 100644 --- a/src/libsystemd/sd-bus/busctl.c +++ b/src/libsystemd/sd-bus/busctl.c @@ -23,6 +23,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-dump.h" #include "bus-internal.h" #include "bus-signature.h" diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 0d92a0d461..a8d79b01b0 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -29,6 +29,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-container.h" #include "bus-control.h" #include "bus-internal.h" diff --git a/src/libsystemd/sd-bus/test-bus-benchmark.c b/src/libsystemd/sd-bus/test-bus-benchmark.c index 549c88cd2d..96a0929a14 100644 --- a/src/libsystemd/sd-bus/test-bus-benchmark.c +++ b/src/libsystemd/sd-bus/test-bus-benchmark.c @@ -23,6 +23,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-internal.h" #include "bus-kernel.h" #include "bus-util.h" diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c index e9e5e4a8e3..767aef63ff 100644 --- a/src/libsystemd/sd-bus/test-bus-chat.c +++ b/src/libsystemd/sd-bus/test-bus-chat.c @@ -26,6 +26,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-internal.h" #include "bus-match.h" diff --git a/src/libsystemd/sd-bus/test-bus-gvariant.c b/src/libsystemd/sd-bus/test-bus-gvariant.c index f94da4cccd..931c001788 100644 --- a/src/libsystemd/sd-bus/test-bus-gvariant.c +++ b/src/libsystemd/sd-bus/test-bus-gvariant.c @@ -25,6 +25,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-dump.h" #include "bus-gvariant.h" #include "bus-internal.h" diff --git a/src/libsystemd/sd-bus/test-bus-kernel-bloom.c b/src/libsystemd/sd-bus/test-bus-kernel-bloom.c index ff7f9cdafa..dbdaa69fbe 100644 --- a/src/libsystemd/sd-bus/test-bus-kernel-bloom.c +++ b/src/libsystemd/sd-bus/test-bus-kernel-bloom.c @@ -21,6 +21,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-kernel.h" #include "bus-util.h" #include "fd-util.h" diff --git a/src/libsystemd/sd-bus/test-bus-kernel.c b/src/libsystemd/sd-bus/test-bus-kernel.c index 7d05953cd0..0080f71d3b 100644 --- a/src/libsystemd/sd-bus/test-bus-kernel.c +++ b/src/libsystemd/sd-bus/test-bus-kernel.c @@ -23,6 +23,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-dump.h" #include "bus-kernel.h" #include "bus-util.h" diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c index 7da1dacd81..0747d6a37c 100644 --- a/src/libsystemd/sd-bus/test-bus-marshal.c +++ b/src/libsystemd/sd-bus/test-bus-marshal.c @@ -32,6 +32,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-dump.h" #include "bus-label.h" #include "bus-message.h" diff --git a/src/libsystemd/sd-bus/test-bus-objects.c b/src/libsystemd/sd-bus/test-bus-objects.c index 138db910ea..5bc72e2355 100644 --- a/src/libsystemd/sd-bus/test-bus-objects.c +++ b/src/libsystemd/sd-bus/test-bus-objects.c @@ -24,6 +24,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-dump.h" #include "bus-internal.h" #include "bus-message.h" diff --git a/src/libsystemd/sd-bus/test-bus-proxy.c b/src/libsystemd/sd-bus/test-bus-proxy.c index ae04ff5b0d..428e185769 100644 --- a/src/libsystemd/sd-bus/test-bus-proxy.c +++ b/src/libsystemd/sd-bus/test-bus-proxy.c @@ -25,6 +25,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-dump.h" #include "bus-kernel.h" #include "bus-util.h" diff --git a/src/libsystemd/sd-bus/test-bus-zero-copy.c b/src/libsystemd/sd-bus/test-bus-zero-copy.c index 1be0dbcd82..ff8df61a9e 100644 --- a/src/libsystemd/sd-bus/test-bus-zero-copy.c +++ b/src/libsystemd/sd-bus/test-bus-zero-copy.c @@ -23,6 +23,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-dump.h" #include "bus-kernel.h" #include "bus-message.h" diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c index 49fac7bdcc..77b5dd52f6 100644 --- a/src/libsystemd/sd-daemon/sd-daemon.c +++ b/src/libsystemd/sd-daemon/sd-daemon.c @@ -35,6 +35,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "fd-util.h" #include "fs-util.h" #include "parse-util.h" diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index e1eb5b26b3..ae3157ee5e 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -20,6 +20,7 @@ #include "sd-device.h" +#include "alloc-util.h" #include "device-enumerator-private.h" #include "device-util.h" #include "dirent-util.h" diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 69288b833e..a13477e753 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -24,6 +24,7 @@ #include "sd-device.h" +#include "alloc-util.h" #include "device-internal.h" #include "device-private.h" #include "device-util.h" diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 3b964de56b..0d40bc5c00 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -24,6 +24,7 @@ #include "sd-device.h" +#include "alloc-util.h" #include "device-internal.h" #include "device-private.h" #include "device-util.h" diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index b3f8881714..ee4886700e 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -27,6 +27,7 @@ #include "sd-event.h" #include "sd-id128.h" +#include "alloc-util.h" #include "fd-util.h" #include "hashmap.h" #include "list.h" diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c index 9304fd376e..0e034863d6 100644 --- a/src/libsystemd/sd-hwdb/sd-hwdb.c +++ b/src/libsystemd/sd-hwdb/sd-hwdb.c @@ -29,6 +29,7 @@ #include "sd-hwdb.h" +#include "alloc-util.h" #include "fd-util.h" #include "hashmap.h" #include "hwdb-internal.h" diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 6b98a7c178..cd766c3f91 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -27,6 +27,7 @@ #include "sd-login.h" +#include "alloc-util.h" #include "cgroup-util.h" #include "dirent-util.h" #include "escape.h" diff --git a/src/libsystemd/sd-login/test-login.c b/src/libsystemd/sd-login/test-login.c index 46aa73b38a..b0f94c9522 100644 --- a/src/libsystemd/sd-login/test-login.c +++ b/src/libsystemd/sd-login/test-login.c @@ -24,6 +24,7 @@ #include "sd-login.h" +#include "alloc-util.h" #include "fd-util.h" #include "formats-util.h" #include "string-util.h" diff --git a/src/libsystemd/sd-netlink/local-addresses.c b/src/libsystemd/sd-netlink/local-addresses.c index e2f637f7f9..a00865b56b 100644 --- a/src/libsystemd/sd-netlink/local-addresses.c +++ b/src/libsystemd/sd-netlink/local-addresses.c @@ -21,6 +21,8 @@ ***/ #include "sd-netlink.h" + +#include "alloc-util.h" #include "netlink-util.h" #include "macro.h" #include "local-addresses.h" diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c index 80ad70cfee..03971b3596 100644 --- a/src/libsystemd/sd-netlink/netlink-message.c +++ b/src/libsystemd/sd-netlink/netlink-message.c @@ -25,6 +25,7 @@ #include "sd-netlink.h" +#include "alloc-util.h" #include "formats-util.h" #include "missing.h" #include "netlink-internal.h" diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 68a4d3c0d1..13945202e4 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -25,6 +25,7 @@ #include "sd-netlink.h" +#include "alloc-util.h" #include "formats-util.h" #include "missing.h" #include "netlink-internal.h" diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index ba1f2a5a42..7c24e053cf 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -24,6 +24,7 @@ #include "sd-netlink.h" +#include "alloc-util.h" #include "fd-util.h" #include "hashmap.h" #include "macro.h" diff --git a/src/libsystemd/sd-netlink/test-local-addresses.c b/src/libsystemd/sd-netlink/test-local-addresses.c index 9867eec065..7180175970 100644 --- a/src/libsystemd/sd-netlink/test-local-addresses.c +++ b/src/libsystemd/sd-netlink/test-local-addresses.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "in-addr-util.h" #include "local-addresses.h" #include "af-list.h" diff --git a/src/libsystemd/sd-network/network-util.c b/src/libsystemd/sd-network/network-util.c index 8070ff07c4..a2d6c59314 100644 --- a/src/libsystemd/sd-network/network-util.c +++ b/src/libsystemd/sd-network/network-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "fd-util.h" #include "network-util.h" #include "strv.h" diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index 6cc3321f42..2eaa2626f7 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -27,6 +27,7 @@ #include "sd-network.h" +#include "alloc-util.h" #include "fileio.h" #include "macro.h" #include "string-util.h" diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index c1d42e96e5..480f1ad065 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -19,6 +19,7 @@ #include "sd-path.h" +#include "alloc-util.h" #include "architecture.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c index 724405d534..48767600c9 100644 --- a/src/libsystemd/sd-resolve/sd-resolve.c +++ b/src/libsystemd/sd-resolve/sd-resolve.c @@ -33,6 +33,7 @@ #include "sd-resolve.h" +#include "alloc-util.h" #include "fd-util.h" #include "io-util.h" #include "list.h" diff --git a/src/libsystemd/sd-resolve/test-resolve.c b/src/libsystemd/sd-resolve/test-resolve.c index 87e6e47041..05544a584c 100644 --- a/src/libsystemd/sd-resolve/test-resolve.c +++ b/src/libsystemd/sd-resolve/test-resolve.c @@ -30,6 +30,7 @@ #include "sd-resolve.h" +#include "alloc-util.h" #include "macro.h" #include "resolve-util.h" #include "socket-util.h" diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index bd349e3f64..814e016800 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -37,6 +37,7 @@ #include "libudev.h" #include "sd-device.h" +#include "alloc-util.h" #include "device-private.h" #include "device-util.h" #include "libudev-device-internal.h" diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 56436772b0..442f9615f2 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -31,6 +31,7 @@ #include "libudev.h" #include "sd-device.h" +#include "alloc-util.h" #include "device-enumerator-private.h" #include "device-util.h" #include "libudev-device-internal.h" diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c index 6dc2b0533e..eba698d163 100644 --- a/src/libudev/libudev-hwdb.c +++ b/src/libudev/libudev-hwdb.c @@ -19,6 +19,7 @@ #include "sd-hwdb.h" +#include "alloc-util.h" #include "hwdb-util.h" #include "libudev-private.h" diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c index 19e9130be0..da496ed456 100644 --- a/src/libudev/libudev-list.c +++ b/src/libudev/libudev-list.c @@ -17,11 +17,12 @@ along with systemd; If not, see . ***/ -#include -#include #include +#include +#include #include +#include "alloc-util.h" #include "libudev-private.h" /** diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index 0059c09e77..fedaea6118 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -30,6 +30,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "formats-util.h" diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index a22994c8a2..58410b1b8f 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "io-util.h" #include "libudev-private.h" diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index afadfe6993..63fb05547d 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -26,6 +26,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "fd-util.h" #include "libudev-private.h" #include "missing.h" diff --git a/src/locale/localed.c b/src/locale/localed.c index 1f25d232d2..720cbbaaba 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -30,6 +30,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-message.h" #include "bus-util.h" diff --git a/src/login/inhibit.c b/src/login/inhibit.c index f79f89af7e..70fef332f7 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -27,6 +27,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "fd-util.h" diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 92443c8190..aff68a49fe 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -27,6 +27,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-show.h" diff --git a/src/login/logind-acl.c b/src/login/logind-acl.c index acb2bd5765..d0dd569a03 100644 --- a/src/login/logind-acl.c +++ b/src/login/logind-acl.c @@ -23,6 +23,7 @@ #include #include "acl-util.h" +#include "alloc-util.h" #include "dirent-util.h" #include "escape.h" #include "fd-util.h" diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 8c452456a0..185108f8f1 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "conf-parser.h" diff --git a/src/login/logind-button.c b/src/login/logind-button.c index b98035be21..b08b69dbfc 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -28,6 +28,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "fd-util.h" #include "logind-button.h" #include "string-util.h" diff --git a/src/login/logind-core.c b/src/login/logind-core.c index c2541e490b..b3f30c8dc9 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-util.h" diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 4204732e7d..7890d68aa0 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -26,6 +26,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "audit-util.h" #include "bus-common-errors.h" #include "bus-error.h" diff --git a/src/login/logind-device.c b/src/login/logind-device.c index ee4c45fb8d..ffb9162e56 100644 --- a/src/login/logind-device.c +++ b/src/login/logind-device.c @@ -21,8 +21,9 @@ #include -#include "util.h" +#include "alloc-util.h" #include "logind-device.h" +#include "util.h" Device* device_new(Manager *m, const char *sysfs, bool master) { Device *d; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 92b5807094..33fbdde557 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 66626b5871..43b578f364 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-label.h" #include "bus-util.h" diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 2dcf8ddc62..1f4936cebe 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -26,6 +26,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "formats-util.h" diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index fe398a5eb6..7810199a54 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-label.h" #include "bus-util.h" diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index 3a0bb720f9..9bf3ca0995 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -27,6 +27,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "bus-util.h" #include "fd-util.h" #include "logind-session-device.h" diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 26c135b2ca..a53dcb9960 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -30,6 +30,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "audit-util.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index 5975b579e9..df901f6558 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "bus-util.h" #include "formats-util.h" #include "logind-user.h" diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 1cf9be7441..56bc5a010c 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "clean-ipc.h" diff --git a/src/login/logind-utmp.c b/src/login/logind-utmp.c index 3f4a629be3..3e7a935a34 100644 --- a/src/login/logind-utmp.c +++ b/src/login/logind-utmp.c @@ -26,6 +26,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "audit-util.h" #include "bus-common-errors.h" #include "bus-error.h" diff --git a/src/login/logind.c b/src/login/logind.c index 957ea1fd7e..4b8c834269 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -27,6 +27,7 @@ #include "libudev.h" #include "sd-daemon.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "conf-parser.h" diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index c37cfdb68b..0d61f528db 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -30,6 +30,7 @@ #include #include +#include "alloc-util.h" #include "audit-util.h" #include "bus-common-errors.h" #include "bus-error.h" diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index 0f671ac90e..e9ca4bb03d 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -24,6 +24,7 @@ #include "libudev.h" +#include "alloc-util.h" #include "locale-util.h" #include "path-util.h" #include "string-util.h" diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c index a287b9697a..4ec1766033 100644 --- a/src/machine/image-dbus.c +++ b/src/machine/image-dbus.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-label.h" #include "bus-util.h" #include "image-dbus.h" diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index 1132d75823..452130a29c 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -29,6 +29,7 @@ #include #undef basename +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-internal.h" #include "bus-label.h" diff --git a/src/machine/machine.c b/src/machine/machine.c index 2889cb3205..fa6b70f788 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -25,6 +25,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "escape.h" diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index b8b9e0f519..7e17c7a41c 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -33,6 +33,7 @@ #include "sd-bus.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-show.h" diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 182dedda89..7827f063c1 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -25,6 +25,7 @@ #include "sd-id128.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "bus-common-errors.h" #include "bus-util.h" diff --git a/src/machine/machined.c b/src/machine/machined.c index 1a61da041d..d6e7ce67fc 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -25,6 +25,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-util.h" diff --git a/src/network/networkctl.c b/src/network/networkctl.c index d0d7669c87..97c1fe6560 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -28,6 +28,7 @@ #include "sd-netlink.h" #include "sd-network.h" +#include "alloc-util.h" #include "arphrd-list.h" #include "device-util.h" #include "ether-addr-util.h" diff --git a/src/network/networkd-address-pool.c b/src/network/networkd-address-pool.c index 08e0b9a64b..889fe1e30d 100644 --- a/src/network/networkd-address-pool.c +++ b/src/network/networkd-address-pool.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "networkd-address-pool.h" #include "networkd.h" #include "set.h" diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 1beb7ffae4..e550ee5701 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "conf-parser.h" #include "firewall-util.h" #include "netlink-util.h" diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 22594a9415..c412a2cc31 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -22,10 +22,11 @@ #include #include +#include "alloc-util.h" +#include "dhcp-lease-internal.h" #include "hostname-util.h" -#include "networkd-link.h" #include "network-internal.h" -#include "dhcp-lease-internal.h" +#include "networkd-link.h" static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { diff --git a/src/network/networkd-fdb.c b/src/network/networkd-fdb.c index 9cb63cb79f..c9222b8cb8 100644 --- a/src/network/networkd-fdb.c +++ b/src/network/networkd-fdb.c @@ -22,12 +22,12 @@ #include #include +#include "alloc-util.h" #include "conf-parser.h" -#include "util.h" #include "netlink-util.h" - -#include "networkd.h" #include "networkd-fdb.h" +#include "networkd.h" +#include "util.h" /* create a new FDB entry or get an existing one. */ int fdb_entry_new_static(Network *const network, diff --git a/src/network/networkd-link-bus.c b/src/network/networkd-link-bus.c index f40a01fd78..7fc4510ac9 100644 --- a/src/network/networkd-link-bus.c +++ b/src/network/networkd-link-bus.c @@ -22,6 +22,7 @@ #include "bus-util.h" #include "strv.h" +#include "alloc-util.h" #include "networkd-link.h" #include "networkd.h" #include "parse-util.h" diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index ab37c43dcb..dcc2569660 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "bus-util.h" #include "dhcp-lease-internal.h" #include "fd-util.h" diff --git a/src/network/networkd-manager-bus.c b/src/network/networkd-manager-bus.c index b281f4fdb6..dafaf2daea 100644 --- a/src/network/networkd-manager-bus.c +++ b/src/network/networkd-manager-bus.c @@ -19,8 +19,8 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-util.h" - #include "networkd.h" static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState); diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index af243c9a70..6b2a661ca7 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -25,6 +25,7 @@ #include "sd-daemon.h" #include "sd-netlink.h" +#include "alloc-util.h" #include "bus-util.h" #include "conf-parser.h" #include "def.h" diff --git a/src/network/networkd-netdev-bond.c b/src/network/networkd-netdev-bond.c index ce9c18d654..70105b8aa0 100644 --- a/src/network/networkd-netdev-bond.c +++ b/src/network/networkd-netdev-bond.c @@ -25,6 +25,7 @@ #include "sd-netlink.h" +#include "alloc-util.h" #include "conf-parser.h" #include "missing.h" #include "networkd-netdev-bond.h" diff --git a/src/network/networkd-netdev-tuntap.c b/src/network/networkd-netdev-tuntap.c index d04bb9bd9f..851e83537e 100644 --- a/src/network/networkd-netdev-tuntap.c +++ b/src/network/networkd-netdev-tuntap.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "networkd-netdev-tuntap.h" #include "user-util.h" diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index 5060888a2f..dd0b400c6a 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "conf-files.h" #include "conf-parser.h" #include "fd-util.h" diff --git a/src/network/networkd-network-bus.c b/src/network/networkd-network-bus.c index 2199b93baa..120760a986 100644 --- a/src/network/networkd-network-bus.c +++ b/src/network/networkd-network-bus.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "networkd.h" #include "string-util.h" #include "strv.h" diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index c8c6f5df11..cc8d019017 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "conf-files.h" #include "conf-parser.h" #include "dns-domain.h" diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 7ae6ca2600..4a74bc69f3 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "conf-parser.h" #include "in-addr-util.h" #include "netlink-util.h" diff --git a/src/network/networkd-wait-online-link.c b/src/network/networkd-wait-online-link.c index cc4b46d5b0..c2779ff773 100644 --- a/src/network/networkd-wait-online-link.c +++ b/src/network/networkd-wait-online-link.c @@ -22,6 +22,7 @@ #include "sd-network.h" +#include "alloc-util.h" #include "networkd-wait-online-link.h" #include "string-util.h" diff --git a/src/network/networkd-wait-online-manager.c b/src/network/networkd-wait-online-manager.c index 112d92a568..0c40ab2bb8 100644 --- a/src/network/networkd-wait-online-manager.c +++ b/src/network/networkd-wait-online-manager.c @@ -23,14 +23,13 @@ #include #include +#include "alloc-util.h" #include "netlink-util.h" - #include "network-internal.h" #include "networkd-wait-online-link.h" #include "networkd-wait-online.h" - -#include "util.h" #include "time-util.h" +#include "util.h" bool manager_ignore_link(Manager *m, Link *link) { char **ignore; diff --git a/src/network/test-network.c b/src/network/test-network.c index bac1d6781d..dbed3795e3 100644 --- a/src/network/test-network.c +++ b/src/network/test-network.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "networkd.h" #include "network-internal.h" #include "dhcp-lease-internal.h" diff --git a/src/notify/notify.c b/src/notify/notify.c index 77f017dbac..b144554702 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -27,6 +27,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "env-util.h" #include "formats-util.h" #include "log.h" diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index 4e86ed13cb..270bcf010f 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "cgroup-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/nspawn/nspawn-expose-ports.c b/src/nspawn/nspawn-expose-ports.c index 89c8240399..38245434da 100644 --- a/src/nspawn/nspawn-expose-ports.c +++ b/src/nspawn/nspawn-expose-ports.c @@ -21,6 +21,7 @@ #include "sd-netlink.h" +#include "alloc-util.h" #include "fd-util.h" #include "firewall-util.h" #include "in-addr-util.h" diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index 81003dff89..ee61306aa5 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "cgroup-util.h" #include "escape.h" #include "fs-util.h" diff --git a/src/nspawn/nspawn-network.c b/src/nspawn/nspawn-network.c index 4af18a4e94..29384b60b2 100644 --- a/src/nspawn/nspawn-network.c +++ b/src/nspawn/nspawn-network.c @@ -26,6 +26,7 @@ #include "sd-id128.h" #include "sd-netlink.h" +#include "alloc-util.h" #include "ether-addr-util.h" #include "netlink-util.h" #include "siphash24.h" diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c index f088884776..ee9e70acec 100644 --- a/src/nspawn/nspawn-settings.c +++ b/src/nspawn/nspawn-settings.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "util.h" #include "conf-parser.h" #include "strv.h" diff --git a/src/nspawn/nspawn-setuid.c b/src/nspawn/nspawn-setuid.c index 6b4ca5a3f3..aa6a16309c 100644 --- a/src/nspawn/nspawn-setuid.c +++ b/src/nspawn/nspawn-setuid.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "mkdir.h" #include "nspawn-setuid.h" diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 1ce219b844..8140cda141 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -46,6 +46,7 @@ #include "sd-daemon.h" #include "sd-id128.h" +#include "alloc-util.h" #include "barrier.h" #include "base-filesystem.h" #include "blkid-util.h" diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c index 009a9ad886..ee10b105ea 100644 --- a/src/nss-myhostname/nss-myhostname.c +++ b/src/nss-myhostname/nss-myhostname.c @@ -26,6 +26,7 @@ #include #include +#include "alloc-util.h" #include "hostname-util.h" #include "local-addresses.h" #include "macro.h" diff --git a/src/nss-mymachines/nss-mymachines.c b/src/nss-mymachines/nss-mymachines.c index b98bde676b..969fa9619e 100644 --- a/src/nss-mymachines/nss-mymachines.c +++ b/src/nss-mymachines/nss-mymachines.c @@ -25,6 +25,7 @@ #include "sd-bus.h" #include "sd-login.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-util.h" #include "hostname-util.h" diff --git a/src/path/path.c b/src/path/path.c index 97e8323de1..0ece72f6fe 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -26,6 +26,7 @@ #include "sd-path.h" +#include "alloc-util.h" #include "log.h" #include "macro.h" #include "string-util.h" diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c index fbfd3a3eba..d857ade36a 100644 --- a/src/random-seed/random-seed.c +++ b/src/random-seed/random-seed.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "io-util.h" #include "log.h" diff --git a/src/rc-local-generator/rc-local-generator.c b/src/rc-local-generator/rc-local-generator.c index 1007de3959..8e5cf0908c 100644 --- a/src/rc-local-generator/rc-local-generator.c +++ b/src/rc-local-generator/rc-local-generator.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "log.h" #include "mkdir.h" #include "string-util.h" diff --git a/src/resolve-host/resolve-host.c b/src/resolve-host/resolve-host.c index 9b808ff110..57739d1f3e 100644 --- a/src/resolve-host/resolve-host.c +++ b/src/resolve-host/resolve-host.c @@ -25,6 +25,7 @@ #include "sd-bus.h" #include "af-list.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "in-addr-util.h" diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c index bf1b7c8ab4..f0a3b607d4 100644 --- a/src/resolve/resolved-bus.c +++ b/src/resolve/resolved-bus.c @@ -19,9 +19,9 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-util.h" - #include "dns-domain.h" #include "resolved-bus.h" #include "resolved-def.h" diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index 17eafec2fa..c9919ced67 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -19,10 +19,11 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "conf-parser.h" +#include "extract-word.h" #include "parse-util.h" #include "resolved-conf.h" -#include "extract-word.h" #include "string-util.h" int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) { @@ -35,7 +36,7 @@ int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) first = type == DNS_SERVER_FALLBACK ? m->fallback_dns_servers : m->dns_servers; for(;;) { - _cleanup_free_ char *word; + _cleanup_free_ char *word = NULL; union in_addr_union addr; bool found = false; DnsServer *s; @@ -44,7 +45,6 @@ int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) r = extract_first_word(&string, &word, NULL, 0); if (r < 0) return log_error_errno(r, "Failed to parse resolved dns server syntax \"%s\": %m", string); - if (r == 0) break; diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c index e1a2865007..3cf9c68074 100644 --- a/src/resolve/resolved-dns-answer.c +++ b/src/resolve/resolved-dns-answer.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "dns-domain.h" #include "resolved-dns-answer.h" #include "string-util.h" diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index ab13636bc1..04f64022e0 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "resolved-dns-cache.h" #include "resolved-dns-packet.h" diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index f7f936d343..f23b3cf893 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "dns-domain.h" #include "resolved-dns-packet.h" #include "string-table.h" diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c index 4b1d18b2ef..f7cb84e2a6 100644 --- a/src/resolve/resolved-dns-query.c +++ b/src/resolve/resolved-dns-query.c @@ -19,10 +19,10 @@ along with systemd; If not, see . ***/ -#include "hostname-util.h" +#include "alloc-util.h" #include "dns-domain.h" +#include "hostname-util.h" #include "local-addresses.h" - #include "resolved-dns-query.h" /* How long to wait for the query in total */ diff --git a/src/resolve/resolved-dns-question.c b/src/resolve/resolved-dns-question.c index 1507f22da0..48951221dc 100644 --- a/src/resolve/resolved-dns-question.c +++ b/src/resolve/resolved-dns-question.c @@ -19,8 +19,9 @@ along with systemd; If not, see . ***/ -#include "resolved-dns-question.h" +#include "alloc-util.h" #include "dns-domain.h" +#include "resolved-dns-question.h" DnsQuestion *dns_question_new(unsigned n) { DnsQuestion *q; diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index 63edee1fd1..ba2ea686f3 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "dns-domain.h" #include "dns-type.h" #include "hexdecoct.h" diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 7c63c63b63..b15370b017 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -22,6 +22,7 @@ #include #include "af-list.h" +#include "alloc-util.h" #include "dns-domain.h" #include "fd-util.h" #include "hostname-util.h" diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c index 8693911e65..e803f635ab 100644 --- a/src/resolve/resolved-dns-server.c +++ b/src/resolve/resolved-dns-server.c @@ -19,9 +19,9 @@ along with systemd; If not, see . ***/ -#include "siphash24.h" - +#include "alloc-util.h" #include "resolved-dns-server.h" +#include "siphash24.h" /* After how much time to repeat classic DNS requests */ #define DNS_TIMEOUT_MIN_USEC (500 * USEC_PER_MSEC) diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index 1150c30677..1c501182fb 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "fd-util.h" #include "io-util.h" #include "missing.h" diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index c60197cf8d..6545f6cd8a 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -20,6 +20,7 @@ ***/ #include "af-list.h" +#include "alloc-util.h" #include "dns-domain.h" #include "fd-util.h" #include "random-util.h" diff --git a/src/resolve/resolved-dns-zone.c b/src/resolve/resolved-dns-zone.c index 8a6086a4de..48dcf76daa 100644 --- a/src/resolve/resolved-dns-zone.c +++ b/src/resolve/resolved-dns-zone.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "dns-domain.h" #include "list.h" #include "resolved-dns-packet.h" diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c index 8c88e2dbf1..2892641075 100644 --- a/src/resolve/resolved-link.c +++ b/src/resolve/resolved-link.c @@ -23,6 +23,7 @@ #include "sd-network.h" +#include "alloc-util.h" #include "missing.h" #include "parse-util.h" #include "resolved-link.h" diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index b9c625b9cf..a588538b52 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -25,6 +25,7 @@ #include #include "af-list.h" +#include "alloc-util.h" #include "dns-domain.h" #include "fd-util.h" #include "fileio-label.h" diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index 5ba1e3d4a8..bb00f99ecf 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -25,6 +25,7 @@ #include "libudev.h" #include "sd-daemon.h" +#include "alloc-util.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/run/run.c b/src/run/run.c index dbcb29546f..38a482bb11 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -25,6 +25,7 @@ #include "sd-bus.h" #include "sd-event.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "calendarspec.h" diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c index e8931daee2..79f5a60579 100644 --- a/src/shared/acl-util.c +++ b/src/shared/acl-util.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "acl-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/shared/acpi-fpdt.c b/src/shared/acpi-fpdt.c index b3d2f96885..8e36067f74 100644 --- a/src/shared/acpi-fpdt.c +++ b/src/shared/acpi-fpdt.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "acpi-fpdt.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/shared/apparmor-util.c b/src/shared/apparmor-util.c index 48d0f84995..f6ac43adfe 100644 --- a/src/shared/apparmor-util.c +++ b/src/shared/apparmor-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "apparmor-util.h" #include "fileio.h" #include "parse-util.h" diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index b2dbf98b8e..c96dbf877a 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -32,6 +32,7 @@ #include #include +#include "alloc-util.h" #include "ask-password-api.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index ff91c6bdc5..e605490c32 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "base-filesystem.h" #include "fd-util.h" #include "log.h" diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 8f6278191a..f4a918063d 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -25,6 +25,7 @@ #include "sd-daemon.h" #include "sd-event.h" +#include "alloc-util.h" #include "bus-error.h" #include "bus-internal.h" #include "bus-label.h" diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index 9e70713ce8..129ffc7056 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "cgroup-show.h" #include "cgroup-util.h" #include "fd-util.h" diff --git a/src/shared/condition.c b/src/shared/condition.c index 2929e3e821..a69719116c 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -27,6 +27,7 @@ #include "sd-id128.h" +#include "alloc-util.h" #include "apparmor-util.h" #include "architecture.h" #include "audit-util.h" diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index fa13eb8075..163a83518b 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -26,6 +26,7 @@ #include "sd-messages.h" +#include "alloc-util.h" #include "conf-files.h" #include "conf-parser.h" #include "fd-util.h" diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c index 0d321af967..ad3c17d5bd 100644 --- a/src/shared/dev-setup.c +++ b/src/shared/dev-setup.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "dev-setup.h" #include "label.h" #include "path-util.h" diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index b6587306a5..7af15e0098 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -24,6 +24,7 @@ #include #endif +#include "alloc-util.h" #include "dns-domain.h" #include "hexdecoct.h" #include "parse-util.h" diff --git a/src/shared/dropin.c b/src/shared/dropin.c index 25400277ff..0d44401cc2 100644 --- a/src/shared/dropin.c +++ b/src/shared/dropin.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "conf-files.h" #include "dropin.h" #include "escape.h" diff --git a/src/shared/efivars.c b/src/shared/efivars.c index e7972d1574..86bb0b57c3 100644 --- a/src/shared/efivars.c +++ b/src/shared/efivars.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "dirent-util.h" #include "efivars.h" #include "fd-util.h" diff --git a/src/shared/firewall-util.c b/src/shared/firewall-util.c index effc6e8e70..e178287872 100644 --- a/src/shared/firewall-util.c +++ b/src/shared/firewall-util.c @@ -27,8 +27,9 @@ #include #include -#include "util.h" +#include "alloc-util.h" #include "firewall-util.h" +#include "util.h" DEFINE_TRIVIAL_CLEANUP_FUNC(struct xtc_handle*, iptc_free); diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 1ea11ea5a4..eb2845cddf 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "device-nodes.h" #include "fstab-util.h" #include "mount-util.h" diff --git a/src/shared/generator.c b/src/shared/generator.c index 203e01318b..cb4ebc606e 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "dropin.h" #include "escape.h" #include "fd-util.h" diff --git a/src/shared/import-util.c b/src/shared/import-util.c index bf5395dee8..ddc8c00a2d 100644 --- a/src/shared/import-util.c +++ b/src/shared/import-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "btrfs-util.h" #include "import-util.h" #include "path-util.h" diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c index 224874f65c..e1cb5d27ff 100644 --- a/src/shared/install-printf.c +++ b/src/shared/install-printf.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "formats-util.h" #include "install-printf.h" #include "specifier.h" diff --git a/src/shared/install.c b/src/shared/install.c index 1f63ae9ce0..c74efede76 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "conf-files.h" #include "conf-parser.h" #include "dirent-util.h" diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 5b4a220e5f..0313b0946f 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "formats-util.h" #include "hashmap.h" diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index a4e77fb8d8..2c1da0a40d 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "btrfs-util.h" #include "chattr-util.h" #include "copy.h" diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c index 1c7e0ef2c1..60b1b3092d 100644 --- a/src/shared/machine-pool.c +++ b/src/shared/machine-pool.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "btrfs-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 1e63c72047..d71f379e76 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "util.h" #include "strv.h" #include "path-util.h" diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index e5e0f37adf..786752ea94 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "ptyfwd.h" #include "util.h" diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 0e232e6aa6..bbbb3460d4 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "conf-parser.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/shared/specifier.c b/src/shared/specifier.c index 610aec0df5..c5c4a4d7d7 100644 --- a/src/shared/specifier.c +++ b/src/shared/specifier.c @@ -22,11 +22,12 @@ #include #include +#include "alloc-util.h" #include "hostname-util.h" #include "macro.h" +#include "specifier.h" #include "string-util.h" #include "util.h" -#include "specifier.h" /* * Generic infrastructure for replacing %x style specifiers in diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 1e6ac2f27d..13b32a0509 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -27,6 +27,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "hostname-util.h" #include "macro.h" diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index e82fb06417..ba82adadb4 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -34,6 +34,7 @@ #include "sd-event.h" #include "sd-resolve.h" +#include "alloc-util.h" #include "fd-util.h" #include "log.h" #include "path-util.h" diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 2faa93ef88..f5efa1a064 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -37,6 +37,7 @@ #include "sd-daemon.h" #include "sd-login.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-message.h" diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 5d2cbe1225..36d310b4c4 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -26,6 +26,7 @@ #include #include +#include "alloc-util.h" #include "conf-files.h" #include "copy.h" #include "fileio-label.h" diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index e4b02ca990..0a0b9269b3 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -25,6 +25,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "hashmap.h" #include "hexdecoct.h" diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c index 12f366a34c..70819b0371 100644 --- a/src/test/test-calendarspec.c +++ b/src/test/test-calendarspec.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "calendarspec.h" #include "string-util.h" #include "util.h" diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c index f43f737951..4418bafda6 100644 --- a/src/test/test-cap-list.c +++ b/src/test/test-cap-list.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "cap-list.h" #include "capability-util.h" #include "fileio.h" diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index e4f6d5168d..a48b324e26 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "cgroup-util.h" #include "dirent-util.h" #include "fd-util.h" diff --git a/src/test/test-condition.c b/src/test/test-condition.c index 365f5794d4..f224c6cdd8 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -19,6 +19,7 @@ #include "sd-id128.h" +#include "alloc-util.h" #include "apparmor-util.h" #include "architecture.h" #include "audit-util.h" diff --git a/src/test/test-conf-files.c b/src/test/test-conf-files.c index f4b23355fc..a69698d4ea 100644 --- a/src/test/test-conf-files.c +++ b/src/test/test-conf-files.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "conf-files.h" #include "fs-util.h" #include "macro.h" diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 4ccf729e80..ad57cb0202 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -19,6 +19,7 @@ #include +#include "alloc-util.h" #include "copy.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/test/test-date.c b/src/test/test-date.c index e1c6ecb2ef..c6d8bf82ea 100644 --- a/src/test/test-date.c +++ b/src/test/test-date.c @@ -21,8 +21,9 @@ #include -#include "util.h" +#include "alloc-util.h" #include "string-util.h" +#include "util.h" static void test_should_pass(const char *p) { usec_t t, q; diff --git a/src/test/test-device-nodes.c b/src/test/test-device-nodes.c index 1c745d6e5b..646b168cc0 100644 --- a/src/test/test-device-nodes.c +++ b/src/test/test-device-nodes.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "device-nodes.h" #include "string-util.h" #include "util.h" diff --git a/src/test/test-dns-domain.c b/src/test/test-dns-domain.c index 1a8541e1cc..d5778748a0 100644 --- a/src/test/test-dns-domain.c +++ b/src/test/test-dns-domain.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "dns-domain.h" #include "macro.h" #include "string-util.h" diff --git a/src/test/test-ellipsize.c b/src/test/test-ellipsize.c index 033d5af719..c597d5aecd 100644 --- a/src/test/test-ellipsize.c +++ b/src/test/test-ellipsize.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "def.h" #include "string-util.h" #include "terminal-util.h" diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index 1c1fed4660..e588681b86 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "ctype.h" #include "def.h" #include "env-util.h" diff --git a/src/test/test-fstab-util.c b/src/test/test-fstab-util.c index b02f3a6e7c..27816ac779 100644 --- a/src/test/test-fstab-util.c +++ b/src/test/test-fstab-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "fstab-util.h" #include "log.h" #include "string-util.h" diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index 2da6446961..6bf33306a9 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -17,6 +17,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "hashmap.h" #include "string-util.h" #include "strv.h" diff --git a/src/test/test-hostname-util.c b/src/test/test-hostname-util.c index ac8f4ecc68..590175433c 100644 --- a/src/test/test-hostname-util.c +++ b/src/test/test-hostname-util.c @@ -21,10 +21,11 @@ along with systemd; If not, see . ***/ -#include "util.h" +#include "alloc-util.h" #include "fileio.h" #include "hostname-util.h" #include "string-util.h" +#include "util.h" static void test_hostname_is_valid(void) { assert_se(hostname_is_valid("foobar", false)); diff --git a/src/test/test-id128.c b/src/test/test-id128.c index 2c8ba70ffb..32cf3f80ca 100644 --- a/src/test/test-id128.c +++ b/src/test/test-id128.c @@ -24,6 +24,7 @@ #include "sd-daemon.h" #include "sd-id128.h" +#include "alloc-util.h" #include "macro.h" #include "string-util.h" #include "util.h" diff --git a/src/test/test-json.c b/src/test/test-json.c index ba4d75c0c8..3995224eea 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "json.h" #include "string-util.h" #include "util.h" diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c index a060a7ba6f..5a12e959d4 100644 --- a/src/test/test-namespace.c +++ b/src/test/test-namespace.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "fd-util.h" #include "namespace.h" #include "process-util.h" diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index e2979a8710..3f0f0264ab 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "macro.h" #include "mount-util.h" diff --git a/src/test/test-path.c b/src/test/test-path.c index 405434c1ff..ff0f044958 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -20,6 +20,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fs-util.h" #include "macro.h" diff --git a/src/test/test-prioq.c b/src/test/test-prioq.c index 1e2e42cbca..07273ffe79 100644 --- a/src/test/test-prioq.c +++ b/src/test/test-prioq.c @@ -21,10 +21,11 @@ #include -#include "util.h" -#include "set.h" +#include "alloc-util.h" #include "prioq.h" +#include "set.h" #include "siphash24.h" +#include "util.h" #define SET_SIZE 1024*4 diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 16a7148b19..fa448348da 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -23,6 +23,7 @@ #include #include +#include "alloc-util.h" #include "log.h" #include "macro.h" #include "process-util.h" diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index 4a2d952c86..b9699b2028 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -17,6 +17,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "async.h" #include "fd-util.h" #include "in-addr-util.h" diff --git a/src/test/test-strv.c b/src/test/test-strv.c index c676893719..c27f15283e 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -22,6 +22,7 @@ #include +#include "alloc-util.h" #include "specifier.h" #include "string-util.h" #include "strv.h" diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c index 683fbe217c..a8bd722e44 100644 --- a/src/test/test-tmpfiles.c +++ b/src/test/test-tmpfiles.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "formats-util.h" diff --git a/src/test/test-uid-range.c b/src/test/test-uid-range.c index 9f69d71203..4dcf10e26d 100644 --- a/src/test/test-uid-range.c +++ b/src/test/test-uid-range.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "uid-range.h" #include "user-util.h" #include "util.h" diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index 226453d06e..c58c48af3c 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -26,6 +26,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "hashmap.h" diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index 5aff771af5..9db7853dd4 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -26,6 +26,7 @@ #include #include +#include "alloc-util.h" #include "hostname-util.h" #include "macro.h" #include "manager.h" diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c index dfd2031998..09d37087e5 100644 --- a/src/test/test-user-util.c +++ b/src/test/test-user-util.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "macro.h" #include "string-util.h" #include "user-util.h" diff --git a/src/test/test-utf8.c b/src/test/test-utf8.c index a8e15b7cf1..0af8349732 100644 --- a/src/test/test-utf8.c +++ b/src/test/test-utf8.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "utf8.h" #include "util.h" #include "string-util.h" diff --git a/src/test/test-util.c b/src/test/test-util.c index 647eff0496..ffde10c7e1 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -31,6 +31,7 @@ #include #include +#include "alloc-util.h" #include "conf-parser.h" #include "cpu-set-util.h" #include "def.h" diff --git a/src/test/test-xml.c b/src/test/test-xml.c index 93b0e7c3fb..548d75a3c3 100644 --- a/src/test/test-xml.c +++ b/src/test/test-xml.c @@ -21,6 +21,7 @@ #include +#include "alloc-util.h" #include "string-util.h" #include "util.h" #include "xml.h" diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 507a83b2a1..968ef8a788 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -27,6 +27,7 @@ #include "sd-event.h" #include "sd-messages.h" +#include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-util.h" diff --git a/src/timesync/timesyncd-conf.c b/src/timesync/timesyncd-conf.c index ad6fd180e4..be651fc636 100644 --- a/src/timesync/timesyncd-conf.c +++ b/src/timesync/timesyncd-conf.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "string-util.h" #include "timesyncd-manager.h" #include "timesyncd-server.h" @@ -35,16 +36,16 @@ int manager_parse_server_string(Manager *m, ServerType type, const char *string) first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers; for (;;) { - _cleanup_free_ char *word; + _cleanup_free_ char *word = NULL; bool found = false; ServerName *n; r = extract_first_word(&string, &word, NULL, 0); if (r < 0) return log_error_errno(r, "Failed to parse timesyncd server syntax \"%s\": %m", string); - if (r == 0) break; + /* Filter out duplicates */ LIST_FOREACH(names, n, first) if (streq_ptr(n->string, word)) { diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 15ca006deb..b4995c3064 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -33,6 +33,7 @@ #include "sd-daemon.h" +#include "alloc-util.h" #include "fd-util.h" #include "fs-util.h" #include "list.h" diff --git a/src/timesync/timesyncd-server.c b/src/timesync/timesyncd-server.c index ec3fe1fc4e..f98e6b4cf0 100644 --- a/src/timesync/timesyncd-server.c +++ b/src/timesync/timesyncd-server.c @@ -19,6 +19,7 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "timesyncd-server.h" int server_address_new( diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 5196447963..3c0b9993e3 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -39,6 +39,7 @@ #include #include "acl-util.h" +#include "alloc-util.h" #include "btrfs-util.h" #include "capability-util.h" #include "chattr-util.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 a6240ae89a..d2938f0872 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -32,6 +32,7 @@ #include #include +#include "alloc-util.h" #include "ask-password-api.h" #include "conf-parser.h" #include "def.h" diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index b234792e23..b6c95cd452 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -24,6 +24,7 @@ #include #include +#include "alloc-util.h" #include "libudev-private.h" #include "macro.h" #include "string-util.h" diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 972841b6d9..776674e994 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -24,6 +24,7 @@ #include "sd-netlink.h" +#include "alloc-util.h" #include "conf-files.h" #include "conf-parser.h" #include "ethtool-util.h" diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index 0976525eb3..d0e47ec6d8 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -29,6 +29,7 @@ #include "sd-id128.h" +#include "alloc-util.h" #include "efivars.h" #include "fd-util.h" #include "gpt.h" diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c index 97a5a9c77f..f4a065a97d 100644 --- a/src/udev/udev-builtin-hwdb.c +++ b/src/udev/udev-builtin-hwdb.c @@ -24,6 +24,7 @@ #include "sd-hwdb.h" +#include "alloc-util.h" #include "hwdb-util.h" #include "string-util.h" #include "udev-util.h" diff --git a/src/udev/udev-builtin-net_setup_link.c b/src/udev/udev-builtin-net_setup_link.c index d4589470fb..f72894b5c5 100644 --- a/src/udev/udev-builtin-net_setup_link.c +++ b/src/udev/udev-builtin-net_setup_link.c @@ -19,9 +19,10 @@ along with systemd; If not, see . ***/ +#include "alloc-util.h" #include "link-config.h" -#include "udev.h" #include "log.h" +#include "udev.h" static link_config_ctx *ctx = NULL; diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index 2c40988c7a..1e190140b2 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -30,6 +30,7 @@ #include #include +#include "alloc-util.h" #include "string-util.h" #include "udev.h" diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index cb531bd168..587649eff0 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -29,6 +29,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "string-util.h" #include "udev.h" diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 937fc4ecd8..1e05be51a5 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -18,6 +18,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "formats-util.h" #include "socket-util.h" diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index bf122f85c7..6b4bd31281 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -30,6 +30,7 @@ #include #include +#include "alloc-util.h" #include "event-util.h" #include "fd-util.h" #include "formats-util.h" diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 7d5f473d45..c06ace09cf 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -29,6 +29,7 @@ #include #include +#include "alloc-util.h" #include "conf-files.h" #include "escape.h" #include "fd-util.h" diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 87468c43ae..031a099d77 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -22,6 +22,7 @@ #include #include +#include "alloc-util.h" #include "conf-files.h" #include "fileio.h" #include "fs-util.h" diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 60fc3179b0..2c152129cc 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -43,6 +43,7 @@ #include "sd-daemon.h" #include "sd-event.h" +#include "alloc-util.h" #include "cgroup-util.h" #include "cpu-set-util.h" #include "dev-setup.h" diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index bcabf65a36..d50063cbcd 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -29,15 +29,16 @@ #include "sd-bus.h" +#include "alloc-util.h" +#include "bus-error.h" +#include "bus-util.h" +#include "formats-util.h" #include "log.h" #include "macro.h" -#include "util.h" #include "special.h" -#include "utmp-wtmp.h" -#include "bus-util.h" -#include "bus-error.h" #include "unit-name.h" -#include "formats-util.h" +#include "util.h" +#include "utmp-wtmp.h" typedef struct Context { sd_bus *bus; diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 2da28f8be0..2298f1c2a9 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -31,6 +31,7 @@ #include #include +#include "alloc-util.h" #include "fd-util.h" #include "fileio.h" #include "io-util.h" -- cgit v1.2.3-54-g00ecf From 7760171904ef007f19e8f46aa240a00e382d5b74 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 14:58:05 +0100 Subject: util-lib: move inotify-related definitions to fs-util.[ch] --- src/basic/fs-util.h | 16 +++++++++++++++- src/basic/util.h | 12 ------------ src/core/cgroup.c | 1 + src/core/path.c | 1 + src/journal/sd-journal.c | 1 + src/libsystemd/sd-network/sd-network.c | 5 +++-- 6 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src/journal') diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index 0e1906ba3f..b94873e65b 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -21,9 +21,11 @@ along with systemd; If not, see . ***/ -#include #include +#include +#include #include +#include #include "time-util.h" @@ -58,3 +60,15 @@ int mknod_atomic(const char *path, mode_t mode, dev_t dev); int mkfifo_atomic(const char *path, mode_t mode); int get_files_in_directory(const char *path, char ***list); + +#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) + +#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ + for ((e) = &buffer.ev; \ + (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \ + (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len)) + +union inotify_event_buffer { + struct inotify_event ev; + uint8_t raw[INOTIFY_EVENT_MAX]; +}; diff --git a/src/basic/util.h b/src/basic/util.h index 2c2cb36190..a8fba372d1 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -181,16 +181,4 @@ uint64_t physical_memory(void); int update_reboot_param_file(const char *param); -#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1) - -#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \ - for ((e) = &buffer.ev; \ - (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \ - (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len)) - -union inotify_event_buffer { - struct inotify_event ev; - uint8_t raw[INOTIFY_EVENT_MAX]; -}; - int version(void); diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 70f6d4af0f..bed01fde21 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -27,6 +27,7 @@ #include "cgroup.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/core/path.c b/src/core/path.c index 9c5309a58a..35e1753583 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -28,6 +28,7 @@ #include "bus-util.h" #include "dbus-path.h" #include "fd-util.h" +#include "fs-util.h" #include "glob-util.h" #include "macro.h" #include "mkdir.h" diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 6eda5162c7..043087485b 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -37,6 +37,7 @@ #include "fd-util.h" #include "fileio.h" #include "formats-util.h" +#include "fs-util.h" #include "hashmap.h" #include "hostname-util.h" #include "io-util.h" diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index 2eaa2626f7..efbceba83d 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -28,13 +28,14 @@ #include "sd-network.h" #include "alloc-util.h" +#include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "macro.h" +#include "parse-util.h" #include "string-util.h" #include "strv.h" #include "util.h" -#include "fd-util.h" -#include "parse-util.h" _public_ int sd_network_get_operational_state(char **state) { _cleanup_free_ char *s = NULL; -- cgit v1.2.3-54-g00ecf