aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0009-util-bypass-unimplemented-_SC_PHYS_PAGES-system-conf.patch
blob: f150bb087ac738d8f09246db0840dd0e9ac885c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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