From: Lennart Poettering Date: Mon, 26 Jun 2023 11:04:59 +0000 (+0200) Subject: bpf-foreign: if one program fails, still load the next X-Git-Tag: v254-rc1~113^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f81450f2415f8fd77fc8edb3b4baab966aefa9fd;p=thirdparty%2Fsystemd.git bpf-foreign: if one program fails, still load the next Let's make sure that if we load one program we don't prematurely fail, and continue with the others still. --- diff --git a/src/core/bpf-foreign.c b/src/core/bpf-foreign.c index 0271f1b3253..4ee76abfc13 100644 --- a/src/core/bpf-foreign.c +++ b/src/core/bpf-foreign.c @@ -56,17 +56,20 @@ DEFINE_PRIVATE_HASH_OPS_FULL(bpf_foreign_by_key_hash_ops, static int attach_programs(Unit *u, const char *path, Hashmap* foreign_by_key, uint32_t attach_flags) { const BPFForeignKey *key; BPFProgram *prog; - int r; + int r, ret = 0; assert(u); HASHMAP_FOREACH_KEY(prog, key, foreign_by_key) { r = bpf_program_cgroup_attach(prog, key->attach_type, path, attach_flags); - if (r < 0) - return log_unit_error_errno(u, r, "bpf-foreign: Attaching foreign BPF program to cgroup %s failed: %m", path); + if (r < 0) { + log_unit_error_errno(u, r, "bpf-foreign: Attaching foreign BPF program to cgroup %s failed: %m", path); + if (ret >= 0) + ret = r; + } } - return 0; + return ret; } /* @@ -124,7 +127,7 @@ static int bpf_foreign_prepare( int bpf_foreign_install(Unit *u) { _cleanup_free_ char *cgroup_path = NULL; CGroupContext *cc; - int r; + int r, ret = 0; assert(u); @@ -138,13 +141,10 @@ int bpf_foreign_install(Unit *u) { LIST_FOREACH(programs, p, cc->bpf_foreign_programs) { r = bpf_foreign_prepare(u, p->attach_type, p->bpffs_path); - if (r < 0) - return r; + if (r < 0 && ret >= 0) + ret = r; } r = attach_programs(u, cgroup_path, u->bpf_foreign_by_key, BPF_F_ALLOW_MULTI); - if (r < 0) - return r; - - return 0; + return ret < 0 ? ret : r; }