mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
basic: add RuntimeScope enum
In various tools and services we have a per-system and per-user concept. So far we sometimes used a boolean indicating whether we are in system mode, or a reversed boolean indicating whether we are in user mode, or the LookupScope enum used by the lookup path logic. Let's address that, in introduce a common enum for this, we can use all across the board. This is mostly just search/replace, no actual code changes.
This commit is contained in:
@@ -72,7 +72,7 @@ static int log_helper(void *userdata, int level, int error, const char *file, in
|
||||
return r;
|
||||
}
|
||||
|
||||
static int verify_conditions(char **lines, LookupScope scope, const char *unit, const char *root) {
|
||||
static int verify_conditions(char **lines, RuntimeScope scope, const char *unit, const char *root) {
|
||||
_cleanup_(manager_freep) Manager *m = NULL;
|
||||
Unit *u;
|
||||
int r, q = 1;
|
||||
@@ -137,7 +137,7 @@ static int verify_conditions(char **lines, LookupScope scope, const char *unit,
|
||||
int verb_condition(int argc, char *argv[], void *userdata) {
|
||||
int r;
|
||||
|
||||
r = verify_conditions(strv_skip(argv, 1), arg_scope, arg_unit, arg_root);
|
||||
r = verify_conditions(strv_skip(argv, 1), arg_runtime_scope, arg_unit, arg_root);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ static int acquire_host_info(sd_bus *bus, HostInfo **hi) {
|
||||
if (!host)
|
||||
return log_oom();
|
||||
|
||||
if (arg_scope != LOOKUP_SCOPE_SYSTEM) {
|
||||
r = bus_connect_transport(arg_transport, arg_host, false, &system_bus);
|
||||
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM) {
|
||||
r = bus_connect_transport(arg_transport, arg_host, RUNTIME_SCOPE_SYSTEM, &system_bus);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to connect to system bus, ignoring: %m");
|
||||
goto manager;
|
||||
@@ -431,7 +431,7 @@ int verb_plot(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||
_cleanup_(unit_times_free_arrayp) UnitTimes *times = NULL;
|
||||
_cleanup_free_ char *pretty_times = NULL;
|
||||
bool use_full_bus = arg_scope == LOOKUP_SCOPE_SYSTEM;
|
||||
bool use_full_bus = arg_runtime_scope == RUNTIME_SCOPE_SYSTEM;
|
||||
BootTimes *boot;
|
||||
int n, r;
|
||||
|
||||
@@ -447,7 +447,7 @@ int verb_plot(int argc, char *argv[], void *userdata) {
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
||||
if (use_full_bus || arg_scope != LOOKUP_SCOPE_SYSTEM) {
|
||||
if (use_full_bus || arg_runtime_scope != RUNTIME_SCOPE_SYSTEM) {
|
||||
n = acquire_host_info(bus, &host);
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
||||
@@ -2665,16 +2665,17 @@ static int offline_security_check(Unit *u,
|
||||
return assess(info, overview_table, flags, threshold, policy, pager_flags, json_format_flags);
|
||||
}
|
||||
|
||||
static int offline_security_checks(char **filenames,
|
||||
JsonVariant *policy,
|
||||
LookupScope scope,
|
||||
bool check_man,
|
||||
bool run_generators,
|
||||
unsigned threshold,
|
||||
const char *root,
|
||||
const char *profile,
|
||||
PagerFlags pager_flags,
|
||||
JsonFormatFlags json_format_flags) {
|
||||
static int offline_security_checks(
|
||||
char **filenames,
|
||||
JsonVariant *policy,
|
||||
RuntimeScope scope,
|
||||
bool check_man,
|
||||
bool run_generators,
|
||||
unsigned threshold,
|
||||
const char *root,
|
||||
const char *profile,
|
||||
PagerFlags pager_flags,
|
||||
JsonFormatFlags json_format_flags) {
|
||||
|
||||
const ManagerTestRunFlags flags =
|
||||
MANAGER_TEST_RUN_MINIMAL |
|
||||
@@ -2779,7 +2780,7 @@ static int offline_security_checks(char **filenames,
|
||||
static int analyze_security(sd_bus *bus,
|
||||
char **units,
|
||||
JsonVariant *policy,
|
||||
LookupScope scope,
|
||||
RuntimeScope scope,
|
||||
bool check_man,
|
||||
bool run_generators,
|
||||
bool offline,
|
||||
@@ -2937,17 +2938,18 @@ int verb_security(int argc, char *argv[], void *userdata) {
|
||||
}
|
||||
}
|
||||
|
||||
return analyze_security(bus,
|
||||
strv_skip(argv, 1),
|
||||
policy,
|
||||
arg_scope,
|
||||
arg_man,
|
||||
arg_generators,
|
||||
arg_offline,
|
||||
arg_threshold,
|
||||
arg_root,
|
||||
arg_profile,
|
||||
arg_json_format_flags,
|
||||
arg_pager_flags,
|
||||
/*flags=*/ 0);
|
||||
return analyze_security(
|
||||
bus,
|
||||
strv_skip(argv, 1),
|
||||
policy,
|
||||
arg_runtime_scope,
|
||||
arg_man,
|
||||
arg_generators,
|
||||
arg_offline,
|
||||
arg_threshold,
|
||||
arg_root,
|
||||
arg_profile,
|
||||
arg_json_format_flags,
|
||||
arg_pager_flags,
|
||||
/*flags=*/ 0);
|
||||
}
|
||||
|
||||
@@ -67,9 +67,9 @@ int acquire_boot_times(sd_bus *bus, BootTimes **ret) {
|
||||
"Please try again later.\n"
|
||||
"Hint: Use 'systemctl%s list-jobs' to see active jobs",
|
||||
times.finish_time,
|
||||
arg_scope == LOOKUP_SCOPE_SYSTEM ? "" : " --user");
|
||||
arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? "" : " --user");
|
||||
|
||||
if (arg_scope == LOOKUP_SCOPE_SYSTEM && times.security_start_time > 0) {
|
||||
if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM && times.security_start_time > 0) {
|
||||
/* security_start_time is set when systemd is not running under container environment. */
|
||||
if (times.initrd_time > 0)
|
||||
times.kernel_done_time = times.initrd_time;
|
||||
|
||||
@@ -21,7 +21,7 @@ int verb_unit_files(int argc, char *argv[], void *userdata) {
|
||||
char **v;
|
||||
int r;
|
||||
|
||||
r = lookup_paths_init_or_warn(&lp, arg_scope, 0, NULL);
|
||||
r = lookup_paths_init_or_warn(&lp, arg_runtime_scope, 0, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ int verb_unit_paths(int argc, char *argv[], void *userdata) {
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
int r;
|
||||
|
||||
r = lookup_paths_init_or_warn(&paths, arg_scope, 0, NULL);
|
||||
r = lookup_paths_init_or_warn(&paths, arg_runtime_scope, 0, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -248,7 +248,14 @@ static void set_destroy_ignore_pointer_max(Set** s) {
|
||||
set_free_free(*s);
|
||||
}
|
||||
|
||||
int verify_units(char **filenames, LookupScope scope, bool check_man, bool run_generators, RecursiveErrors recursive_errors, const char *root) {
|
||||
int verify_units(
|
||||
char **filenames,
|
||||
RuntimeScope scope,
|
||||
bool check_man,
|
||||
bool run_generators,
|
||||
RecursiveErrors recursive_errors,
|
||||
const char *root) {
|
||||
|
||||
const ManagerTestRunFlags flags =
|
||||
MANAGER_TEST_RUN_MINIMAL |
|
||||
MANAGER_TEST_RUN_ENV_GENERATORS |
|
||||
|
||||
@@ -17,7 +17,7 @@ typedef enum RecursiveErrors {
|
||||
int verify_generate_path(char **var, char **filenames);
|
||||
int verify_prepare_filename(const char *filename, char **ret);
|
||||
int verify_executable(Unit *u, const ExecCommand *exec, const char *root);
|
||||
int verify_units(char **filenames, LookupScope scope, bool check_man, bool run_generators, RecursiveErrors recursive_errors, const char *root);
|
||||
int verify_units(char **filenames, RuntimeScope scope, bool check_man, bool run_generators, RecursiveErrors recursive_errors, const char *root);
|
||||
|
||||
const char* recursive_errors_to_string(RecursiveErrors i) _const_;
|
||||
RecursiveErrors recursive_errors_from_string(const char *s) _pure_;
|
||||
|
||||
@@ -66,5 +66,5 @@ int verb_verify(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Couldn't process aliases: %m");
|
||||
|
||||
return verify_units(filenames, arg_scope, arg_man, arg_generators, arg_recursive_errors, arg_root);
|
||||
return verify_units(filenames, arg_runtime_scope, arg_man, arg_generators, arg_recursive_errors, arg_root);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ usec_t arg_fuzz = 0;
|
||||
PagerFlags arg_pager_flags = 0;
|
||||
BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
|
||||
const char *arg_host = NULL;
|
||||
LookupScope arg_scope = LOOKUP_SCOPE_SYSTEM;
|
||||
RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
|
||||
RecursiveErrors arg_recursive_errors = _RECURSIVE_ERRORS_INVALID;
|
||||
bool arg_man = true;
|
||||
bool arg_generators = false;
|
||||
@@ -118,18 +118,17 @@ STATIC_DESTRUCTOR_REGISTER(arg_unit, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_profile, freep);
|
||||
|
||||
int acquire_bus(sd_bus **bus, bool *use_full_bus) {
|
||||
bool user = arg_scope != LOOKUP_SCOPE_SYSTEM;
|
||||
int r;
|
||||
|
||||
if (use_full_bus && *use_full_bus) {
|
||||
r = bus_connect_transport(arg_transport, arg_host, user, bus);
|
||||
r = bus_connect_transport(arg_transport, arg_host, arg_runtime_scope, bus);
|
||||
if (IN_SET(r, 0, -EHOSTDOWN))
|
||||
return r;
|
||||
|
||||
*use_full_bus = false;
|
||||
}
|
||||
|
||||
return bus_connect_transport_systemd(arg_transport, arg_host, user, bus);
|
||||
return bus_connect_transport_systemd(arg_transport, arg_host, arg_runtime_scope, bus);
|
||||
}
|
||||
|
||||
int bus_get_unit_property_strv(sd_bus *bus, const char *path, const char *property, char ***strv) {
|
||||
@@ -384,15 +383,15 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_SYSTEM:
|
||||
arg_scope = LOOKUP_SCOPE_SYSTEM;
|
||||
arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
|
||||
break;
|
||||
|
||||
case ARG_USER:
|
||||
arg_scope = LOOKUP_SCOPE_USER;
|
||||
arg_runtime_scope = RUNTIME_SCOPE_USER;
|
||||
break;
|
||||
|
||||
case ARG_GLOBAL:
|
||||
arg_scope = LOOKUP_SCOPE_GLOBAL;
|
||||
arg_runtime_scope = RUNTIME_SCOPE_GLOBAL;
|
||||
break;
|
||||
|
||||
case ARG_ORDER:
|
||||
@@ -540,12 +539,12 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Option --threshold= is only supported for security right now.");
|
||||
|
||||
if (arg_scope == LOOKUP_SCOPE_GLOBAL &&
|
||||
if (arg_runtime_scope == RUNTIME_SCOPE_GLOBAL &&
|
||||
!STR_IN_SET(argv[optind] ?: "time", "dot", "unit-paths", "verify"))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Option --global only makes sense with verbs dot, unit-paths, verify.");
|
||||
|
||||
if (streq_ptr(argv[optind], "cat-config") && arg_scope == LOOKUP_SCOPE_USER)
|
||||
if (streq_ptr(argv[optind], "cat-config") && arg_runtime_scope == RUNTIME_SCOPE_USER)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Option --user is not supported for cat-config right now.");
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ extern usec_t arg_fuzz;
|
||||
extern PagerFlags arg_pager_flags;
|
||||
extern BusTransport arg_transport;
|
||||
extern const char *arg_host;
|
||||
extern LookupScope arg_scope;
|
||||
extern RuntimeScope arg_runtime_scope;
|
||||
extern RecursiveErrors arg_recursive_errors;
|
||||
extern bool arg_man;
|
||||
extern bool arg_generators;
|
||||
|
||||
@@ -71,6 +71,7 @@ basic_sources = files(
|
||||
'recurse-dir.c',
|
||||
'replace-var.c',
|
||||
'rlimit-util.c',
|
||||
'runtime-scope.c',
|
||||
'sigbus.c',
|
||||
'signal-util.c',
|
||||
'siphash24.c',
|
||||
|
||||
@@ -232,7 +232,7 @@ bool path_is_user_config_dir(const char *path) {
|
||||
}
|
||||
|
||||
static int acquire_generator_dirs(
|
||||
LookupScope scope,
|
||||
RuntimeScope scope,
|
||||
const char *tempdir,
|
||||
char **generator,
|
||||
char **generator_early,
|
||||
@@ -244,17 +244,17 @@ static int acquire_generator_dirs(
|
||||
assert(generator);
|
||||
assert(generator_early);
|
||||
assert(generator_late);
|
||||
assert(IN_SET(scope, LOOKUP_SCOPE_SYSTEM, LOOKUP_SCOPE_USER, LOOKUP_SCOPE_GLOBAL));
|
||||
assert(IN_SET(scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER, RUNTIME_SCOPE_GLOBAL));
|
||||
|
||||
if (scope == LOOKUP_SCOPE_GLOBAL)
|
||||
if (scope == RUNTIME_SCOPE_GLOBAL)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (tempdir)
|
||||
prefix = tempdir;
|
||||
else if (scope == LOOKUP_SCOPE_SYSTEM)
|
||||
else if (scope == RUNTIME_SCOPE_SYSTEM)
|
||||
prefix = "/run/systemd";
|
||||
else {
|
||||
/* LOOKUP_SCOPE_USER */
|
||||
/* RUNTIME_SCOPE_USER */
|
||||
const char *e;
|
||||
|
||||
e = getenv("XDG_RUNTIME_DIR");
|
||||
@@ -288,21 +288,21 @@ static int acquire_generator_dirs(
|
||||
}
|
||||
|
||||
static int acquire_transient_dir(
|
||||
LookupScope scope,
|
||||
RuntimeScope scope,
|
||||
const char *tempdir,
|
||||
char **ret) {
|
||||
|
||||
char *transient;
|
||||
|
||||
assert(ret);
|
||||
assert(IN_SET(scope, LOOKUP_SCOPE_SYSTEM, LOOKUP_SCOPE_USER, LOOKUP_SCOPE_GLOBAL));
|
||||
assert(IN_SET(scope, RUNTIME_SCOPE_SYSTEM, RUNTIME_SCOPE_USER, RUNTIME_SCOPE_GLOBAL));
|
||||
|
||||
if (scope == LOOKUP_SCOPE_GLOBAL)
|
||||
if (scope == RUNTIME_SCOPE_GLOBAL)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (tempdir)
|
||||
transient = path_join(tempdir, "transient");
|
||||
else if (scope == LOOKUP_SCOPE_SYSTEM)
|
||||
else if (scope == RUNTIME_SCOPE_SYSTEM)
|
||||
transient = strdup("/run/systemd/transient");
|
||||
else
|
||||
return xdg_user_runtime_dir(ret, "/systemd/transient");
|
||||
@@ -313,7 +313,7 @@ static int acquire_transient_dir(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int acquire_config_dirs(LookupScope scope, char **persistent, char **runtime) {
|
||||
static int acquire_config_dirs(RuntimeScope scope, char **persistent, char **runtime) {
|
||||
_cleanup_free_ char *a = NULL, *b = NULL;
|
||||
int r;
|
||||
|
||||
@@ -322,17 +322,17 @@ static int acquire_config_dirs(LookupScope scope, char **persistent, char **runt
|
||||
|
||||
switch (scope) {
|
||||
|
||||
case LOOKUP_SCOPE_SYSTEM:
|
||||
case RUNTIME_SCOPE_SYSTEM:
|
||||
a = strdup(SYSTEM_CONFIG_UNIT_DIR);
|
||||
b = strdup("/run/systemd/system");
|
||||
break;
|
||||
|
||||
case LOOKUP_SCOPE_GLOBAL:
|
||||
case RUNTIME_SCOPE_GLOBAL:
|
||||
a = strdup(USER_CONFIG_UNIT_DIR);
|
||||
b = strdup("/run/systemd/user");
|
||||
break;
|
||||
|
||||
case LOOKUP_SCOPE_USER:
|
||||
case RUNTIME_SCOPE_USER:
|
||||
r = xdg_user_config_dir(&a, "/systemd/user");
|
||||
if (r < 0 && r != -ENXIO)
|
||||
return r;
|
||||
@@ -364,7 +364,7 @@ static int acquire_config_dirs(LookupScope scope, char **persistent, char **runt
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int acquire_control_dirs(LookupScope scope, char **persistent, char **runtime) {
|
||||
static int acquire_control_dirs(RuntimeScope scope, char **persistent, char **runtime) {
|
||||
_cleanup_free_ char *a = NULL;
|
||||
int r;
|
||||
|
||||
@@ -373,7 +373,7 @@ static int acquire_control_dirs(LookupScope scope, char **persistent, char **run
|
||||
|
||||
switch (scope) {
|
||||
|
||||
case LOOKUP_SCOPE_SYSTEM: {
|
||||
case RUNTIME_SCOPE_SYSTEM: {
|
||||
_cleanup_free_ char *b = NULL;
|
||||
|
||||
a = strdup("/etc/systemd/system.control");
|
||||
@@ -389,7 +389,7 @@ static int acquire_control_dirs(LookupScope scope, char **persistent, char **run
|
||||
break;
|
||||
}
|
||||
|
||||
case LOOKUP_SCOPE_USER:
|
||||
case RUNTIME_SCOPE_USER:
|
||||
r = xdg_user_config_dir(&a, "/systemd/user.control");
|
||||
if (r < 0 && r != -ENXIO)
|
||||
return r;
|
||||
@@ -406,7 +406,7 @@ static int acquire_control_dirs(LookupScope scope, char **persistent, char **run
|
||||
|
||||
break;
|
||||
|
||||
case LOOKUP_SCOPE_GLOBAL:
|
||||
case RUNTIME_SCOPE_GLOBAL:
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
default:
|
||||
@@ -419,7 +419,7 @@ static int acquire_control_dirs(LookupScope scope, char **persistent, char **run
|
||||
}
|
||||
|
||||
static int acquire_attached_dirs(
|
||||
LookupScope scope,
|
||||
RuntimeScope scope,
|
||||
char **ret_persistent,
|
||||
char **ret_runtime) {
|
||||
|
||||
@@ -429,7 +429,7 @@ static int acquire_attached_dirs(
|
||||
assert(ret_runtime);
|
||||
|
||||
/* Portable services are not available to regular users for now. */
|
||||
if (scope != LOOKUP_SCOPE_SYSTEM)
|
||||
if (scope != RUNTIME_SCOPE_SYSTEM)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
a = strdup("/etc/systemd/system.attached");
|
||||
@@ -509,7 +509,7 @@ static int get_paths_from_environ(const char *var, char ***paths, bool *append)
|
||||
|
||||
int lookup_paths_init(
|
||||
LookupPaths *lp,
|
||||
LookupScope scope,
|
||||
RuntimeScope scope,
|
||||
LookupPathsFlags flags,
|
||||
const char *root_dir) {
|
||||
|
||||
@@ -528,14 +528,14 @@ int lookup_paths_init(
|
||||
|
||||
assert(lp);
|
||||
assert(scope >= 0);
|
||||
assert(scope < _LOOKUP_SCOPE_MAX);
|
||||
assert(scope < _RUNTIME_SCOPE_MAX);
|
||||
|
||||
#if HAVE_SPLIT_USR
|
||||
flags |= LOOKUP_PATHS_SPLIT_USR;
|
||||
#endif
|
||||
|
||||
if (!empty_or_root(root_dir)) {
|
||||
if (scope == LOOKUP_SCOPE_USER)
|
||||
if (scope == RUNTIME_SCOPE_USER)
|
||||
return -EINVAL;
|
||||
|
||||
r = is_dir(root_dir, true);
|
||||
@@ -560,8 +560,8 @@ int lookup_paths_init(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (scope == LOOKUP_SCOPE_USER) {
|
||||
r = acquire_config_dirs(LOOKUP_SCOPE_GLOBAL, &global_persistent_config, &global_runtime_config);
|
||||
if (scope == RUNTIME_SCOPE_USER) {
|
||||
r = acquire_config_dirs(RUNTIME_SCOPE_GLOBAL, &global_persistent_config, &global_runtime_config);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@@ -606,7 +606,7 @@ int lookup_paths_init(
|
||||
|
||||
switch (scope) {
|
||||
|
||||
case LOOKUP_SCOPE_SYSTEM:
|
||||
case RUNTIME_SCOPE_SYSTEM:
|
||||
add = strv_new(
|
||||
/* If you modify this you also want to modify
|
||||
* systemdsystemunitpath= in systemd.pc.in! */
|
||||
@@ -629,7 +629,7 @@ int lookup_paths_init(
|
||||
STRV_IFNOTNULL(generator_late));
|
||||
break;
|
||||
|
||||
case LOOKUP_SCOPE_GLOBAL:
|
||||
case RUNTIME_SCOPE_GLOBAL:
|
||||
add = strv_new(
|
||||
/* If you modify this you also want to modify
|
||||
* systemduserunitpath= in systemd.pc.in, and
|
||||
@@ -652,7 +652,7 @@ int lookup_paths_init(
|
||||
STRV_IFNOTNULL(generator_late));
|
||||
break;
|
||||
|
||||
case LOOKUP_SCOPE_USER:
|
||||
case RUNTIME_SCOPE_USER:
|
||||
add = user_dirs(persistent_config, runtime_config,
|
||||
global_persistent_config, global_runtime_config,
|
||||
generator, generator_early, generator_late,
|
||||
@@ -741,7 +741,7 @@ int lookup_paths_init(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lookup_paths_init_or_warn(LookupPaths *lp, LookupScope scope, LookupPathsFlags flags, const char *root_dir) {
|
||||
int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir) {
|
||||
int r;
|
||||
|
||||
r = lookup_paths_init(lp, scope, flags, root_dir);
|
||||
@@ -790,7 +790,7 @@ void lookup_paths_log(LookupPaths *lp) {
|
||||
}
|
||||
}
|
||||
|
||||
char **generator_binary_paths(LookupScope scope) {
|
||||
char **generator_binary_paths(RuntimeScope scope) {
|
||||
bool append = false; /* Add items from SYSTEMD_GENERATOR_PATH before normal directories */
|
||||
_cleanup_strv_free_ char **paths = NULL;
|
||||
int r;
|
||||
@@ -805,15 +805,15 @@ char **generator_binary_paths(LookupScope scope) {
|
||||
|
||||
switch (scope) {
|
||||
|
||||
case LOOKUP_SCOPE_SYSTEM:
|
||||
case RUNTIME_SCOPE_SYSTEM:
|
||||
add = strv_new("/run/systemd/system-generators",
|
||||
"/etc/systemd/system-generators",
|
||||
"/usr/local/lib/systemd/system-generators",
|
||||
SYSTEM_GENERATOR_DIR);
|
||||
break;
|
||||
|
||||
case LOOKUP_SCOPE_GLOBAL:
|
||||
case LOOKUP_SCOPE_USER:
|
||||
case RUNTIME_SCOPE_GLOBAL:
|
||||
case RUNTIME_SCOPE_USER:
|
||||
add = strv_new("/run/systemd/user-generators",
|
||||
"/etc/systemd/user-generators",
|
||||
"/usr/local/lib/systemd/user-generators",
|
||||
@@ -823,7 +823,6 @@ char **generator_binary_paths(LookupScope scope) {
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
if (!add)
|
||||
return NULL;
|
||||
|
||||
@@ -840,10 +839,9 @@ char **generator_binary_paths(LookupScope scope) {
|
||||
return TAKE_PTR(paths);
|
||||
}
|
||||
|
||||
char **env_generator_binary_paths(bool is_system) {
|
||||
char **env_generator_binary_paths(RuntimeScope runtime_scope) {
|
||||
_cleanup_strv_free_ char **paths = NULL, **add = NULL;
|
||||
bool append = false; /* Add items from SYSTEMD_ENVIRONMENT_GENERATOR_PATH before normal directories */
|
||||
_cleanup_strv_free_ char **paths = NULL;
|
||||
_cleanup_strv_free_ char **add = NULL;
|
||||
int r;
|
||||
|
||||
/* First priority is whatever has been passed to us via env vars */
|
||||
@@ -852,17 +850,25 @@ char **env_generator_binary_paths(bool is_system) {
|
||||
return NULL;
|
||||
|
||||
if (!paths || append) {
|
||||
if (is_system)
|
||||
switch (runtime_scope) {
|
||||
|
||||
case RUNTIME_SCOPE_SYSTEM:
|
||||
add = strv_new("/run/systemd/system-environment-generators",
|
||||
"/etc/systemd/system-environment-generators",
|
||||
"/usr/local/lib/systemd/system-environment-generators",
|
||||
SYSTEM_ENV_GENERATOR_DIR);
|
||||
else
|
||||
break;
|
||||
|
||||
case RUNTIME_SCOPE_USER:
|
||||
add = strv_new("/run/systemd/user-environment-generators",
|
||||
"/etc/systemd/user-environment-generators",
|
||||
"/usr/local/lib/systemd/user-environment-generators",
|
||||
USER_ENV_GENERATOR_DIR);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
if (!add)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "constants.h"
|
||||
#include "macro.h"
|
||||
#include "runtime-scope.h"
|
||||
|
||||
typedef enum LookupPathsFlags {
|
||||
LOOKUP_PATHS_EXCLUDE_GENERATED = 1 << 0,
|
||||
@@ -12,14 +13,6 @@ typedef enum LookupPathsFlags {
|
||||
LOOKUP_PATHS_SPLIT_USR = 1 << 2,
|
||||
} LookupPathsFlags;
|
||||
|
||||
typedef enum LookupScope {
|
||||
LOOKUP_SCOPE_SYSTEM,
|
||||
LOOKUP_SCOPE_GLOBAL,
|
||||
LOOKUP_SCOPE_USER,
|
||||
_LOOKUP_SCOPE_MAX,
|
||||
_LOOKUP_SCOPE_INVALID = -EINVAL,
|
||||
} LookupScope;
|
||||
|
||||
typedef struct LookupPaths {
|
||||
/* Where we look for unit files. This includes the individual special paths below, but also any vendor
|
||||
* supplied, static unit file paths. */
|
||||
@@ -59,8 +52,8 @@ typedef struct LookupPaths {
|
||||
char *temporary_dir;
|
||||
} LookupPaths;
|
||||
|
||||
int lookup_paths_init(LookupPaths *lp, LookupScope scope, LookupPathsFlags flags, const char *root_dir);
|
||||
int lookup_paths_init_or_warn(LookupPaths *lp, LookupScope scope, LookupPathsFlags flags, const char *root_dir);
|
||||
int lookup_paths_init(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir);
|
||||
int lookup_paths_init_or_warn(LookupPaths *lp, RuntimeScope scope, LookupPathsFlags flags, const char *root_dir);
|
||||
|
||||
int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs);
|
||||
int xdg_user_runtime_dir(char **ret, const char *suffix);
|
||||
@@ -73,8 +66,8 @@ bool path_is_user_config_dir(const char *path);
|
||||
void lookup_paths_log(LookupPaths *p);
|
||||
void lookup_paths_free(LookupPaths *p);
|
||||
|
||||
char **generator_binary_paths(LookupScope scope);
|
||||
char **env_generator_binary_paths(bool is_system);
|
||||
char **generator_binary_paths(RuntimeScope scope);
|
||||
char **env_generator_binary_paths(RuntimeScope scope);
|
||||
|
||||
#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network"))
|
||||
#define NETWORK_DIRS_NULSTR CONF_PATHS_NULSTR("systemd/network")
|
||||
|
||||
12
src/basic/runtime-scope.c
Normal file
12
src/basic/runtime-scope.c
Normal file
@@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "runtime-scope.h"
|
||||
#include "string-table.h"
|
||||
|
||||
static const char* const runtime_scope_table[_RUNTIME_SCOPE_MAX] = {
|
||||
[RUNTIME_SCOPE_SYSTEM] = "system",
|
||||
[RUNTIME_SCOPE_USER] = "user",
|
||||
[RUNTIME_SCOPE_GLOBAL] = "global",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(runtime_scope, RuntimeScope);
|
||||
17
src/basic/runtime-scope.h
Normal file
17
src/basic/runtime-scope.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
typedef enum RuntimeScope {
|
||||
RUNTIME_SCOPE_SYSTEM, /* for the system */
|
||||
RUNTIME_SCOPE_USER, /* for a user */
|
||||
RUNTIME_SCOPE_GLOBAL, /* for all users */
|
||||
_RUNTIME_SCOPE_MAX,
|
||||
_RUNTIME_SCOPE_INVALID = -EINVAL,
|
||||
} RuntimeScope;
|
||||
|
||||
const char *runtime_scope_to_string(RuntimeScope scope) _const_;
|
||||
RuntimeScope runtime_scope_from_string(const char *s) _const_;
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "pretty-print.h"
|
||||
#include "runtime-scope.h"
|
||||
#include "set.h"
|
||||
#include "sort-util.h"
|
||||
#include "strv.h"
|
||||
@@ -47,7 +48,7 @@ static bool arg_show_machine = false;
|
||||
static char **arg_matches = NULL;
|
||||
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
|
||||
static const char *arg_host = NULL;
|
||||
static bool arg_user = false;
|
||||
static RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
|
||||
static size_t arg_snaplen = 4096;
|
||||
static bool arg_list = false;
|
||||
static bool arg_quiet = false;
|
||||
@@ -109,10 +110,21 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) {
|
||||
switch (arg_transport) {
|
||||
|
||||
case BUS_TRANSPORT_LOCAL:
|
||||
if (arg_user)
|
||||
|
||||
switch (arg_runtime_scope) {
|
||||
|
||||
case RUNTIME_SCOPE_USER:
|
||||
r = bus_set_address_user(bus);
|
||||
else
|
||||
break;
|
||||
|
||||
case RUNTIME_SCOPE_SYSTEM:
|
||||
r = bus_set_address_system(bus);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BUS_TRANSPORT_REMOTE:
|
||||
@@ -120,7 +132,7 @@ static int acquire_bus(bool set_monitor, sd_bus **ret) {
|
||||
break;
|
||||
|
||||
case BUS_TRANSPORT_MACHINE:
|
||||
r = bus_set_address_machine(bus, arg_user, arg_host);
|
||||
r = bus_set_address_machine(bus, arg_runtime_scope, arg_host);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2405,11 +2417,11 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_USER:
|
||||
arg_user = true;
|
||||
arg_runtime_scope = RUNTIME_SCOPE_USER;
|
||||
break;
|
||||
|
||||
case ARG_SYSTEM:
|
||||
arg_user = false;
|
||||
arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
|
||||
break;
|
||||
|
||||
case ARG_ADDRESS:
|
||||
|
||||
@@ -215,9 +215,10 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
if (!bus) {
|
||||
/* Connect to the bus only if necessary */
|
||||
r = bus_connect_transport_systemd(BUS_TRANSPORT_LOCAL, NULL,
|
||||
arg_show_unit == SHOW_UNIT_USER,
|
||||
&bus);
|
||||
r = bus_connect_transport_systemd(
|
||||
BUS_TRANSPORT_LOCAL, NULL,
|
||||
arg_show_unit == SHOW_UNIT_USER ? RUNTIME_SCOPE_USER : RUNTIME_SCOPE_SYSTEM,
|
||||
&bus);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
|
||||
}
|
||||
|
||||
@@ -2113,7 +2113,7 @@ static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata,
|
||||
if (!h)
|
||||
return -ENOMEM;
|
||||
|
||||
r = unit_file_get_list(m->unit_file_scope, NULL, h, states, patterns);
|
||||
r = unit_file_get_list(m->runtime_scope, NULL, h, states, patterns);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
@@ -2179,7 +2179,7 @@ static int method_get_unit_file_state(sd_bus_message *message, void *userdata, s
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = unit_file_get_state(m->unit_file_scope, NULL, name, &state);
|
||||
r = unit_file_get_state(m->runtime_scope, NULL, name, &state);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -2199,7 +2199,7 @@ static int method_get_default_target(sd_bus_message *message, void *userdata, sd
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = unit_file_get_default(m->unit_file_scope, NULL, &default_target);
|
||||
r = unit_file_get_default(m->runtime_scope, NULL, &default_target);
|
||||
if (r == -ERFKILL)
|
||||
sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked.");
|
||||
if (r < 0)
|
||||
@@ -2392,7 +2392,7 @@ static int reply_install_changes_and_free(
|
||||
static int method_enable_unit_files_generic(
|
||||
sd_bus_message *message,
|
||||
Manager *m,
|
||||
int (*call)(LookupScope scope, UnitFileFlags flags, const char *root_dir, char *files[], InstallChange **changes, size_t *n_changes),
|
||||
int (*call)(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char *files[], InstallChange **changes, size_t *n_changes),
|
||||
bool carries_install_info,
|
||||
sd_bus_error *error) {
|
||||
|
||||
@@ -2433,7 +2433,7 @@ static int method_enable_unit_files_generic(
|
||||
if (r == 0)
|
||||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
|
||||
|
||||
r = call(m->unit_file_scope, flags, NULL, l, &changes, &n_changes);
|
||||
r = call(m->runtime_scope, flags, NULL, l, &changes, &n_changes);
|
||||
if (r < 0)
|
||||
return install_error(error, r, changes, n_changes);
|
||||
|
||||
@@ -2456,7 +2456,7 @@ static int method_link_unit_files(sd_bus_message *message, void *userdata, sd_bu
|
||||
return method_enable_unit_files_generic(message, userdata, unit_file_link, /* carries_install_info = */ false, error);
|
||||
}
|
||||
|
||||
static int unit_file_preset_without_mode(LookupScope scope, UnitFileFlags flags, const char *root_dir, char **files, InstallChange **changes, size_t *n_changes) {
|
||||
static int unit_file_preset_without_mode(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char **files, InstallChange **changes, size_t *n_changes) {
|
||||
return unit_file_preset(scope, flags, root_dir, files, UNIT_FILE_PRESET_FULL, changes, n_changes);
|
||||
}
|
||||
|
||||
@@ -2505,7 +2505,7 @@ static int method_preset_unit_files_with_mode(sd_bus_message *message, void *use
|
||||
if (r == 0)
|
||||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
|
||||
|
||||
r = unit_file_preset(m->unit_file_scope, flags, NULL, l, preset_mode, &changes, &n_changes);
|
||||
r = unit_file_preset(m->runtime_scope, flags, NULL, l, preset_mode, &changes, &n_changes);
|
||||
if (r < 0)
|
||||
return install_error(error, r, changes, n_changes);
|
||||
|
||||
@@ -2515,7 +2515,7 @@ static int method_preset_unit_files_with_mode(sd_bus_message *message, void *use
|
||||
static int method_disable_unit_files_generic(
|
||||
sd_bus_message *message,
|
||||
Manager *m,
|
||||
int (*call)(LookupScope scope, UnitFileFlags flags, const char *root_dir, char *files[], InstallChange **changes, size_t *n_changes),
|
||||
int (*call)(RuntimeScope scope, UnitFileFlags flags, const char *root_dir, char *files[], InstallChange **changes, size_t *n_changes),
|
||||
bool carries_install_info,
|
||||
sd_bus_error *error) {
|
||||
|
||||
@@ -2558,7 +2558,7 @@ static int method_disable_unit_files_generic(
|
||||
if (r == 0)
|
||||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
|
||||
|
||||
r = call(m->unit_file_scope, flags, NULL, l, &changes, &n_changes);
|
||||
r = call(m->runtime_scope, flags, NULL, l, &changes, &n_changes);
|
||||
if (r < 0)
|
||||
return install_error(error, r, changes, n_changes);
|
||||
|
||||
@@ -2600,7 +2600,7 @@ static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_
|
||||
if (r == 0)
|
||||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
|
||||
|
||||
r = unit_file_revert(m->unit_file_scope, NULL, l, &changes, &n_changes);
|
||||
r = unit_file_revert(m->runtime_scope, NULL, l, &changes, &n_changes);
|
||||
if (r < 0)
|
||||
return install_error(error, r, changes, n_changes);
|
||||
|
||||
@@ -2630,7 +2630,7 @@ static int method_set_default_target(sd_bus_message *message, void *userdata, sd
|
||||
if (r == 0)
|
||||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
|
||||
|
||||
r = unit_file_set_default(m->unit_file_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes);
|
||||
r = unit_file_set_default(m->runtime_scope, force ? UNIT_FILE_FORCE : 0, NULL, name, &changes, &n_changes);
|
||||
if (r < 0)
|
||||
return install_error(error, r, changes, n_changes);
|
||||
|
||||
@@ -2672,7 +2672,7 @@ static int method_preset_all_unit_files(sd_bus_message *message, void *userdata,
|
||||
if (r == 0)
|
||||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
|
||||
|
||||
r = unit_file_preset_all(m->unit_file_scope, flags, NULL, preset_mode, &changes, &n_changes);
|
||||
r = unit_file_preset_all(m->runtime_scope, flags, NULL, preset_mode, &changes, &n_changes);
|
||||
if (r < 0)
|
||||
return install_error(error, r, changes, n_changes);
|
||||
|
||||
@@ -2711,7 +2711,7 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd
|
||||
if (dep < 0)
|
||||
return -EINVAL;
|
||||
|
||||
r = unit_file_add_dependency(m->unit_file_scope, flags, NULL, l, target, dep, &changes, &n_changes);
|
||||
r = unit_file_add_dependency(m->runtime_scope, flags, NULL, l, target, dep, &changes, &n_changes);
|
||||
if (r < 0)
|
||||
return install_error(error, r, changes, n_changes);
|
||||
|
||||
@@ -2738,7 +2738,7 @@ static int method_get_unit_file_links(sd_bus_message *message, void *userdata, s
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = unit_file_disable(m->unit_file_scope,
|
||||
r = unit_file_disable(m->runtime_scope,
|
||||
UNIT_FILE_DRY_RUN | (runtime ? UNIT_FILE_RUNTIME : 0),
|
||||
NULL, STRV_MAKE(name), &changes, &n_changes);
|
||||
if (r < 0) {
|
||||
|
||||
@@ -1993,7 +1993,6 @@ static int bus_set_transient_emergency_action(
|
||||
const char *s;
|
||||
EmergencyAction v;
|
||||
int r;
|
||||
bool system;
|
||||
|
||||
assert(p);
|
||||
|
||||
@@ -2001,8 +2000,7 @@ static int bus_set_transient_emergency_action(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
system = MANAGER_IS_SYSTEM(u->manager);
|
||||
r = parse_emergency_action(s, system, &v);
|
||||
r = parse_emergency_action(s, u->manager->runtime_scope, &v);
|
||||
if (r < 0)
|
||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||
r == -EOPNOTSUPP ? "%s setting invalid for manager type: %s"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user