diff options
Diffstat (limited to 'src')
52 files changed, 214 insertions, 107 deletions
diff --git a/src/ac-power/ac-power.c b/src/ac-power/ac-power.c index 2d8cbb985f..090b6b1783 100644 --- a/src/ac-power/ac-power.c +++ b/src/ac-power/ac-power.c @@ -2,6 +2,7 @@ #include <getopt.h> +#include "main-func.h" #include "util.h" static bool arg_verbose = false; diff --git a/src/basic/json.h b/src/basic/json.h index 42be60e055..c9482d23eb 100644 --- a/src/basic/json.h +++ b/src/basic/json.h @@ -274,7 +274,7 @@ int json_log_internal(JsonVariant *variant, int level, int error, const char *fi #define _JSON_VARIANT_STRING_CONST(xq, x) \ ({ \ - __attribute__((aligned(2))) static const char UNIQ_T(json_string_const, xq)[] = (x); \ + __attribute__((__aligned__(2))) static const char UNIQ_T(json_string_const, xq)[] = (x); \ assert((((uintptr_t) UNIQ_T(json_string_const, xq)) & 1) == 0); \ (JsonVariant*) ((uintptr_t) UNIQ_T(json_string_const, xq) + 1); \ }) diff --git a/src/basic/macro.h b/src/basic/macro.h index c52d8e4e3f..b529fb15ff 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -8,30 +8,30 @@ #include <sys/sysmacros.h> #include <sys/types.h> -#define _printf_(a, b) __attribute__ ((format (printf, a, b))) +#define _printf_(a, b) __attribute__ ((__format__(printf, a, b))) #ifdef __clang__ # define _alloc_(...) #else -# define _alloc_(...) __attribute__ ((alloc_size(__VA_ARGS__))) +# define _alloc_(...) __attribute__ ((__alloc_size__(__VA_ARGS__))) #endif -#define _sentinel_ __attribute__ ((sentinel)) -#define _unused_ __attribute__ ((unused)) -#define _destructor_ __attribute__ ((destructor)) -#define _pure_ __attribute__ ((pure)) -#define _const_ __attribute__ ((const)) -#define _deprecated_ __attribute__ ((deprecated)) -#define _packed_ __attribute__ ((packed)) -#define _malloc_ __attribute__ ((malloc)) -#define _weak_ __attribute__ ((weak)) +#define _sentinel_ __attribute__ ((__sentinel__)) +#define _unused_ __attribute__ ((__unused__)) +#define _destructor_ __attribute__ ((__destructor__)) +#define _pure_ __attribute__ ((__pure__)) +#define _const_ __attribute__ ((__const__)) +#define _deprecated_ __attribute__ ((__deprecated__)) +#define _packed_ __attribute__ ((__packed__)) +#define _malloc_ __attribute__ ((__malloc__)) +#define _weak_ __attribute__ ((__weak__)) #define _likely_(x) (__builtin_expect(!!(x), 1)) #define _unlikely_(x) (__builtin_expect(!!(x), 0)) -#define _public_ __attribute__ ((visibility("default"))) -#define _hidden_ __attribute__ ((visibility("hidden"))) -#define _weakref_(x) __attribute__((weakref(#x))) -#define _alignas_(x) __attribute__((aligned(__alignof(x)))) -#define _cleanup_(x) __attribute__((cleanup(x))) +#define _public_ __attribute__ ((__visibility__("default"))) +#define _hidden_ __attribute__ ((__visibility__("hidden"))) +#define _weakref_(x) __attribute__((__weakref__(#x))) +#define _alignas_(x) __attribute__((__aligned__(__alignof(x)))) +#define _cleanup_(x) __attribute__((__cleanup__(x))) #if __GNUC__ >= 7 -#define _fallthrough_ __attribute__((fallthrough)) +#define _fallthrough_ __attribute__((__fallthrough__)) #else #define _fallthrough_ #endif @@ -41,7 +41,7 @@ #if __STDC_VERSION__ >= 201112L #define _noreturn_ _Noreturn #else -#define _noreturn_ __attribute__((noreturn)) +#define _noreturn_ __attribute__((__noreturn__)) #endif #endif @@ -506,23 +506,4 @@ static inline int __coverity_check__(int condition) { DEFINE_PUBLIC_TRIVIAL_REF_FUNC(type, name); \ DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC(type, name, free_func); -/* Negative return values from impl are mapped to EXIT_FAILURE, and - * everything else means success! */ -#define DEFINE_MAIN_FUNCTION(impl) \ - int main(int argc, char *argv[]) { \ - int r; \ - r = impl(argc, argv); \ - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; \ - } - -/* Zero is mapped to EXIT_SUCCESS, and both negative and positive values - * are mapped to EXIT_FAILURE. - * Note: this means "true" maps to EXIT_FAILURE. */ -#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \ - int main(int argc, char *argv[]) { \ - int r; \ - r = impl(argc, argv); \ - return r != 0 ? EXIT_FAILURE : EXIT_SUCCESS; \ - } - #include "log.h" diff --git a/src/basic/main-func.h b/src/basic/main-func.h new file mode 100644 index 0000000000..caa5885e8b --- /dev/null +++ b/src/basic/main-func.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +#include <stdlib.h> + +#include "static-destruct.h" + +/* Negative return values from impl are mapped to EXIT_FAILURE, and + * everything else means success! */ +#define DEFINE_MAIN_FUNCTION(impl) \ + int main(int argc, char *argv[]) { \ + int r; \ + r = impl(argc, argv); \ + static_destruct(); \ + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; \ + } + +/* Zero is mapped to EXIT_SUCCESS, and both negative and positive values + * are mapped to EXIT_FAILURE. + * Note: this means "true" maps to EXIT_FAILURE. */ +#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \ + int main(int argc, char *argv[]) { \ + int r; \ + r = impl(argc, argv); \ + static_destruct(); \ + return r != 0 ? EXIT_FAILURE : EXIT_SUCCESS; \ + } diff --git a/src/basic/meson.build b/src/basic/meson.build index ac580c283c..3e2325f41f 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -129,10 +129,10 @@ basic_sources = files(''' nss-util.h ordered-set.c ordered-set.h - pager.c - pager.h os-util.c os-util.h + pager.c + pager.h parse-util.c parse-util.h path-util.c @@ -183,6 +183,7 @@ basic_sources = files(''' special.h stat-util.c stat-util.h + static-destruct.h stdio-util.h strbuf.c strbuf.h diff --git a/src/basic/process-util.c b/src/basic/process-util.c index b3f69b2542..8f7f4b5e25 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -831,7 +831,7 @@ int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) { void sigkill_wait(pid_t pid) { assert(pid > 1); - if (kill(pid, SIGKILL) > 0) + if (kill(pid, SIGKILL) >= 0) (void) wait_for_terminate(pid, NULL); } @@ -849,7 +849,7 @@ void sigkill_waitp(pid_t *pid) { void sigterm_wait(pid_t pid) { assert(pid > 1); - if (kill_and_sigcont(pid, SIGTERM) > 0) + if (kill_and_sigcont(pid, SIGTERM) >= 0) (void) wait_for_terminate(pid, NULL); } diff --git a/src/basic/sparse-endian.h b/src/basic/sparse-endian.h index 8540ccd0ba..9583dda9e5 100644 --- a/src/basic/sparse-endian.h +++ b/src/basic/sparse-endian.h @@ -27,8 +27,8 @@ #include <stdint.h> #ifdef __CHECKER__ -#define __sd_bitwise __attribute__((bitwise)) -#define __sd_force __attribute__((force)) +#define __sd_bitwise __attribute__((__bitwise__)) +#define __sd_force __attribute__((__force__)) #else #define __sd_bitwise #define __sd_force diff --git a/src/basic/static-destruct.h b/src/basic/static-destruct.h new file mode 100644 index 0000000000..cad838083f --- /dev/null +++ b/src/basic/static-destruct.h @@ -0,0 +1,51 @@ +#pragma once + +#include "macro.h" + +/* A framework for registering static variables that shall be freed on shutdown of a process. It's a bit like gcc's + * destructor attribute, but allows us to precisely schedule when we want to free the variables. This is supposed to + * feel a bit like the gcc cleanup attribute, but for static variables. Note that this does not work for static + * variables declared in .so's, as the list is private to the same linking unit. But maybe that's a good thing. */ + +typedef struct StaticDestructor { + void *data; + void (*destroy)(void *p); +} StaticDestructor; + +#define STATIC_DESTRUCTOR_REGISTER(variable, func) \ + _STATIC_DESTRUCTOR_REGISTER(UNIQ, variable, func) + +#define _STATIC_DESTRUCTOR_REGISTER(uq, variable, func) \ + /* Type-safe destructor */ \ + static void UNIQ_T(static_destructor_wrapper, uq)(void *p) { \ + typeof(variable) *q = p; \ + func(q); \ + } \ + /* The actual destructor structure */ \ + __attribute__ ((__section__("SYSTEMD_STATIC_DESTRUCT"))) \ + __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))) \ + __attribute__ ((__used__)) \ + static const StaticDestructor UNIQ_T(static_destructor_entry, uq) = { \ + .data = &(variable), \ + .destroy = UNIQ_T(static_destructor_wrapper, uq), \ + } + +/* Beginning and end of our section listing the destructors. We define these as weak as we want this to work even if + * there's not a single destructor is defined in which case the section will be missing. */ +extern const struct StaticDestructor __attribute__((__weak__)) __start_SYSTEMD_STATIC_DESTRUCT[]; +extern const struct StaticDestructor __attribute__((__weak__)) __stop_SYSTEMD_STATIC_DESTRUCT[]; + +/* The function to destroy everything. (Note that this must be static inline, as it's key that it remains in the same + * linking unit as the variables we want to destroy. */ +static inline void static_destruct(void) { + const StaticDestructor *d; + + if (!__start_SYSTEMD_STATIC_DESTRUCT) + return; + + d = ALIGN_TO_PTR(__start_SYSTEMD_STATIC_DESTRUCT, __BIGGEST_ALIGNMENT__); + while (d < __stop_SYSTEMD_STATIC_DESTRUCT) { + d->destroy(d->data); + d = ALIGN_TO_PTR(d + 1, __BIGGEST_ALIGNMENT__); + } +} diff --git a/src/basic/unaligned.h b/src/basic/unaligned.h index e62188d1a7..00c17f8769 100644 --- a/src/basic/unaligned.h +++ b/src/basic/unaligned.h @@ -7,37 +7,37 @@ /* BE */ static inline uint16_t unaligned_read_be16(const void *_u) { - const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u; + const struct __attribute__((__packed__, __may_alias__)) { uint16_t x; } *u = _u; return be16toh(u->x); } static inline uint32_t unaligned_read_be32(const void *_u) { - const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u; + const struct __attribute__((__packed__, __may_alias__)) { uint32_t x; } *u = _u; return be32toh(u->x); } static inline uint64_t unaligned_read_be64(const void *_u) { - const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u; + const struct __attribute__((__packed__, __may_alias__)) { uint64_t x; } *u = _u; return be64toh(u->x); } static inline void unaligned_write_be16(void *_u, uint16_t a) { - struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u; + struct __attribute__((__packed__, __may_alias__)) { uint16_t x; } *u = _u; u->x = be16toh(a); } static inline void unaligned_write_be32(void *_u, uint32_t a) { - struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u; + struct __attribute__((__packed__, __may_alias__)) { uint32_t x; } *u = _u; u->x = be32toh(a); } static inline void unaligned_write_be64(void *_u, uint64_t a) { - struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u; + struct __attribute__((__packed__, __may_alias__)) { uint64_t x; } *u = _u; u->x = be64toh(a); } @@ -45,37 +45,37 @@ static inline void unaligned_write_be64(void *_u, uint64_t a) { /* LE */ static inline uint16_t unaligned_read_le16(const void *_u) { - const struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u; + const struct __attribute__((__packed__, __may_alias__)) { uint16_t x; } *u = _u; return le16toh(u->x); } static inline uint32_t unaligned_read_le32(const void *_u) { - const struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u; + const struct __attribute__((__packed__, __may_alias__)) { uint32_t x; } *u = _u; return le32toh(u->x); } static inline uint64_t unaligned_read_le64(const void *_u) { - const struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u; + const struct __attribute__((__packed__, __may_alias__)) { uint64_t x; } *u = _u; return le64toh(u->x); } static inline void unaligned_write_le16(void *_u, uint16_t a) { - struct __attribute__((packed, may_alias)) { uint16_t x; } *u = _u; + struct __attribute__((__packed__, __may_alias__)) { uint16_t x; } *u = _u; u->x = le16toh(a); } static inline void unaligned_write_le32(void *_u, uint32_t a) { - struct __attribute__((packed, may_alias)) { uint32_t x; } *u = _u; + struct __attribute__((__packed__, __may_alias__)) { uint32_t x; } *u = _u; u->x = le32toh(a); } static inline void unaligned_write_le64(void *_u, uint64_t a) { - struct __attribute__((packed, may_alias)) { uint64_t x; } *u = _u; + struct __attribute__((__packed__, __may_alias__)) { uint64_t x; } *u = _u; u->x = le64toh(a); } diff --git a/src/basic/util.h b/src/basic/util.h index fd180cb787..2f3d1eeab8 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -172,7 +172,8 @@ static inline void _reset_errno_(int *saved_errno) { errno = *saved_errno; } -#define PROTECT_ERRNO _cleanup_(_reset_errno_) __attribute__((unused)) int _saved_errno_ = errno +#define PROTECT_ERRNO \ + _cleanup_(_reset_errno_) __attribute__((__unused__)) int _saved_errno_ = errno static inline int negative_errno(void) { /* This helper should be used to shut up gcc if you know 'errno' is diff --git a/src/boot/bless-boot.c b/src/boot/bless-boot.c index 84ac9e39e4..2455f3703f 100644 --- a/src/boot/bless-boot.c +++ b/src/boot/bless-boot.c @@ -9,6 +9,7 @@ #include "fd-util.h" #include "fs-util.h" #include "log.h" +#include "main-func.h" #include "parse-util.h" #include "path-util.h" #include "util.h" diff --git a/src/boot/boot-check-no-failures.c b/src/boot/boot-check-no-failures.c index 1674517d48..3284a04793 100644 --- a/src/boot/boot-check-no-failures.c +++ b/src/boot/boot-check-no-failures.c @@ -10,6 +10,7 @@ #include "alloc-util.h" #include "bus-error.h" #include "log.h" +#include "main-func.h" #include "util.h" static int help(void) { diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index f7e0e49c06..4ba7050a91 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -41,7 +41,7 @@ static inline void FreePoolp(void *p) { FreePool(q); } -#define _cleanup_(x) __attribute__((cleanup(x))) +#define _cleanup_(x) __attribute__((__cleanup__(x))) #define _cleanup_freepool_ _cleanup_(FreePoolp) static inline void FileHandleClosep(EFI_FILE_HANDLE *handle) { diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 2cc869dcbd..cad274a633 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -19,6 +19,7 @@ #include "fd-util.h" #include "fileio.h" #include "hashmap.h" +#include "main-func.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" diff --git a/src/core/main.c b/src/core/main.c index f1dad983b7..70227da4b7 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -767,8 +767,10 @@ static void set_manager_defaults(Manager *m) { m->default_tasks_accounting = arg_default_tasks_accounting; m->default_tasks_max = arg_default_tasks_max; - manager_set_default_rlimits(m, arg_default_rlimit); - manager_transient_environment_add(m, arg_default_environment); + (void) manager_set_default_rlimits(m, arg_default_rlimit); + + (void) manager_default_environment(m); + (void) manager_transient_environment_add(m, arg_default_environment); } static void set_manager_settings(Manager *m) { diff --git a/src/core/manager.c b/src/core/manager.c index 14be38600d..f4fdd91c2c 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -600,7 +600,7 @@ static char** sanitize_environment(char **l) { return l; } -static int manager_default_environment(Manager *m) { +int manager_default_environment(Manager *m) { assert(m); m->transient_environment = strv_free(m->transient_environment); @@ -623,7 +623,7 @@ static int manager_default_environment(Manager *m) { m->transient_environment = strv_copy(environ); if (!m->transient_environment) - return -ENOMEM; + return log_oom(); sanitize_environment(m->transient_environment); @@ -3875,7 +3875,7 @@ int manager_transient_environment_add(Manager *m, char **plus) { a = strv_env_merge(2, m->transient_environment, plus); if (!a) - return -ENOMEM; + return log_oom(); sanitize_environment(a); diff --git a/src/core/manager.h b/src/core/manager.h index b65c4c8451..f3ad44d26e 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -442,6 +442,7 @@ void manager_clear_jobs(Manager *m); unsigned manager_dispatch_load_queue(Manager *m); +int manager_default_environment(Manager *m); int manager_transient_environment_add(Manager *m, char **plus); int manager_client_environment_modify(Manager *m, char **minus, char **plus); int manager_get_effective_environment(Manager *m, char ***ret); diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 764ee2a945..46536b7c84 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -34,6 +34,7 @@ #include "journal-importer.h" #include "log.h" #include "macro.h" +#include "main-func.h" #include "missing.h" #include "mkdir.h" #include "parse-util.h" diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index a9497fe587..73a8d35271 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include "alloc-util.h" +#include "main-func.h" #include "mkdir.h" #include "parse-util.h" #include "proc-cmdline.h" @@ -16,6 +17,10 @@ static char **arg_mask = NULL; static char **arg_wants = NULL; static bool arg_debug_shell = false; +STATIC_DESTRUCTOR_REGISTER(arg_default_unit, freep); +STATIC_DESTRUCTOR_REGISTER(arg_mask, strv_freep); +STATIC_DESTRUCTOR_REGISTER(arg_wants, strv_freep); + static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { int r; @@ -136,12 +141,12 @@ static int generate_wants_symlinks(void) { return r; } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { int r, q; if (argc > 1 && argc != 4) { log_error("This program takes three or no arguments."); - return EXIT_FAILURE; + return -EINVAL; } if (argc > 1) @@ -160,22 +165,14 @@ int main(int argc, char *argv[]) { if (arg_debug_shell) { r = strv_extend(&arg_wants, "debug-shell.service"); - if (r < 0) { - r = log_oom(); - goto finish; - } + if (r < 0) + return log_oom(); } r = generate_mask_symlinks(); - q = generate_wants_symlinks(); - if (q < 0) - r = q; - -finish: - arg_default_unit = mfree(arg_default_unit); - strv_free(arg_wants); - strv_free(arg_mask); - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return r < 0 ? r : q; } + +DEFINE_MAIN_FUNCTION(run); diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c index d1a2ab95a0..f1259fdcd5 100644 --- a/src/detect-virt/detect-virt.c +++ b/src/detect-virt/detect-virt.c @@ -6,6 +6,7 @@ #include <stdlib.h> #include "alloc-util.h" +#include "main-func.h" #include "string-table.h" #include "terminal-util.h" #include "util.h" diff --git a/src/escape/escape.c b/src/escape/escape.c index ed42ad65ad..b03c9e661d 100644 --- a/src/escape/escape.c +++ b/src/escape/escape.c @@ -6,6 +6,7 @@ #include "alloc-util.h" #include "log.h" +#include "main-func.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 54d6d26fb5..821ad15c5f 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -22,6 +22,7 @@ #include "device-util.h" #include "fd-util.h" #include "fs-util.h" +#include "main-func.h" #include "parse-util.h" #include "path-util.h" #include "proc-cmdline.h" diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 8220741efa..0d40d17a55 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -14,6 +14,7 @@ #include "bus-error.h" #include "bus-util.h" #include "hostname-util.h" +#include "main-func.h" #include "spawn-polkit-agent.h" #include "terminal-util.h" #include "util.h" diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c index 87b84b70a9..89e3138542 100644 --- a/src/hwdb/hwdb.c +++ b/src/hwdb/hwdb.c @@ -6,6 +6,7 @@ #include "alloc-util.h" #include "hwdb-util.h" +#include "main-func.h" #include "selinux-util.h" #include "terminal-util.h" #include "util.h" diff --git a/src/id128/id128.c b/src/id128/id128.c index 6b7045b3e7..cbd7464d2c 100644 --- a/src/id128/id128.c +++ b/src/id128/id128.c @@ -5,6 +5,7 @@ #include "alloc-util.h" #include "id128-print.h" +#include "main-func.h" #include "terminal-util.h" #include "util.h" #include "verbs.h" diff --git a/src/import/export.c b/src/import/export.c index 317ac1bba7..e07aa5d6d5 100644 --- a/src/import/export.c +++ b/src/import/export.c @@ -13,6 +13,7 @@ #include "hostname-util.h" #include "import-util.h" #include "machine-image.h" +#include "main-func.h" #include "signal-util.h" #include "string-util.h" #include "verbs.h" diff --git a/src/import/import.c b/src/import/import.c index 69fe8a8a37..9dca2f3d41 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -13,6 +13,7 @@ #include "import-tar.h" #include "import-util.h" #include "machine-image.h" +#include "main-func.h" #include "signal-util.h" #include "string-util.h" #include "verbs.h" diff --git a/src/import/importd.c b/src/import/importd.c index b5265a7ed3..f17cdf10d4 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -13,6 +13,7 @@ #include "hostname-util.h" #include "import-util.h" #include "machine-pool.h" +#include "main-func.h" #include "missing.h" #include "mkdir.h" #include "parse-util.h" diff --git a/src/import/pull.c b/src/import/pull.c index 821c9772e4..810cab53ba 100644 --- a/src/import/pull.c +++ b/src/import/pull.c @@ -9,6 +9,7 @@ #include "hostname-util.h" #include "import-util.h" #include "machine-image.h" +#include "main-func.h" #include "parse-util.h" #include "pull-raw.h" #include "pull-tar.h" diff --git a/src/journal/cat.c b/src/journal/cat.c index 1576199deb..3198d3261b 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -11,11 +11,12 @@ #include "alloc-util.h" #include "fd-util.h" +#include "main-func.h" #include "parse-util.h" #include "string-util.h" #include "syslog-util.h" -#include "util.h" #include "terminal-util.h" +#include "util.h" static const char *arg_identifier = NULL; static int arg_priority = LOG_INFO; diff --git a/src/libsystemd/sd-bus/bus-error.h b/src/libsystemd/sd-bus/bus-error.h index 06c478a362..e8e743c0d7 100644 --- a/src/libsystemd/sd-bus/bus-error.h +++ b/src/libsystemd/sd-bus/bus-error.h @@ -33,11 +33,12 @@ int bus_error_set_errnofv(sd_bus_error *e, int error, const char *format, va_lis #define BUS_ERROR_MAP_ELF_REGISTER \ __attribute__ ((__section__("BUS_ERROR_MAP"))) \ __attribute__ ((__used__)) \ - __attribute__ ((aligned(8))) + __attribute__ ((__aligned__(8))) #define BUS_ERROR_MAP_ELF_USE(errors) \ extern const sd_bus_error_map errors[]; \ - __attribute__ ((used)) static const sd_bus_error_map * const CONCATENATE(errors ## _copy_, __COUNTER__) = errors; + __attribute__ ((__used__)) \ + static const sd_bus_error_map * const CONCATENATE(errors ## _copy_, __COUNTER__) = errors; /* We use something exotic as end marker, to ensure people build the * maps using the macsd-ros. */ diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index 8f2d4b09ac..3e3d0591dd 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -24,9 +24,9 @@ struct udev *udev_new(void); void udev_set_log_fn(struct udev *udev, void (*log_fn)(struct udev *udev, int priority, const char *file, int line, const char *fn, - const char *format, va_list args)) __attribute__ ((deprecated)); -int udev_get_log_priority(struct udev *udev) __attribute__ ((deprecated)); -void udev_set_log_priority(struct udev *udev, int priority) __attribute__ ((deprecated)); + const char *format, va_list args)) __attribute__((__deprecated__)); +int udev_get_log_priority(struct udev *udev) __attribute__((__deprecated__)); +void udev_set_log_priority(struct udev *udev, int priority) __attribute__((__deprecated__)); void *udev_get_userdata(struct udev *udev); void udev_set_userdata(struct udev *udev, void *userdata); @@ -153,16 +153,16 @@ struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue); struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue); struct udev *udev_queue_get_udev(struct udev_queue *udev_queue); struct udev_queue *udev_queue_new(struct udev *udev); -unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__ ((deprecated)); -unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__ ((deprecated)); +unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__)); + unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__)); int udev_queue_get_udev_is_active(struct udev_queue *udev_queue); int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue); -int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__ ((deprecated)); +int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__((__deprecated__)); int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue, - unsigned long long int start, unsigned long long int end) __attribute__ ((deprecated)); + unsigned long long int start, unsigned long long int end) __attribute__((__deprecated__)); int udev_queue_get_fd(struct udev_queue *udev_queue); int udev_queue_flush(struct udev_queue *udev_queue); -struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__ ((deprecated)); +struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__((__deprecated__)); /* * udev_hwdb diff --git a/src/login/inhibit.c b/src/login/inhibit.c index ca24aea5a7..508c539044 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -14,6 +14,7 @@ #include "fd-util.h" #include "format-table.h" #include "format-util.h" +#include "main-func.h" #include "pager.h" #include "process-util.h" #include "signal-util.h" diff --git a/src/login/logind.c b/src/login/logind.c index e71ac0ee6d..5f2243a15d 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -19,6 +19,7 @@ #include "format-util.h" #include "fs-util.h" #include "logind.h" +#include "main-func.h" #include "parse-util.h" #include "process-util.h" #include "selinux-util.h" diff --git a/src/login/user-runtime-dir.c b/src/login/user-runtime-dir.c index b3a6e5c740..8a1110491a 100644 --- a/src/login/user-runtime-dir.c +++ b/src/login/user-runtime-dir.c @@ -8,6 +8,7 @@ #include "bus-error.h" #include "fs-util.h" #include "label.h" +#include "main-func.h" #include "mkdir.h" #include "mount-util.h" #include "path-util.h" diff --git a/src/machine/machined.c b/src/machine/machined.c index 24850af5bc..a2e7a30240 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -17,6 +17,7 @@ #include "label.h" #include "machine-image.h" #include "machined.h" +#include "main-func.h" #include "process-util.h" #include "signal-util.h" #include "special.h" diff --git a/src/notify/notify.c b/src/notify/notify.c index 149cd0d050..fdf4598941 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -12,6 +12,7 @@ #include "env-util.h" #include "format-util.h" #include "log.h" +#include "main-func.h" #include "parse-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/partition/makefs.c b/src/partition/makefs.c index dcc69c6a20..b2702d20f7 100644 --- a/src/partition/makefs.c +++ b/src/partition/makefs.c @@ -11,6 +11,7 @@ #include "alloc-util.h" #include "dissect-image.h" +#include "main-func.h" #include "process-util.h" #include "signal-util.h" #include "string-util.h" diff --git a/src/path/path.c b/src/path/path.c index 1b7e0c547a..4a2e2ca3f6 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -10,6 +10,7 @@ #include "alloc-util.h" #include "log.h" #include "macro.h" +#include "main-func.h" #include "string-util.h" #include "terminal-util.h" #include "util.h" diff --git a/src/portable/portabled.c b/src/portable/portabled.c index a853257bc0..313211a792 100644 --- a/src/portable/portabled.c +++ b/src/portable/portabled.c @@ -6,6 +6,7 @@ #include "alloc-util.h" #include "bus-util.h" #include "def.h" +#include "main-func.h" #include "portabled-bus.h" #include "portabled-image-bus.h" #include "portabled.h" diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index e3c50c366a..7b11f29507 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -6,6 +6,7 @@ #include <sys/prctl.h> #include <unistd.h> +#include "main-func.h" #include "proc-cmdline.h" #include "process-util.h" #include "signal-util.h" diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c index f5a7eca93c..6162f8d6bf 100644 --- a/src/random-seed/random-seed.c +++ b/src/random-seed/random-seed.c @@ -12,6 +12,7 @@ #include "fd-util.h" #include "io-util.h" #include "log.h" +#include "main-func.h" #include "mkdir.h" #include "string-util.h" #include "util.h" diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c index 9a0c39e16f..ece7f2955d 100644 --- a/src/remount-fs/remount-fs.c +++ b/src/remount-fs/remount-fs.c @@ -10,6 +10,7 @@ #include "exit-status.h" #include "log.h" +#include "main-func.h" #include "mount-setup.h" #include "mount-util.h" #include "path-util.h" diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index df15b660ec..9ba6978962 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -16,6 +16,7 @@ #include "fd-util.h" #include "fileio.h" #include "parse-util.h" +#include "path-util.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" @@ -590,6 +591,18 @@ int find_esp_and_warn( goto found; } + path = getenv("SYSTEMD_ESP_PATH"); + if (path) { + if (!path_is_valid(path) || !path_is_absolute(path)) { + log_error("$SYSTEMD_ESP_PATH does not refer to absolute path, refusing to use it: %s", path); + return -EINVAL; + } + + /* Note: when the user explicitly configured things with an env var we won't validate the mount + * point. After all we want this to be useful for testing. */ + goto found; + } + FOREACH_STRING(path, "/efi", "/boot", "/boot/efi") { r = verify_esp(path, true, unprivileged_mode, ret_part, ret_pstart, ret_psize, ret_uuid); diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 6010611366..f1f4da8886 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -16,6 +16,7 @@ #include "fd-util.h" #include "fileio.h" #include "log.h" +#include "main-func.h" #include "parse-util.h" #include "sleep-config.h" #include "stdio-util.h" diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c index 9efd6c216f..9ceb3f8d13 100644 --- a/src/stdio-bridge/stdio-bridge.c +++ b/src/stdio-bridge/stdio-bridge.c @@ -11,10 +11,11 @@ #include "sd-daemon.h" #include "alloc-util.h" +#include "build.h" #include "bus-internal.h" #include "bus-util.h" -#include "build.h" #include "log.h" +#include "main-func.h" #include "util.h" #define DEFAULT_BUS_PATH "unix:path=/run/dbus/system_bus_socket" diff --git a/src/systemd/_sd-common.h b/src/systemd/_sd-common.h index 4742b2e742..b026b5c551 100644 --- a/src/systemd/_sd-common.h +++ b/src/systemd/_sd-common.h @@ -25,22 +25,22 @@ #ifndef _sd_printf_ # if __GNUC__ >= 4 -# define _sd_printf_(a,b) __attribute__ ((format (printf, a, b))) +# define _sd_printf_(a,b) __attribute__ ((__format__(printf, a, b))) # else # define _sd_printf_(a,b) # endif #endif #ifndef _sd_sentinel_ -# define _sd_sentinel_ __attribute__((sentinel)) +# define _sd_sentinel_ __attribute__((__sentinel__)) #endif #ifndef _sd_packed_ -# define _sd_packed_ __attribute__((packed)) +# define _sd_packed_ __attribute__((__packed__)) #endif #ifndef _sd_pure_ -# define _sd_pure_ __attribute__((pure)) +# define _sd_pure_ __attribute__((__pure__)) #endif #ifndef _SD_STRINGIFY diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 255adeaa19..c92d7f841a 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -14,6 +14,7 @@ #include "hexdecoct.h" #include "install.h" #include "log.h" +#include "main-func.h" #include "mkdir.h" #include "path-lookup.h" #include "path-util.h" diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 0e378f68c0..0f66df66c7 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -54,7 +54,7 @@ static void check(Manager *m, Unit *unit, int status_expected, int code_expected n = now(CLOCK_MONOTONIC); if (ts + timeout < n) { log_error("Test timeout when testing %s", unit->id); - r = UNIT_VTABLE(unit)->kill(unit, KILL_ALL, 9, NULL); + r = unit_kill(unit, KILL_ALL, SIGKILL, NULL); if (r < 0) log_error_errno(r, "Failed to kill %s: %m", unit->id); exit(EXIT_FAILURE); @@ -153,7 +153,7 @@ static void test(Manager *m, const char *unit_name, int status_expected, int cod assert_se(unit_name); assert_se(manager_load_startable_unit_or_warn(m, unit_name, NULL, &unit) >= 0); - assert_se(UNIT_VTABLE(unit)->start(unit) >= 0); + assert_se(unit_start(unit) >= 0); check(m, unit, status_expected, code_expected); } diff --git a/src/test/test-path.c b/src/test/test-path.c index 0b5537b364..edc0479522 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -103,7 +103,7 @@ static void check_stop_unlink(Manager *m, Unit *unit, const char *test_path, con } } - assert_se(UNIT_VTABLE(unit)->stop(unit) >= 0); + assert_se(unit_stop(unit) >= 0); (void) rm_rf(test_path, REMOVE_ROOT|REMOVE_PHYSICAL); } @@ -114,7 +114,7 @@ static void test_path_exists(Manager *m) { assert_se(m); assert_se(manager_load_startable_unit_or_warn(m, "path-exists.path", NULL, &unit) >= 0); - assert_se(UNIT_VTABLE(unit)->start(unit) >= 0); + assert_se(unit_start(unit) >= 0); assert_se(touch(test_path) >= 0); @@ -127,7 +127,7 @@ static void test_path_existsglob(Manager *m) { assert_se(m); assert_se(manager_load_startable_unit_or_warn(m, "path-existsglob.path", NULL, &unit) >= 0); - assert_se(UNIT_VTABLE(unit)->start(unit) >= 0); + assert_se(unit_start(unit) >= 0); assert_se(touch(test_path) >= 0); @@ -144,7 +144,7 @@ static void test_path_changed(Manager *m) { assert_se(touch(test_path) >= 0); assert_se(manager_load_startable_unit_or_warn(m, "path-changed.path", NULL, &unit) >= 0); - assert_se(UNIT_VTABLE(unit)->start(unit) >= 0); + assert_se(unit_start(unit) >= 0); f = fopen(test_path, "w"); assert_se(f); @@ -163,7 +163,7 @@ static void test_path_modified(Manager *m) { assert_se(touch(test_path) >= 0); assert_se(manager_load_startable_unit_or_warn(m, "path-modified.path", NULL, &unit) >= 0); - assert_se(UNIT_VTABLE(unit)->start(unit) >= 0); + assert_se(unit_start(unit) >= 0); f = fopen(test_path, "w"); assert_se(f); @@ -179,7 +179,7 @@ static void test_path_unit(Manager *m) { assert_se(m); assert_se(manager_load_startable_unit_or_warn(m, "path-unit.path", NULL, &unit) >= 0); - assert_se(UNIT_VTABLE(unit)->start(unit) >= 0); + assert_se(unit_start(unit) >= 0); assert_se(touch(test_path) >= 0); @@ -195,7 +195,7 @@ static void test_path_directorynotempty(Manager *m) { assert_se(access(test_path, F_OK) < 0); assert_se(manager_load_startable_unit_or_warn(m, "path-directorynotempty.path", NULL, &unit) >= 0); - assert_se(UNIT_VTABLE(unit)->start(unit) >= 0); + assert_se(unit_start(unit) >= 0); /* MakeDirectory default to no */ assert_se(access(test_path, F_OK) < 0); @@ -216,7 +216,7 @@ static void test_path_makedirectory_directorymode(Manager *m) { assert_se(access(test_path, F_OK) < 0); assert_se(manager_load_startable_unit_or_warn(m, "path-makedirectory.path", NULL, &unit) >= 0); - assert_se(UNIT_VTABLE(unit)->start(unit) >= 0); + assert_se(unit_start(unit) >= 0); /* Check if the directory has been created */ assert_se(access(test_path, F_OK) >= 0); @@ -227,7 +227,7 @@ static void test_path_makedirectory_directorymode(Manager *m) { assert_se((s.st_mode & S_IRWXG) == 0040); assert_se((s.st_mode & S_IRWXO) == 0004); - assert_se(UNIT_VTABLE(unit)->stop(unit) >= 0); + assert_se(unit_stop(unit) >= 0); (void) rm_rf(test_path, REMOVE_ROOT|REMOVE_PHYSICAL); } 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 1c965217d9..609839c5a1 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -30,6 +30,7 @@ #include "hashmap.h" #include "io-util.h" #include "macro.h" +#include "main-func.h" #include "mkdir.h" #include "path-util.h" #include "process-util.h" diff --git a/src/volatile-root/volatile-root.c b/src/volatile-root/volatile-root.c index ab7dca37b1..b08d42834f 100644 --- a/src/volatile-root/volatile-root.c +++ b/src/volatile-root/volatile-root.c @@ -4,12 +4,13 @@ #include "alloc-util.h" #include "fs-util.h" +#include "main-func.h" #include "mkdir.h" #include "mount-util.h" +#include "path-util.h" #include "stat-util.h" -#include "volatile-util.h" #include "string-util.h" -#include "path-util.h" +#include "volatile-util.h" static int make_volatile(const char *path) { _cleanup_free_ char *old_usr = NULL; |