Skip to content

Commit c99e656

Browse files
authored
Merge pull request #1092 from rioriost/main
fix: get container ID from /proc/self/mountinfo (for podman)
2 parents 624a9ec + cf43aca commit c99e656

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/functions.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,15 @@ function get_self_cid {
199199

200200
# Try the /proc files methods first then resort to the Docker API.
201201
if [[ -f /proc/1/cpuset ]]; then
202-
self_cid="$(grep -Eo '[[:alnum:]]{64}' /proc/1/cpuset)"
202+
self_cid="$(grep -Eo -m 1 '[[:alnum:]]{64}' /proc/1/cpuset)"
203203
fi
204204
if [[ ( ${#self_cid} != 64 ) && ( -f /proc/self/cgroup ) ]]; then
205205
self_cid="$(grep -Eo -m 1 '[[:alnum:]]{64}' /proc/self/cgroup)"
206206
fi
207+
# cgroups v2
208+
if [[ ( ${#self_cid} != 64 ) && ( -f /proc/self/mountinfo ) ]]; then
209+
self_cid="$(grep '/userdata/hostname' /proc/self/mountinfo | grep -Eo -m 1 '[[:alnum:]]{64}')"
210+
fi
207211
if [[ ( ${#self_cid} != 64 ) ]]; then
208212
self_cid="$(docker_api "/containers/$(hostname)/json" | jq -r '.Id')"
209213
fi

0 commit comments

Comments
 (0)