diff options
author | David Tardon <dtardon@redhat.com> | 2022-08-09 14:35:15 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2022-09-13 08:13:27 +0200 |
commit | 995340074e554b4bf4a0fdb0cb7436692c5a4ffd (patch) | |
tree | ca3ee001db3e608ee80478f42fea9c3b409f1b7b /src/nspawn/nspawn-oci.c | |
parent | Merge pull request #23087 from yuwata/udev-watch (diff) | |
download | systemd-995340074e554b4bf4a0fdb0cb7436692c5a4ffd.tar.xz systemd-995340074e554b4bf4a0fdb0cb7436692c5a4ffd.zip |
tree-wide: use ASSERT_PTR more
Diffstat (limited to 'src/nspawn/nspawn-oci.c')
-rw-r--r-- | src/nspawn/nspawn-oci.c | 138 |
1 files changed, 35 insertions, 103 deletions
diff --git a/src/nspawn/nspawn-oci.c b/src/nspawn/nspawn-oci.c index a8c7b4e434..02142a9352 100644 --- a/src/nspawn/nspawn-oci.c +++ b/src/nspawn/nspawn-oci.c @@ -99,11 +99,9 @@ static int oci_terminal(const char *name, JsonVariant *v, JsonDispatchFlags flag } static int oci_console_dimension(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { - unsigned *u = userdata; + unsigned *u = ASSERT_PTR(userdata); uint64_t k; - assert(u); - k = json_variant_unsigned(variant); if (k == 0) return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), @@ -128,11 +126,9 @@ static int oci_console_size(const char *name, JsonVariant *v, JsonDispatchFlags } static int oci_absolute_path(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - char **p = userdata; + char **p = ASSERT_PTR(userdata); const char *n; - assert(p); - n = json_variant_string(v); if (!path_is_absolute(n)) @@ -143,12 +139,10 @@ static int oci_absolute_path(const char *name, JsonVariant *v, JsonDispatchFlags } static int oci_env(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - char ***l = userdata; + char ***l = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(l); - JSON_VARIANT_ARRAY_FOREACH(e, v) { const char *n; @@ -172,11 +166,9 @@ static int oci_env(const char *name, JsonVariant *v, JsonDispatchFlags flags, vo static int oci_args(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { _cleanup_strv_free_ char **l = NULL; - char ***value = userdata; + char ***value = ASSERT_PTR(userdata); int r; - assert(value); - r = json_variant_strv(v, &l); if (r < 0) return json_log(v, flags, r, "Cannot parse arguments as list of strings: %m"); @@ -214,9 +206,7 @@ static int oci_rlimit_type(const char *name, JsonVariant *v, JsonDispatchFlags f } static int oci_rlimit_value(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - rlim_t z, *value = userdata; - - assert(value); + rlim_t z, *value = ASSERT_PTR(userdata); if (json_variant_is_negative(v)) z = RLIM_INFINITY; @@ -238,12 +228,10 @@ static int oci_rlimit_value(const char *name, JsonVariant *v, JsonDispatchFlags static int oci_rlimits(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { struct rlimit_data { @@ -328,11 +316,9 @@ static int oci_capabilities(const char *name, JsonVariant *v, JsonDispatchFlags {} }; - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); int r; - assert(s); - r = json_dispatch(v, table, oci_unexpected, flags, &s->full_capabilities); if (r < 0) return r; @@ -346,11 +332,9 @@ static int oci_capabilities(const char *name, JsonVariant *v, JsonDispatchFlags } static int oci_oom_score_adj(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); int64_t k; - assert(s); - k = json_variant_integer(v); if (k < OOM_SCORE_ADJ_MIN || k > OOM_SCORE_ADJ_MAX) return json_log(v, flags, SYNTHETIC_ERRNO(EINVAL), @@ -384,12 +368,10 @@ static int oci_uid_gid(const char *name, JsonVariant *v, JsonDispatchFlags flags } static int oci_supplementary_gids(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { gid_t gid, *a; @@ -472,11 +454,9 @@ static int oci_root(const char *name, JsonVariant *v, JsonDispatchFlags flags, v } static int oci_hostname(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); const char *n; - assert(s); - assert_se(n = json_variant_string(v)); if (!hostname_is_valid(n, 0)) @@ -539,12 +519,10 @@ static void cleanup_oci_mount_data(oci_mount_data *data) { } static int oci_mounts(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { static const JsonDispatch table[] = { { "destination", JSON_VARIANT_STRING, oci_absolute_path, offsetof(oci_mount_data, destination), JSON_MANDATORY }, @@ -604,10 +582,9 @@ static int oci_mounts(const char *name, JsonVariant *v, JsonDispatchFlags flags, } static int oci_namespace_type(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - unsigned long *nsflags = userdata; + unsigned long *nsflags = ASSERT_PTR(userdata); const char *n; - assert(nsflags); assert_se(n = json_variant_string(v)); /* We don't use namespace_flags_from_string() here, as the OCI spec uses slightly different names than the @@ -739,12 +716,10 @@ static int oci_uid_gid_mappings(const char *name, JsonVariant *v, JsonDispatchFl {} }; - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(s); - if (json_variant_elements(v) == 0) return 0; @@ -783,10 +758,9 @@ static int oci_uid_gid_mappings(const char *name, JsonVariant *v, JsonDispatchFl } static int oci_device_type(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - mode_t *mode = userdata; + mode_t *mode = ASSERT_PTR(userdata); const char *t; - assert(mode); assert_se(t = json_variant_string(v)); if (STR_IN_SET(t, "c", "u")) @@ -850,12 +824,10 @@ static int oci_device_file_mode(const char *name, JsonVariant *v, JsonDispatchFl } static int oci_devices(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { static const JsonDispatch table[] = { @@ -936,12 +908,10 @@ static int oci_devices(const char *name, JsonVariant *v, JsonDispatchFlags flags static int oci_cgroups_path(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { _cleanup_free_ char *slice = NULL, *backwards = NULL; - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); const char *p; int r; - assert(s); - assert_se(p = json_variant_string(v)); r = cg_path_get_slice(p, &slice); @@ -1016,14 +986,12 @@ static int oci_cgroup_device_access(const char *name, JsonVariant *v, JsonDispat static int oci_cgroup_devices(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { _cleanup_free_ struct device_data *list = NULL; - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); size_t n_list = 0, i; bool noop = false; JsonVariant *e; int r; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { struct device_data data = { @@ -1175,11 +1143,9 @@ static int oci_cgroup_devices(const char *name, JsonVariant *v, JsonDispatchFlag } static int oci_cgroup_memory_limit(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - uint64_t *m = userdata; + uint64_t *m = ASSERT_PTR(userdata); uint64_t k; - assert(m); - if (json_variant_is_negative(v)) { *m = UINT64_MAX; return 0; @@ -1275,11 +1241,9 @@ struct cpu_data { }; static int oci_cgroup_cpu_shares(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - uint64_t *u = userdata; + uint64_t *u = ASSERT_PTR(userdata); uint64_t k; - assert(u); - k = json_variant_unsigned(v); if (k < CGROUP_CPU_SHARES_MIN || k > CGROUP_CPU_SHARES_MAX) return json_log(v, flags, SYNTHETIC_ERRNO(ERANGE), @@ -1290,11 +1254,9 @@ static int oci_cgroup_cpu_shares(const char *name, JsonVariant *v, JsonDispatchF } static int oci_cgroup_cpu_quota(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - uint64_t *u = userdata; + uint64_t *u = ASSERT_PTR(userdata); uint64_t k; - assert(u); - k = json_variant_unsigned(v); if (k <= 0 || k >= UINT64_MAX) return json_log(v, flags, SYNTHETIC_ERRNO(ERANGE), @@ -1305,13 +1267,11 @@ static int oci_cgroup_cpu_quota(const char *name, JsonVariant *v, JsonDispatchFl } static int oci_cgroup_cpu_cpus(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - struct cpu_data *data = userdata; + struct cpu_data *data = ASSERT_PTR(userdata); CPUSet set; const char *n; int r; - assert(data); - assert_se(n = json_variant_string(v)); r = parse_cpu_set(n, &set); @@ -1382,12 +1342,10 @@ static int oci_cgroup_cpu(const char *name, JsonVariant *v, JsonDispatchFlags fl } static int oci_cgroup_block_io_weight(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); uint64_t k; int r; - assert(s); - k = json_variant_unsigned(v); if (k < CGROUP_BLKIO_WEIGHT_MIN || k > CGROUP_BLKIO_WEIGHT_MAX) return json_log(v, flags, SYNTHETIC_ERRNO(ERANGE), @@ -1405,12 +1363,10 @@ static int oci_cgroup_block_io_weight(const char *name, JsonVariant *v, JsonDisp } static int oci_cgroup_block_io_weight_device(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { struct device_data { unsigned major; @@ -1460,13 +1416,11 @@ static int oci_cgroup_block_io_weight_device(const char *name, JsonVariant *v, J } static int oci_cgroup_block_io_throttle(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); const char *pname; JsonVariant *e; int r; - assert(s); - pname = streq(name, "throttleReadBpsDevice") ? "IOReadBandwidthMax" : streq(name, "throttleWriteBpsDevice") ? "IOWriteBandwidthMax" : streq(name, "throttleReadIOPSDevice") ? "IOReadIOPSMax" : @@ -1539,12 +1493,10 @@ static int oci_cgroup_pids(const char *name, JsonVariant *v, JsonDispatchFlags f }; _cleanup_(json_variant_unrefp) JsonVariant *k = NULL; - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); uint64_t m; int r; - assert(s); - r = json_dispatch(v, table, oci_unexpected, flags, &k); if (r < 0) return r; @@ -1623,13 +1575,11 @@ static bool sysctl_key_valid(const char *s) { } static int oci_sysctl(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *w; const char *k; int r; - assert(s); - JSON_VARIANT_OBJECT_FOREACH(k, w, v) { const char *m; @@ -1759,12 +1709,10 @@ static int oci_seccomp_compare_from_string(const char *name, enum scmp_compare * } static int oci_seccomp_archs(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - scmp_filter_ctx *sc = userdata; + scmp_filter_ctx *sc = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(sc); - JSON_VARIANT_ARRAY_FOREACH(e, v) { uint32_t a; @@ -1801,11 +1749,9 @@ static void syscall_rule_free(struct syscall_rule *rule) { }; static int oci_seccomp_action(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - uint32_t *action = userdata; + uint32_t *action = ASSERT_PTR(userdata); int r; - assert(action); - r = oci_seccomp_action_from_string(json_variant_string(v), action); if (r < 0) return json_log(v, flags, r, "Unknown system call action '%s': %m", json_variant_string(v)); @@ -1814,11 +1760,9 @@ static int oci_seccomp_action(const char *name, JsonVariant *v, JsonDispatchFlag } static int oci_seccomp_op(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - enum scmp_compare *op = userdata; + enum scmp_compare *op = ASSERT_PTR(userdata); int r; - assert(op); - r = oci_seccomp_compare_from_string(json_variant_string(v), op); if (r < 0) return json_log(v, flags, r, "Unknown seccomp operator '%s': %m", json_variant_string(v)); @@ -1827,12 +1771,10 @@ static int oci_seccomp_op(const char *name, JsonVariant *v, JsonDispatchFlags fl } static int oci_seccomp_args(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - struct syscall_rule *rule = userdata; + struct syscall_rule *rule = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(rule); - JSON_VARIANT_ARRAY_FOREACH(e, v) { static const struct JsonDispatch table[] = { { "index", JSON_VARIANT_UNSIGNED, json_dispatch_uint32, offsetof(struct scmp_arg_cmp, arg), JSON_MANDATORY }, @@ -1878,12 +1820,10 @@ static int oci_seccomp_args(const char *name, JsonVariant *v, JsonDispatchFlags } static int oci_seccomp_syscalls(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - scmp_filter_ctx *sc = userdata; + scmp_filter_ctx *sc = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(sc); - JSON_VARIANT_ARRAY_FOREACH(e, v) { static const JsonDispatch table[] = { { "names", JSON_VARIANT_ARRAY, json_dispatch_strv, offsetof(struct syscall_rule, names), JSON_MANDATORY }, @@ -1941,13 +1881,11 @@ static int oci_seccomp(const char *name, JsonVariant *v, JsonDispatchFlags flags }; _cleanup_(seccomp_releasep) scmp_filter_ctx sc = NULL; - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *def; uint32_t d; int r; - assert(s); - def = json_variant_by_key(v, "defaultAction"); if (!def) return json_log(v, flags, SYNTHETIC_ERRNO(EINVAL), "defaultAction element missing."); @@ -1988,11 +1926,9 @@ static int oci_rootfs_propagation(const char *name, JsonVariant *v, JsonDispatch } static int oci_masked_paths(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { _cleanup_free_ char *destination = NULL; CustomMount *m; @@ -2030,11 +1966,9 @@ static int oci_masked_paths(const char *name, JsonVariant *v, JsonDispatchFlags } static int oci_readonly_paths(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { _cleanup_free_ char *source = NULL, *destination = NULL; CustomMount *m; @@ -2109,12 +2043,10 @@ static int oci_hook_timeout(const char *name, JsonVariant *v, JsonDispatchFlags } static int oci_hooks_array(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) { - Settings *s = userdata; + Settings *s = ASSERT_PTR(userdata); JsonVariant *e; int r; - assert(s); - JSON_VARIANT_ARRAY_FOREACH(e, v) { static const JsonDispatch table[] = { |