1
0

Update functions.sh

With cgroup v2, CID can be read from /proc/self/mountinfo
This commit is contained in:
Rio Fujita 2024-01-28 11:32:37 +09:00 committed by GitHub
parent 013005aca1
commit d110a065b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -204,6 +204,10 @@ function get_self_cid {
if [[ ( ${#self_cid} != 64 ) && ( -f /proc/self/cgroup ) ]]; then
self_cid="$(grep -Eo -m 1 '[[:alnum:]]{64}' /proc/self/cgroup)"
fi
# cgroups v2
if [[ ( ${#self_cid} != 64 ) && ( -f /proc/self/mountinfo ) ]]; then
self_cid="$(grep '/userdata/hostname' /proc/self/mountinfo | grep -Eo '[[:alnum:]]{64}')"
fi
if [[ ( ${#self_cid} != 64 ) ]]; then
self_cid="$(docker_api "/containers/$(hostname)/json" | jq -r '.Id')"
fi