From: Lennart Poettering Date: Thu, 3 May 2018 17:01:21 +0000 (+0200) Subject: core: move config_parse_limit() to the generic conf-parser.[ch] X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=479f41009ad4ea369a382b255bdf0378a3153356;p=elogind.git 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. --- 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,