From 0fec0e1b3bb14fc3675d6600070d440a0d6ee6b6 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 8 Mar 2026 21:36:34 +1300 Subject: [PATCH] Move timeout into _sudo helper instead of each call site --- app/gather_info.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/gather_info.sh b/app/gather_info.sh index 108704c..d6c074e 100755 --- a/app/gather_info.sh +++ b/app/gather_info.sh @@ -223,15 +223,15 @@ gather_container_stats() { # Use sudo if available and needed (infmap user won't have direct access) _sudo() { if [ "$(id -u)" -eq 0 ]; then - "$@" + timeout 10 "$@" else - sudo -n "$@" 2>/dev/null + timeout 10 sudo -n "$@" 2>/dev/null fi } # Proxmox LXC (pct) if command -v pct &>/dev/null; then - timeout 10 _sudo pct list 2>/dev/null | tail -n +2 | while read -r line; do + _sudo pct list 2>/dev/null | tail -n +2 | while read -r line; do [ -z "$line" ] && continue vmid=$(echo "$line" | awk '{print $1}') status=$(echo "$line" | awk '{print $2}') @@ -250,7 +250,7 @@ fi # Proxmox VMs (qm) if command -v qm &>/dev/null; then - timeout 10 _sudo qm list 2>/dev/null | tail -n +2 | while read -r vmid name status _ mem _; do + _sudo qm list 2>/dev/null | tail -n +2 | while read -r vmid name status _ mem _; do [ -z "$vmid" ] && continue echo "[container:qm-${vmid}]" echo "type=vm" @@ -271,7 +271,7 @@ fi # Plain LXC (lxc/lxd) if command -v lxc &>/dev/null && ! command -v pct &>/dev/null; then - timeout 10 _sudo lxc list --format csv -c nsN 2>/dev/null | while IFS=',' read -r name status network; do + _sudo lxc list --format csv -c nsN 2>/dev/null | while IFS=',' read -r name status network; do [ -z "$name" ] && continue echo "[container:lxc-${name}]" echo "type=lxc" @@ -288,7 +288,7 @@ fi # libvirt VMs (virsh) if command -v virsh &>/dev/null; then - timeout 10 _sudo virsh list --all --name 2>/dev/null | while read -r name; do + _sudo virsh list --all --name 2>/dev/null | while read -r name; do [ -z "$name" ] && continue state=$(_sudo virsh domstate "$name" 2>/dev/null | head -1) echo "[container:virsh-${name}]" @@ -305,7 +305,7 @@ fi # Docker containers if command -v docker &>/dev/null; then - timeout 10 _sudo docker ps -a --format '{{.Names}}\t{{.State}}\t{{.Image}}\t{{.Status}}' 2>/dev/null | while IFS=$'\t' read -r name state image status_text; do + _sudo docker ps -a --format '{{.Names}}\t{{.State}}\t{{.Image}}\t{{.Status}}' 2>/dev/null | while IFS=$'\t' read -r name state image status_text; do [ -z "$name" ] && continue echo "[container:docker-${name}]" echo "type=docker" @@ -319,7 +319,7 @@ if command -v docker &>/dev/null; then docker_ip=$(_sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$name" 2>/dev/null) [ -n "$docker_ip" ] && echo "ip=$docker_ip" # Get memory/cpu stats (one-shot, no stream) - stats=$(timeout 5 _sudo docker stats --no-stream --format '{{.MemUsage}}\t{{.MemPerc}}\t{{.CPUPerc}}' "$name" 2>/dev/null) + stats=$(_sudo docker stats --no-stream --format '{{.MemUsage}}\t{{.MemPerc}}\t{{.CPUPerc}}' "$name" 2>/dev/null) if [ -n "$stats" ]; then mem_pct=$(echo "$stats" | cut -f2 | tr -d '%') cpu_pct=$(echo "$stats" | cut -f3 | tr -d '%')