blob: f150bb087ac738d8f09246db0840dd0e9ac885c1 [file] [log] [blame]
From 085c8b6f253726ad547e7be84ff3f2b99701488b Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Wed, 9 Nov 2016 19:38:07 -0800
Subject: [PATCH 09/19] util: bypass unimplemented _SC_PHYS_PAGES system
configuration API on uclibc
Upstream-Status: Inappropriate [uclibc-specific]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
src/basic/util.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/basic/util.c b/src/basic/util.c
index c1b5ca1..4c62d43 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -742,6 +742,20 @@ uint64_t physical_memory(void) {
* In order to support containers nicely that have a configured memory limit we'll take the minimum of the
* physically reported amount of memory and the limit configured for the root cgroup, if there is any. */
+#ifdef __UCLIBC__
+ char line[128];
+ FILE *f = fopen("/proc/meminfo", "r");
+ if (f == NULL)
+ return 0;
+ while (!feof(f) && fgets(line, sizeof(line)-1, f)) {
+ if (sscanf(line, "MemTotal: %li kB", &mem) == 1) {
+ mem *= 1024;
+ break;
+ }
+ }
+ fclose(f);
+ return (uint64_t) mem;
+#else
sc = sysconf(_SC_PHYS_PAGES);
assert(sc > 0);
@@ -762,6 +776,7 @@ uint64_t physical_memory(void) {
lim *= ps;
return MIN(mem, lim);
+#endif
}
uint64_t physical_memory_scale(uint64_t v, uint64_t max) {
--
2.10.2