summaryrefslogtreecommitdiff
path: root/src/analyze
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-03-10 09:47:10 +0100
committerLennart Poettering <lennart@poettering.net>2023-03-10 09:47:39 +0100
commit4870133bfaaf97189a970a29bf47e0e38fa721aa (patch)
treed2fa9a5699a8b4c948179afabf3da2f9da322ce5 /src/analyze
parent5f64d2bf332371bdfdcb91b588e57d4c0c20428f (diff)
downloadsystemd-4870133bfaaf97189a970a29bf47e0e38fa721aa.tar.gz
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.
Diffstat (limited to 'src/analyze')
-rw-r--r--src/analyze/analyze-condition.c4
-rw-r--r--src/analyze/analyze-plot.c8
-rw-r--r--src/analyze/analyze-security.c50
-rw-r--r--src/analyze/analyze-time-data.c4
-rw-r--r--src/analyze/analyze-unit-files.c2
-rw-r--r--src/analyze/analyze-unit-paths.c2
-rw-r--r--src/analyze/analyze-verify-util.c9
-rw-r--r--src/analyze/analyze-verify-util.h2
-rw-r--r--src/analyze/analyze-verify.c2
-rw-r--r--src/analyze/analyze.c17
-rw-r--r--src/analyze/analyze.h2
11 files changed, 55 insertions, 47 deletions
diff --git a/src/analyze/analyze-condition.c b/src/analyze/analyze-condition.c
index b29fc0cd71..6da61cd0cf 100644
--- a/src/analyze/analyze-condition.c
+++ b/src/analyze/analyze-condition.c
@@ -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;
diff --git a/src/analyze/analyze-plot.c b/src/analyze/analyze-plot.c
index 8aca691b3d..0f39484f92 100644
--- a/src/analyze/analyze-plot.c
+++ b/src/analyze/analyze-plot.c
@@ -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;
diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c
index 585dd01f68..7662bf1827 100644
--- a/src/analyze/analyze-security.c
+++ b/src/analyze/analyze-security.c
@@ -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);
}
diff --git a/src/analyze/analyze-time-data.c b/src/analyze/analyze-time-data.c
index aa42d69322..07843f74bc 100644
--- a/src/analyze/analyze-time-data.c
+++ b/src/analyze/analyze-time-data.c
@@ -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;
diff --git a/src/analyze/analyze-unit-files.c b/src/analyze/analyze-unit-files.c
index ec9be336e1..d9b3313be4 100644
--- a/src/analyze/analyze-unit-files.c
+++ b/src/analyze/analyze-unit-files.c
@@ -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;
diff --git a/src/analyze/analyze-unit-paths.c b/src/analyze/analyze-unit-paths.c
index c2254619bc..bb00a4fcd2 100644
--- a/src/analyze/analyze-unit-paths.c
+++ b/src/analyze/analyze-unit-paths.c
@@ -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;
diff --git a/src/analyze/analyze-verify-util.c b/src/analyze/analyze-verify-util.c
index b9f08b6d85..132a84649b 100644
--- a/src/analyze/analyze-verify-util.c
+++ b/src/analyze/analyze-verify-util.c
@@ -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 |
diff --git a/src/analyze/analyze-verify-util.h b/src/analyze/analyze-verify-util.h
index 385d635e33..2e3b0604c3 100644
--- a/src/analyze/analyze-verify-util.h
+++ b/src/analyze/analyze-verify-util.h
@@ -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_;
diff --git a/src/analyze/analyze-verify.c b/src/analyze/analyze-verify.c
index 35e4e1eb31..98d48f6276 100644
--- a/src/analyze/analyze-verify.c
+++ b/src/analyze/analyze-verify.c
@@ -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);
}
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index d7688c1a85..12c0bd653f 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -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.");
diff --git a/src/analyze/analyze.h b/src/analyze/analyze.h
index 35b1cddb38..2f623e3201 100644
--- a/src/analyze/analyze.h
+++ b/src/analyze/analyze.h
@@ -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;