X Tutup
Skip to content

Commit 47dba9f

Browse files
committed
path unit: add TriggerLimitBurst= and TriggerLimitIntervalSec=
Given there's now a default for these settings, also allow users to configure them, matching socket units
1 parent ef1aa10 commit 47dba9f

File tree

7 files changed

+63
-4
lines changed

7 files changed

+63
-4
lines changed

man/org.freedesktop.systemd1.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9357,6 +9357,10 @@ node /org/freedesktop/systemd1/unit/cups_2epath {
93579357
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
93589358
readonly u DirectoryMode = ...;
93599359
readonly s Result = '...';
9360+
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
9361+
readonly t TriggerLimitIntervalUSec = ...;
9362+
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
9363+
readonly u TriggerLimitBurst = ...;
93609364
};
93619365
interface org.freedesktop.DBus.Peer { ... };
93629366
interface org.freedesktop.DBus.Introspectable { ... };
@@ -9369,6 +9373,10 @@ node /org/freedesktop/systemd1/unit/cups_2epath {
93699373

93709374
<!--property DirectoryMode is not documented!-->
93719375

9376+
<!--property TriggerLimitIntervalUSec is not documented!-->
9377+
9378+
<!--property TriggerLimitBurst is not documented!-->
9379+
93729380
<!--Autogenerated cross-references for systemd.directives, do not edit-->
93739381

93749382
<variablelist class="dbus-interface" generated="True" extra-ref="org.freedesktop.systemd1.Unit"/>
@@ -9389,6 +9397,10 @@ node /org/freedesktop/systemd1/unit/cups_2epath {
93899397

93909398
<variablelist class="dbus-property" generated="True" extra-ref="Result"/>
93919399

9400+
<variablelist class="dbus-property" generated="True" extra-ref="TriggerLimitIntervalUSec"/>
9401+
9402+
<variablelist class="dbus-property" generated="True" extra-ref="TriggerLimitBurst"/>
9403+
93929404
<!--End of Autogenerated section-->
93939405

93949406
<refsect2>

man/systemd.path.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@
186186
in question. Takes an access mode in octal notation. Defaults
187187
to <option>0755</option>.</para></listitem>
188188
</varlistentry>
189+
<varlistentry>
190+
<term><varname>TriggerLimitIntervalSec=</varname></term>
191+
<term><varname>TriggerLimitBurst=</varname></term>
192+
193+
<listitem><para>Configures a limit on how often this path unit may be activated within a specific time
194+
interval. The <varname>TriggerLimitIntervalSec=</varname> may be used to configure the length of the time
195+
interval in the usual time units <literal>us</literal>, <literal>ms</literal>, <literal>s</literal>,
196+
<literal>min</literal>, <literal>h</literal>, … and defaults to 2s (See
197+
<citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry> for details on
198+
the various time units understood). The <varname>TriggerLimitBurst=</varname> setting takes a positive integer
199+
value and specifies the number of permitted activations per time interval, and defaults to 200. Set either to
200+
0 to disable any form of trigger rate limiting. If the limit is hit, the unit is placed into a failure mode,
201+
and will not watch the path(s) anymore until restarted. Note that this limit is enforced before the service
202+
activation is enqueued.</para></listitem>
203+
</varlistentry>
189204
</variablelist>
190205

191206
<xi:include href="systemd.service.xml" xpointer="shared-unit-options" />

src/core/dbus-path.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const sd_bus_vtable bus_path_vtable[] = {
4949
SD_BUS_PROPERTY("MakeDirectory", "b", bus_property_get_bool, offsetof(Path, make_directory), SD_BUS_VTABLE_PROPERTY_CONST),
5050
SD_BUS_PROPERTY("DirectoryMode", "u", bus_property_get_mode, offsetof(Path, directory_mode), SD_BUS_VTABLE_PROPERTY_CONST),
5151
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Path, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
52+
SD_BUS_PROPERTY("TriggerLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Path, trigger_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST),
53+
SD_BUS_PROPERTY("TriggerLimitBurst", "u", bus_property_get_unsigned, offsetof(Path, trigger_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST),
5254
SD_BUS_VTABLE_END
5355
};
5456

@@ -136,6 +138,12 @@ static int bus_path_set_transient_property(
136138
return 1;
137139
}
138140

141+
if (streq(name, "TriggerLimitBurst"))
142+
return bus_set_transient_unsigned(u, name, &p->trigger_limit.burst, message, flags, error);
143+
144+
if (streq(name, "TriggerLimitIntervalUSec"))
145+
return bus_set_transient_usec(u, name, &p->trigger_limit.interval, message, flags, error);
146+
139147
return 0;
140148
}
141149

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ Path.DirectoryNotEmpty, config_parse_path_spec,
542542
Path.Unit, config_parse_trigger_unit, 0, 0
543543
Path.MakeDirectory, config_parse_bool, 0, offsetof(Path, make_directory)
544544
Path.DirectoryMode, config_parse_mode, 0, offsetof(Path, directory_mode)
545+
Path.TriggerLimitIntervalSec, config_parse_sec, 0, offsetof(Path, trigger_limit.interval)
546+
Path.TriggerLimitBurst, config_parse_unsigned, 0, offsetof(Path, trigger_limit.burst)
545547
{{ CGROUP_CONTEXT_CONFIG_ITEMS('Slice') }}
546548
{{ CGROUP_CONTEXT_CONFIG_ITEMS('Scope') }}
547549
{{ KILL_CONTEXT_CONFIG_ITEMS('Scope') }}

src/core/path.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ static void path_init(Unit *u) {
266266

267267
p->directory_mode = 0755;
268268

269-
p->trigger_limit.interval = 2 * USEC_PER_SEC;
270-
p->trigger_limit.burst = 200;
269+
p->trigger_limit.interval = USEC_INFINITY;
270+
p->trigger_limit.burst = UINT_MAX;
271271
}
272272

273273
void path_free_specs(Path *p) {
@@ -356,6 +356,16 @@ static int path_add_trigger_dependencies(Path *p) {
356356
static int path_add_extras(Path *p) {
357357
int r;
358358

359+
assert(p);
360+
361+
/* To avoid getting pid1 in a busy-loop state (eg: failed condition on associated service),
362+
* set a default trigger limit if the user didn't specify any. */
363+
if (p->trigger_limit.interval == USEC_INFINITY)
364+
p->trigger_limit.interval = 2 * USEC_PER_SEC;
365+
366+
if (p->trigger_limit.burst == UINT_MAX)
367+
p->trigger_limit.burst = 200;
368+
359369
r = path_add_trigger_dependencies(p);
360370
if (r < 0)
361371
return r;
@@ -403,12 +413,16 @@ static void path_dump(Unit *u, FILE *f, const char *prefix) {
403413
"%sResult: %s\n"
404414
"%sUnit: %s\n"
405415
"%sMakeDirectory: %s\n"
406-
"%sDirectoryMode: %04o\n",
416+
"%sDirectoryMode: %04o\n"
417+
"%sTriggerLimitIntervalSec: %s\n"
418+
"%sTriggerLimitBurst: %u\n",
407419
prefix, path_state_to_string(p->state),
408420
prefix, path_result_to_string(p->result),
409421
prefix, trigger ? trigger->id : "n/a",
410422
prefix, yes_no(p->make_directory),
411-
prefix, p->directory_mode);
423+
prefix, p->directory_mode,
424+
prefix, FORMAT_TIMESPAN(p->trigger_limit.interval, USEC_PER_SEC),
425+
prefix, p->trigger_limit.burst);
412426

413427
LIST_FOREACH(spec, s, p->specs)
414428
path_spec_dump(s, f, prefix);

src/shared/bus-unit-util.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,6 +2113,12 @@ static int bus_append_path_property(sd_bus_message *m, const char *field, const
21132113
return 1;
21142114
}
21152115

2116+
if (streq(field, "TriggerLimitBurst"))
2117+
return bus_append_safe_atou(m, field, eq);
2118+
2119+
if (streq(field, "TriggerLimitIntervalSec"))
2120+
return bus_append_parse_sec_rename(m, field, eq);
2121+
21162122
return 0;
21172123
}
21182124

test/fuzz/fuzz-unit-file/directives.path

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ PathChanged=
77
PathExists=
88
PathExistsGlob=
99
PathModified=
10+
TriggerLimitBurst=
11+
TriggerLimitIntervalSec=
1012
Unit=

0 commit comments

Comments
 (0)
X Tutup