summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2021-11-11 18:49:50 +0000
committerGitHub <noreply@github.com>2021-11-11 18:49:50 +0000
commit1977d1477f635057a87c0a5a59fc5d4e0b8ed6ec (patch)
treecfe3ed1779c23d7905c90191772e87b57c0e7e1b
parentaf11e0ef843c19cbf8ccaefb93a44dbe4602f7a8 (diff)
parentdedca960afdee5797d19929c43853513711e3e3d (diff)
downloadsystemd-1977d1477f635057a87c0a5a59fc5d4e0b8ed6ec.tar.gz
Merge pull request #21241 from wat-ze-hex/2021-11-04-fix-bpf-foreign-realization
core, bpf: fix bpf-foreign cgroup controller realization
-rw-r--r--src/core/bpf-foreign.c20
-rw-r--r--src/core/bpf-foreign.h5
2 files changed, 14 insertions, 11 deletions
diff --git a/src/core/bpf-foreign.c b/src/core/bpf-foreign.c
index 6b93b9785f..8538792b60 100644
--- a/src/core/bpf-foreign.c
+++ b/src/core/bpf-foreign.c
@@ -4,8 +4,10 @@
#include "bpf-program.h"
#include "cgroup.h"
#include "memory-util.h"
+#include "missing_magic.h"
#include "mountpoint-util.h"
#include "set.h"
+#include "stat-util.h"
typedef struct BPFForeignKey BPFForeignKey;
struct BPFForeignKey {
@@ -84,6 +86,14 @@ static int bpf_foreign_prepare(
assert(u);
assert(bpffs_path);
+ r = path_is_fs_type(bpffs_path, BPF_FS_MAGIC);
+ if (r < 0)
+ return log_unit_error_errno(u, r,
+ "Failed to determine filesystem type of %s: %m", bpffs_path);
+ if (r == 0)
+ return log_unit_error_errno(u, SYNTHETIC_ERRNO(EINVAL),
+ "Path in BPF filesystem is expected.");
+
r = bpf_program_new_from_bpffs_path(bpffs_path, &prog);
if (r < 0)
return log_unit_error_errno(u, r, "Failed to create foreign BPFProgram: %m");
@@ -111,16 +121,6 @@ static int bpf_foreign_prepare(
return 0;
}
-int bpf_foreign_supported(void) {
- int r;
-
- r = cg_all_unified();
- if (r <= 0)
- return r;
-
- return path_is_mount_point("/sys/fs/bpf", NULL, 0);
-}
-
int bpf_foreign_install(Unit *u) {
_cleanup_free_ char *cgroup_path = NULL;
CGroupBPFForeignProgram *p;
diff --git a/src/core/bpf-foreign.h b/src/core/bpf-foreign.h
index 9559cd7981..e387b1b1d3 100644
--- a/src/core/bpf-foreign.h
+++ b/src/core/bpf-foreign.h
@@ -4,7 +4,10 @@
#include "unit.h"
-int bpf_foreign_supported(void);
+static inline int bpf_foreign_supported(void) {
+ return cg_all_unified();
+}
+
/*
* Attach cgroup-bpf programs foreign to systemd, i.e. loaded to the kernel by an entity
* external to systemd.