]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bpf-foreign: if one program fails, still load the next
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Jun 2023 11:04:59 +0000 (13:04 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Jun 2023 11:04:59 +0000 (13:04 +0200)
Let's make sure that if we load one program we don't prematurely fail,
and continue with the others still.

src/core/bpf-foreign.c

index 0271f1b325326c81afd24ee94e57504a6c5362c9..4ee76abfc13b26e62f78ff635d0fa00f4cbf19b0 100644 (file)
@@ -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;
 }