1
0
mirror of https://github.com/systemd/systemd synced 2026-04-23 07:24:51 +02:00

Compare commits

..

No commits in common. "e8aba093b405bb53cd26d82d26436aa4836b2e83" and "da29de23ef200b17bb780e5a0efb6cff28c72287" have entirely different histories.

7 changed files with 66 additions and 106 deletions

View File

@ -6080,11 +6080,9 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
} }
#if HAVE_LIBBPF #if HAVE_LIBBPF
if (exec_context_restrict_filesystems_set(c)) { if (exec_context_restrict_filesystems_set(c))
char *fs; SET_FOREACH(e, c->restrict_filesystems)
SET_FOREACH(fs, c->restrict_filesystems) fprintf(f, "%sRestrictFileSystems: %s\n", prefix, *e);
fprintf(f, "%sRestrictFileSystems: %s\n", prefix, fs);
}
#endif #endif
if (c->network_namespace_path) if (c->network_namespace_path)

View File

@ -578,7 +578,8 @@ int sd_radv_set_preference(sd_radv *ra, unsigned preference) {
int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) { int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) {
_cleanup_free_ char *addr_p = NULL; _cleanup_free_ char *addr_p = NULL;
sd_radv_prefix *cur, *found = NULL; sd_radv_prefix *cur;
bool update = false;
int r; int r;
assert_return(ra, -EINVAL); assert_return(ra, -EINVAL);
@ -603,7 +604,7 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) {
continue; continue;
if (cur->opt.prefixlen == p->opt.prefixlen) { if (cur->opt.prefixlen == p->opt.prefixlen) {
found = cur; update = true;
break; break;
} }
@ -614,13 +615,15 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) {
strna(addr_p), strna(addr_cur)); strna(addr_p), strna(addr_cur));
} }
if (found) { if (update) {
assert(cur);
/* p and cur may be equivalent. First increment the reference counter. */ /* p and cur may be equivalent. First increment the reference counter. */
sd_radv_prefix_ref(p); sd_radv_prefix_ref(p);
/* Then, remove the old entry. */ /* Then, remove the old entry. */
LIST_REMOVE(prefix, ra->prefixes, found); LIST_REMOVE(prefix, ra->prefixes, cur);
sd_radv_prefix_unref(found); sd_radv_prefix_unref(cur);
/* Finally, add the new entry. */ /* Finally, add the new entry. */
LIST_APPEND(prefix, ra->prefixes, p); LIST_APPEND(prefix, ra->prefixes, p);
@ -656,20 +659,15 @@ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p) {
return 0; return 0;
} }
void sd_radv_remove_prefix( sd_radv_prefix *sd_radv_remove_prefix(sd_radv *ra,
sd_radv *ra, const struct in6_addr *prefix,
const struct in6_addr *prefix, unsigned char prefixlen) {
unsigned char prefixlen) { sd_radv_prefix *cur, *next;
sd_radv_prefix *cur; assert_return(ra, NULL);
assert_return(prefix, NULL);
if (!ra) LIST_FOREACH_SAFE(prefix, cur, next, ra->prefixes) {
return;
if (!prefix)
return;
LIST_FOREACH(prefix, cur, ra->prefixes) {
if (prefixlen != cur->opt.prefixlen) if (prefixlen != cur->opt.prefixlen)
continue; continue;
@ -679,13 +677,17 @@ void sd_radv_remove_prefix(
LIST_REMOVE(prefix, ra->prefixes, cur); LIST_REMOVE(prefix, ra->prefixes, cur);
ra->n_prefixes--; ra->n_prefixes--;
sd_radv_prefix_unref(cur); sd_radv_prefix_unref(cur);
return;
break;
} }
return cur;
} }
int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) { int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) {
_cleanup_free_ char *addr_p = NULL; _cleanup_free_ char *addr_p = NULL;
sd_radv_route_prefix *cur, *found = NULL; sd_radv_route_prefix *cur;
bool update = false;
int r; int r;
assert_return(ra, -EINVAL); assert_return(ra, -EINVAL);
@ -706,7 +708,7 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) {
continue; continue;
if (cur->opt.prefixlen == p->opt.prefixlen) { if (cur->opt.prefixlen == p->opt.prefixlen) {
found = cur; update = true;
break; break;
} }
@ -717,13 +719,15 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) {
strna(addr_p), strna(addr_cur)); strna(addr_p), strna(addr_cur));
} }
if (found) { if (update) {
assert(cur);
/* p and cur may be equivalent. First increment the reference counter. */ /* p and cur may be equivalent. First increment the reference counter. */
sd_radv_route_prefix_ref(p); sd_radv_route_prefix_ref(p);
/* Then, remove the old entry. */ /* Then, remove the old entry. */
LIST_REMOVE(prefix, ra->route_prefixes, found); LIST_REMOVE(prefix, ra->route_prefixes, cur);
sd_radv_route_prefix_unref(found); sd_radv_route_prefix_unref(cur);
/* Finally, add the new entry. */ /* Finally, add the new entry. */
LIST_APPEND(prefix, ra->route_prefixes, p); LIST_APPEND(prefix, ra->route_prefixes, p);
@ -758,12 +762,8 @@ int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p) {
return 0; return 0;
} }
int sd_radv_set_rdnss( int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime,
sd_radv *ra, const struct in6_addr *dns, size_t n_dns) {
uint32_t lifetime,
const struct in6_addr *dns,
size_t n_dns) {
_cleanup_free_ struct sd_radv_opt_dns *opt_rdnss = NULL; _cleanup_free_ struct sd_radv_opt_dns *opt_rdnss = NULL;
size_t len; size_t len;
@ -796,11 +796,8 @@ int sd_radv_set_rdnss(
return 0; return 0;
} }
int sd_radv_set_dnssl( int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime,
sd_radv *ra, char **search_list) {
uint32_t lifetime,
char **search_list) {
_cleanup_free_ struct sd_radv_opt_dns *opt_dnssl = NULL; _cleanup_free_ struct sd_radv_opt_dns *opt_dnssl = NULL;
size_t len = 0; size_t len = 0;
char **s; char **s;
@ -879,11 +876,8 @@ int sd_radv_prefix_new(sd_radv_prefix **ret) {
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv_prefix, sd_radv_prefix, mfree); DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv_prefix, sd_radv_prefix, mfree);
int sd_radv_prefix_set_prefix( int sd_radv_prefix_set_prefix(sd_radv_prefix *p, const struct in6_addr *in6_addr,
sd_radv_prefix *p, unsigned char prefixlen) {
const struct in6_addr *in6_addr,
unsigned char prefixlen) {
assert_return(p, -EINVAL); assert_return(p, -EINVAL);
assert_return(in6_addr, -EINVAL); assert_return(in6_addr, -EINVAL);
@ -900,11 +894,8 @@ int sd_radv_prefix_set_prefix(
return 0; return 0;
} }
int sd_radv_prefix_get_prefix( int sd_radv_prefix_get_prefix(sd_radv_prefix *p, struct in6_addr *ret_in6_addr,
sd_radv_prefix *p, unsigned char *ret_prefixlen) {
struct in6_addr *ret_in6_addr,
unsigned char *ret_prefixlen) {
assert_return(p, -EINVAL); assert_return(p, -EINVAL);
assert_return(ret_in6_addr, -EINVAL); assert_return(ret_in6_addr, -EINVAL);
assert_return(ret_prefixlen, -EINVAL); assert_return(ret_prefixlen, -EINVAL);
@ -923,7 +914,8 @@ int sd_radv_prefix_set_onlink(sd_radv_prefix *p, int onlink) {
return 0; return 0;
} }
int sd_radv_prefix_set_address_autoconfiguration(sd_radv_prefix *p, int address_autoconfiguration) { int sd_radv_prefix_set_address_autoconfiguration(sd_radv_prefix *p,
int address_autoconfiguration) {
assert_return(p, -EINVAL); assert_return(p, -EINVAL);
SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_AUTO, address_autoconfiguration); SET_FLAG(p->opt.flags, ND_OPT_PI_FLAG_AUTO, address_autoconfiguration);
@ -975,11 +967,8 @@ int sd_radv_route_prefix_new(sd_radv_route_prefix **ret) {
DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv_route_prefix, sd_radv_route_prefix, mfree); DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_radv_route_prefix, sd_radv_route_prefix, mfree);
int sd_radv_route_prefix_set_prefix( int sd_radv_route_prefix_set_prefix(sd_radv_route_prefix *p, const struct in6_addr *in6_addr,
sd_radv_route_prefix *p, unsigned char prefixlen) {
const struct in6_addr *in6_addr,
unsigned char prefixlen) {
assert_return(p, -EINVAL); assert_return(p, -EINVAL);
assert_return(in6_addr, -EINVAL); assert_return(in6_addr, -EINVAL);

View File

@ -187,7 +187,7 @@ int dhcp_pd_remove(Link *link, bool only_marked) {
continue; continue;
if (link->radv) if (link->radv)
sd_radv_remove_prefix(link->radv, &route->dst.in6, 64); (void) sd_radv_remove_prefix(link->radv, &route->dst.in6, 64);
link_remove_dhcp_pd_subnet_prefix(link, &route->dst.in6); link_remove_dhcp_pd_subnet_prefix(link, &route->dst.in6);
@ -212,7 +212,7 @@ int dhcp_pd_remove(Link *link, bool only_marked) {
in6_addr_mask(&prefix, 64); in6_addr_mask(&prefix, 64);
if (link->radv) if (link->radv)
sd_radv_remove_prefix(link->radv, &prefix, 64); (void) sd_radv_remove_prefix(link->radv, &prefix, 64);
link_remove_dhcp_pd_subnet_prefix(link, &prefix); link_remove_dhcp_pd_subnet_prefix(link, &prefix);

View File

@ -1778,11 +1778,11 @@ static int context_load_partition_table(
} }
sz = fdisk_partition_get_size(p); sz = fdisk_partition_get_size(p);
assert(sz <= UINT64_MAX/secsz); assert_se(sz <= UINT64_MAX/secsz);
sz *= secsz; sz *= secsz;
start = fdisk_partition_get_start(p); start = fdisk_partition_get_start(p);
assert(start <= UINT64_MAX/secsz); assert_se(start <= UINT64_MAX/secsz);
start *= secsz; start *= secsz;
partno = fdisk_partition_get_partno(p); partno = fdisk_partition_get_partno(p);
@ -4799,7 +4799,7 @@ static int determine_auto_size(Context *c) {
uint64_t sum; uint64_t sum;
Partition *p; Partition *p;
assert(c); assert_se(c);
sum = round_up_size(GPT_METADATA_SIZE, 4096); sum = round_up_size(GPT_METADATA_SIZE, 4096);
@ -4981,7 +4981,7 @@ static int run(int argc, char *argv[]) {
/* Flush out everything again, and let's grow the file first, then start fresh */ /* Flush out everything again, and let's grow the file first, then start fresh */
context_unload_partition_table(context); context_unload_partition_table(context);
assert(arg_size != UINT64_MAX); assert_se(arg_size != UINT64_MAX);
r = resize_backing_fd( r = resize_backing_fd(
node, node,
&backing_fd, &backing_fd,

View File

@ -1660,7 +1660,6 @@ int varlink_errorb(Varlink *v, const char *error_id, ...) {
} }
int varlink_error_invalid_parameter(Varlink *v, JsonVariant *parameters) { int varlink_error_invalid_parameter(Varlink *v, JsonVariant *parameters) {
int r;
assert_return(v, -EINVAL); assert_return(v, -EINVAL);
assert_return(parameters, -EINVAL); assert_return(parameters, -EINVAL);
@ -1670,33 +1669,13 @@ int varlink_error_invalid_parameter(Varlink *v, JsonVariant *parameters) {
* variant in which case we'll pull out the first key. The latter mode is useful in functions that * variant in which case we'll pull out the first key. The latter mode is useful in functions that
* don't expect any arguments. */ * don't expect any arguments. */
/* varlink_error(...) expects a json object as the third parameter. Passing a string variant causes if (json_variant_is_string(parameters))
* parameter sanitization to fail, and it returns -EINVAL. */ return varlink_error(v, VARLINK_ERROR_INVALID_PARAMETER, parameters);
if (json_variant_is_string(parameters)) {
_cleanup_(json_variant_unrefp) JsonVariant *parameters_obj = NULL;
r = json_build(&parameters_obj,
JSON_BUILD_OBJECT(
JSON_BUILD_PAIR("parameter", JSON_BUILD_VARIANT(parameters))));
if (r < 0)
return r;
return varlink_error(v, VARLINK_ERROR_INVALID_PARAMETER, parameters_obj);
}
if (json_variant_is_object(parameters) && if (json_variant_is_object(parameters) &&
json_variant_elements(parameters) > 0) { json_variant_elements(parameters) > 0)
_cleanup_(json_variant_unrefp) JsonVariant *parameters_obj = NULL; return varlink_error(v, VARLINK_ERROR_INVALID_PARAMETER,
json_variant_by_index(parameters, 0));
r = json_build(&parameters_obj,
JSON_BUILD_OBJECT(
JSON_BUILD_PAIR("parameter", JSON_BUILD_VARIANT(json_variant_by_index(parameters, 0)))));
if (r < 0)
return r;
return varlink_error(v, VARLINK_ERROR_INVALID_PARAMETER, parameters_obj);
}
return -EINVAL; return -EINVAL;
} }

View File

@ -59,7 +59,8 @@ int sd_radv_set_other_information(sd_radv *ra, int other);
int sd_radv_set_preference(sd_radv *ra, unsigned preference); int sd_radv_set_preference(sd_radv *ra, unsigned preference);
int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p); int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p);
int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p); int sd_radv_add_route_prefix(sd_radv *ra, sd_radv_route_prefix *p);
void sd_radv_remove_prefix(sd_radv *ra, const struct in6_addr *prefix, unsigned char prefixlen); sd_radv_prefix *sd_radv_remove_prefix(sd_radv *ra, const struct in6_addr *prefix,
unsigned char prefixlen);
int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime, int sd_radv_set_rdnss(sd_radv *ra, uint32_t lifetime,
const struct in6_addr *dns, size_t n_dns); const struct in6_addr *dns, size_t n_dns);
int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime, char **search_list); int sd_radv_set_dnssl(sd_radv *ra, uint32_t lifetime, char **search_list);

View File

@ -102,18 +102,15 @@ static void unit_status_info_clear(UnitStatusInfo *p) {
p->active_state = mfree(p->active_state); p->active_state = mfree(p->active_state);
} }
static UnitStatusInfo *unit_status_info_free(UnitStatusInfo *p) { static void unit_status_info_free(UnitStatusInfo *p) {
if (!p) assert(p);
return NULL;
unit_status_info_clear(p); unit_status_info_clear(p);
free(p->name); free(p->name);
free(p->path); free(p->path);
return mfree(p); free(p);
} }
DEFINE_TRIVIAL_CLEANUP_FUNC(UnitStatusInfo*, unit_status_info_free);
static void context_clear(Context *c) { static void context_clear(Context *c) {
UnitStatusInfo *p; UnitStatusInfo *p;
@ -132,13 +129,8 @@ static void context_clear(Context *c) {
} }
static int context_add_ntp_service(Context *c, const char *s, const char *source) { static int context_add_ntp_service(Context *c, const char *s, const char *source) {
_cleanup_(unit_status_info_freep) UnitStatusInfo *unit = NULL;
UnitStatusInfo *u; UnitStatusInfo *u;
assert(c);
assert(s);
assert(source);
if (!unit_name_is_valid(s, UNIT_NAME_PLAIN)) if (!unit_name_is_valid(s, UNIT_NAME_PLAIN))
return -EINVAL; return -EINVAL;
@ -147,17 +139,18 @@ static int context_add_ntp_service(Context *c, const char *s, const char *source
if (streq(u->name, s)) if (streq(u->name, s))
return 0; return 0;
unit = new0(UnitStatusInfo, 1); u = new0(UnitStatusInfo, 1);
if (!unit) if (!u)
return -ENOMEM; return -ENOMEM;
unit->name = strdup(s); u->name = strdup(s);
if (!unit->name) if (!u->name) {
free(u);
return -ENOMEM; return -ENOMEM;
}
LIST_APPEND(units, c->units, unit); LIST_APPEND(units, c->units, u);
log_unit_debug(unit, "added from %s.", source); log_unit_debug(u, "added from %s.", source);
TAKE_PTR(unit);
return 0; return 0;
} }