1
0
mirror of https://github.com/systemd/systemd synced 2025-10-01 17:54:45 +02:00

Compare commits

..

No commits in common. "bfe6043454da12ef4e48856974b44fafc0b7028f" and "1f3315b8bdbc9240f70f90373f2b9043f2087ac5" have entirely different histories.

60 changed files with 606 additions and 947 deletions

View File

@ -10,4 +10,3 @@ jobs:
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/labeler.yml
sync-labels: "" # This is a workaround for issue 18671

8
NEWS
View File

@ -153,8 +153,8 @@ CHANGES WITH 248:
ManageTemporaryAddress= switch.
.network files gained a new ActivationPolicy= setting which allows
configuration how the UP state of an interface shall be managed,
i.e. whether the interface is always upped, always downed, or may be
configuraiton how the UP state of an interface shall be managed,
i.e. whether the iterface is always upped, always downed, or may be
upped/downed by the user using "ip dev".
* systemd.netdev files gained a [VLAN] Protocol=, IngressQOSMaps=,
@ -261,7 +261,7 @@ CHANGES WITH 248:
specific variables, and not the full inherited environment.
* systemctl's status output now shows unit state with a more careful
selection of Unicode characters: units in maintenance show a "○"
selection of Unicode characters: units in maintainance show a "○"
symbol instead of the usual "●", failed units show "×", and services
being reloaded "↻".
@ -277,7 +277,7 @@ CHANGES WITH 248:
many terminal colours are used in output.
* less 568 or newer is now required. Hyperlink ANSI sequences in
terminal output are now used even if a pager is used, and older
termina output are now used even if a pager is used, and older
versions of less are not able to display these sequences
correctly. SYSTEMD_URLIFY=0 may be used to disable it.

View File

@ -48,38 +48,36 @@
<variablelist class='config-directives'>
<varlistentry>
<term><varname>SwapUsedLimit=</varname></term>
<term><varname>SwapUsedLimitPercent=</varname></term>
<listitem><para>Sets the limit for swap usage on the system before <command>systemd-oomd</command>
will take action. If the fraction of swap used on the system is more than what is defined here,
<command>systemd-oomd</command> will act on eligible descendant control groups, starting from the
ones with the highest swap usage to the lowest swap usage. Which control groups are monitored and
what action gets taken depends on what the unit has configured for
<varname>ManagedOOMSwap=</varname>. Takes a value specified in percent (when suffixed with "%"),
permille ("‰") or permyriad ("‱"), between 0% and 100%, inclusive. Defaults to 90%.</para></listitem>
<listitem><para>Sets the limit for swap usage on the system before <command>systemd-oomd</command> will
take action. If the percentage of swap used on the system is more than what is defined here,
<command>systemd-oomd</command> will act on eligible descendant cgroups, starting from the ones with the
highest swap usage to the lowest swap usage. Which cgroups are monitored and what
action gets taken depends on what the unit has configured for <varname>ManagedOOMSwap=</varname>.
Takes a percentage value between 0% and 100%, inclusive. Defaults to 90%.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>DefaultMemoryPressureLimit=</varname></term>
<listitem><para>Sets the limit for memory pressure on the unit's control group before
<command>systemd-oomd</command> will take action. A unit can override this value with
<varname>ManagedOOMMemoryPressureLimit=</varname>. The memory pressure for this property represents
the fraction of time in a 10 second window in which all tasks in the control group were delayed. For
each monitored control group, if the memory pressure on that control group exceeds the limit set for
longer than the duration set by <varname>DefaultMemoryPressureDurationSec=</varname>,
<command>systemd-oomd</command> will act on eligible descendant control groups, starting from the
ones with the most reclaim activity to the least reclaim activity. Which control groups are monitored
and what action gets taken depends on what the unit has configured for
<varname>ManagedOOMMemoryPressure=</varname>. Takes a fraction specified in the same way as
<varname>SwapUsedLimit=</varname> above. Defaults to 60%.</para></listitem>
<listitem><para>Sets the limit for memory pressure on the unit's cgroup before <command>systemd-oomd</command>
will take action. A unit can override this value with <varname>ManagedOOMMemoryPressureLimit=</varname>.
The memory pressure for this property represents the fraction of time in a 10 second window in which all tasks
in the cgroup were delayed. For each monitored cgroup, if the memory pressure on that cgroup exceeds the
limit set for longer than the duration set by <varname>DefaultMemoryPressureDurationSec=</varname>,
<command>systemd-oomd</command> will act on eligible descendant cgroups,
starting from the ones with the most reclaim activity to the least reclaim activity. Which cgroups are
monitored and what action gets taken depends on what the unit has configured for
<varname>ManagedOOMMemoryPressure=</varname>. Takes a percentage value between 0% and 100%, inclusive.
Defaults to 60%.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>DefaultMemoryPressureDurationSec=</varname></term>
<listitem><para>Sets the amount of time a unit's control group needs to have exceeded memory pressure
limits before <command>systemd-oomd</command> will take action. Memory pressure limits are defined by
<listitem><para>Sets the amount of time a unit's cgroup needs to have exceeded memory pressure limits before
<command>systemd-oomd</command> will take action. Memory pressure limits are defined by
<varname>DefaultMemoryPressureLimit=</varname> and <varname>ManagedOOMMemoryPressureLimit=</varname>.
Defaults to 30 seconds when this property is unset or set to 0.</para></listitem>
</varlistentry>

View File

