|
|
803fb7 |
From 128ef85392f68fa32650deab12d6cd2e01ad52cf Mon Sep 17 00:00:00 2001
|
|
|
803fb7 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
803fb7 |
Date: Tue, 10 Nov 2015 16:52:52 +0100
|
|
|
803fb7 |
Subject: [PATCH] core: accept time units for time-based resource limits
|
|
|
803fb7 |
|
|
|
803fb7 |
Let's make sure "LimitCPU=30min" can be parsed properly, following the
|
|
|
803fb7 |
usual logic how we parse time values. Similar for LimitRTTIME=.
|
|
|
803fb7 |
|
|
|
803fb7 |
While we are at it, extend a bit on the man page section about resource
|
|
|
803fb7 |
limits.
|
|
|
803fb7 |
|
|
|
803fb7 |
Fixes: #1772
|
|
|
803fb7 |
|
|
|
803fb7 |
Cherry-picked from: a4c1800284e3546bbfab2dc19eb59bcb91c4a2ca
|
|
|
803fb7 |
Related: #1351415
|
|
|
803fb7 |
---
|
|
|
de8967 |
man/systemd.exec.xml | 86 ++++++++++++++++------
|
|
|
803fb7 |
src/core/load-fragment-gperf.gperf.m4 | 4 +-
|
|
|
de8967 |
src/core/load-fragment.c | 101 ++++++++++++++++++++++++++
|
|
|
803fb7 |
src/core/load-fragment.h | 2 +
|
|
|
de8967 |
src/test/test-unit-file.c | 61 ++++++++++++++++
|
|
|
803fb7 |
5 files changed, 231 insertions(+), 23 deletions(-)
|
|
|
803fb7 |
|
|
|
803fb7 |
diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
|
|
|
803fb7 |
index 25aea1655..cfdcc3d17 100644
|
|
|
803fb7 |
--- a/man/systemd.exec.xml
|
|
|
803fb7 |
+++ b/man/systemd.exec.xml
|
|
|
803fb7 |
@@ -559,90 +559,133 @@
|
|
|
803fb7 |
of various resources for executed processes. See
|
|
|
803fb7 |
<citerefentry><refentrytitle>setrlimit</refentrytitle><manvolnum>2</manvolnum></citerefentry>
|
|
|
803fb7 |
for details. Use the string <varname>infinity</varname> to
|
|
|
803fb7 |
- configure no limit on a specific resource. The multiplicative suffixes
|
|
|
803fb7 |
- K (=1024), M (=1024*1024) and so on for G, T, P and E may be used for
|
|
|
803fb7 |
- resource limits measured in bytes (e.g. LimitAS=16G).</para></listitem>
|
|
|
803fb7 |
+ configure no limit on a specific resource. The multiplicative
|
|
|
803fb7 |
+ suffixes K (=1024), M (=1024*1024) and so on for G, T, P and E
|
|
|
803fb7 |
+ may be used for resource limits measured in bytes
|
|
|
803fb7 |
+ (e.g. LimitAS=16G). For the limits referring to time values,
|
|
|
803fb7 |
+ the usual time units ms, s, min, h and so on may be used (see
|
|
|
803fb7 |
+ <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>
|
|
|
803fb7 |
+ for details). Note that if no time unit is specified for
|
|
|
803fb7 |
+ <varname>LimitCPU=</varname> the default unit of seconds is
|
|
|
803fb7 |
+ implied, while for <varname>LimitRTTIME=</varname> the default
|
|
|
803fb7 |
+ unit of microseconds is implied. Also, note that the effective
|
|
|
803fb7 |
+ granularity of the limits might influence their
|
|
|
803fb7 |
+ enforcement. For example, time limits specified for
|
|
|
803fb7 |
+ <varname>LimitCPU=</varname> will be rounded up implicitly to
|
|
|
803fb7 |
+ multiples of 1s.</para>
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ <para>Note that most process resource limits configured with
|
|
|
803fb7 |
+ these options are per-process, and processes may fork in order
|
|
|
803fb7 |
+ to acquire a new set of resources that are accounted
|
|
|
803fb7 |
+ independently of the original process, and may thus escape
|
|
|
803fb7 |
+ limits set. Also note that <varname>LimitRSS=</varname> is not
|
|
|
803fb7 |
+ implemented on Linux, and setting it has no effect. Often it
|
|
|
803fb7 |
+ is advisable to prefer the resource controls listed in
|
|
|
803fb7 |
+ <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
|
|
803fb7 |
+ over these per-process limits, as they apply to services as a
|
|
|
803fb7 |
+ whole, may be altered dynamically at runtime, and are
|
|
|
803fb7 |
+ generally more expressive. For example,
|
|
|
803fb7 |
+ <varname>MemoryLimit=</varname> is a more powerful (and
|
|
|
803fb7 |
+ working) replacement for <varname>LimitRSS=</varname>.</para>
|
|
|
803fb7 |
|
|
|
803fb7 |
|
|
|
803fb7 |
<title>Limit directives and their equivalent with ulimit</title>
|
|
|
803fb7 |
|
|
|
803fb7 |
- <tgroup cols='2'>
|
|
|
803fb7 |
+ <tgroup cols='3'>
|
|
|
803fb7 |
<colspec colname='directive' />
|
|
|
803fb7 |
<colspec colname='equivalent' />
|
|
|
803fb7 |
+ <colspec colname='unit' />
|
|
|
803fb7 |
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
<entry>Directive</entry>
|
|
|
803fb7 |
<entry>ulimit equivalent</entry>
|
|
|
803fb7 |
+ <entry>Unit</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
|
|
|
803fb7 |
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitCPU</entry>
|
|
|
803fb7 |
+ <entry>LimitCPU=</entry>
|
|
|
803fb7 |
<entry>ulimit -t</entry>
|
|
|
803fb7 |
+ <entry>Seconds</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitFSIZE</entry>
|
|
|
803fb7 |
+ <entry>LimitFSIZE=</entry>
|
|
|
803fb7 |
<entry>ulimit -f</entry>
|
|
|
803fb7 |
+ <entry>Bytes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitDATA</entry>
|
|
|
803fb7 |
+ <entry>LimitDATA=</entry>
|
|
|
803fb7 |
<entry>ulimit -d</entry>
|
|
|
803fb7 |
+ <entry>Bytes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitSTACK</entry>
|
|
|
803fb7 |
+ <entry>LimitSTACK=</entry>
|
|
|
803fb7 |
<entry>ulimit -s</entry>
|
|
|
803fb7 |
+ <entry>Bytes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitCORE</entry>
|
|
|
803fb7 |
+ <entry>LimitCORE=</entry>
|
|
|
803fb7 |
<entry>ulimit -c</entry>
|
|
|
803fb7 |
+ <entry>Bytes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitRSS</entry>
|
|
|
803fb7 |
+ <entry>LimitRSS=</entry>
|
|
|
803fb7 |
<entry>ulimit -m</entry>
|
|
|
803fb7 |
+ <entry>Bytes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitNOFILE</entry>
|
|
|
803fb7 |
+ <entry>LimitNOFILE=</entry>
|
|
|
803fb7 |
<entry>ulimit -n</entry>
|
|
|
803fb7 |
+ <entry>Number of File Descriptors</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitAS</entry>
|
|
|
803fb7 |
+ <entry>LimitAS=</entry>
|
|
|
803fb7 |
<entry>ulimit -v</entry>
|
|
|
803fb7 |
+ <entry>Bytes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitNPROC</entry>
|
|
|
803fb7 |
+ <entry>LimitNPROC=</entry>
|
|
|
803fb7 |
<entry>ulimit -u</entry>
|
|
|
803fb7 |
+ <entry>Number of Processes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitMEMLOCK</entry>
|
|
|
803fb7 |
+ <entry>LimitMEMLOCK=</entry>
|
|
|
803fb7 |
<entry>ulimit -l</entry>
|
|
|
803fb7 |
+ <entry>Bytes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitLOCKS</entry>
|
|
|
803fb7 |
+ <entry>LimitLOCKS=</entry>
|
|
|
803fb7 |
<entry>ulimit -x</entry>
|
|
|
803fb7 |
+ <entry>Number of Locks</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitSIGPENDING</entry>
|
|
|
803fb7 |
+ <entry>LimitSIGPENDING=</entry>
|
|
|
803fb7 |
<entry>ulimit -i</entry>
|
|
|
803fb7 |
+ <entry>Number of Queued Signals</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitMSGQUEUE</entry>
|
|
|
803fb7 |
+ <entry>LimitMSGQUEUE=</entry>
|
|
|
803fb7 |
<entry>ulimit -q</entry>
|
|
|
803fb7 |
+ <entry>Bytes</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitNICE</entry>
|
|
|
803fb7 |
+ <entry>LimitNICE=</entry>
|
|
|
803fb7 |
<entry>ulimit -e</entry>
|
|
|
803fb7 |
+ <entry>Nice Level</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitRTPRIO</entry>
|
|
|
803fb7 |
+ <entry>LimitRTPRIO=</entry>
|
|
|
803fb7 |
<entry>ulimit -r</entry>
|
|
|
803fb7 |
+ <entry>Realtime Priority</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
<row>
|
|
|
803fb7 |
- <entry>LimitRTTIME</entry>
|
|
|
803fb7 |
+ <entry>LimitRTTIME=</entry>
|
|
|
803fb7 |
<entry>No equivalent</entry>
|
|
|
803fb7 |
+ <entry>Microseconds</entry>
|
|
|
803fb7 |
</row>
|
|
|
803fb7 |
|
|
|
803fb7 |
</tgroup>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
+ </listitem>
|
|
|
803fb7 |
</varlistentry>
|
|
|
803fb7 |
|
|
|
803fb7 |
<varlistentry>
|
|
|
803fb7 |
@@ -1266,6 +1309,7 @@
|
|
|
803fb7 |
<citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
|
|
|
803fb7 |
<citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
|
|
|
803fb7 |
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
|
|
|
803fb7 |
+ <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
|
|
|
803fb7 |
<citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
|
|
|
803fb7 |
<citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
|
|
|
803fb7 |
<citerefentry project='man-pages'><refentrytitle>exec</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
803fb7 |
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
|
|
|
803fb7 |
index c3461a0a6..ce1397c7e 100644
|
|
|
803fb7 |
--- a/src/core/load-fragment-gperf.gperf.m4
|
|
|
803fb7 |
+++ b/src/core/load-fragment-gperf.gperf.m4
|
|
|
803fb7 |
@@ -58,7 +58,7 @@ $1.RestrictAddressFamilies, config_parse_address_families, 0,
|
|
|
803fb7 |
$1.SystemCallArchitectures, config_parse_warn_compat, DISABLED_CONFIGURATION, 0
|
|
|
803fb7 |
$1.SystemCallErrorNumber, config_parse_warn_compat, DISABLED_CONFIGURATION, 0
|
|
|
803fb7 |
$1.RestrictAddressFamilies, config_parse_warn_compat, DISABLED_CONFIGURATION, 0')
|
|
|
803fb7 |
-$1.LimitCPU, config_parse_limit, RLIMIT_CPU, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
+$1.LimitCPU, config_parse_sec_limit, RLIMIT_CPU, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
$1.LimitFSIZE, config_parse_bytes_limit, RLIMIT_FSIZE, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
$1.LimitDATA, config_parse_bytes_limit, RLIMIT_DATA, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
$1.LimitSTACK, config_parse_bytes_limit, RLIMIT_STACK, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
@@ -73,7 +73,7 @@ $1.LimitSIGPENDING, config_parse_limit, RLIMIT_SIGP
|
|
|
803fb7 |
$1.LimitMSGQUEUE, config_parse_bytes_limit, RLIMIT_MSGQUEUE, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
$1.LimitNICE, config_parse_limit, RLIMIT_NICE, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
$1.LimitRTPRIO, config_parse_limit, RLIMIT_RTPRIO, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
-$1.LimitRTTIME, config_parse_limit, RLIMIT_RTTIME, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
+$1.LimitRTTIME, config_parse_usec_limit, RLIMIT_RTTIME, offsetof($1, exec_context.rlimit)
|
|
|
803fb7 |
$1.ReadWriteDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.read_write_dirs)
|
|
|
803fb7 |
$1.ReadOnlyDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.read_only_dirs)
|
|
|
803fb7 |
$1.InaccessibleDirectories, config_parse_namespace_path_strv, 0, offsetof($1, exec_context.inaccessible_dirs)
|
|
|
803fb7 |
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
|
|
|
803fb7 |
index dbb45b20f..8afe9d7e8 100644
|
|
|
803fb7 |
--- a/src/core/load-fragment.c
|
|
|
803fb7 |
+++ b/src/core/load-fragment.c
|
|
|
803fb7 |
@@ -1162,6 +1162,107 @@ int config_parse_bytes_limit(const char *unit,
|
|
|
803fb7 |
return 0;
|
|
|
803fb7 |
}
|
|
|
803fb7 |
|
|
|
803fb7 |
+int config_parse_sec_limit(
|
|
|
803fb7 |
+ const char *unit,
|
|
|
803fb7 |
+ const char *filename,
|
|
|
803fb7 |
+ unsigned line,
|
|
|
803fb7 |
+ const char *section,
|
|
|
803fb7 |
+ unsigned section_line,
|
|
|
803fb7 |
+ const char *lvalue,
|
|
|
803fb7 |
+ int ltype,
|
|
|
803fb7 |
+ const char *rvalue,
|
|
|
803fb7 |
+ void *data,
|
|
|
803fb7 |
+ void *userdata) {
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ struct rlimit **rl = data;
|
|
|
803fb7 |
+ rlim_t seconds;
|
|
|
803fb7 |
+ int r;
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert(filename);
|
|
|
803fb7 |
+ assert(lvalue);
|
|
|
803fb7 |
+ assert(rvalue);
|
|
|
803fb7 |
+ assert(data);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ rl += ltype;
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ if (streq(rvalue, "infinity"))
|
|
|
803fb7 |
+ seconds = RLIM_INFINITY;
|
|
|
803fb7 |
+ else {
|
|
|
803fb7 |
+ usec_t t;
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ r = parse_sec(rvalue, &t);
|
|
|
803fb7 |
+ if (r < 0) {
|
|
|
803fb7 |
+ log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse resource value, ignoring: %s", rvalue);
|
|
|
803fb7 |
+ return 0;
|
|
|
803fb7 |
+ }
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ if (t == USEC_INFINITY)
|
|
|
803fb7 |
+ seconds = RLIM_INFINITY;
|
|
|
803fb7 |
+ else
|
|
|
803fb7 |
+ seconds = (rlim_t) (DIV_ROUND_UP(t, USEC_PER_SEC));
|
|
|
803fb7 |
+ }
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ if (!*rl) {
|
|
|
803fb7 |
+ *rl = new(struct rlimit, 1);
|
|
|
803fb7 |
+ if (!*rl)
|
|
|
803fb7 |
+ return log_oom();
|
|
|
803fb7 |
+ }
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ (*rl)->rlim_cur = (*rl)->rlim_max = seconds;
|
|
|
803fb7 |
+ return 0;
|
|
|
803fb7 |
+}
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+int config_parse_usec_limit(
|
|
|
803fb7 |
+ const char *unit,
|
|
|
803fb7 |
+ const char *filename,
|
|
|
803fb7 |
+ unsigned line,
|
|
|
803fb7 |
+ const char *section,
|
|
|
803fb7 |
+ unsigned section_line,
|
|
|
803fb7 |
+ const char *lvalue,
|
|
|
803fb7 |
+ int ltype,
|
|
|
803fb7 |
+ const char *rvalue,
|
|
|
803fb7 |
+ void *data,
|
|
|
803fb7 |
+ void *userdata) {
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ struct rlimit **rl = data;
|
|
|
803fb7 |
+ rlim_t useconds;
|
|
|
803fb7 |
+ int r;
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert(filename);
|
|
|
803fb7 |
+ assert(lvalue);
|
|
|
803fb7 |
+ assert(rvalue);
|
|
|
803fb7 |
+ assert(data);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ rl += ltype;
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ if (streq(rvalue, "infinity"))
|
|
|
803fb7 |
+ useconds = RLIM_INFINITY;
|
|
|
803fb7 |
+ else {
|
|
|
803fb7 |
+ usec_t t;
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ r = parse_time(rvalue, &t, 1);
|
|
|
803fb7 |
+ if (r < 0) {
|
|
|
803fb7 |
+ log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse resource value, ignoring: %s", rvalue);
|
|
|
803fb7 |
+ return 0;
|
|
|
803fb7 |
+ }
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ if (t == USEC_INFINITY)
|
|
|
803fb7 |
+ useconds = RLIM_INFINITY;
|
|
|
803fb7 |
+ else
|
|
|
803fb7 |
+ useconds = (rlim_t) t;
|
|
|
803fb7 |
+ }
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ if (!*rl) {
|
|
|
803fb7 |
+ *rl = new(struct rlimit, 1);
|
|
|
803fb7 |
+ if (!*rl)
|
|
|
803fb7 |
+ return log_oom();
|
|
|
803fb7 |
+ }
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ (*rl)->rlim_cur = (*rl)->rlim_max = useconds;
|
|
|
803fb7 |
+ return 0;
|
|
|
803fb7 |
+}
|
|
|
803fb7 |
+
|
|
|
803fb7 |
#ifdef HAVE_SYSV_COMPAT
|
|
|
803fb7 |
int config_parse_sysv_priority(const char *unit,
|
|
|
803fb7 |
const char *filename,
|
|
|
803fb7 |
diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h
|
|
|
803fb7 |
index 2d509d0cb..359794d0a 100644
|
|
|
803fb7 |
--- a/src/core/load-fragment.h
|
|
|
803fb7 |
+++ b/src/core/load-fragment.h
|
|
|
803fb7 |
@@ -57,6 +57,8 @@ int config_parse_exec_secure_bits(const char *unit, const char *filename, unsign
|
|
|
803fb7 |
int config_parse_bounding_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);
|
|
|
803fb7 |
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);
|
|
|
803fb7 |
int config_parse_bytes_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);
|
|
|
803fb7 |
+int config_parse_sec_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);
|
|
|
803fb7 |
+int config_parse_usec_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);
|
|
|
803fb7 |
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);
|
|
|
803fb7 |
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);
|
|
|
803fb7 |
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);
|
|
|
803fb7 |
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
|
|
|
803fb7 |
index 550098332..d15173796 100644
|
|
|
803fb7 |
--- a/src/test/test-unit-file.c
|
|
|
803fb7 |
+++ b/src/test/test-unit-file.c
|
|
|
803fb7 |
@@ -545,6 +545,66 @@ static void test_install_printf(void) {
|
|
|
803fb7 |
expect(i4, "%U", "0");
|
|
|
803fb7 |
}
|
|
|
803fb7 |
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+static void test_config_parse_rlimit(void) {
|
|
|
803fb7 |
+ struct rlimit * rl[_RLIMIT_MAX] = {};
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_limit(NULL, "fake", 1, "section", 1, "LimitNOFILE", RLIMIT_NOFILE, "55", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_NOFILE]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_NOFILE]->rlim_cur == 55);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_NOFILE]->rlim_cur == rl[RLIMIT_NOFILE]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_limit(NULL, "fake", 1, "section", 1, "LimitNOFILE", RLIMIT_NOFILE, "infinity", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_NOFILE]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_NOFILE]->rlim_cur == RLIM_INFINITY);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_NOFILE]->rlim_cur == rl[RLIMIT_NOFILE]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ rl[RLIMIT_NOFILE] = free(rl[RLIMIT_NOFILE]);
|
|
|
803fb7 |
+ assert_se(config_parse_sec_limit(NULL, "fake", 1, "section", 1, "LimitCPU", RLIMIT_CPU, "56", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]->rlim_cur == 56);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]->rlim_cur == rl[RLIMIT_CPU]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_sec_limit(NULL, "fake", 1, "section", 1, "LimitCPU", RLIMIT_CPU, "57s", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]->rlim_cur == 57);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]->rlim_cur == rl[RLIMIT_CPU]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_sec_limit(NULL, "fake", 1, "section", 1, "LimitCPU", RLIMIT_CPU, "infinity", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]->rlim_cur == RLIM_INFINITY);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]->rlim_cur == rl[RLIMIT_CPU]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_sec_limit(NULL, "fake", 1, "section", 1, "LimitCPU", RLIMIT_CPU, "1234ms", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]->rlim_cur == 2);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_CPU]->rlim_cur == rl[RLIMIT_CPU]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ rl[RLIMIT_CPU] = free(rl[RLIMIT_CPU]);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_usec_limit(NULL, "fake", 1, "section", 1, "LimitRTTIME", RLIMIT_RTTIME, "58", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]->rlim_cur == 58);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]->rlim_cur == rl[RLIMIT_RTTIME]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_usec_limit(NULL, "fake", 1, "section", 1, "LimitRTTIME", RLIMIT_RTTIME, "59s", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]->rlim_cur == 59 * USEC_PER_SEC);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]->rlim_cur == rl[RLIMIT_RTTIME]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_usec_limit(NULL, "fake", 1, "section", 1, "LimitRTTIME", RLIMIT_RTTIME, "infinity", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]->rlim_cur == RLIM_INFINITY);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]->rlim_cur == rl[RLIMIT_RTTIME]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ assert_se(config_parse_usec_limit(NULL, "fake", 1, "section", 1, "LimitRTTIME", RLIMIT_RTTIME, "2345ms", rl, NULL) >= 0);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]->rlim_cur == 2345 * USEC_PER_MSEC);
|
|
|
803fb7 |
+ assert_se(rl[RLIMIT_RTTIME]->rlim_cur == rl[RLIMIT_RTTIME]->rlim_max);
|
|
|
803fb7 |
+
|
|
|
803fb7 |
+ rl[RLIMIT_RTTIME] = free(rl[RLIMIT_RTTIME]);
|
|
|
803fb7 |
+}
|
|
|
803fb7 |
+
|
|
|
803fb7 |
int main(int argc, char *argv[]) {
|
|
|
803fb7 |
int r;
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -553,6 +613,7 @@ int main(int argc, char *argv[]) {
|
|
|
803fb7 |
|
|
|
803fb7 |
r = test_unit_file_get_set();
|
|
|
803fb7 |
test_config_parse_exec();
|
|
|
803fb7 |
+ test_config_parse_rlimit();
|
|
|
803fb7 |
test_load_env_file_1();
|
|
|
803fb7 |
test_load_env_file_2();
|
|
|
803fb7 |
test_load_env_file_3();
|