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