Skip to content
Snippets Groups Projects
Commit ef6f9645 authored by Thomas Bellman's avatar Thomas Bellman
Browse files

Forbid minus-prefixed option names in systemd::unit.

In systemd::unit_options, you can prefix an option name with a minus
sign (Unicode 002D "hyphen-minus") to "reset" a list option to the
empty list, so the new values don't just append to the existing list
of values.  That makes sense when overriding/supplementing options in
earlier unit files, but systemd::unit installs the "main" unit file,
the one that is read first, so list options *always* have the empty
list as their value when the file is read.

We here modify the unitfile.erb template file to see if it is called
from systemd::unit or systemd::unit_options, and if the former, it
raises an error if it encounters an option name starting with a minus
sign.  And of course also remove the paragraph describing that beha-
viour in the 'options' parameter documentation.
parent a6807aed
No related branches found
No related tags found
No related merge requests found
......@@ -35,11 +35,6 @@ define systemd::unit(
# support multi-value options, e.g. "ExecStart" in a service config,
# or "ListenStream" in a socket config.
#
# If the option name starts with a minus sign ("-"), an extra line
# setting that option to the empty string is prepended, in order to
# reset that option to the empty list, as systemd would otherwise
# just append the new value(s) to the existing list.
#
$options=undef,
# String to put in the unit file. This is equivalent to the
......
......@@ -13,9 +13,17 @@
[<%= section_name %>]
<% section_options.sort.each do |optname,value| -%>
<% if optname =~ /^-(.*)/
if @systemd_resource_type == 'Unit_options'
optname = $1
-%>
<%= optname %>=
<% elsif @systemd_resource_type == 'Unit'
raise(Puppet::ParseError, "Bad option name, ``#{optname}''")
else
raise(Puppet::ParseError,
'Internal error: $systemd_resource_type bad value')
-%>
<% end -%>
<% end -%>
<% [value].flatten.each do |v| -%>
<%= optname %>=<%= v %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment