Skip to content

Commit 164e3a3

Browse files
davidkoppclaude
andauthored
Detect systemd cgroup path using cgroup name (instead of container id) (#1270)
* Fix missing dependencies in Makefiles Add proper dependencies to Makefile targets that use gmt-lib.o and detect_cgroup_path.o object files. This ensures Make will rebuild the metric-provider-binary when dependency objects change. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Add systemd cgroup path using cgroup name instead of container id * Use full cgroup name [skip ci] * Add header files as dependencies in Makefiles * Replace long lib c paths in Makefiles with variable --------- Co-authored-by: Claude <[email protected]>
1 parent e95c991 commit 164e3a3

File tree

26 files changed

+112
-77
lines changed

26 files changed

+112
-77
lines changed

lib/c/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ CFLAGS = -O3 -Wall
22

33
all: gmt-lib.o detect_cgroup_path.o
44

5-
gmt-lib.o: gmt-lib.c
5+
gmt-lib.o: gmt-lib.c gmt-lib.h
66
gcc -c $< $(CFLAGS) -o $@
77

8-
detect_cgroup_path.o: detect_cgroup_path.c
8+
detect_cgroup_path.o: detect_cgroup_path.c detect_cgroup_path.h
99
gcc -c $< $(CFLAGS) -o $@

lib/c/detect_cgroup_path.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ char* detect_cgroup_path(const char* controller, int user_id, const char* id) {
8585
return path;
8686
}
8787

88+
// Try cgroups v2 with full cgroup name (typically used for debug purposes)
89+
snprintf(path, PATH_MAX,
90+
"/sys/fs/cgroup/%s/%s",
91+
id, controller);
92+
fd = fopen(path, "r");
93+
if (fd != NULL) {
94+
fclose(fd);
95+
return path;
96+
}
8897

8998
// If no valid path is found, free the allocated memory and error
9099
free(path);
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
CFLAGS = -O3 -Wall -Werror -lm -I../../../../../../lib/c
1+
LIB_C = ../../../../../../lib/c
2+
CFLAGS = -O3 -Wall -Werror -lm -I$(LIB_C)
23

3-
metric-provider-binary: source.c
4-
gcc ../../../../../../lib/c/gmt-lib.o $< $(CFLAGS) -o $@
4+
metric-provider-binary: source.c $(LIB_C)/gmt-lib.o $(LIB_C)/gmt-lib.h
5+
gcc $(LIB_C)/gmt-lib.o $< $(CFLAGS) -o $@
56
sudo chown root $@
67
sudo chmod u+s $@
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
CFLAGS = -O3 -Wall -Werror -lm -I../../../../../lib/c
1+
LIB_C = ../../../../../lib/c
2+
CFLAGS = -O3 -Wall -Werror -lm -I$(LIB_C)
23

3-
metric-provider-binary: source.c
4-
gcc ../../../../../lib/c/gmt-lib.o $< $(CFLAGS) -o $@
4+
metric-provider-binary: source.c $(LIB_C)/gmt-lib.o $(LIB_C)/gmt-lib.h
5+
gcc $(LIB_C)/gmt-lib.o $< $(CFLAGS) -o $@
56
sudo chown root $@
67
sudo chmod u+s $@
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CFLAGS = -O3 -Wall -Werror -I../../../../../lib/c
1+
LIB_C = ../../../../../lib/c
2+
CFLAGS = -O3 -Wall -Werror -I$(LIB_C)
23

3-
metric-provider-binary: source.c
4-
gcc ../../../../../lib/c/gmt-lib.o ../../../../../lib/c/detect_cgroup_path.o $< $(CFLAGS) -o $@
4+
metric-provider-binary: source.c $(LIB_C)/gmt-lib.o $(LIB_C)/gmt-lib.h $(LIB_C)/detect_cgroup_path.o $(LIB_C)/detect_cgroup_path.h
5+
gcc $(LIB_C)/gmt-lib.o $(LIB_C)/detect_cgroup_path.o $< $(CFLAGS) -o $@
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CFLAGS = -O3 -Wall -Werror -I../../../../../lib/c
1+
LIB_C = ../../../../../lib/c
2+
CFLAGS = -O3 -Wall -Werror -I$(LIB_C)
23

3-
metric-provider-binary: source.c
4-
gcc ../../../../../lib/c/gmt-lib.o $< $(CFLAGS) -o $@
4+
metric-provider-binary: source.c $(LIB_C)/gmt-lib.o $(LIB_C)/gmt-lib.h
5+
gcc $(LIB_C)/gmt-lib.o $< $(CFLAGS) -o $@
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CFLAGS = -O3 -Wall -Werror -I../../../../../lib/c
1+
LIB_C = ../../../../../lib/c
2+
CFLAGS = -O3 -Wall -Werror -I$(LIB_C)
23

3-
metric-provider-binary: source.c
4-
gcc ../../../../../lib/c/gmt-lib.o $< $(CFLAGS) -o $@
4+
metric-provider-binary: source.c $(LIB_C)/gmt-lib.o $(LIB_C)/gmt-lib.h
5+
gcc $(LIB_C)/gmt-lib.o $< $(CFLAGS) -o $@
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CFLAGS = -O3 -Wall -Werror -I../../../../../lib/c
1+
LIB_C = ../../../../../lib/c
2+
CFLAGS = -O3 -Wall -Werror -I$(LIB_C)
23

3-
metric-provider-binary: source.c
4-
gcc ../../../../../lib/c/gmt-lib.o ../../../../../lib/c/detect_cgroup_path.o $< $(CFLAGS) -o $@
4+
metric-provider-binary: source.c $(LIB_C)/gmt-lib.o $(LIB_C)/gmt-lib.h $(LIB_C)/detect_cgroup_path.o $(LIB_C)/detect_cgroup_path.h
5+
gcc $(LIB_C)/gmt-lib.o $(LIB_C)/detect_cgroup_path.o $< $(CFLAGS) -o $@
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CFLAGS = -O3 -Wall -Werror -I../../../../../lib/c
1+
LIB_C = ../../../../../lib/c
2+
CFLAGS = -O3 -Wall -Werror -I$(LIB_C)
23

3-
metric-provider-binary: source.c
4-
gcc ../../../../../lib/c/gmt-lib.o ../../../../../lib/c/detect_cgroup_path.o $< $(CFLAGS) -o $@
4+
metric-provider-binary: source.c $(LIB_C)/gmt-lib.o $(LIB_C)/gmt-lib.h $(LIB_C)/detect_cgroup_path.o $(LIB_C)/detect_cgroup_path.h
5+
gcc $(LIB_C)/gmt-lib.o $(LIB_C)/detect_cgroup_path.o $< $(CFLAGS) -o $@
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
CFLAGS = -O3 -Wall -Werror -I../../../../../lib/c
1+
LIB_C = ../../../../../lib/c
2+
CFLAGS = -O3 -Wall -Werror -I$(LIB_C)
23

3-
metric-provider-binary: source.c
4-
gcc ../../../../../lib/c/gmt-lib.o $< $(CFLAGS) -o $@
4+
metric-provider-binary: source.c $(LIB_C)/gmt-lib.o $(LIB_C)/gmt-lib.h
5+
gcc $(LIB_C)/gmt-lib.o $< $(CFLAGS) -o $@

0 commit comments

Comments
 (0)