chiark / gitweb /
core: move config_parse_limit() to the generic conf-parser.[ch]
authorLennart Poettering <lennart@poettering.net>
Thu, 3 May 2018 17:01:21 +0000 (19:01 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
That way we can use it in nspawn.

Also, while we are at it, let's rename the call config_parse_rlimit(),
i.e. insert the "r", to clarify what kind of limit this is about.

src/shared/conf-parser.c
src/shared/conf-parser.h

index 73591f70f536e1df1e8dec110d02cb5cffa46746..d570a7068938c28989441779cd331d3caad2b9fd 100644 (file)
@@ -37,6 +37,7 @@
 /// Additional includes needed by elogind
 #include "def.h"
 #include "fileio.h"
+//#include "rlimit-util.h"
 
 int config_item_table_lookup(
                 const void *table,
@@ -1232,3 +1233,42 @@ int config_parse_mtu(
 
         return 0;
 }
+
+int config_parse_rlimit(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        struct rlimit **rl = data, d = {};
+        int r;
+
+        assert(rvalue);
+        assert(rl);
+
+        r = rlimit_parse(ltype, rvalue, &d);
+        if (r == -EILSEQ) {
+                log_syntax(unit, LOG_WARNING, filename, line, r, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue);
+                return 0;
+        }
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse resource value, ignoring: %s", rvalue);
+                return 0;
+        }
+
+        if (rl[ltype])
+                *rl[ltype] = d;
+        else {
+                rl[ltype] = newdup(struct rlimit, &d, 1);
+                if (!rl[ltype])
+                        return log_oom();
+        }
+
+        return 0;
+}
index 38a82f6e3300ec2413f9c1cf27d875b010b34768..7b5a3c2b3c3a3affba671226b668c8e612b6c376 100644 (file)
@@ -163,6 +163,7 @@ int config_parse_ip_port(GENERIC_PARSER_ARGS);
 int config_parse_join_controllers(GENERIC_PARSER_ARGS);
 #endif // 0
 int config_parse_mtu(GENERIC_PARSER_ARGS);
+int config_parse_rlimit(GENERIC_PARSER_ARGS);
 
 typedef enum Disabled {
         DISABLED_CONFIGURATION,