@@ -99,7 +99,7 @@ usage_percentage=$(df -P "$target_dir" | awk 'NR==2 {print $5}' | sed 's/%%//')
9999echo "[disk usage checker] Volume usage percentage: current = ${usage_percentage} ; allowed = ${usage_percentage_limit}"
100100if [ "$usage_percentage" -gt "$usage_percentage_limit" ]; then
101101 echo "[disk usage checker] Disk usage exceeds the volume percentage of ${usage_percentage_limit} for mounted directory, terminating..."
102- if command -v setsid >/dev/null 2>&1 && command -v ps >/dev/null 2>&1 && command -v pkill >/dev/null 2>&1 ; then
102+ if [ "$HAVE_SESSION_TOOLS" = "true" ] ; then
103103 ps -o sess --no-headers | sort -u | while read sid; do
104104 [[ "$sid" -eq "${$}" ]] && continue
105105 pkill --signal SIGKILL --session "$sid"
@@ -1325,14 +1325,21 @@ func buildPodCommand(
13251325) string {
13261326 var cmd strings.Builder
13271327
1328+ // Check if session management tools are available once and store in a variable.
1329+ cmd .WriteString ("if command -v setsid >/dev/null 2>&1 && command -v ps >/dev/null 2>&1 && command -v pkill >/dev/null 2>&1; then\n " )
1330+ cmd .WriteString (" HAVE_SESSION_TOOLS=true\n " )
1331+ cmd .WriteString ("else\n " )
1332+ cmd .WriteString (" HAVE_SESSION_TOOLS=false\n " )
1333+ cmd .WriteString ("fi\n \n " )
1334+
13281335 // Start the checker in the background.
13291336 cmd .WriteString (volumeCheckerScript )
13301337 cmd .WriteString (` & ` )
13311338
13321339 // Start the gather command in a separate session if setsid, ps, and pkill are available.
13331340 // Fall back to simpler approach if any of these tools are not present (minimal images).
1334- cmd .WriteString (" if command -v setsid >/dev/null 2>&1 && command -v ps >/dev/null 2>&1 && command -v pkill >/dev/null 2>&1 ; then\n " )
1335- cmd .WriteString (" setsid -w bash <<-MUSTGATHER_EOF\n " )
1341+ cmd .WriteString (` if [ "$HAVE_SESSION_TOOLS" = "true" ] ; then` )
1342+ cmd .WriteString ("\n setsid -w bash <<-MUSTGATHER_EOF\n " )
13361343 cmd .WriteString (gatherCommand )
13371344 cmd .WriteString ("\n MUSTGATHER_EOF\n " )
13381345 cmd .WriteString ("else\n " )
0 commit comments