Skip to content

Commit cf43aca

Browse files
committed
refactor: ensure we never grep more than one container id
1 parent d110a06 commit cf43aca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/functions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ 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
207207
# cgroups v2
208208
if [[ ( ${#self_cid} != 64 ) && ( -f /proc/self/mountinfo ) ]]; then
209-
self_cid="$(grep '/userdata/hostname' /proc/self/mountinfo | grep -Eo '[[:alnum:]]{64}')"
209+
self_cid="$(grep '/userdata/hostname' /proc/self/mountinfo | grep -Eo -m 1 '[[:alnum:]]{64}')"
210210
fi
211211
if [[ ( ${#self_cid} != 64 ) ]]; then
212212
self_cid="$(docker_api "/containers/$(hostname)/json" | jq -r '.Id')"

0 commit comments

Comments
 (0)