summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-05-03 19:01:21 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commit479f41009ad4ea369a382b255bdf0378a3153356 (patch)
treef57125fbe00cdce69bc70f1055dfcfb0e7f2053a /src/shared
parent54b2f26b4022d7bb19bca1fc0bb192a5f34bcebb (diff)
core: move config_parse_limit() to the generic conf-parser.[ch]
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.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/conf-parser.c40
-rw-r--r--src/shared/conf-parser.h1
2 files changed, 41 insertions, 0 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 73591f70f..d570a7068 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -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;
+}
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index 38a82f6e3..7b5a3c2b3 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -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,