Skip to content

system: read uptime/load/memory/swap from /proc for container correctness - #52

Open
YTjungle666 wants to merge 1 commit into
openwrt:mainfrom
YTjungle666:system-info-procfs
Open

YTjungle666 wants to merge 1 commit into
openwrt:mainfrom
YTjungle666:system-info-procfs

Conversation

@YTjungle666

Copy link
Copy Markdown

system_info() reads uptime, load, memory and swap via sysinfo(2), which always reports host-wide values — even inside a container. With LXC (with or without LXCFS), /proc is virtualized to the container's view, but sysinfo(2) is not, so ubus call system info (and consumers such as the LuCI status page) showed the host's memory, uptime and swap inside containers.

This makes system.c read the standard /proc interfaces first and fall back to sysinfo(2) per field when a source is unavailable:

item source
uptime /proc/uptime
load /proc/loadavg (1<<16 fixed-point scaling kept)
memory /proc/meminfo (MemTotal, MemFree, Shmem, Buffers, MemAvailable, Cached)
swap /proc/meminfo → /proc/swaps → sysinfo(2)

No container detection is performed: bare metal, VMs and containers all simply read their own /proc — on bare metal the values are identical to before (the same interfaces uptime/free read). The ubus JSON schema, field names, units and load scaling are unchanged, so no consumer needs modification.

Tested on x86_64 (OpenWrt 25.12, musl) inside an LXC with LXCFS: ubus call system info now reports the container's own uptime/load/memory/swap, and all services (netifd, dnsmasq, dropbear, LuCI) operate normally.

The change touches system.c only (base commit 58eb263d, openwrt-25.12; rebased onto current main).

…ness

sysinfo(2) reports host-wide uptime, load, memory and swap even inside a
container, while /proc is virtualized to the container view (e.g. LXC
with LXCFS). Read /proc/uptime, /proc/loadavg, /proc/meminfo and
/proc/swaps first and fall back to sysinfo(2) per field when a source is
unavailable.

The ubus "system info" JSON schema, field names, units and the 1<<16
load scaling are unchanged, so consumers such as LuCI keep working
unmodified on bare metal, VMs and containers.
YTjungle666 added a commit to YTjungle666/procd-lxcfs-fix that referenced this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant