chiark / gitweb /
strv: add new STR_IN_SET() macro that operates similar to IN_SET() but for strings
[elogind.git] / src / shared / util.c
index 285a263cdbe5cc13a8946bc6c699e6e92fb88e43..8c7cfbd6df7f548dd21e12b72c3471e82598ea3b 100644 (file)
@@ -83,6 +83,7 @@
 #include "gunicode.h"
 #include "virt.h"
 #include "def.h"
+#include "missing.h"
 
 int saved_argc = 0;
 char **saved_argv = NULL;
@@ -4713,7 +4714,7 @@ static const char* const sched_policy_table[] = {
 
 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX);
 
-static const char* const rlimit_table[] = {
+static const char* const rlimit_table[_RLIMIT_MAX] = {
         [RLIMIT_CPU] = "LimitCPU",
         [RLIMIT_FSIZE] = "LimitFSIZE",
         [RLIMIT_DATA] = "LimitDATA",
@@ -6291,3 +6292,15 @@ const char* personality_to_string(unsigned long p) {
 
         return NULL;
 }
+
+uint64_t physical_memory(void) {
+        long mem;
+
+        /* We return this as uint64_t in case we are running as 32bit
+         * process on a 64bit kernel with huge amounts of memory */
+
+        mem = sysconf(_SC_PHYS_PAGES);
+        assert(mem > 0);
+
+        return (uint64_t) mem * (uint64_t) page_size();
+}