summaryrefslogtreecommitdiffstats
path: root/src/shared/user-record.c
diff options
context:
space:
mode:
authorIvan Kruglov <mail@ikruglov.com>2024-11-01 12:05:43 +0100
committerIvan Kruglov <mail@ikruglov.com>2024-11-06 11:37:51 +0100
commit7779d4944ccd723b2f3ecc888a984732e4038c5e (patch)
tree89b9d4e0a516eaa40b6eda9efc9fb20c707c2027 /src/shared/user-record.c
parentmachine: machine_default_shell_path() & machine_default_shell_args() helper f... (diff)
downloadsystemd-7779d4944ccd723b2f3ecc888a984732e4038c5e.tar.xz
systemd-7779d4944ccd723b2f3ecc888a984732e4038c5e.zip
json: introduce json_dispatch_strv_environment()
I just moved json_dispatch_environment() from src/shared/user-record.c under name 'json_dispatch_strv_environment()' to shared json code.
Diffstat (limited to '')
-rw-r--r--src/shared/user-record.c38
1 files changed, 2 insertions, 36 deletions
diff --git a/src/shared/user-record.c b/src/shared/user-record.c
index 47eea9b19a..a63b907c74 100644
--- a/src/shared/user-record.c
+++ b/src/shared/user-record.c
@@ -493,40 +493,6 @@ static int json_dispatch_access_mode(const char *name, sd_json_variant *variant,
return 0;
}
-static int json_dispatch_environment(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
- _cleanup_strv_free_ char **n = NULL;
- char ***l = userdata;
- int r;
-
- if (sd_json_variant_is_null(variant)) {
- *l = strv_free(*l);
- return 0;
- }
-
- if (!sd_json_variant_is_array(variant))
- return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array.", strna(name));
-
- for (size_t i = 0; i < sd_json_variant_elements(variant); i++) {
- sd_json_variant *e;
- const char *a;
-
- e = sd_json_variant_by_index(variant, i);
- if (!sd_json_variant_is_string(e))
- return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array of strings.", strna(name));
-
- assert_se(a = sd_json_variant_string(e));
-
- if (!env_assignment_is_valid(a))
- return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an array of environment variables.", strna(name));
-
- r = strv_env_replace_strdup(&n, a);
- if (r < 0)
- return json_log_oom(variant, flags);
- }
-
- return strv_free_and_replace(*l, n);
-}
-
static int json_dispatch_locale(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) {
char **s = userdata;
const char *n;
@@ -1237,7 +1203,7 @@ static int dispatch_per_machine(const char *name, sd_json_variant *variant, sd_j
{ "location", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(UserRecord, location), 0 },
{ "shell", SD_JSON_VARIANT_STRING, json_dispatch_filename_or_path, offsetof(UserRecord, shell), 0 },
{ "umask", SD_JSON_VARIANT_UNSIGNED, json_dispatch_umask, offsetof(UserRecord, umask), 0 },
- { "environment", SD_JSON_VARIANT_ARRAY, json_dispatch_environment, offsetof(UserRecord, environment), 0 },
+ { "environment", SD_JSON_VARIANT_ARRAY, json_dispatch_strv_environment, offsetof(UserRecord, environment), 0 },
{ "timeZone", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(UserRecord, time_zone), SD_JSON_STRICT },
{ "preferredLanguage", SD_JSON_VARIANT_STRING, json_dispatch_locale, offsetof(UserRecord, preferred_language), 0 },
{ "additionalLanguages", SD_JSON_VARIANT_ARRAY, json_dispatch_locales, offsetof(UserRecord, additional_languages), 0 },
@@ -1583,7 +1549,7 @@ int user_record_load(UserRecord *h, sd_json_variant *v, UserRecordLoadFlags load
{ "lastPasswordChangeUSec", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(UserRecord, last_password_change_usec), 0 },
{ "shell", SD_JSON_VARIANT_STRING, json_dispatch_filename_or_path, offsetof(UserRecord, shell), 0 },
{ "umask", SD_JSON_VARIANT_UNSIGNED, json_dispatch_umask, offsetof(UserRecord, umask), 0 },
- { "environment", SD_JSON_VARIANT_ARRAY, json_dispatch_environment, offsetof(UserRecord, environment), 0 },
+ { "environment", SD_JSON_VARIANT_ARRAY, json_dispatch_strv_environment, offsetof(UserRecord, environment), 0 },
{ "timeZone", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(UserRecord, time_zone), SD_JSON_STRICT },
{ "preferredLanguage", SD_JSON_VARIANT_STRING, json_dispatch_locale, offsetof(UserRecord, preferred_language), 0 },
{ "additionalLanguages", SD_JSON_VARIANT_ARRAY, json_dispatch_locales, offsetof(UserRecord, additional_languages), 0 },