From cf43aca15c460d36c05f1b90be734756cd6248b0 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Sat, 4 May 2024 12:41:47 +0200 Subject: [PATCH] refactor: ensure we never grep more than one container id --- app/functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/functions.sh b/app/functions.sh index 65467cc..2fc8fec 100644 --- a/app/functions.sh +++ b/app/functions.sh @@ -199,14 +199,14 @@ function get_self_cid { # Try the /proc files methods first then resort to the Docker API. if [[ -f /proc/1/cpuset ]]; then - self_cid="$(grep -Eo '[[:alnum:]]{64}' /proc/1/cpuset)" + self_cid="$(grep -Eo -m 1 '[[:alnum:]]{64}' /proc/1/cpuset)" fi 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}')" + self_cid="$(grep '/userdata/hostname' /proc/self/mountinfo | grep -Eo -m 1 '[[:alnum:]]{64}')" fi if [[ ( ${#self_cid} != 64 ) ]]; then self_cid="$(docker_api "/containers/$(hostname)/json" | jq -r '.Id')"