diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/cgroup-util.h | 2 | ||||
-rw-r--r-- | src/basic/env-util.c | 19 | ||||
-rw-r--r-- | src/basic/env-util.h | 2 | ||||
-rw-r--r-- | src/basic/macro.h | 74 | ||||
-rw-r--r-- | src/basic/missing_syscall.h | 4 | ||||
-rw-r--r-- | src/basic/os-util.h | 2 | ||||
-rw-r--r-- | src/basic/process-util.c | 46 | ||||
-rw-r--r-- | src/basic/process-util.h | 2 |
8 files changed, 77 insertions, 74 deletions
diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index 04370b01ec..a64bdcf7a9 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -36,7 +36,7 @@ typedef enum CGroupController { CGROUP_CONTROLLER_BPF_SOCKET_BIND, CGROUP_CONTROLLER_BPF_RESTRICT_NETWORK_INTERFACES, /* The BPF hook implementing RestrictFileSystems= is not defined here. - * It's applied as late as possible in exec_child() so we don't block + * It's applied as late as possible in exec_invoke() so we don't block * our own unit setup code. */ _CGROUP_CONTROLLER_MAX, diff --git a/src/basic/env-util.c b/src/basic/env-util.c index 44772f778d..d3bf73385f 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -1074,3 +1074,22 @@ int getenv_steal_erase(const char *name, char **ret) { return 1; } + +int set_full_environment(char **env) { + int r; + + clearenv(); + + STRV_FOREACH(e, env) { + _cleanup_free_ char *k = NULL, *v = NULL; + + r = split_pair(*e, "=", &k, &v); + if (r < 0) + return r; + + if (setenv(k, v, /* overwrite= */ true) < 0) + return -errno; + } + + return 0; +} diff --git a/src/basic/env-util.h b/src/basic/env-util.h index ec3ac199ef..f7fb1e9082 100644 --- a/src/basic/env-util.h +++ b/src/basic/env-util.h @@ -77,3 +77,5 @@ int setenv_systemd_exec_pid(bool update_only); int getenv_path_list(const char *name, char ***ret_paths); int getenv_steal_erase(const char *name, char **ret); + +int set_full_environment(char **env); diff --git a/src/basic/macro.h b/src/basic/macro.h index 7f650d0719..dcd1ca96fd 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -30,31 +30,6 @@ #define _function_no_sanitize_float_cast_overflow_ #endif -/* Temporarily disable some warnings */ -#define DISABLE_WARNING_DEPRECATED_DECLARATIONS \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") - -#define DISABLE_WARNING_FORMAT_NONLITERAL \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") - -#define DISABLE_WARNING_MISSING_PROTOTYPES \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wmissing-prototypes\"") - -#define DISABLE_WARNING_NONNULL \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wnonnull\"") - -#define DISABLE_WARNING_SHADOW \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wshadow\"") - -#define DISABLE_WARNING_INCOMPATIBLE_POINTER_TYPES \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wincompatible-pointer-types\"") - #if HAVE_WSTRINGOP_TRUNCATION # define DISABLE_WARNING_STRINGOP_TRUNCATION \ _Pragma("GCC diagnostic push"); \ @@ -64,18 +39,7 @@ _Pragma("GCC diagnostic push") #endif -#define DISABLE_WARNING_TYPE_LIMITS \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Wtype-limits\"") - -#define DISABLE_WARNING_ADDRESS \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Waddress\"") - -#define REENABLE_WARNING \ - _Pragma("GCC diagnostic pop") - -/* automake test harness */ +/* test harness */ #define EXIT_TEST_SKIP 77 /* builtins */ @@ -310,42 +274,6 @@ static inline int __coverity_check_and_return__(int condition) { #define FOREACH_ARRAY(i, array, num) \ _FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(end, UNIQ)) -/* A wrapper for 'func' to return void. - * Only useful when a void-returning function is required by some API. */ -#define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func) \ - static inline void name(type *p) { \ - func(p); \ - } - -/* When func() returns the void value (NULL, -1, …) of the appropriate type */ -#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \ - static inline void func##p(type *p) { \ - if (*p) \ - *p = func(*p); \ - } - -/* When func() doesn't return the appropriate type, set variable to empty afterwards. - * The func() may be provided by a dynamically loaded shared library, hence add an assertion. */ -#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(type, func, empty) \ - static inline void func##p(type *p) { \ - if (*p != (empty)) { \ - DISABLE_WARNING_ADDRESS; \ - assert(func); \ - REENABLE_WARNING; \ - func(*p); \ - *p = (empty); \ - } \ - } - -/* When func() doesn't return the appropriate type, and is also a macro, set variable to empty afterwards. */ -#define DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO(type, func, empty) \ - static inline void func##p(type *p) { \ - if (*p != (empty)) { \ - func(*p); \ - *p = (empty); \ - } \ - } - #define _DEFINE_TRIVIAL_REF_FUNC(type, name, scope) \ scope type *name##_ref(type *p) { \ if (!p) \ diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index ddee457f44..83ec137fa5 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -539,6 +539,10 @@ static inline int missing_open_tree( /* ======================================================================= */ +#ifndef MOVE_MOUNT_BENEATH +#define MOVE_MOUNT_BENEATH 0x00000200 +#endif + #if !HAVE_MOVE_MOUNT #ifndef MOVE_MOUNT_F_EMPTY_PATH diff --git a/src/basic/os-util.h b/src/basic/os-util.h index 11afc4c6ca..7cee3dd119 100644 --- a/src/basic/os-util.h +++ b/src/basic/os-util.h @@ -10,7 +10,9 @@ typedef enum ImageClass { IMAGE_MACHINE, IMAGE_PORTABLE, IMAGE_SYSEXT, + _IMAGE_CLASS_EXTENSION_FIRST = IMAGE_SYSEXT, /* First "extension" image type, so that we can easily generically iterate through them */ IMAGE_CONFEXT, + _IMAGE_CLASS_EXTENSION_LAST = IMAGE_CONFEXT, /* Last "extension image type */ _IMAGE_CLASS_MAX, _IMAGE_CLASS_INVALID = -EINVAL, } ImageClass; diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 7cebbe1cc1..ed096900ac 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -5,6 +5,7 @@ #include <limits.h> #include <linux/oom.h> #include <pthread.h> +#include <spawn.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -1759,6 +1760,51 @@ int make_reaper_process(bool b) { return 0; } +int posix_spawn_wrapper(const char *path, char *const *argv, char *const *envp, pid_t *ret_pid) { + posix_spawnattr_t attr; + sigset_t mask; + pid_t pid; + int r; + + /* Forks and invokes 'path' with 'argv' and 'envp' using CLONE_VM and CLONE_VFORK, which means the + * caller will be blocked until the child either exits or exec's. The memory of the child will be + * fully shared with the memory of the parent, so that there are no copy-on-write or memory.max + * issues. */ + + assert(path); + assert(argv); + assert(ret_pid); + + assert_se(sigfillset(&mask) >= 0); + + r = posix_spawnattr_init(&attr); + if (r != 0) + return -r; /* These functions return a positive errno on failure */ + r = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK); + if (r != 0) + goto fail; + r = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF); /* Set all signals to SIG_DFL */ + if (r != 0) + goto fail; + r = posix_spawnattr_setsigmask(&attr, &mask); + if (r != 0) + goto fail; + + r = posix_spawn(&pid, path, NULL, &attr, argv, envp); + if (r != 0) + goto fail; + + *ret_pid = pid; + + posix_spawnattr_destroy(&attr); + return 0; + +fail: + assert(r > 0); + posix_spawnattr_destroy(&attr); + return -r; +} + static const char *const sigchld_code_table[] = { [CLD_EXITED] = "exited", [CLD_KILLED] = "killed", diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 7acc102f40..7dfa510b93 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -213,3 +213,5 @@ int get_process_threads(pid_t pid); int is_reaper_process(void); int make_reaper_process(bool b); + +int posix_spawn_wrapper(const char *path, char *const *argv, char *const *envp, pid_t *ret_pid); |