@ -2469,7 +2469,7 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMMemoryPressure = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly u ManagedOOMMemoryPressureLimit = ...;
readonly u ManagedOOMMemoryPressureLimitPermyriad = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMPreference = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
@ -2994,7 +2994,7 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
<!--property ManagedOOMMemoryPressure is not documented!-->
<!--property ManagedOOMMemoryPressureLimit is not documented!-->
<!--property ManagedOOMMemoryPressureLimitPermyriad is not documented!-->
<!--property ManagedOOMPreference is not documented!-->
@ -3560,7 +3560,7 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressure"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimit"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimitPermyriad"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMPreference"/>
@ -4229,7 +4229,7 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket {
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMMemoryPressure = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly u ManagedOOMMemoryPressureLimit = ...;
readonly u ManagedOOMMemoryPressureLimitPermyriad = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMPreference = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
@ -4782,7 +4782,7 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket {
<!--property ManagedOOMMemoryPressure is not documented!-->
<!--property ManagedOOMMemoryPressureLimit is not documented!-->
<!--property ManagedOOMMemoryPressureLimitPermyriad is not documented!-->
<!--property ManagedOOMPreference is not documented!-->
@ -5346,7 +5346,7 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket {
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressure"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimit"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimitPermyriad"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMPreference"/>
@ -5928,7 +5928,7 @@ node /org/freedesktop/systemd1/unit/home_2emount {
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMMemoryPressure = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly u ManagedOOMMemoryPressureLimit = ...;
readonly u ManagedOOMMemoryPressureLimitPermyriad = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMPreference = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
@ -6409,7 +6409,7 @@ node /org/freedesktop/systemd1/unit/home_2emount {
<!--property ManagedOOMMemoryPressure is not documented!-->
<!--property ManagedOOMMemoryPressureLimit is not documented!-->
<!--property ManagedOOMMemoryPressureLimitPermyriad is not documented!-->
<!--property ManagedOOMPreference is not documented!-->
@ -6891,7 +6891,7 @@ node /org/freedesktop/systemd1/unit/home_2emount {
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressure"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimit"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimitPermyriad"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMPreference"/>
@ -7594,7 +7594,7 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap {
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMMemoryPressure = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly u ManagedOOMMemoryPressureLimit = ...;
readonly u ManagedOOMMemoryPressureLimitPermyriad = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMPreference = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
@ -8061,7 +8061,7 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap {
<!--property ManagedOOMMemoryPressure is not documented!-->
<!--property ManagedOOMMemoryPressureLimit is not documented!-->
<!--property ManagedOOMMemoryPressureLimitPermyriad is not documented!-->
<!--property ManagedOOMPreference is not documented!-->
@ -8529,7 +8529,7 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap {
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressure"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimit"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimitPermyriad"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMPreference"/>
@ -9085,7 +9085,7 @@ node /org/freedesktop/systemd1/unit/system_2eslice {
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMMemoryPressure = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly u ManagedOOMMemoryPressureLimit = ...;
readonly u ManagedOOMMemoryPressureLimitPermyriad = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMPreference = '...';
};
@ -9222,7 +9222,7 @@ node /org/freedesktop/systemd1/unit/system_2eslice {
<!--property ManagedOOMMemoryPressure is not documented!-->
<!--property ManagedOOMMemoryPressureLimit is not documented!-->
<!--property ManagedOOMMemoryPressureLimitPermyriad is not documented!-->
<!--property ManagedOOMPreference is not documented!-->
@ -9364,7 +9364,7 @@ node /org/freedesktop/systemd1/unit/system_2eslice {
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressure"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimit"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimitPermyriad"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMPreference"/>
@ -9526,7 +9526,7 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMMemoryPressure = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly u ManagedOOMMemoryPressureLimit = ...;
readonly u ManagedOOMMemoryPressureLimitPermyriad = ...;
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
readonly s ManagedOOMPreference = '...';
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
@ -9679,7 +9679,7 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
<!--property ManagedOOMMemoryPressure is not documented!-->
<!--property ManagedOOMMemoryPressureLimit is not documented!-->
<!--property ManagedOOMMemoryPressureLimitPermyriad is not documented!-->
<!--property ManagedOOMPreference is not documented!-->
@ -9847,7 +9847,7 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressure"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimit"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMMemoryPressureLimitPermyriad"/>
<variablelist class="dbus-property" generated="True" extra-ref="ManagedOOMPreference"/>

View File

@ -55,7 +55,7 @@
<varlistentry>
<term><command>query</command> <replaceable>HOSTNAME|ADDRESS</replaceable></term>
<listitem><para>Resolve domain names, as well as IPv4 and IPv6 addresses. When used in conjunction
<listitem><para>Resolve domain names, as well as IPv4 and IPv6 addresses. When used in conjuntion
with <option>--type=</option> or <option>--class=</option> (see below), resolves low-level DNS
resource records.</para>

View File

@ -44,9 +44,8 @@
<para>The default configuration is set during compilation, so configuration is only needed when it is
necessary to deviate from those defaults. Initially, the main configuration file in
<filename>/etc/systemd/</filename> contains commented out entries showing the defaults as a guide to the
administrator. Local overrides can be created by editing this file or by creating drop-ins, as described
below. Using drop-ins for local configuration is recommended over modifications to the main configuration
file.</para>
administrator. Local overrides can be created by editing this file or by creating drop-ins, see below.
</para>
<para>In addition to the "main" configuration file, drop-in configuration snippets are read from
<filename>/usr/lib/systemd/*.conf.d/</filename>, <filename>/usr/local/lib/systemd/*.conf.d/</filename>,

View File

@ -77,13 +77,7 @@ uint64_t physical_memory(void) {
}
uint64_t physical_memory_scale(uint64_t v, uint64_t max) {
uint64_t p, m, ps;
/* Shortcut two special cases */
if (v == 0)
return 0;
if (v == max)
return physical_memory();
uint64_t p, m, ps, r;
assert(max > 0);
@ -96,16 +90,17 @@ uint64_t physical_memory_scale(uint64_t v, uint64_t max) {
p = physical_memory() / ps;
assert(p > 0);
if (v > UINT64_MAX / p)
m = p * v;
if (m / p != v)
return UINT64_MAX;
m = p * v;
m /= max;
if (m > UINT64_MAX / ps)
r = m * ps;
if (r / ps != m)
return UINT64_MAX;
return m * ps;
return r;
}
uint64_t system_tasks_max(void) {
@ -143,12 +138,6 @@ uint64_t system_tasks_max(void) {
uint64_t system_tasks_max_scale(uint64_t v, uint64_t max) {
uint64_t t, m;
/* Shortcut two special cases */
if (v == 0)
return 0;
if (v == max)
return system_tasks_max();
assert(max > 0);
/* Multiply the system's task value by the fraction v/max. Hence, if max==100 this calculates percentages
@ -157,9 +146,9 @@ uint64_t system_tasks_max_scale(uint64_t v, uint64_t max) {
t = system_tasks_max();
assert(t > 0);
if (v > UINT64_MAX / t) /* overflow? */
m = t * v;
if (m / t != v) /* overflow? */
return UINT64_MAX;
m = t * v;
return m / max;
}

View File

@ -176,8 +176,6 @@ basic_sources = files('''
path-lookup.h
path-util.c
path-util.h
percent-util.c
percent-util.h
prioq.c
prioq.h
proc-cmdline.c

View File

@ -627,6 +627,146 @@ int parse_fractional_part_u(const char **p, size_t digits, unsigned *res) {
return 0;
}
static int parse_parts_value_whole(const char *p, const char *symbol) {
const char *pc, *n;
int r, v;
pc = endswith(p, symbol);
if (!pc)
return -EINVAL;
n = strndupa(p, pc - p);
r = safe_atoi(n, &v);
if (r < 0)
return r;
if (v < 0)
return -ERANGE;
return v;
}
static int parse_parts_value_with_tenths_place(const char *p, const char *symbol) {
const char *pc, *dot, *n;
int r, q, v;
pc = endswith(p, symbol);
if (!pc)
return -EINVAL;
dot = memchr(p, '.', pc - p);
if (dot) {
if (dot + 2 != pc)
return -EINVAL;
if (dot[1] < '0' || dot[1] > '9')
return -EINVAL;
q = dot[1] - '0';
n = strndupa(p, dot - p);
} else {
q = 0;
n = strndupa(p, pc - p);
}
r = safe_atoi(n, &v);
if (r < 0)
return r;
if (v < 0)
return -ERANGE;
if (v > (INT_MAX - q) / 10)
return -ERANGE;
v = v * 10 + q;
return v;
}
static int parse_parts_value_with_hundredths_place(const char *p, const char *symbol) {
const char *pc, *dot, *n;
int r, q, v;
pc = endswith(p, symbol);
if (!pc)
return -EINVAL;
dot = memchr(p, '.', pc - p);
if (dot) {
if (dot + 3 != pc)
return -EINVAL;
if (dot[1] < '0' || dot[1] > '9' || dot[2] < '0' || dot[2] > '9')
return -EINVAL;
q = (dot[1] - '0') * 10 + (dot[2] - '0');
n = strndupa(p, dot - p);
} else {
q = 0;
n = strndupa(p, pc - p);
}
r = safe_atoi(n, &v);
if (r < 0)
return r;
if (v < 0)
return -ERANGE;
if (v > (INT_MAX - q) / 100)
return -ERANGE;
v = v * 100 + q;
return v;
}
int parse_percent_unbounded(const char *p) {
return parse_parts_value_whole(p, "%");
}
int parse_percent(const char *p) {
int v;
v = parse_percent_unbounded(p);
if (v > 100)
return -ERANGE;
return v;
}
int parse_permille_unbounded(const char *p) {
const char *pm;
pm = endswith(p, "");
if (pm)
return parse_parts_value_whole(p, "");
return parse_parts_value_with_tenths_place(p, "%");
}
int parse_permille(const char *p) {
int v;
v = parse_permille_unbounded(p);
if (v > 1000)
return -ERANGE;
return v;
}
int parse_permyriad_unbounded(const char *p) {
const char *pm;
pm = endswith(p, "");
if (pm)
return parse_parts_value_whole(p, "");
pm = endswith(p, "");
if (pm)
return parse_parts_value_with_tenths_place(p, "");
return parse_parts_value_with_hundredths_place(p, "%");
}
int parse_permyriad(const char *p) {
int v;
v = parse_permyriad_unbounded(p);
if (v > 10000)
return -ERANGE;
return v;
}
int parse_nice(const char *p, int *ret) {
int n, r;

View File

@ -127,6 +127,15 @@ int safe_atod(const char *s, double *ret_d);
int parse_fractional_part_u(const char **s, size_t digits, unsigned *res);
int parse_percent_unbounded(const char *p);
int parse_percent(const char *p);
int parse_permille_unbounded(const char *p);
int parse_permille(const char *p);
int parse_permyriad_unbounded(const char *p);
int parse_permyriad(const char *p);
int parse_nice(const char *p, int *ret);
int parse_ip_port(const char *s, uint16_t *ret);

View File

@ -1,157 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "percent-util.h"
#include "string-util.h"
#include "parse-util.h"
static int parse_parts_value_whole(const char *p, const char *symbol) {
const char *pc, *n;
int r, v;
pc = endswith(p, symbol);
if (!pc)
return -EINVAL;
n = strndupa(p, pc - p);
r = safe_atoi(n, &v);
if (r < 0)
return r;
if (v < 0)
return -ERANGE;
return v;
}
static int parse_parts_value_with_tenths_place(const char *p, const char *symbol) {
const char *pc, *dot, *n;
int r, q, v;
pc = endswith(p, symbol);
if (!pc)
return -EINVAL;
dot = memchr(p, '.', pc - p);
if (dot) {
if (dot + 2 != pc)
return -EINVAL;
if (dot[1] < '0' || dot[1] > '9')
return -EINVAL;
q = dot[1] - '0';
n = strndupa(p, dot - p);
} else {
q = 0;
n = strndupa(p, pc - p);
}
r = safe_atoi(n, &v);
if (r < 0)
return r;
if (v < 0)
return -ERANGE;
if (v > (INT_MAX - q) / 10)
return -ERANGE;
v = v * 10 + q;
return v;
}
static int parse_parts_value_with_hundredths_place(const char *p, const char *symbol) {
const char *pc, *dot, *n;
int r, q, v;
pc = endswith(p, symbol);
if (!pc)
return -EINVAL;
dot = memchr(p, '.', pc - p);
if (dot) {
if (dot + 3 == pc) {
/* Support two places after the dot */
if (dot[1] < '0' || dot[1] > '9' || dot[2] < '0' || dot[2] > '9')
return -EINVAL;
q = (dot[1] - '0') * 10 + (dot[2] - '0');
} else if (dot + 2 == pc) {
/* Support one place after the dot */
if (dot[1] < '0' || dot[1] > '9')
return -EINVAL;
q = (dot[1] - '0') * 10;
} else
/* We do not support zero or more than two places */
return -EINVAL;
n = strndupa(p, dot - p);
} else {
q = 0;
n = strndupa(p, pc - p);
}
r = safe_atoi(n, &v);
if (r < 0)
return r;
if (v < 0)
return -ERANGE;
if (v > (INT_MAX - q) / 100)
return -ERANGE;
v = v * 100 + q;
return v;
}
int parse_percent_unbounded(const char *p) {
return parse_parts_value_whole(p, "%");
}
int parse_percent(const char *p) {
int v;
v = parse_percent_unbounded(p);
if (v > 100)
return -ERANGE;
return v;
}
int parse_permille_unbounded(const char *p) {
const char *pm;
pm = endswith(p, "");
if (pm)
return parse_parts_value_whole(p, "");
return parse_parts_value_with_tenths_place(p, "%");
}
int parse_permille(const char *p) {
int v;
v = parse_permille_unbounded(p);
if (v > 1000)
return -ERANGE;
return v;
}
int parse_permyriad_unbounded(const char *p) {
const char *pm;
pm = endswith(p, "");
if (pm)
return parse_parts_value_whole(p, "");
pm = endswith(p, "");
if (pm)
return parse_parts_value_with_tenths_place(p, "");
return parse_parts_value_with_hundredths_place(p, "%");
}
int parse_permyriad(const char *p) {
int v;
v = parse_permyriad_unbounded(p);
if (v > 10000)
return -ERANGE;
return v;
}

View File

@ -1,64 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <errno.h>
#include <inttypes.h>
#include "macro.h"
int parse_percent_unbounded(const char *p);
int parse_percent(const char *p);
int parse_permille_unbounded(const char *p);
int parse_permille(const char *p);
int parse_permyriad_unbounded(const char *p);
int parse_permyriad(const char *p);
/* Some macro-like helpers that convert a percent/permille/permyriad value (as parsed by parse_percent()) to
* a value relative to 100% == 2^32-1. Rounds to closest. */
static inline uint32_t UINT32_SCALE_FROM_PERCENT(int percent) {
assert_cc(INT_MAX <= UINT32_MAX);
return (uint32_t) (((uint64_t) percent * UINT32_MAX + 50) / 100U);
}
static inline uint32_t UINT32_SCALE_FROM_PERMILLE(int permille) {
return (uint32_t) (((uint64_t) permille * UINT32_MAX + 500) / 1000U);
}
static inline uint32_t UINT32_SCALE_FROM_PERMYRIAD(int permyriad) {
return (uint32_t) (((uint64_t) permyriad * UINT32_MAX + 5000) / 10000U);
}
static inline int UINT32_SCALE_TO_PERCENT(uint32_t scale) {
uint32_t u;
u = (uint32_t) ((((uint64_t) scale) * 100U + UINT32_MAX/2) / UINT32_MAX);
if (u > INT_MAX)
return -ERANGE;
return (int) u;
}
static inline int UINT32_SCALE_TO_PERMILLE(uint32_t scale) {
uint32_t u;
u = (uint32_t) ((((uint64_t) scale) * 1000U + UINT32_MAX/2) / UINT32_MAX);
if (u > INT_MAX)
return -ERANGE;
return (int) u;
}
static inline int UINT32_SCALE_TO_PERMYRIAD(uint32_t scale) {
uint32_t u;
u = (uint32_t) ((((uint64_t) scale) * 10000U + UINT32_MAX/2) / UINT32_MAX);
if (u > INT_MAX)
return -ERANGE;
return (int) u;
}
#define PERMYRIAD_AS_PERCENT_FORMAT_STR "%i.%02i%%"
#define PERMYRIAD_AS_PERCENT_FORMAT_VAL(x) ((x)/100), ((x)%100)

View File

@ -21,7 +21,6 @@
#include "nulstr-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "process-util.h"
#include "procfs-util.h"
#include "special.h"
@ -419,7 +418,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
"%sDelegate: %s\n"
"%sManagedOOMSwap: %s\n"
"%sManagedOOMMemoryPressure: %s\n"
"%sManagedOOMMemoryPressureLimit: " PERMYRIAD_AS_PERCENT_FORMAT_STR "\n"
"%sManagedOOMMemoryPressureLimit: %" PRIu32 ".%02" PRIu32 "%%\n"
"%sManagedOOMPreference: %s%%\n",
prefix, yes_no(c->cpu_accounting),
prefix, yes_no(c->io_accounting),
@ -453,7 +452,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
prefix, yes_no(c->delegate),
prefix, managed_oom_mode_to_string(c->moom_swap),
prefix, managed_oom_mode_to_string(c->moom_mem_pressure),
prefix, PERMYRIAD_AS_PERCENT_FORMAT_VAL(UINT32_SCALE_TO_PERMYRIAD(c->moom_mem_pressure_limit)),
prefix, c->moom_mem_pressure_limit_permyriad / 100, c->moom_mem_pressure_limit_permyriad % 100,
prefix, managed_oom_preference_to_string(c->moom_preference));
if (c->delegate) {

View File

@ -163,7 +163,7 @@ struct CGroupContext {
/* Settings for systemd-oomd */
ManagedOOMMode moom_swap;
ManagedOOMMode moom_mem_pressure;
uint32_t moom_mem_pressure_limit; /* Normalized to 2^32-1 == 100% */
uint32_t moom_mem_pressure_limit_permyriad;
ManagedOOMPreference moom_preference;
};

View File

@ -83,7 +83,7 @@ static int build_managed_oom_json_array_element(Unit *u, const char *property, J
JSON_BUILD_PAIR("mode", JSON_BUILD_STRING(mode)),
JSON_BUILD_PAIR("path", JSON_BUILD_STRING(u->cgroup_path)),
JSON_BUILD_PAIR("property", JSON_BUILD_STRING(property)),
JSON_BUILD_PAIR_CONDITION(use_limit, "limit", JSON_BUILD_UNSIGNED(c->moom_mem_pressure_limit))));
JSON_BUILD_PAIR_CONDITION(use_limit, "limit", JSON_BUILD_UNSIGNED(c->moom_mem_pressure_limit_permyriad))));
}
int manager_varlink_send_managed_oom_update(Unit *u) {

View File

@ -16,7 +16,6 @@
#include "fileio.h"
#include "limits-util.h"
#include "path-util.h"
#include "percent-util.h"
BUS_DEFINE_PROPERTY_GET(bus_property_get_tasks_max, "t", TasksMax, tasks_max_resolve);
@ -396,7 +395,7 @@ const sd_bus_vtable bus_cgroup_vtable[] = {
SD_BUS_PROPERTY("DisableControllers", "as", property_get_cgroup_mask, offsetof(CGroupContext, disable_controllers), 0),
SD_BUS_PROPERTY("ManagedOOMSwap", "s", property_get_managed_oom_mode, offsetof(CGroupContext, moom_swap), 0),
SD_BUS_PROPERTY("ManagedOOMMemoryPressure", "s", property_get_managed_oom_mode, offsetof(CGroupContext, moom_mem_pressure), 0),
SD_BUS_PROPERTY("ManagedOOMMemoryPressureLimit", "u", NULL, offsetof(CGroupContext, moom_mem_pressure_limit), 0),
SD_BUS_PROPERTY("ManagedOOMMemoryPressureLimitPermyriad", "u", NULL, offsetof(CGroupContext, moom_mem_pressure_limit_permyriad), 0),
SD_BUS_PROPERTY("ManagedOOMPreference", "s", property_get_managed_oom_preference, offsetof(CGroupContext, moom_preference), 0),
SD_BUS_VTABLE_END
};
@ -705,10 +704,10 @@ static int bus_cgroup_set_boolean(
/* Prepare to chop off suffix */ \
assert_se(endswith(name, "Scale")); \
\
int scaled = UINT32_SCALE_TO_PERMYRIAD(raw); \
unit_write_settingf(u, flags, name, "%.*s=" PERMYRIAD_AS_PERCENT_FORMAT_STR, \
uint32_t scaled = DIV_ROUND_UP((uint64_t) raw * 1000, (uint64_t) UINT32_MAX); \
unit_write_settingf(u, flags, name, "%.*s=%" PRIu32 ".%" PRIu32 "%%", \
(int)(strlen(name) - strlen("Scale")), name, \
PERMYRIAD_AS_PERCENT_FORMAT_VAL(scaled)); \
scaled / 10, scaled % 10); \
} \
\
return 1; \
@ -1699,7 +1698,7 @@ int bus_cgroup_set_property(
return 1;
}
if (streq(name, "ManagedOOMMemoryPressureLimit")) {
if (streq(name, "ManagedOOMMemoryPressureLimitPermyriad")) {
uint32_t v;
if (!UNIT_VTABLE(u)->can_set_managed_oom)
@ -1709,11 +1708,12 @@ int bus_cgroup_set_property(
if (r < 0)
return r;
if (v > 10000)
return -ERANGE;
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->moom_mem_pressure_limit = v;
unit_write_settingf(u, flags, name,
"ManagedOOMMemoryPressureLimit=" PERMYRIAD_AS_PERCENT_FORMAT_STR,
PERMYRIAD_AS_PERCENT_FORMAT_VAL(UINT32_SCALE_TO_PERMYRIAD(v)));
c->moom_mem_pressure_limit_permyriad = v;
unit_write_settingf(u, flags, name, "ManagedOOMMemoryPressureLimit=%" PRIu32 ".%02" PRIu32 "%%", v / 100, v % 100);
}
if (c->moom_mem_pressure == MANAGED_OOM_KILL)

View File

@ -229,7 +229,7 @@ $1.IPIngressFilterPath, config_parse_ip_filter_bpf_progs,
$1.IPEgressFilterPath, config_parse_ip_filter_bpf_progs, 0, offsetof($1, cgroup_context.ip_filters_egress)
$1.ManagedOOMSwap, config_parse_managed_oom_mode, 0, offsetof($1, cgroup_context.moom_swap)
$1.ManagedOOMMemoryPressure, config_parse_managed_oom_mode, 0, offsetof($1, cgroup_context.moom_mem_pressure)
$1.ManagedOOMMemoryPressureLimit, config_parse_managed_oom_mem_pressure_limit, 0, offsetof($1, cgroup_context.moom_mem_pressure_limit)
$1.ManagedOOMMemoryPressureLimit, config_parse_managed_oom_mem_pressure_limit, 0, offsetof($1, cgroup_context.moom_mem_pressure_limit_permyriad)
$1.ManagedOOMPreference, config_parse_managed_oom_preference, 0, offsetof($1, cgroup_context.moom_preference)
$1.NetClass, config_parse_warn_compat, DISABLED_LEGACY, 0'
)m4_dnl

View File

@ -46,7 +46,6 @@
#include "nulstr-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "process-util.h"
#if HAVE_SECCOMP
#include "seccomp-util.h"
@ -3594,13 +3593,13 @@ int config_parse_cpu_quota(
return 0;
}
r = parse_permyriad_unbounded(rvalue);
r = parse_permille_unbounded(rvalue);
if (r <= 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid CPU quota '%s', ignoring.", rvalue);
return 0;
}
c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 10000U;
c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 1000U;
return 0;
}
@ -3665,7 +3664,7 @@ int config_parse_memory_limit(
bytes = CGROUP_LIMIT_MIN;
else if (!isempty(rvalue) && !streq(rvalue, "infinity")) {
r = parse_permyriad(rvalue);
r = parse_permille(rvalue);
if (r < 0) {
r = parse_size(rvalue, 1024, &bytes);
if (r < 0) {
@ -3673,7 +3672,7 @@ int config_parse_memory_limit(
return 0;
}
} else
bytes = physical_memory_scale(r, 10000U);
bytes = physical_memory_scale(r, 1000U);
if (bytes >= UINT64_MAX ||
(bytes <= 0 && !STR_IN_SET(lvalue, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
@ -3735,9 +3734,9 @@ int config_parse_tasks_max(
return 0;
}
r = parse_permyriad(rvalue);
r = parse_permille(rvalue);
if (r >= 0)
*tasks_max = (TasksMax) { r, 10000U }; /* r‱ */
*tasks_max = (TasksMax) { r, 1000U }; /* r‰ */
else {
r = safe_atou64(rvalue, &v);
if (r < 0) {
@ -3843,7 +3842,6 @@ int config_parse_managed_oom_mode(
const char *rvalue,
void *data,
void *userdata) {
ManagedOOMMode *mode = data, m;
UnitType t;
@ -3863,7 +3861,6 @@ int config_parse_managed_oom_mode(
log_syntax(unit, LOG_WARNING, filename, line, m, "Invalid syntax, ignoring: %s", rvalue);
return 0;
}
*mode = m;
return 0;
}
@ -3879,7 +3876,6 @@ int config_parse_managed_oom_mem_pressure_limit(
const char *rvalue,
void *data,
void *userdata) {
uint32_t *limit = data;
UnitType t;
int r;
@ -3901,8 +3897,7 @@ int config_parse_managed_oom_mem_pressure_limit(
return 0;
}
/* Normalize to 2^32-1 == 100% */
*limit = UINT32_SCALE_FROM_PERMYRIAD(r);
*limit = r;
return 0;
}

View File

@ -1256,8 +1256,8 @@ static int bump_rlimit_memlock(struct rlimit *saved_rlimit) {
* must be unsigned, hence this is a given, but let's make this clear here. */
assert_cc(RLIM_INFINITY > 0);
mm = physical_memory_scale(1, 8); /* Let's scale how much we allow to be locked by the amount of physical
* RAM. We allow an eighth to be locked by us, just to pick a value. */
mm = physical_memory() / 8; /* Let's scale how much we allow to be locked by the amount of physical
* RAM. We allow an eighth to be locked by us, just to pick a value. */
new_rlimit = (struct rlimit) {
.rlim_cur = MAX3(HIGH_RLIMIT_MEMLOCK, saved_rlimit->rlim_cur, mm),

View File

@ -1,14 +1,13 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See systemd-system.conf(5) for details.

View File

@ -1,16 +1,14 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# You can override the directives in this file by creating files in
# /etc/systemd/user.conf.d/*.conf.
#
# See systemd-user.conf(5) for details.
# See systemd-user.conf(5) for details
[Manager]
#LogLevel=info

View File

@ -1,14 +1,13 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See coredump.conf(5) for details.

View File

@ -26,7 +26,6 @@
#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "pkcs11-util.h"
#include "pretty-print.h"
#include "process-util.h"
@ -1568,7 +1567,7 @@ static int resize_home(int argc, char *argv[], void *userdata) {
(void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
if (arg_disk_size_relative != UINT64_MAX ||
(argc > 2 && parse_permyriad(argv[2]) >= 0))
(argc > 2 && parse_percent(argv[2]) >= 0))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Relative disk size specification currently not supported when resizing.");
@ -2654,7 +2653,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
}
r = parse_permyriad(optarg);
r = parse_permille(optarg);
if (r < 0) {
r = parse_size(optarg, 1024, &arg_disk_size);
if (r < 0)
@ -2671,7 +2670,7 @@ static int parse_argv(int argc, char *argv[]) {
arg_disk_size_relative = UINT64_MAX;
} else {
/* Normalize to UINT32_MAX == 100% */
arg_disk_size_relative = UINT32_SCALE_FROM_PERMYRIAD(r);
arg_disk_size_relative = (uint64_t) r * UINT32_MAX / 1000U;
r = drop_from_identity("diskSize");
if (r < 0)

View File

@ -1,16 +1,15 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See homed.conf(5) for details.
# See homed.conf(5) for details
[Home]
#DefaultStorage=

View File

@ -22,7 +22,6 @@
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "process-util.h"
#include "service-util.h"
#include "signal-util.h"

View File

@ -1,16 +1,15 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journal-remote.conf(5) for details.
# See journal-remote.conf(5) for details
[Remote]
# Seal=false

View File

@ -1,16 +1,15 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journal-upload.conf(5) for details.
# See journal-upload.conf(5) for details
[Upload]
# URL=

View File

@ -1,14 +1,13 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journald.conf(5) for details.

View File

@ -19,12 +19,11 @@
#include "label.h"
#include "limits-util.h"
#include "logind-dbus.h"
#include "logind-user-dbus.h"
#include "logind-user.h"
#include "logind-user-dbus.h"
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "rm-rf.h"
#include "serialize.h"
#include "special.h"
@ -908,9 +907,9 @@ int config_parse_tmpfs_size(
assert(data);
/* First, try to parse as percentage */
r = parse_permyriad(rvalue);
if (r > 0)
*sz = physical_memory_scale(r, 10000U);
r = parse_permille(rvalue);
if (r > 0 && r < 1000)
*sz = physical_memory_scale(r, 1000U);
else {
uint64_t k;

View File

@ -1,14 +1,13 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See logind.conf(5) for details.

View File

@ -34,7 +34,6 @@
#include "pam-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "process-util.h"
#include "rlimit-util.h"
#include "socket-util.h"
@ -335,9 +334,9 @@ static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, co
return PAM_SUCCESS;
}
r = parse_permyriad(limit);
r = parse_permille(limit);
if (r >= 0) {
r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", UINT32_SCALE_FROM_PERMYRIAD(r));
r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", (uint32_t) (((uint64_t) r * UINT32_MAX) / 1000U));
if (r < 0)
return pam_bus_log_create_error(handle, r);

View File

@ -217,44 +217,7 @@ static int nexthop_add(Link *link, const NextHop *in, NextHop **ret) {
return is_new;
}
static int nexthop_update(Link *link, NextHop *nexthop, const NextHop *in) {
int r;
assert(link);
assert(nexthop);
assert(in);
assert(in->id > 0);
/* Currently, this only updates ID. */
if (nexthop->id > 0)
return nexthop->id == in->id ? 0 : -EINVAL;
nexthop = set_remove(link->nexthops, nexthop);
if (!nexthop)
return -ENOENT;
nexthop->id = in->id;
r = set_put(link->nexthops, nexthop);
if (r <= 0) {
int k;
/* On failure, revert the change. */
nexthop->id = 0;
k = set_put(link->nexthops, nexthop);
if (k <= 0) {
nexthop_free(nexthop);
return k < 0 ? k : -EEXIST;
}
return r < 0 ? r : -EEXIST;
}
return 0;
}
static void log_nexthop_debug(const NextHop *nexthop, uint32_t id, const char *str, const Link *link) {
static void log_nexthop_debug(const NextHop *nexthop, const char *str, const Link *link) {
assert(nexthop);
assert(str);
assert(link);
@ -264,12 +227,8 @@ static void log_nexthop_debug(const NextHop *nexthop, uint32_t id, const char *s
(void) in_addr_to_string(nexthop->family, &nexthop->gw, &gw);
if (nexthop->id == id)
log_link_debug(link, "%s nexthop: id: %"PRIu32", gw: %s",
str, nexthop->id, strna(gw));
else
log_link_debug(link, "%s nexthop: id: %"PRIu32"→%"PRIu32", gw: %s",
str, nexthop->id, id, strna(gw));
log_link_debug(link, "%s nexthop: id: %"PRIu32", gw: %s",
str, nexthop->id, strna(gw));
}
}
@ -292,12 +251,9 @@ static int nexthop_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
}
if (link->nexthop_messages == 0) {
log_link_debug(link, "Nexthops set");
log_link_debug(link, "Nexthop set");
link->static_nexthops_configured = true;
/* Now all nexthops are configured. Let's configure remaining routes. */
r = link_set_routes_with_gateway(link);
if (r < 0)
link_enter_failed(link);
link_check_ready(link);
}
return 1;
@ -313,7 +269,7 @@ static int nexthop_configure(const NextHop *nexthop, Link *link) {
assert(link->ifindex > 0);
assert(IN_SET(nexthop->family, AF_INET, AF_INET6));
log_nexthop_debug(nexthop, nexthop->id, "Configuring", link);
log_nexthop_debug(nexthop, "Configuring", link);
r = sd_rtnl_message_new_nexthop(link->manager->rtnl, &req,
RTM_NEWNEXTHOP, nexthop->family,
@ -351,7 +307,7 @@ static int nexthop_configure(const NextHop *nexthop, Link *link) {
return r;
}
int link_set_nexthops(Link *link) {
int link_set_nexthop(Link *link) {
enum {
PHASE_ID, /* First phase: Nexthops with ID */
PHASE_WITHOUT_ID, /* Second phase: Nexthops without ID */
@ -384,14 +340,13 @@ int link_set_nexthops(Link *link) {
if (link->nexthop_messages == 0) {
link->static_nexthops_configured = true;
/* Finaly, configure routes with gateways. */
return link_set_routes_with_gateway(link);
link_check_ready(link);
} else {
log_link_debug(link, "Setting nexthop");
link_set_state(link, LINK_STATE_CONFIGURING);
}
log_link_debug(link, "Setting nexthops");
link_set_state(link, LINK_STATE_CONFIGURING);
return 0;
return 1;
}
int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) {
@ -471,41 +426,23 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message,
return 0;
}
r = nexthop_get(link, tmp, &nexthop);
if (r < 0) {
uint32_t id;
/* The nexthop may be created without setting NHA_ID. */
id = tmp->id;
tmp->id = 0;
(void) nexthop_get(link, tmp, &nexthop);
tmp->id = id;
}
(void) nexthop_get(link, tmp, &nexthop);
switch (type) {
case RTM_NEWNEXTHOP:
if (nexthop)
log_nexthop_debug(nexthop, tmp->id, "Received remembered", link);
log_nexthop_debug(tmp, "Received remembered", link);
else {
log_nexthop_debug(tmp, tmp->id, "Remembering foreign", link);
log_nexthop_debug(tmp, "Remembering foreign", link);
r = nexthop_add_foreign(link, tmp, &nexthop);
if (r < 0) {
log_link_warning_errno(link, r, "Could not remember foreign nexthop, ignoring: %m");
return 0;
}
}
r = nexthop_update(link, nexthop, tmp);
if (r < 0) {
log_link_warning_errno(link, r, "Could not update nexthop, ignoring: %m");
return 0;
}
break;
case RTM_DELNEXTHOP:
log_nexthop_debug(tmp, tmp->id, nexthop ? "Forgetting" : "Kernel removed unknown", link);
log_nexthop_debug(tmp, nexthop ? "Forgetting" : "Kernel removed unknown", link);
nexthop_free(nexthop);
break;

View File

@ -33,7 +33,7 @@ NextHop *nexthop_free(NextHop *nexthop);
void network_drop_invalid_nexthops(Network *network);
int link_set_nexthops(Link *link);
int link_set_nexthop(Link *link);
int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);

View File

@ -1193,7 +1193,7 @@ int route_configure(
return k;
}
static int route_handler_with_gateway(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
@ -1206,113 +1206,27 @@ static int route_handler_with_gateway(sd_netlink *rtnl, sd_netlink_message *m, L
r = sd_netlink_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
log_link_message_warning_errno(link, m, r, "Could not set route with gateway");
log_link_message_warning_errno(link, m, r, "Could not set route");
link_enter_failed(link);
return 1;
}
if (link->route_messages == 0) {
log_link_debug(link, "Routes with gateway set");
log_link_debug(link, "Routes set");
link->static_routes_configured = true;
link_check_ready(link);
link_set_nexthop(link);
}
return 1;
}
static int route_handler_without_gateway(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
assert(link->route_messages > 0);
link->route_messages--;
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
return 1;
r = sd_netlink_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
log_link_message_warning_errno(link, m, r, "Could not set route without gateway");
link_enter_failed(link);
return 1;
}
if (link->route_messages == 0) {
log_link_debug(link, "Routes set without gateway");
/* Now, we can talk to gateways, let's configure nexthops. */
r = link_set_nexthops(link);
if (r < 0)
link_enter_failed(link);
}
return 1;
}
static bool route_has_gateway(const Route *route) {
assert(route);
if (in_addr_is_set(route->gw_family, &route->gw))
return true;
if (!ordered_set_isempty(route->multipath_routes))
return true;
return false;
}
static int link_set_routes_internal(Link *link, bool with_gateway) {
Route *rt;
int r;
assert(link);
assert(link->network);
HASHMAP_FOREACH(rt, link->network->routes_by_section) {
if (rt->gateway_from_dhcp_or_ra)
continue;
if (route_has_gateway(rt) != with_gateway)
continue;
r = route_configure(rt, link, with_gateway ? route_handler_with_gateway : route_handler_without_gateway, NULL);
if (r < 0)
return log_link_warning_errno(link, r, "Could not set routes: %m");
link->route_messages++;
}
return 0;
}
int link_set_routes_with_gateway(Link *link) {
int r;
assert(link);
assert(link->network);
if (!link_has_carrier(link) && !link->network->configure_without_carrier)
/* During configuring addresses, the link lost its carrier. As networkd is dropping
* the addresses now, let's not configure the routes either. */
return 0;
/* Finaly, add routes that needs a gateway. */
r = link_set_routes_internal(link, true);
if (r < 0)
return r;
if (link->route_messages == 0) {
link->static_routes_configured = true;
link_check_ready(link);
} else {
log_link_debug(link, "Setting routes with gateway");
link_set_state(link, LINK_STATE_CONFIGURING);
}
return 0;
}
int link_set_routes(Link *link) {
enum {
PHASE_NON_GATEWAY, /* First phase: Routes without a gateway */
PHASE_GATEWAY, /* Second phase: Routes with a gateway */
_PHASE_MAX
} phase;
Route *rt;
int r;
assert(link);
@ -1338,17 +1252,29 @@ int link_set_routes(Link *link) {
if (r < 0)
return r;
/* First, add the routes that enable us to talk to gateways. */
r = link_set_routes_internal(link, false);
if (r < 0)
return r;
/* First add the routes that enable us to talk to gateways, then add in the others that need a gateway. */
for (phase = 0; phase < _PHASE_MAX; phase++)
HASHMAP_FOREACH(rt, link->network->routes_by_section) {
if (rt->gateway_from_dhcp_or_ra)
continue;
if (link->route_messages == 0)
/* If no route is configured, then configure nexthops. */
return link_set_nexthops(link);
if ((!in_addr_is_set(rt->gw_family, &rt->gw) && ordered_set_isempty(rt->multipath_routes)) != (phase == PHASE_NON_GATEWAY))
continue;
log_link_debug(link, "Setting routes without gateway");
link_set_state(link, LINK_STATE_CONFIGURING);
r = route_configure(rt, link, route_handler, NULL);
if (r < 0)
return log_link_warning_errno(link, r, "Could not set routes: %m");
link->route_messages++;
}
if (link->route_messages == 0) {
link->static_routes_configured = true;
link_set_nexthop(link);
} else {
log_link_debug(link, "Setting routes");
link_set_state(link, LINK_STATE_CONFIGURING);
}
return 0;
}

View File

@ -74,7 +74,6 @@ int route_configure(const Route *route, Link *link, link_netlink_message_handler
int route_remove(const Route *route, Manager *manager, Link *link, link_netlink_message_handler_t callback);
int link_set_routes(Link *link);
int link_set_routes_with_gateway(Link *link);
int link_drop_routes(Link *link);
int link_drop_foreign_routes(Link *link);

View File

@ -1,16 +1,15 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See networkd.conf(5) for details.
# See networkd.conf(5) for details
[Network]
#SpeedMeter=no

View File

@ -5,7 +5,6 @@
#include "extract-word.h"
#include "fileio.h"
#include "parse-util.h"
#include "percent-util.h"
#include "tc-util.h"
#include "time-util.h"
@ -58,17 +57,17 @@ int tc_time_to_tick(usec_t t, uint32_t *ret) {
return 0;
}
int parse_tc_percent(const char *s, uint32_t *ret_fraction) {
int parse_tc_percent(const char *s, uint32_t *percent) {
int r;
assert(s);
assert(ret_fraction);
assert(percent);
r = parse_permyriad(s);
r = parse_permille(s);
if (r < 0)
return r;
*ret_fraction = (double) r / 10000 * UINT32_MAX;
*percent = (double) r / 1000 * UINT32_MAX;
return 0;
}

View File

@ -10,13 +10,12 @@
#include "oomd-manager-bus.h"
#include "oomd-manager.h"
#include "path-util.h"
#include "percent-util.h"
typedef struct ManagedOOMReply {
ManagedOOMMode mode;
char *path;
char *property;
uint32_t limit;
unsigned limit;
} ManagedOOMReply;
static void managed_oom_reply_destroy(ManagedOOMReply *reply) {
@ -53,10 +52,10 @@ static int process_managed_oom_reply(
assert(m);
static const JsonDispatch dispatch_table[] = {
{ "mode", JSON_VARIANT_STRING, managed_oom_mode, offsetof(ManagedOOMReply, mode), JSON_MANDATORY },
{ "path", JSON_VARIANT_STRING, json_dispatch_string, offsetof(ManagedOOMReply, path), JSON_MANDATORY },
{ "property", JSON_VARIANT_STRING, json_dispatch_string, offsetof(ManagedOOMReply, property), JSON_MANDATORY },
{ "limit", JSON_VARIANT_UNSIGNED, json_dispatch_uint32, offsetof(ManagedOOMReply, limit), 0 },
{ "mode", JSON_VARIANT_STRING, managed_oom_mode, offsetof(ManagedOOMReply, mode), JSON_MANDATORY },
{ "path", JSON_VARIANT_STRING, json_dispatch_string, offsetof(ManagedOOMReply, path), JSON_MANDATORY },
{ "property", JSON_VARIANT_STRING, json_dispatch_string, offsetof(ManagedOOMReply, property), JSON_MANDATORY },
{ "limit", JSON_VARIANT_UNSIGNED, json_dispatch_unsigned, offsetof(ManagedOOMReply, limit), 0 },
{},
};
@ -87,8 +86,7 @@ static int process_managed_oom_reply(
if (ret == -ENOMEM) {
r = ret;
goto finish;
}
if (ret < 0)
} else if (ret < 0)
continue;
monitor_hm = streq(reply.property, "ManagedOOMSwap") ?
@ -101,15 +99,14 @@ static int process_managed_oom_reply(
limit = m->default_mem_pressure_limit;
if (streq(reply.property, "ManagedOOMMemoryPressure") && reply.limit > 0) {
int permyriad = UINT32_SCALE_TO_PERMYRIAD(reply.limit);
ret = store_loadavg_fixed_point(
(unsigned long) permyriad / 100,
(unsigned long) permyriad % 100,
&limit);
if (ret < 0)
if (streq(reply.property, "ManagedOOMMemoryPressure")) {
if (reply.limit > 10000)
continue;
else if (reply.limit != 0) {
ret = store_loadavg_fixed_point((unsigned long) reply.limit / 100, (unsigned long) reply.limit % 100, &limit);
if (ret < 0)
continue;
}
}
ret = oomd_insert_cgroup_context(NULL, monitor_hm, empty_to_root(reply.path));
@ -351,11 +348,11 @@ static int monitor_cgroup_contexts_handler(sd_event_source *s, uint64_t usec, vo
}
}
if (oomd_swap_free_below(&m->system_context, 10000 - m->swap_used_limit_permyriad)) {
if (oomd_swap_free_below(&m->system_context, (100 - m->swap_used_limit))) {
_cleanup_hashmap_free_ Hashmap *candidates = NULL;
log_notice("Swap used (%"PRIu64") / total (%"PRIu64") is more than " PERMYRIAD_AS_PERCENT_FORMAT_STR,
m->system_context.swap_used, m->system_context.swap_total, PERMYRIAD_AS_PERCENT_FORMAT_VAL(m->swap_used_limit_permyriad));
log_notice("Swap used (%"PRIu64") / total (%"PRIu64") is more than %u%%",
m->system_context.swap_used, m->system_context.swap_total, m->swap_used_limit);
r = get_monitored_cgroup_contexts_candidates(m->monitored_swap_cgroup_contexts, &candidates);
if (r == -ENOMEM)
@ -481,13 +478,7 @@ static int manager_connect_bus(Manager *m) {
return 0;
}
int manager_start(
Manager *m,
bool dry_run,
int swap_used_limit_permyriad,
int mem_pressure_limit_permyriad,
usec_t mem_pressure_usec) {
int manager_start(Manager *m, bool dry_run, int swap_used_limit, int mem_pressure_limit_permyriad, usec_t mem_pressure_usec) {
unsigned long l, f;
int r;
@ -495,10 +486,10 @@ int manager_start(
m->dry_run = dry_run;
m->swap_used_limit_permyriad = swap_used_limit_permyriad >= 0 ? swap_used_limit_permyriad : DEFAULT_SWAP_USED_LIMIT_PERCENT * 100;
assert(m->swap_used_limit_permyriad <= 10000);
m->swap_used_limit = swap_used_limit != -1 ? swap_used_limit : DEFAULT_SWAP_USED_LIMIT;
assert(m->swap_used_limit <= 100);
if (mem_pressure_limit_permyriad >= 0) {
if (mem_pressure_limit_permyriad != -1) {
assert(mem_pressure_limit_permyriad <= 10000);
l = mem_pressure_limit_permyriad / 100;
@ -546,12 +537,12 @@ int manager_get_dump_string(Manager *m, char **ret) {
fprintf(f,
"Dry Run: %s\n"
"Swap Used Limit: " PERMYRIAD_AS_PERCENT_FORMAT_STR "\n"
"Swap Used Limit: %u%%\n"
"Default Memory Pressure Limit: %lu.%02lu%%\n"
"Default Memory Pressure Duration: %s\n"
"System Context:\n",
yes_no(m->dry_run),
PERMYRIAD_AS_PERCENT_FORMAT_VAL(m->swap_used_limit_permyriad),
m->swap_used_limit,
LOAD_INT(m->default_mem_pressure_limit), LOAD_FRAC(m->default_mem_pressure_limit),
format_timespan(buf, sizeof(buf), m->default_mem_pressure_duration_usec, USEC_PER_SEC));
oomd_dump_system_context(&m->system_context, f, "\t");

View File

@ -18,7 +18,7 @@
* system.slice are assumed to be less latency sensitive. */
#define DEFAULT_MEM_PRESSURE_DURATION_USEC (30 * USEC_PER_SEC)
#define DEFAULT_MEM_PRESSURE_LIMIT_PERCENT 60
#define DEFAULT_SWAP_USED_LIMIT_PERCENT 90
#define DEFAULT_SWAP_USED_LIMIT 90
#define RECLAIM_DURATION_USEC (30 * USEC_PER_SEC)
#define POST_ACTION_DELAY_USEC (15 * USEC_PER_SEC)
@ -32,7 +32,7 @@ struct Manager {
Hashmap *polkit_registry;
bool dry_run;
int swap_used_limit_permyriad;
unsigned swap_used_limit;
loadavg_t default_mem_pressure_limit;
usec_t default_mem_pressure_duration_usec;
@ -56,7 +56,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
int manager_new(Manager **ret);
int manager_start(Manager *m, bool dry_run, int swap_used_limit_permyriad, int mem_pressure_limit_permyriad, usec_t mem_pressure_usec);
int manager_start(Manager *m, bool dry_run, int swap_used_limit, int mem_pressure_limit_permyriad, usec_t mem_pressure_usec);
int manager_get_dump_string(Manager *m, char **ret);

View File

@ -134,13 +134,13 @@ bool oomd_memory_reclaim(Hashmap *h) {
return pgscan_of > last_pgscan_of;
}
bool oomd_swap_free_below(const OomdSystemContext *ctx, int threshold_permyriad) {
bool oomd_swap_free_below(const OomdSystemContext *ctx, uint64_t threshold_percent) {
uint64_t swap_threshold;
assert(ctx);
assert(threshold_permyriad <= 10000);
assert(threshold_percent <= 100);
swap_threshold = ctx->swap_total * threshold_permyriad / (uint64_t) 10000;
swap_threshold = ctx->swap_total * threshold_percent / ((uint64_t) 100);
return (ctx->swap_total - ctx->swap_used) < swap_threshold;
}

View File

@ -61,8 +61,8 @@ int oomd_pressure_above(Hashmap *h, usec_t duration, Set **ret);
* current sum is higher than the last interval's sum (there was some reclaim activity). */
bool oomd_memory_reclaim(Hashmap *h);
/* Returns true if the amount of swap free is below the permyriad of swap specified by `threshold_permyriad`. */
bool oomd_swap_free_below(const OomdSystemContext *ctx, int threshold_permyriad);
/* Returns true if the amount of swap free is below the percentage of swap specified by `threshold_percent`. */
bool oomd_swap_free_below(const OomdSystemContext *ctx, uint64_t threshold_percent);
/* The compare functions will sort from largest to smallest, putting all the contexts with "avoid" at the end
* (after the smallest values). */

View File

@ -17,13 +17,13 @@
#include "signal-util.h"
static bool arg_dry_run = false;
static int arg_swap_used_limit_permyriad = -1;
static int arg_swap_used_limit = -1;
static int arg_mem_pressure_limit_permyriad = -1;
static usec_t arg_mem_pressure_usec = 0;
static int parse_config(void) {
static const ConfigTableItem items[] = {
{ "OOM", "SwapUsedLimit", config_parse_permyriad, 0, &arg_swap_used_limit_permyriad },
{ "OOM", "SwapUsedLimitPercent", config_parse_percent, 0, &arg_swap_used_limit },
{ "OOM", "DefaultMemoryPressureLimit", config_parse_permyriad, 0, &arg_mem_pressure_limit_permyriad },
{ "OOM", "DefaultMemoryPressureDurationSec", config_parse_sec, 0, &arg_mem_pressure_usec },
{}
@ -159,12 +159,7 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return log_error_errno(r, "Failed to create manager: %m");
r = manager_start(
m,
arg_dry_run,
arg_swap_used_limit_permyriad,
arg_mem_pressure_limit_permyriad,
arg_mem_pressure_usec);
r = manager_start(m, arg_dry_run, arg_swap_used_limit, arg_mem_pressure_limit_permyriad, arg_mem_pressure_usec);
if (r < 0)
return log_error_errno(r, "Failed to start up daemon: %m");

View File

@ -1,18 +1,17 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See oomd.conf(5) for details
[OOM]
#SwapUsedLimit=90%
#SwapUsedLimitPercent=90%
#DefaultMemoryPressureLimit=60%
#DefaultMemoryPressureDurationSec=30s

View File

@ -302,19 +302,19 @@ static void test_oomd_swap_free_below(void) {
.swap_total = 20971512 * 1024U,
.swap_used = 20971440 * 1024U,
};
assert_se(oomd_swap_free_below(&ctx, 2000) == true);
assert_se(oomd_swap_free_below(&ctx, 20) == true);
ctx = (OomdSystemContext) {
.swap_total = 20971512 * 1024U,
.swap_used = 3310136 * 1024U,
};
assert_se(oomd_swap_free_below(&ctx, 2000) == false);
assert_se(oomd_swap_free_below(&ctx, 20) == false);
ctx = (OomdSystemContext) {
.swap_total = 0,
.swap_used = 0,
};
assert_se(oomd_swap_free_below(&ctx, 2000) == false);
assert_se(oomd_swap_free_below(&ctx, 20) == false);
}
static void test_oomd_sort_cgroups(void) {

View File

@ -1,14 +1,13 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See pstore.conf(5) for details.

View File

@ -679,7 +679,7 @@ DnsScopeMatch dns_scope_good_domain(
dns_name_endswith(domain, "local") > 0)
return DNS_SCOPE_NO;
/* If the IP address to look up matches the local subnet, then implicitly synthesizes
/* If the IP address to look up matches the local subnet, then implicity synthesizes
* DNS_SCOPE_YES_BASE + 0 on this interface, i.e. preferably resolve IP addresses via the DNS
* server belonging to this interface. */
m = match_subnet_reverse_lookups(s, domain, false);

View File

@ -639,8 +639,8 @@ int dns_server_adjust_opt(DnsServer *server, DnsPacket *packet, DnsServerFeature
if (server->packet_fragmented)
packet_size = MIN(server->received_udp_fragment_max, packet_size);
/* Let's not pick ridiculously large sizes, i.e. not more than 4K. No one appears
* to ever use such large sized on the Internet IRL, hence let's not either. */
/* Let's not pick ridiculously large sizes, i.e. not more than 4K. Noone appears to
* ever use such large sized on the Internet IRL, hence let's not either. */
packet_size = MIN(packet_size, 4096U);
}

View File

@ -415,7 +415,7 @@ static const char *nsid_string(void) {
SD_ID128_MAKE(ed,d3,12,5d,16,b9,41,f9,a1,49,5f,ab,15,62,ab,27),
&id);
if (r < 0) {
log_debug_errno(r, "Failed to determine machine ID, ignoring: %m");
log_debug_errno(r, "Failed to determine machine ID, igoring: %m");
return NULL;
}

View File

@ -1,16 +1,15 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details.
# See resolved.conf(5) for details
[Resolve]
# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:

View File

@ -28,7 +28,6 @@
#include "numa-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "process-util.h"
#include "rlimit-util.h"
#if HAVE_SECCOMP
@ -441,12 +440,15 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
return bus_append_string(m, field, eq);
if (STR_IN_SET(field, "ManagedOOMMemoryPressureLimit")) {
char *n;
r = parse_permyriad(eq);
if (r < 0)
return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
/* Pass around scaled to 2^32-1 == 100% */
r = sd_bus_message_append(m, "(sv)", field, "u", UINT32_SCALE_FROM_PERMYRIAD(r));
n = strjoina(field, "Permyriad");
r = sd_bus_message_append(m, "(sv)", n, "u", (uint32_t) r);
if (r < 0)
return bus_log_create_error(r);
@ -537,7 +539,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
return 1;
}
r = parse_permyriad(eq);
r = parse_permille(eq);
if (r >= 0) {
char *n;
@ -546,7 +548,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
* size can be determined server-side. */
n = strjoina(field, "Scale");
r = sd_bus_message_append(m, "(sv)", n, "u", UINT32_SCALE_FROM_PERMYRIAD(r));
r = sd_bus_message_append(m, "(sv)", n, "u", (uint32_t) (((uint64_t) r * UINT32_MAX) / 1000U));
if (r < 0)
return bus_log_create_error(r);
@ -563,14 +565,14 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY);
else {
r = parse_permyriad_unbounded(eq);
r = parse_permille_unbounded(eq);
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(ERANGE),
"CPU quota too small.");
if (r < 0)
return log_error_errno(r, "CPU quota '%s' invalid.", eq);
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", (((uint64_t) r * USEC_PER_SEC) / 10000U));
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", (((uint64_t) r * USEC_PER_SEC) / 1000U));
}
if (r < 0)

View File

@ -22,7 +22,6 @@
#include "nulstr-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "percent-util.h"
#include "process-util.h"
#include "rlimit-util.h"
#include "sd-id128.h"

View File

@ -2258,12 +2258,6 @@ int table_print(Table *t, FILE *f) {
if (!aligned)
return -ENOMEM;
/* Drop trailing white spaces of last column when no cosmetics is set. */
if (j == display_columns - 1 &&
(!colors_enabled() || !table_data_color(d)) &&
(!urlify_enabled() || !d->url))
delete_trailing_chars(aligned, NULL);
free_and_replace(buffer, aligned);
field = buffer;
}

View File

@ -8,7 +8,7 @@
#include "string-table.h"
#include "string-util.h"
/* All functions in this file emit warnings. */
/* All functions in this file emit warnigs. */
int parse_boolean_argument(const char *optname, const char *s, bool *ret) {
int r;

View File

@ -1,16 +1,15 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See systemd-sleep.conf(5) for details.
# See systemd-sleep.conf(5) for details
[Sleep]
#AllowSuspend=yes

View File

@ -63,7 +63,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
mac_selinux_finish();
/* Call static destructors to do global state cleanup. We do it here, and not in fuzz-main.c so that
* any global state is destroyed between fuzzer runs. */
* any global state is destoyed between fuzzer runs. */
static_destruct();
return 0;

View File

@ -547,8 +547,6 @@ tests += [
[['src/test/test-bus-util.c']],
[['src/test/test-percent-util.c']],
[['src/test/test-sd-hwdb.c']],
[['src/test/test-sd-path.c']],

View File

@ -29,7 +29,7 @@ static void test_issue_9549(void) {
printf("%s\n", formatted);
assert_se(streq(formatted,
"NAME TYPE RO USAGE CREATED MODIFIED\n"
"NAME TYPE RO USAGE CREATED MODIFIED \n"
"foooo raw no 673.6M Wed 2018-07-11 00:10:33 J… Wed 2018-07-11 00:16:00 JST\n"
));
}
@ -72,7 +72,7 @@ static void test_multiline(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"));
"lines \n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
@ -82,7 +82,7 @@ static void test_multiline(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"));
"lines \n"));
formatted = mfree(formatted);
assert_se(table_add_many(table,
@ -123,7 +123,7 @@ static void test_multiline(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"
"lines \n"
"short a\n"
" pair\n"
"short2 a\n"
@ -138,7 +138,7 @@ static void test_multiline(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"
"lines \n"
"short a\n"
" pair\n"
"short2 a\n"
@ -186,7 +186,7 @@ static void test_strv(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"));
"lines \n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, (size_t) -1);
@ -196,7 +196,7 @@ static void test_strv(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"));
"lines \n"));
formatted = mfree(formatted);
assert_se(table_add_many(table,
@ -237,7 +237,7 @@ static void test_strv(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"
"lines \n"
"short a\n"
" pair\n"
"short2 a\n"
@ -252,7 +252,7 @@ static void test_strv(void) {
"FOO BAR\n"
"three two\n"
"different lines\n"
"lines \n"
"lines \n"
"short a\n"
" pair\n"
"short2 a\n"
@ -333,7 +333,7 @@ static void test_strv_wrapped(void) {
assert_se(streq(formatted,
"FOO BAR\n"
"three different two lines\n"
"lines \n"
"lines \n"
"short a pair\n"
"short2 a eight line ćęłł\n"
" ___5___ ___6___…\n"));
@ -345,7 +345,7 @@ static void test_strv_wrapped(void) {
assert_se(streq(formatted,
"FOO BAR\n"
"three different two lines\n"
"lines \n"
"lines \n"
"short a pair\n"
"short2 a eight line ćęłł\n"
" ___5___ ___6___\n"
@ -358,7 +358,7 @@ static void test_strv_wrapped(void) {
assert_se(streq(formatted,
"FOO BAR\n"
"three different two lines\n"
"lines \n"
"lines \n"
"short a pair\n"
"short2 a eight line ćęłł\n"
" ___5___ ___6___\n"
@ -493,17 +493,17 @@ int main(int argc, char *argv[]) {
if (isatty(STDOUT_FILENO))
assert_se(streq(formatted,
" no a long f… no a long f… a long fi…\n"
" no fäää no fäää fäää\n"
" yes fäää yes fäää fäää\n"
" yes xxx yes xxx xxx\n"
"5min 5min \n"));
" no fäää no fäää fäää \n"
" yes fäää yes fäää fäää \n"
" yes xxx yes xxx xxx \n"
"5min 5min \n"));
else
assert_se(streq(formatted,
" no a long field no a long field a long field\n"
" no fäää no fäää fäää\n"
" yes fäää yes fäää fäää\n"
" yes xxx yes xxx xxx\n"
"5min 5min \n"));
" no fäää no fäää fäää \n"
" yes fäää yes fäää fäää \n"
" yes xxx yes xxx xxx \n"
"5min 5min \n"));
test_issue_9549();
test_multiline();

View File

@ -718,6 +718,144 @@ static void test_safe_atod(void) {
assert_se(r == -EINVAL);
}
static void test_parse_percent(void) {
assert_se(parse_percent("") == -EINVAL);
assert_se(parse_percent("foo") == -EINVAL);
assert_se(parse_percent("0") == -EINVAL);
assert_se(parse_percent("50") == -EINVAL);
assert_se(parse_percent("100") == -EINVAL);
assert_se(parse_percent("-1") == -EINVAL);
assert_se(parse_percent("0%") == 0);
assert_se(parse_percent("55%") == 55);
assert_se(parse_percent("100%") == 100);
assert_se(parse_percent("-7%") == -ERANGE);
assert_se(parse_percent("107%") == -ERANGE);
assert_se(parse_percent("%") == -EINVAL);
assert_se(parse_percent("%%") == -EINVAL);
assert_se(parse_percent("%1") == -EINVAL);
assert_se(parse_percent("1%%") == -EINVAL);
assert_se(parse_percent("3.2%") == -EINVAL);
}
static void test_parse_percent_unbounded(void) {
assert_se(parse_percent_unbounded("101%") == 101);
assert_se(parse_percent_unbounded("400%") == 400);
}
static void test_parse_permille(void) {
assert_se(parse_permille("") == -EINVAL);
assert_se(parse_permille("foo") == -EINVAL);
assert_se(parse_permille("0") == -EINVAL);
assert_se(parse_permille("50") == -EINVAL);
assert_se(parse_permille("100") == -EINVAL);
assert_se(parse_permille("-1") == -EINVAL);
assert_se(parse_permille("0‰") == 0);
assert_se(parse_permille("555‰") == 555);
assert_se(parse_permille("1000‰") == 1000);
assert_se(parse_permille("-7‰") == -ERANGE);
assert_se(parse_permille("1007‰") == -ERANGE);
assert_se(parse_permille("") == -EINVAL);
assert_se(parse_permille("‰‰") == -EINVAL);
assert_se(parse_permille("‰1") == -EINVAL);
assert_se(parse_permille("1‰‰") == -EINVAL);
assert_se(parse_permille("3.2‰") == -EINVAL);
assert_se(parse_permille("0%") == 0);
assert_se(parse_permille("55%") == 550);
assert_se(parse_permille("55.5%") == 555);
assert_se(parse_permille("100%") == 1000);
assert_se(parse_permille("-7%") == -ERANGE);
assert_se(parse_permille("107%") == -ERANGE);
assert_se(parse_permille("%") == -EINVAL);
assert_se(parse_permille("%%") == -EINVAL);
assert_se(parse_permille("%1") == -EINVAL);
assert_se(parse_permille("1%%") == -EINVAL);
assert_se(parse_permille("3.21%") == -EINVAL);
}
static void test_parse_permille_unbounded(void) {
assert_se(parse_permille_unbounded("1001‰") == 1001);
assert_se(parse_permille_unbounded("4000‰") == 4000);
assert_se(parse_permille_unbounded("2147483647‰") == 2147483647);
assert_se(parse_permille_unbounded("2147483648‰") == -ERANGE);
assert_se(parse_permille_unbounded("4294967295‰") == -ERANGE);
assert_se(parse_permille_unbounded("4294967296‰") == -ERANGE);
assert_se(parse_permille_unbounded("101%") == 1010);
assert_se(parse_permille_unbounded("400%") == 4000);
assert_se(parse_permille_unbounded("214748364.7%") == 2147483647);
assert_se(parse_permille_unbounded("214748364.8%") == -ERANGE);
assert_se(parse_permille_unbounded("429496729.5%") == -ERANGE);
assert_se(parse_permille_unbounded("429496729.6%") == -ERANGE);
}
static void test_parse_permyriad(void) {
assert_se(parse_permyriad("") == -EINVAL);
assert_se(parse_permyriad("foo") == -EINVAL);
assert_se(parse_permyriad("0") == -EINVAL);
assert_se(parse_permyriad("50") == -EINVAL);
assert_se(parse_permyriad("100") == -EINVAL);
assert_se(parse_permyriad("-1") == -EINVAL);
assert_se(parse_permyriad("0‱") == 0);
assert_se(parse_permyriad("555‱") == 555);
assert_se(parse_permyriad("1000‱") == 1000);
assert_se(parse_permyriad("-7‱") == -ERANGE);
assert_se(parse_permyriad("10007‱") == -ERANGE);
assert_se(parse_permyriad("") == -EINVAL);
assert_se(parse_permyriad("‱‱") == -EINVAL);
assert_se(parse_permyriad("‱1") == -EINVAL);
assert_se(parse_permyriad("1‱‱") == -EINVAL);
assert_se(parse_permyriad("3.2‱") == -EINVAL);
assert_se(parse_permyriad("0‰") == 0);
assert_se(parse_permyriad("555.5‰") == 5555);
assert_se(parse_permyriad("1000.0‰") == 10000);
assert_se(parse_permyriad("-7‰") == -ERANGE);
assert_se(parse_permyriad("1007‰") == -ERANGE);
assert_se(parse_permyriad("") == -EINVAL);
assert_se(parse_permyriad("‰‰") == -EINVAL);
assert_se(parse_permyriad("‰1") == -EINVAL);
assert_se(parse_permyriad("1‰‰") == -EINVAL);
assert_se(parse_permyriad("3.22‰") == -EINVAL);
assert_se(parse_permyriad("0%") == 0);
assert_se(parse_permyriad("55%") == 5500);
assert_se(parse_permyriad("55.53%") == 5553);
assert_se(parse_permyriad("100%") == 10000);
assert_se(parse_permyriad("-7%") == -ERANGE);
assert_se(parse_permyriad("107%") == -ERANGE);
assert_se(parse_permyriad("%") == -EINVAL);
assert_se(parse_permyriad("%%") == -EINVAL);
assert_se(parse_permyriad("%1") == -EINVAL);
assert_se(parse_permyriad("1%%") == -EINVAL);
assert_se(parse_permyriad("3.212%") == -EINVAL);
}
static void test_parse_permyriad_unbounded(void) {
assert_se(parse_permyriad_unbounded("1001‱") == 1001);
assert_se(parse_permyriad_unbounded("4000‱") == 4000);
assert_se(parse_permyriad_unbounded("2147483647‱") == 2147483647);
assert_se(parse_permyriad_unbounded("2147483648‱") == -ERANGE);
assert_se(parse_permyriad_unbounded("4294967295‱") == -ERANGE);
assert_se(parse_permyriad_unbounded("4294967296‱") == -ERANGE);
assert_se(parse_permyriad_unbounded("101‰") == 1010);
assert_se(parse_permyriad_unbounded("400‰") == 4000);
assert_se(parse_permyriad_unbounded("214748364.7‰") == 2147483647);
assert_se(parse_permyriad_unbounded("214748364.8‰") == -ERANGE);
assert_se(parse_permyriad_unbounded("429496729.5‰") == -ERANGE);
assert_se(parse_permyriad_unbounded("429496729.6‰") == -ERANGE);
assert_se(parse_permyriad_unbounded("99%") == 9900);
assert_se(parse_permyriad_unbounded("40%") == 4000);
assert_se(parse_permyriad_unbounded("21474836.47%") == 2147483647);
assert_se(parse_permyriad_unbounded("21474836.48%") == -ERANGE);
assert_se(parse_permyriad_unbounded("42949672.95%") == -ERANGE);
assert_se(parse_permyriad_unbounded("42949672.96%") == -ERANGE);
}
static void test_parse_nice(void) {
int n;
@ -911,6 +1049,12 @@ int main(int argc, char *argv[]) {
test_safe_atoi64();
test_safe_atoux64();
test_safe_atod();
test_parse_percent();
test_parse_percent_unbounded();
test_parse_permille();
test_parse_permille_unbounded();
test_parse_permyriad();
test_parse_permyriad_unbounded();
test_parse_nice();
test_parse_dev();
test_parse_errno();

View File

@ -1,211 +0,0 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "percent-util.h"
#include "tests.h"
#include "time-util.h"
static void test_parse_percent(void) {
assert_se(parse_percent("") == -EINVAL);
assert_se(parse_percent("foo") == -EINVAL);
assert_se(parse_percent("0") == -EINVAL);
assert_se(parse_percent("0.1") == -EINVAL);
assert_se(parse_percent("50") == -EINVAL);
assert_se(parse_percent("100") == -EINVAL);
assert_se(parse_percent("-1") == -EINVAL);
assert_se(parse_percent("0%") == 0);
assert_se(parse_percent("55%") == 55);
assert_se(parse_percent("100%") == 100);
assert_se(parse_percent("-7%") == -ERANGE);
assert_se(parse_percent("107%") == -ERANGE);
assert_se(parse_percent("%") == -EINVAL);
assert_se(parse_percent("%%") == -EINVAL);
assert_se(parse_percent("%1") == -EINVAL);
assert_se(parse_percent("1%%") == -EINVAL);
assert_se(parse_percent("3.2%") == -EINVAL);
}
static void test_parse_percent_unbounded(void) {
assert_se(parse_percent_unbounded("101%") == 101);
assert_se(parse_percent_unbounded("400%") == 400);
}
static void test_parse_permille(void) {
assert_se(parse_permille("") == -EINVAL);
assert_se(parse_permille("foo") == -EINVAL);
assert_se(parse_permille("0") == -EINVAL);
assert_se(parse_permille("50") == -EINVAL);
assert_se(parse_permille("100") == -EINVAL);
assert_se(parse_permille("-1") == -EINVAL);
assert_se(parse_permille("0.1") == -EINVAL);
assert_se(parse_permille("5%") == 50);
assert_se(parse_permille("5.5%") == 55);
assert_se(parse_permille("5.12%") == -EINVAL);
assert_se(parse_permille("0‰") == 0);
assert_se(parse_permille("555‰") == 555);
assert_se(parse_permille("1000‰") == 1000);
assert_se(parse_permille("-7‰") == -ERANGE);
assert_se(parse_permille("1007‰") == -ERANGE);
assert_se(parse_permille("") == -EINVAL);
assert_se(parse_permille("‰‰") == -EINVAL);
assert_se(parse_permille("‰1") == -EINVAL);
assert_se(parse_permille("1‰‰") == -EINVAL);
assert_se(parse_permille("3.2‰") == -EINVAL);
assert_se(parse_permille("0.1‰") == -EINVAL);
assert_se(parse_permille("0%") == 0);
assert_se(parse_permille("55%") == 550);
assert_se(parse_permille("55.5%") == 555);
assert_se(parse_permille("100%") == 1000);
assert_se(parse_permille("-7%") == -ERANGE);
assert_se(parse_permille("107%") == -ERANGE);
assert_se(parse_permille("%") == -EINVAL);
assert_se(parse_permille("%%") == -EINVAL);
assert_se(parse_permille("%1") == -EINVAL);
assert_se(parse_permille("1%%") == -EINVAL);
assert_se(parse_permille("3.21%") == -EINVAL);
assert_se(parse_permille("0.1%") == 1);
}
static void test_parse_permille_unbounded(void) {
assert_se(parse_permille_unbounded("1001‰") == 1001);
assert_se(parse_permille_unbounded("4000‰") == 4000);
assert_se(parse_permille_unbounded("2147483647‰") == 2147483647);
assert_se(parse_permille_unbounded("2147483648‰") == -ERANGE);
assert_se(parse_permille_unbounded("4294967295‰") == -ERANGE);
assert_se(parse_permille_unbounded("4294967296‰") == -ERANGE);
assert_se(parse_permille_unbounded("101%") == 1010);
assert_se(parse_permille_unbounded("400%") == 4000);
assert_se(parse_permille_unbounded("214748364.7%") == 2147483647);
assert_se(parse_permille_unbounded("214748364.8%") == -ERANGE);
assert_se(parse_permille_unbounded("429496729.5%") == -ERANGE);
assert_se(parse_permille_unbounded("429496729.6%") == -ERANGE);
}
static void test_parse_permyriad(void) {
assert_se(parse_permyriad("") == -EINVAL);
assert_se(parse_permyriad("foo") == -EINVAL);
assert_se(parse_permyriad("0") == -EINVAL);
assert_se(parse_permyriad("50") == -EINVAL);
assert_se(parse_permyriad("100") == -EINVAL);
assert_se(parse_permyriad("-1") == -EINVAL);
assert_se(parse_permyriad("0‱") == 0);
assert_se(parse_permyriad("555‱") == 555);
assert_se(parse_permyriad("1000‱") == 1000);
assert_se(parse_permyriad("-7‱") == -ERANGE);
assert_se(parse_permyriad("10007‱") == -ERANGE);
assert_se(parse_permyriad("") == -EINVAL);
assert_se(parse_permyriad("‱‱") == -EINVAL);
assert_se(parse_permyriad("‱1") == -EINVAL);
assert_se(parse_permyriad("1‱‱") == -EINVAL);
assert_se(parse_permyriad("3.2‱") == -EINVAL);
assert_se(parse_permyriad("0‰") == 0);
assert_se(parse_permyriad("555.5‰") == 5555);
assert_se(parse_permyriad("1000.0‰") == 10000);
assert_se(parse_permyriad("-7‰") == -ERANGE);
assert_se(parse_permyriad("1007‰") == -ERANGE);
assert_se(parse_permyriad("") == -EINVAL);
assert_se(parse_permyriad("‰‰") == -EINVAL);
assert_se(parse_permyriad("‰1") == -EINVAL);
assert_se(parse_permyriad("1‰‰") == -EINVAL);
assert_se(parse_permyriad("3.22‰") == -EINVAL);
assert_se(parse_permyriad("0%") == 0);
assert_se(parse_permyriad("55%") == 5500);
assert_se(parse_permyriad("55.5%") == 5550);
assert_se(parse_permyriad("55.50%") == 5550);
assert_se(parse_permyriad("55.53%") == 5553);
assert_se(parse_permyriad("100%") == 10000);
assert_se(parse_permyriad("-7%") == -ERANGE);
assert_se(parse_permyriad("107%") == -ERANGE);
assert_se(parse_permyriad("%") == -EINVAL);
assert_se(parse_permyriad("%%") == -EINVAL);
assert_se(parse_permyriad("%1") == -EINVAL);
assert_se(parse_permyriad("1%%") == -EINVAL);
assert_se(parse_permyriad("3.212%") == -EINVAL);
}
static void test_parse_permyriad_unbounded(void) {
assert_se(parse_permyriad_unbounded("1001‱") == 1001);
assert_se(parse_permyriad_unbounded("4000‱") == 4000);
assert_se(parse_permyriad_unbounded("2147483647‱") == 2147483647);
assert_se(parse_permyriad_unbounded("2147483648‱") == -ERANGE);
assert_se(parse_permyriad_unbounded("4294967295‱") == -ERANGE);
assert_se(parse_permyriad_unbounded("4294967296‱") == -ERANGE);
assert_se(parse_permyriad_unbounded("101‰") == 1010);
assert_se(parse_permyriad_unbounded("400‰") == 4000);
assert_se(parse_permyriad_unbounded("214748364.7‰") == 2147483647);
assert_se(parse_permyriad_unbounded("214748364.8‰") == -ERANGE);
assert_se(parse_permyriad_unbounded("429496729.5‰") == -ERANGE);
assert_se(parse_permyriad_unbounded("429496729.6‰") == -ERANGE);
assert_se(parse_permyriad_unbounded("99%") == 9900);
assert_se(parse_permyriad_unbounded("40%") == 4000);
assert_se(parse_permyriad_unbounded("21474836.47%") == 2147483647);
assert_se(parse_permyriad_unbounded("21474836.48%") == -ERANGE);
assert_se(parse_permyriad_unbounded("42949672.95%") == -ERANGE);
assert_se(parse_permyriad_unbounded("42949672.96%") == -ERANGE);
}
static void test_scale(void) {
/* Check some fixed values */
assert_se(UINT32_SCALE_FROM_PERCENT(0) == 0);
assert_se(UINT32_SCALE_FROM_PERCENT(50) == UINT32_MAX/2+1);
assert_se(UINT32_SCALE_FROM_PERCENT(100) == UINT32_MAX);
assert_se(UINT32_SCALE_FROM_PERMILLE(0) == 0);
assert_se(UINT32_SCALE_FROM_PERMILLE(500) == UINT32_MAX/2+1);
assert_se(UINT32_SCALE_FROM_PERMILLE(1000) == UINT32_MAX);
assert_se(UINT32_SCALE_FROM_PERMYRIAD(0) == 0);
assert_se(UINT32_SCALE_FROM_PERMYRIAD(5000) == UINT32_MAX/2+1);
assert_se(UINT32_SCALE_FROM_PERMYRIAD(10000) == UINT32_MAX);
/* Make sure there's no numeric noise on the 0%…100% scale when converting from percent and back. */
for (int percent = 0; percent <= 100; percent++) {
log_debug("%i%% → %" PRIu32 " → %i%%",
percent,
UINT32_SCALE_FROM_PERCENT(percent),
UINT32_SCALE_TO_PERCENT(UINT32_SCALE_FROM_PERCENT(percent)));
assert_se(UINT32_SCALE_TO_PERCENT(UINT32_SCALE_FROM_PERCENT(percent)) == percent);
}
/* Make sure there's no numeric noise on the 0‰…1000‰ scale when converting from permille and back. */
for (int permille = 0; permille <= 1000; permille++) {
log_debug("%i‰ → %" PRIu32 " → %i‰",
permille,
UINT32_SCALE_FROM_PERMILLE(permille),
UINT32_SCALE_TO_PERMILLE(UINT32_SCALE_FROM_PERMILLE(permille)));
assert_se(UINT32_SCALE_TO_PERMILLE(UINT32_SCALE_FROM_PERMILLE(permille)) == permille);
}
/* Make sure there's no numeric noise on the 0‱…10000‱ scale when converting from permyriad and back. */
for (int permyriad = 0; permyriad <= 10000; permyriad++) {
log_debug("%i‱ → %" PRIu32 " → %i‱",
permyriad,
UINT32_SCALE_FROM_PERMYRIAD(permyriad),
UINT32_SCALE_TO_PERMYRIAD(UINT32_SCALE_FROM_PERMYRIAD(permyriad)));
assert_se(UINT32_SCALE_TO_PERMYRIAD(UINT32_SCALE_FROM_PERMYRIAD(permyriad)) == permyriad);
}
}
int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
test_parse_percent();
test_parse_percent_unbounded();
test_parse_permille();
test_parse_permille_unbounded();
test_parse_permyriad();
test_parse_permyriad_unbounded();
test_scale();
return 0;
}

View File

@ -1,14 +1,13 @@
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.