X Tutup
Skip to content

Commit 4f424df

Browse files
committed
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.
1 parent 6550c24 commit 4f424df

File tree

7 files changed

+95
-96
lines changed

7 files changed

+95
-96
lines changed

src/core/load-fragment-gperf.gperf.m4

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,22 @@ $1.RestrictNamespaces, config_parse_warn_compat, DISABLED_CO
8282
$1.RestrictRealtime, config_parse_warn_compat, DISABLED_CONFIGURATION, 0
8383
$1.RestrictAddressFamilies, config_parse_warn_compat, DISABLED_CONFIGURATION, 0
8484
$1.LockPersonality, config_parse_warn_compat, DISABLED_CONFIGURATION, 0')
85-
$1.LimitCPU, config_parse_limit, RLIMIT_CPU, offsetof($1, exec_context.rlimit)
86-
$1.LimitFSIZE, config_parse_limit, RLIMIT_FSIZE, offsetof($1, exec_context.rlimit)
87-
$1.LimitDATA, config_parse_limit, RLIMIT_DATA, offsetof($1, exec_context.rlimit)
88-
$1.LimitSTACK, config_parse_limit, RLIMIT_STACK, offsetof($1, exec_context.rlimit)
89-
$1.LimitCORE, config_parse_limit, RLIMIT_CORE, offsetof($1, exec_context.rlimit)
90-
$1.LimitRSS, config_parse_limit, RLIMIT_RSS, offsetof($1, exec_context.rlimit)
91-
$1.LimitNOFILE, config_parse_limit, RLIMIT_NOFILE, offsetof($1, exec_context.rlimit)
92-
$1.LimitAS, config_parse_limit, RLIMIT_AS, offsetof($1, exec_context.rlimit)
93-
$1.LimitNPROC, config_parse_limit, RLIMIT_NPROC, offsetof($1, exec_context.rlimit)
94-
$1.LimitMEMLOCK, config_parse_limit, RLIMIT_MEMLOCK, offsetof($1, exec_context.rlimit)
95-
$1.LimitLOCKS, config_parse_limit, RLIMIT_LOCKS, offsetof($1, exec_context.rlimit)
96-
$1.LimitSIGPENDING, config_parse_limit, RLIMIT_SIGPENDING, offsetof($1, exec_context.rlimit)
97-
$1.LimitMSGQUEUE, config_parse_limit, RLIMIT_MSGQUEUE, offsetof($1, exec_context.rlimit)
98-
$1.LimitNICE, config_parse_limit, RLIMIT_NICE, offsetof($1, exec_context.rlimit)
99-
$1.LimitRTPRIO, config_parse_limit, RLIMIT_RTPRIO, offsetof($1, exec_context.rlimit)
100-
$1.LimitRTTIME, config_parse_limit, RLIMIT_RTTIME, offsetof($1, exec_context.rlimit)
85+
$1.LimitCPU, config_parse_rlimit, RLIMIT_CPU, offsetof($1, exec_context.rlimit)
86+
$1.LimitFSIZE, config_parse_rlimit, RLIMIT_FSIZE, offsetof($1, exec_context.rlimit)
87+
$1.LimitDATA, config_parse_rlimit, RLIMIT_DATA, offsetof($1, exec_context.rlimit)
88+
$1.LimitSTACK, config_parse_rlimit, RLIMIT_STACK, offsetof($1, exec_context.rlimit)
89+
$1.LimitCORE, config_parse_rlimit, RLIMIT_CORE, offsetof($1, exec_context.rlimit)
90+
$1.LimitRSS, config_parse_rlimit, RLIMIT_RSS, offsetof($1, exec_context.rlimit)
91+
$1.LimitNOFILE, config_parse_rlimit, RLIMIT_NOFILE, offsetof($1, exec_context.rlimit)
92+
$1.LimitAS, config_parse_rlimit, RLIMIT_AS, offsetof($1, exec_context.rlimit)
93+
$1.LimitNPROC, config_parse_rlimit, RLIMIT_NPROC, offsetof($1, exec_context.rlimit)
94+
$1.LimitMEMLOCK, config_parse_rlimit, RLIMIT_MEMLOCK, offsetof($1, exec_context.rlimit)
95+
$1.LimitLOCKS, config_parse_rlimit, RLIMIT_LOCKS, offsetof($1, exec_context.rlimit)
96+
$1.LimitSIGPENDING, config_parse_rlimit, RLIMIT_SIGPENDING, offsetof($1, exec_context.rlimit)
97+
$1.LimitMSGQUEUE, config_parse_rlimit, RLIMIT_MSGQUEUE, offsetof($1, exec_context.rlimit)
98+
$1.LimitNICE, config_parse_rlimit, RLIMIT_NICE, offsetof($1, exec_context.rlimit)
99+
$1.LimitRTPRIO, config_parse_rlimit, RLIMIT_RTPRIO, offsetof($1, exec_context.rlimit)
100+
$1.LimitRTTIME, config_parse_rlimit, RLIMIT_RTTIME, offsetof($1, exec_context.rlimit)
101101
$1.ReadWriteDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.read_write_paths)
102102
$1.ReadOnlyDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.read_only_paths)
103103
$1.InaccessibleDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.inaccessible_paths)

