check-reqs.eclass: properly extract memory and swap for Darwin and Solaris

Use the proper methods on Darwin and Solaris hosts to get available
memory and available swap in kibibytes.

Closes: https://bugs.gentoo.org/404207
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
This commit is contained in:
Fabian Groffen
2025-12-19 21:13:55 +01:00
parent 82944f38fc
commit 8c77c5ad0a

View File

@@ -333,7 +333,28 @@ _check-reqs_memory() {
if [[ -r /proc/meminfo ]] ; then
actual_memory=$(awk '/MemTotal/ { print $2 }' /proc/meminfo)
actual_swap=$(awk '/SwapTotal/ { print $2 }' /proc/meminfo)
elif [[ ${CBUILD:-${CHOST}} == *-darwin* ]] ; then
# bug #404207
actual_memory=$(sysctl -n hw.memsize 2>/dev/null)
[[ $? -eq 0 ]] && actual_memory=$((actual_memory / 1024))
actual_swap=$(sysctl -n vm.swapusage 2>/dev/null)
if [[ $? -eq 0 ]] ; then
actual_swap=$(awk '{
split($3, v, 'M', s); print int(v[0] * 1024)
}' <<<"${actual_swap}")
fi
elif [[ ${CBUILD:-${CHOST}} == *-solaris* ]] ; then
actual_memory=$(prtconf 2>/dev/null | grep Memory)
if [[ $? -eq 0 ]] ; then
actual_memory=$(awk '{
print int($3 * 1024)
}' <<<"${actual_memory}")
fi
actual_swap=$(swap -s 2>/dev/null)
[[ $? -eq 0 ]] && actual_swap=$(
sed -n 's/^.*, \([0-9]\+\)k available.*$/\1/p' <<<"${actual_swap}")
else
# FreeBSD
actual_memory=$(sysctl hw.physmem 2>/dev/null)
[[ $? -eq 0 ]] && actual_memory=$(echo "${actual_memory}" \
| sed -e 's/^[^:=]*[:=][[:space:]]*//')