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.
This commit is contained in:
Lennart Poettering
2018-05-17 20:36:52 +02:00
parent 6550c24c7f
commit 4f424df760
7 changed files with 95 additions and 96 deletions
+40
View File
@@ -33,6 +33,7 @@
#include "syslog-util.h"
#include "time-util.h"
#include "utf8.h"
#include "rlimit-util.h"
int config_item_table_lookup(
const void *table,
@@ -1214,3 +1215,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;
}
+1
View File
@@ -147,6 +147,7 @@ int config_parse_ifname(GENERIC_PARSER_ARGS);
int config_parse_ip_port(GENERIC_PARSER_ARGS);
int config_parse_join_controllers(GENERIC_PARSER_ARGS);
int config_parse_mtu(GENERIC_PARSER_ARGS);
int config_parse_rlimit(GENERIC_PARSER_ARGS);
typedef enum Disabled {
DISABLED_CONFIGURATION,