src/core/load-fragment.c

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "parse-util.h"
4646
#include "path-util.h"
4747
#include "process-util.h"
48-
#include "rlimit-util.h"
4948
#if HAVE_SECCOMP
5049
#include "seccomp-util.h"
5150
#endif
@@ -1370,47 +1369,6 @@ int config_parse_capability_set(
13701369
return 0;
13711370
}
13721371

1373-
int config_parse_limit(
1374-
const char *unit,
1375-
const char *filename,
1376-
unsigned line,
1377-
const char *section,
1378-
unsigned section_line,
1379-
const char *lvalue,
1380-
int ltype,
1381-
const char *rvalue,
1382-
void *data,
1383-
void *userdata) {
1384-
1385-
struct rlimit **rl = data, d = {};
1386-
int r;
1387-
1388-
assert(filename);
1389-
assert(lvalue);
1390-
assert(rvalue);
1391-
assert(data);
1392-
1393-
r = rlimit_parse(ltype, rvalue, &d);
1394-
if (r == -EILSEQ) {
1395-
log_syntax(unit, LOG_WARNING, filename, line, r, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue);
1396-
return 0;
1397-
}
1398-
if (r < 0) {
1399-
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse resource value, ignoring: %s", rvalue);
1400-
return 0;
1401-
}
1402-
1403-
if (rl[ltype])
1404-
*rl[ltype] = d;
1405-
else {
1406-
rl[ltype] = newdup(struct rlimit, &d, 1);
1407-
if (!rl[ltype])
1408-
return log_oom();
1409-
}
1410-
1411-
return 0;
1412-
}
1413-
14141372
#if HAVE_SYSV_COMPAT
14151373
int config_parse_sysv_priority(const char *unit,
14161374
const char *filename,
@@ -4914,7 +4872,7 @@ void unit_dump_config_items(FILE *f) {
49144872
{ config_parse_log_level, "LEVEL" },
49154873
{ config_parse_exec_secure_bits, "SECUREBITS" },
49164874
{ config_parse_capability_set, "BOUNDINGSET" },
4917-
{ config_parse_limit, "LIMIT" },
4875+
{ config_parse_rlimit, "LIMIT" },
49184876
{ config_parse_unit_deps, "UNIT [...]" },
49194877
{ config_parse_exec, "PATH [ARGUMENT [...]]" },
49204878
{ config_parse_service_type, "SERVICETYPE" },

src/core/load-fragment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ int config_parse_exec_cpu_sched_prio(const char *unit, const char *filename, uns
4343
int config_parse_exec_cpu_affinity(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);
4444
int config_parse_exec_secure_bits(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);
4545
int config_parse_capability_set(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);
46-
int config_parse_limit(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);
4746
int config_parse_sysv_priority(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);
4847
int config_parse_kill_signal(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);
4948
int config_parse_exec_mount_flags(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);

src/core/main.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -675,22 +675,22 @@ static int parse_config_file(void) {
675675
{ "Manager", "DefaultStartLimitIntervalSec",config_parse_sec, 0, &arg_default_start_limit_interval },
676676
{ "Manager", "DefaultStartLimitBurst", config_parse_unsigned, 0, &arg_default_start_limit_burst },
677677
{ "Manager", "DefaultEnvironment", config_parse_environ, 0, &arg_default_environment },
678-
{ "Manager", "DefaultLimitCPU", config_parse_limit, RLIMIT_CPU, arg_default_rlimit },
679-
{ "Manager", "DefaultLimitFSIZE", config_parse_limit, RLIMIT_FSIZE, arg_default_rlimit },
680-
{ "Manager", "DefaultLimitDATA", config_parse_limit, RLIMIT_DATA, arg_default_rlimit },
681-
{ "Manager", "DefaultLimitSTACK", config_parse_limit, RLIMIT_STACK, arg_default_rlimit },
682-
{ "Manager", "DefaultLimitCORE", config_parse_limit, RLIMIT_CORE, arg_default_rlimit },
683-
{ "Manager", "DefaultLimitRSS", config_parse_limit, RLIMIT_RSS, arg_default_rlimit },
684-
{ "Manager", "DefaultLimitNOFILE", config_parse_limit, RLIMIT_NOFILE, arg_default_rlimit },
685-
{ "Manager", "DefaultLimitAS", config_parse_limit, RLIMIT_AS, arg_default_rlimit },
686-
{ "Manager", "DefaultLimitNPROC", config_parse_limit, RLIMIT_NPROC, arg_default_rlimit },
687-
{ "Manager", "DefaultLimitMEMLOCK", config_parse_limit, RLIMIT_MEMLOCK, arg_default_rlimit },
688-
{ "Manager", "DefaultLimitLOCKS", config_parse_limit, RLIMIT_LOCKS, arg_default_rlimit },
689-
{ "Manager", "DefaultLimitSIGPENDING", config_parse_limit, RLIMIT_SIGPENDING, arg_default_rlimit },
690-
{ "Manager", "DefaultLimitMSGQUEUE", config_parse_limit, RLIMIT_MSGQUEUE, arg_default_rlimit },
691-
{ "Manager", "DefaultLimitNICE", config_parse_limit, RLIMIT_NICE, arg_default_rlimit },
692-
{ "Manager", "DefaultLimitRTPRIO", config_parse_limit, RLIMIT_RTPRIO, arg_default_rlimit },
693-
{ "Manager", "DefaultLimitRTTIME", config_parse_limit, RLIMIT_RTTIME, arg_default_rlimit },
678+
{ "Manager", "DefaultLimitCPU", config_parse_rlimit, RLIMIT_CPU, arg_default_rlimit },
679+
{ "Manager", "DefaultLimitFSIZE", config_parse_rlimit, RLIMIT_FSIZE, arg_default_rlimit },
680+
{ "Manager", "DefaultLimitDATA", config_parse_rlimit, RLIMIT_DATA, arg_default_rlimit },
681+
{ "Manager", "DefaultLimitSTACK", config_parse_rlimit, RLIMIT_STACK, arg_default_rlimit },
682+
{ "Manager", "DefaultLimitCORE", config_parse_rlimit, RLIMIT_CORE, arg_default_rlimit },
683+
{ "Manager", "DefaultLimitRSS", config_parse_rlimit, RLIMIT_RSS, arg_default_rlimit },
684+
{ "Manager", "DefaultLimitNOFILE", config_parse_rlimit, RLIMIT_NOFILE, arg_default_rlimit },
685+
{ "Manager", "DefaultLimitAS", config_parse_rlimit, RLIMIT_AS, arg_default_rlimit },
686+
{ "Manager", "DefaultLimitNPROC", config_parse_rlimit, RLIMIT_NPROC, arg_default_rlimit },
687+
{ "Manager", "DefaultLimitMEMLOCK", config_parse_rlimit, RLIMIT_MEMLOCK, arg_default_rlimit },
688+
{ "Manager", "DefaultLimitLOCKS", config_parse_rlimit, RLIMIT_LOCKS, arg_default_rlimit },
689+
{ "Manager", "DefaultLimitSIGPENDING", config_parse_rlimit, RLIMIT_SIGPENDING, arg_default_rlimit },
690+
{ "Manager", "DefaultLimitMSGQUEUE", config_parse_rlimit, RLIMIT_MSGQUEUE, arg_default_rlimit },
691+
{ "Manager", "DefaultLimitNICE", config_parse_rlimit, RLIMIT_NICE, arg_default_rlimit },
692+
{ "Manager", "DefaultLimitRTPRIO", config_parse_rlimit, RLIMIT_RTPRIO, arg_default_rlimit },
693+
{ "Manager", "DefaultLimitRTTIME", config_parse_rlimit, RLIMIT_RTTIME, arg_default_rlimit },
694694
{ "Manager", "DefaultCPUAccounting", config_parse_bool, 0, &arg_default_cpu_accounting },
695695
{ "Manager", "DefaultIOAccounting", config_parse_bool, 0, &arg_default_io_accounting },
696696
{ "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_default_ip_accounting },

src/shared/conf-parser.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "syslog-util.h"
3434
#include "time-util.h"
3535
#include "utf8.h"
36+
#include "rlimit-util.h"
3637

3738
int config_item_table_lookup(
3839
const void *table,
@@ -1214,3 +1215,42 @@ int config_parse_mtu(
12141215

12151216
return 0;
12161217
}
1218+
1219+
int config_parse_rlimit(
1220+
const char *unit,
1221+
const char *filename,
1222+
unsigned line,
1223+
const char *section,
1224+
unsigned section_line,
1225+
const char *lvalue,
1226+
int ltype,
1227+
const char *rvalue,
1228+
void *data,
1229+
void *userdata) {
1230+
1231+
struct rlimit **rl = data, d = {};
1232+
int r;
1233+
1234+
assert(rvalue);
1235+
assert(rl);
1236+
1237+
r = rlimit_parse(ltype, rvalue, &d);
1238+
if (r == -EILSEQ) {
1239+
log_syntax(unit, LOG_WARNING, filename, line, r, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue);
1240+
return 0;
1241+
}
1242+
if (r < 0) {
1243+
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse resource value, ignoring: %s", rvalue);
1244+
return 0;
1245+
}
1246+
1247+
if (rl[ltype])
1248+
*rl[ltype] = d;
1249+
else {
1250+
rl[ltype] = newdup(struct rlimit, &d, 1);
1251+
if (!rl[ltype])
1252+
return log_oom();
1253+
}
1254+
1255+
return 0;
1256+
}

src/shared/conf-parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ int config_parse_ifname(GENERIC_PARSER_ARGS);
147147
int config_parse_ip_port(GENERIC_PARSER_ARGS);
148148
int config_parse_join_controllers(GENERIC_PARSER_ARGS);
149149
int config_parse_mtu(GENERIC_PARSER_ARGS);
150+
int config_parse_rlimit(GENERIC_PARSER_ARGS);
150151

151152
typedef enum Disabled {
152153
DISABLED_CONFIGURATION,

0 commit comments

Comments
 (0)
X Tutup