Merge pull request #15745 from keszybz/one-more-specifier

Add %l as specifier for short hostname
This commit is contained in:
Lennart Poettering 2020-05-07 22:18:59 +02:00 committed by GitHub
commit c60bc8d4fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 423 additions and 284 deletions

190
man/directives-template.xml Normal file
View file

@ -0,0 +1,190 @@
<!-- SPDX-License-Identifier: LGPL-2.1+ -->
<refentry id="systemd.directives" conditional="HAVE_PYTHON">
<refentryinfo>
<title>systemd.directives</title>
<productname>systemd</productname>
</refentryinfo>
<refmeta>
<refentrytitle>systemd.directives</refentrytitle>
<manvolnum>7</manvolnum>
</refmeta>
<refnamediv>
<refname>systemd.directives</refname>
<refpurpose>Index of configuration directives</refpurpose>
</refnamediv>
<refsect1>
<title>Unit directives</title>
<para>Directives for configuring units, used in unit files.</para>
<variablelist id='unit-directives' />
</refsect1>
<refsect1>
<title>Options on the kernel command line</title>
<para>Kernel boot options for configuring the behaviour of the systemd process.</para>
<variablelist id='kernel-commandline-options' />
</refsect1>
<refsect1>
<title>Environment variables</title>
<para>Environment variables understood by the systemd manager and other programs and environment
variable-compatible settings.</para>
<variablelist id='environment-variables' />
</refsect1>
<refsect1>
<title>EFI variables</title>
<para>EFI variables understood by
<citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>
and other programs.</para>
<variablelist id='efi-variables' />
</refsect1>
<refsect1>
<title>UDEV directives</title>
<para>Directives for configuring systemd units through the udev database.</para>
<variablelist id='udev-directives' />
</refsect1>
<refsect1>
<title>Network directives</title>
<para>Directives for configuring network links through the net-setup-link udev builtin and networks
through systemd-networkd.</para>
<variablelist id='network-directives' />
</refsect1>
<refsect1>
<title>Journal fields</title>
<para>Fields in the journal events with a well known meaning.</para>
<variablelist id='journal-directives' />
</refsect1>
<refsect1>
<title>PAM configuration directives</title>
<para>Directives for configuring PAM behaviour.</para>
<variablelist id='pam-directives' />
</refsect1>
<refsect1>
<title><filename>/etc/crypttab</filename> and
<filename>/etc/fstab</filename> options</title>
<para>Options which influence mounted filesystems and encrypted volumes.</para>
<variablelist id='fstab-options' />
</refsect1>
<refsect1>
<title><citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry>
directives</title>
<para>Directives for configuring systemd-nspawn containers.</para>
<variablelist id='nspawn-directives' />
</refsect1>
<refsect1>
<title>Program configuration options</title>
<para>Directives for configuring the behaviour of the systemd process and other tools through
configuration files.</para>
<variablelist id='config-directives' />
</refsect1>
<refsect1>
<title>Command line options</title>
<para>Command-line options accepted by programs in the systemd suite.</para>
<variablelist id='options' />
</refsect1>
<refsect1>
<title>Constants</title>
<para>Various constant used and/or defined by systemd.</para>
<variablelist id='constants' />
</refsect1>
<refsect1>
<title>Miscellaneous options and directives</title>
<para>Other configuration elements which don't fit in any of the above groups.</para>
<variablelist id='miscellaneous' />
</refsect1>
<refsect1>
<title>Specifiers</title>
<para>Short strings which are substituted in configuration directives.</para>
<variablelist id='specifiers' />
</refsect1>
<refsect1>
<title>Files and directories</title>
<para>Paths and file names referred to in the documentation.</para>
<variablelist id='filenames' />
</refsect1>
<refsect1>
<title>D-Bus interfaces</title>
<para>Interfaces exposed over D-Bus.</para>
<variablelist id='dbus-interface' />
</refsect1>
<refsect1>
<title>D-Bus methods</title>
<para>Methods exposed in the D-Bus interface.</para>
<variablelist id='dbus-method' />
</refsect1>
<refsect1>
<title>D-Bus properties</title>
<para>Properties exposed in the D-Bus interface.</para>
<variablelist id='dbus-property' />
</refsect1>
<refsect1>
<title>D-Bus signals</title>
<para>Signals emitted in the D-Bus interface.</para>
<variablelist id='dbus-signal' />
</refsect1>
<refsect1>
<title>Colophon</title>
<para id='colophon' />
</refsect1>
</refentry>

View file

@ -110,9 +110,9 @@ endif
systemd_directives_xml = custom_target( systemd_directives_xml = custom_target(
'systemd.directives.xml', 'systemd.directives.xml',
input : source_xml_files, input : ['directives-template.xml', source_xml_files],
output : 'systemd.directives.xml', output : 'systemd.directives.xml',
command : [make_directive_index_py, '@OUTPUT@'] + source_xml_files) command : [make_directive_index_py, '@OUTPUT@', '@INPUT@'])
nonindex_xml_files = source_xml_files + [systemd_directives_xml] nonindex_xml_files = source_xml_files + [systemd_directives_xml]
systemd_index_xml = custom_target( systemd_index_xml = custom_target(
@ -217,7 +217,7 @@ if git.found()
output : 'update-man-rules', output : 'update-man-rules',
command : ['sh', '-c', command : ['sh', '-c',
'cd @0@ && '.format(meson.build_root()) + 'cd @0@ && '.format(meson.build_root()) +
'python3 @0@/tools/make-man-rules.py $(git ls-files ":/man/*.xml") >t && '.format(project_source_root) + 'python3 @0@/tools/update-man-rules.py $(git ls-files ":/man/*.xml") >t && '.format(project_source_root) +
'mv t @0@/rules/meson.build'.format(meson.current_source_dir())], 'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
depend_files : custom_entities_ent) depend_files : custom_entities_ent)
endif endif

View file

@ -259,31 +259,31 @@
<variablelist class='pam-directives'> <variablelist class='pam-directives'>
<varlistentry> <varlistentry>
<term><varname>systemd.memory_max</varname></term> <term><varname>systemd.memory_max=</varname></term>
<listitem><para>Sets unit <varname>MemoryMax=</varname>.</para></listitem> <listitem><para>Sets unit <varname>MemoryMax=</varname>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>systemd.tasks_max</varname></term> <term><varname>systemd.tasks_max=</varname></term>
<listitem><para>Sets unit <varname>TasksMax=</varname>.</para></listitem> <listitem><para>Sets unit <varname>TasksMax=</varname>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>systemd.cpu_weight</varname></term> <term><varname>systemd.cpu_weight=</varname></term>
<listitem><para>Sets unit <varname>CPUWeight=</varname>.</para></listitem> <listitem><para>Sets unit <varname>CPUWeight=</varname>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>systemd.io_weight</varname></term> <term><varname>systemd.io_weight=</varname></term>
<listitem><para>Sets unit <varname>IOWeight=</varname>.</para></listitem> <listitem><para>Sets unit <varname>IOWeight=</varname>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><varname>systemd.runtime_max_sec</varname></term> <term><varname>systemd.runtime_max_sec=</varname></term>
<listitem><para>Sets unit <varname>RuntimeMaxSec=</varname>.</para></listitem> <listitem><para>Sets unit <varname>RuntimeMaxSec=</varname>.</para></listitem>
</varlistentry> </varlistentry>

View file

@ -1,4 +1,4 @@
# Do not edit. Generated by make-man-rules.py. # Do not edit. Generated by update-man-rules.py.
# Update with: # Update with:
# ninja -C build man/update-man-rules # ninja -C build man/update-man-rules
manpages = [ manpages = [

View file

@ -24,6 +24,11 @@
<entry>Host name</entry> <entry>Host name</entry>
<entry>The hostname of the running system.</entry> <entry>The hostname of the running system.</entry>
</row> </row>
<row id='l'>
<entry><literal>%l</literal></entry>
<entry>Short host name</entry>
<entry>The hostname of the running system, truncated at the first dot to remove any domain component.</entry>
</row>
<row id='m'> <row id='m'>
<entry><literal>%m</literal></entry> <entry><literal>%m</literal></entry>
<entry>Machine ID</entry> <entry>Machine ID</entry>

View file

@ -75,7 +75,7 @@
<para>An instance name of the network service as defined in the section 4.1.1 of <ulink <para>An instance name of the network service as defined in the section 4.1.1 of <ulink
url="https://tools.ietf.org/html/rfc6763">RFC 6763</ulink>, e.g. <literal>webserver</literal>.</para> url="https://tools.ietf.org/html/rfc6763">RFC 6763</ulink>, e.g. <literal>webserver</literal>.</para>
<para>The option supports simple specifier expansion. The following expansions are understood:</para> <para>The option supports simple specifier expansion. The following expansions are understood:</para>
<table> <table class='specifiers'>
<title>Specifiers available</title> <title>Specifiers available</title>
<tgroup cols='3' align='left' colsep='1' rowsep='1'> <tgroup cols='3' align='left' colsep='1' rowsep='1'>
<colspec colname="spec" /> <colspec colname="spec" />

View file

@ -444,9 +444,9 @@
created. (See created. (See
<citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for more information.) This option is mandatory. Note that the usual specifier expansion is applied for more information.) This option is mandatory. Note that the usual specifier expansion is applied
to this setting, literal percent characters should hence be written as <literal>%%</literal>. If this to this setting, literal percent characters should hence be written as <literal
mount is a bind mount and the specified path does not exist yet it is created as class='specifiers'>%%</literal>. If this mount is a bind mount and the specified path does not exist
directory.</para></listitem> yet it is created as directory.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -469,7 +469,7 @@
<listitem><para>Mount options to use when mounting. This takes a comma-separated list of options. This setting <listitem><para>Mount options to use when mounting. This takes a comma-separated list of options. This setting
is optional. Note that the usual specifier expansion is applied to this setting, literal percent characters is optional. Note that the usual specifier expansion is applied to this setting, literal percent characters
should hence be written as <literal>%%</literal>.</para></listitem> should hence be written as <literal class='specifiers'>%%</literal>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View file

@ -184,11 +184,13 @@
project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> for project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
details. If this refers to a device node, a dependency on the respective device unit is automatically details. If this refers to a device node, a dependency on the respective device unit is automatically
created. (See created. (See
<citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>
information.) If this refers to a file, a dependency on the respective mount unit is automatically for more information.) If this refers to a file, a dependency on the respective mount unit is
created. (See <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry> automatically created. (See
for more information.) This option is mandatory. Note that the usual specifier expansion is applied to this <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
setting, literal percent characters should hence be written as <literal>%%</literal>.</para></listitem> more information.) This option is mandatory. Note that the usual specifier expansion is applied to
this setting, literal percent characters should hence be written as
<literal class='specifiers'>%%</literal>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View file

@ -1695,7 +1695,7 @@
and resolvable for the setting to be valid. The following and resolvable for the setting to be valid. The following
specifiers are understood:</para> specifiers are understood:</para>
<table> <table class='specifiers'>
<title>Specifiers available in unit files</title> <title>Specifiers available in unit files</title>
<tgroup cols='3' align='left' colsep='1' rowsep='1'> <tgroup cols='3' align='left' colsep='1' rowsep='1'>
<colspec colname="spec" /> <colspec colname="spec" />
@ -1710,7 +1710,8 @@
</thead> </thead>
<tbody> <tbody>
<row> <row>
<!-- We do not use the common definition from standard-specifiers.xml here since it includes a reference onto our own man page, which would make the rendered version self-referential. --> <!-- We do not use the common definition from standard-specifiers.xml here since it includes a
reference onto our own man page, which would make the rendered version self-referential. -->
<entry><literal>%a</literal></entry> <entry><literal>%a</literal></entry>
<entry>Architecture</entry> <entry>Architecture</entry>
<entry>A short string identifying the architecture of the local system. A string such as <constant>x86</constant>, <constant>x86-64</constant> or <constant>arm64</constant>. See the architectures defined for <varname>ConditionArchitecture=</varname> above for a full list.</entry> <entry>A short string identifying the architecture of the local system. A string such as <constant>x86</constant>, <constant>x86-64</constant> or <constant>arm64</constant>. See the architectures defined for <varname>ConditionArchitecture=</varname> above for a full list.</entry>
@ -1740,11 +1741,17 @@
Note that this setting is <emphasis>not</emphasis> influenced by the <varname>User=</varname> setting configurable in the [Service] section of the service unit.</entry> Note that this setting is <emphasis>not</emphasis> influenced by the <varname>User=</varname> setting configurable in the [Service] section of the service unit.</entry>
</row> </row>
<row> <row>
<!-- We do not use the common definition from standard-specifiers.xml here since we want a slightly more verbose explanation here, referring to the reload cycle. --> <!-- We do not use the common definition from standard-specifiers.xml here since we want a
slightly more verbose explanation here, referring to the reload cycle. -->
<entry><literal>%H</literal></entry> <entry><literal>%H</literal></entry>
<entry>Host name</entry> <entry>Host name</entry>
<entry>The hostname of the running system at the point in time the unit configuration is loaded.</entry> <entry>The hostname of the running system at the point in time the unit configuration is loaded.</entry>
</row> </row>
<row>
<entry><literal>%l</literal></entry>
<entry>Short host name</entry>
<entry>The hostname of the running system at the point in time the unit configuration is loaded, truncated at the first dot to remove any domain component.</entry>
</row>
<row> <row>
<entry><literal>%i</literal></entry> <entry><literal>%i</literal></entry>
<entry>Instance name</entry> <entry>Instance name</entry>

View file

@ -234,46 +234,49 @@ r - 500-900
<refsect1> <refsect1>
<title>Specifiers</title> <title>Specifiers</title>
<para>Specifiers can be used in the "Name", "ID", "GECOS", "Home directory", and "Shell" fields. <para>Specifiers can be used in the <literal>Name</literal>, <literal>ID</literal>,
An unknown or unresolvable specifier is treated as invalid configuration. <literal>GECOS</literal>, <literal>Home directory</literal>, and <literal>Shell</literal> fields. An
The following expansions are understood:</para> unknown or unresolvable specifier is treated as invalid configuration. The following expansions are
<table> understood:</para>
<title>Specifiers available</title>
<tgroup cols='3' align='left' colsep='1' rowsep='1'> <table class='specifiers'>
<colspec colname="spec" /> <title>Specifiers available</title>
<colspec colname="mean" /> <tgroup cols='3' align='left' colsep='1' rowsep='1'>
<colspec colname="detail" /> <colspec colname="spec" />
<thead> <colspec colname="mean" />
<row> <colspec colname="detail" />
<entry>Specifier</entry> <thead>
<entry>Meaning</entry> <row>
<entry>Details</entry> <entry>Specifier</entry>
</row> <entry>Meaning</entry>
</thead> <entry>Details</entry>
<tbody> </row>
<xi:include href="standard-specifiers.xml" xpointer="a"/> </thead>
<xi:include href="standard-specifiers.xml" xpointer="b"/> <tbody>
<xi:include href="standard-specifiers.xml" xpointer="B"/> <xi:include href="standard-specifiers.xml" xpointer="a"/>
<xi:include href="standard-specifiers.xml" xpointer="H"/> <xi:include href="standard-specifiers.xml" xpointer="b"/>
<xi:include href="standard-specifiers.xml" xpointer="m"/> <xi:include href="standard-specifiers.xml" xpointer="B"/>
<xi:include href="standard-specifiers.xml" xpointer="o"/> <xi:include href="standard-specifiers.xml" xpointer="H"/>
<row> <xi:include href="standard-specifiers.xml" xpointer="l"/>
<entry><literal>%T</literal></entry> <xi:include href="standard-specifiers.xml" xpointer="m"/>
<entry>Directory for temporary files</entry> <xi:include href="standard-specifiers.xml" xpointer="o"/>
<entry>This is either <filename>/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry> <row>
</row> <entry><literal>%T</literal></entry>
<xi:include href="standard-specifiers.xml" xpointer="v"/> <entry>Directory for temporary files</entry>
<row> <entry>This is either <filename>/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry>
<entry><literal>%V</literal></entry> </row>
<entry>Directory for larger and persistent temporary files</entry> <xi:include href="standard-specifiers.xml" xpointer="v"/>
<entry>This is either <filename>/var/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry> <row>
</row> <entry><literal>%V</literal></entry>
<xi:include href="standard-specifiers.xml" xpointer="w"/> <entry>Directory for larger and persistent temporary files</entry>
<xi:include href="standard-specifiers.xml" xpointer="W"/> <entry>This is either <filename>/var/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry>
<xi:include href="standard-specifiers.xml" xpointer="percent"/> </row>
</tbody> <xi:include href="standard-specifiers.xml" xpointer="w"/>
</tgroup> <xi:include href="standard-specifiers.xml" xpointer="W"/>
</table> <xi:include href="standard-specifiers.xml" xpointer="percent"/>
</tbody>
</tgroup>
</table>
</refsect1> </refsect1>
<refsect1> <refsect1>

View file

@ -618,7 +618,7 @@ w- /proc/sys/vm/swappiness - - - - 10</programlisting></para>
<para>Specifiers can be used in the "path" and "argument" fields. <para>Specifiers can be used in the "path" and "argument" fields.
An unknown or unresolvable specifier is treated as invalid configuration. An unknown or unresolvable specifier is treated as invalid configuration.
The following expansions are understood:</para> The following expansions are understood:</para>
<table> <table class='specifiers'>
<title>Specifiers available</title> <title>Specifiers available</title>
<tgroup cols='3' align='left' colsep='1' rowsep='1'> <tgroup cols='3' align='left' colsep='1' rowsep='1'>
<colspec colname="spec" /> <colspec colname="spec" />
@ -646,6 +646,7 @@ w- /proc/sys/vm/swappiness - - - - 10</programlisting></para>
<entry>This is the home directory of the user running the command. In case of the system instance this resolves to <literal>/root</literal>.</entry> <entry>This is the home directory of the user running the command. In case of the system instance this resolves to <literal>/root</literal>.</entry>
</row> </row>
<xi:include href="standard-specifiers.xml" xpointer="H"/> <xi:include href="standard-specifiers.xml" xpointer="H"/>
<xi:include href="standard-specifiers.xml" xpointer="l"/>
<row> <row>
<entry><literal>%L</literal></entry> <entry><literal>%L</literal></entry>
<entry>System or user log directory</entry> <entry>System or user log directory</entry>

View file

@ -299,7 +299,7 @@ substs.set('BUILD_ROOT', project_build_root
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
pkgconfig = import('pkgconfig') pkgconfig = import('pkgconfig')
check_compilation_sh = find_program('tools/meson-check-compilation.sh') check_compilation_sh = find_program('tools/check-compilation.sh')
meson_build_sh = find_program('tools/meson-build.sh') meson_build_sh = find_program('tools/meson-build.sh')
want_tests = get_option('tests') want_tests = get_option('tests')
@ -639,7 +639,14 @@ endforeach
############################################################ ############################################################
conf.set_quoted('FALLBACK_HOSTNAME', get_option('fallback-hostname')) fallback_hostname = get_option('fallback-hostname')
if fallback_hostname == '' or fallback_hostname[0] == '.' or fallback_hostname[0] == '-'
error('Invalid fallback-hostname configuration')
# A more extensive test is done in test-hostname-util. Let's catch
# the most obvious errors here so we don't fail with an assert later.
endif
conf.set_quoted('FALLBACK_HOSTNAME', fallback_hostname)
conf.set10('ENABLE_COMPAT_GATEWAY_HOSTNAME', get_option('compat-gateway-hostname')) conf.set10('ENABLE_COMPAT_GATEWAY_HOSTNAME', get_option('compat-gateway-hostname'))
gateway_hostnames = ['_gateway'] + (conf.get('ENABLE_COMPAT_GATEWAY_HOSTNAME') == 1 ? ['gateway'] : []) gateway_hostnames = ['_gateway'] + (conf.get('ENABLE_COMPAT_GATEWAY_HOSTNAME') == 1 ? ['gateway'] : [])
@ -3244,8 +3251,8 @@ run_target(
make_directive_index_py = find_program('tools/make-directive-index.py') make_directive_index_py = find_program('tools/make-directive-index.py')
make_man_index_py = find_program('tools/make-man-index.py') make_man_index_py = find_program('tools/make-man-index.py')
xml_helper_py = find_program('tools/xml_helper.py') xml_helper_py = find_program('tools/xml_helper.py')
hwdb_update_sh = find_program('tools/meson-hwdb-update.sh') hwdb_update_sh = find_program('tools/hwdb-update.sh')
autosuspend_update_sh = find_program('tools/meson-autosuspend-update.sh') autosuspend_update_sh = find_program('tools/autosuspend-update.sh')
subdir('sysctl.d') subdir('sysctl.d')
subdir('sysusers.d') subdir('sysusers.d')
@ -3286,13 +3293,13 @@ meson.add_install_script('sh', '-c', 'touch $DESTDIR@0@'.format(prefixdir))
############################################################ ############################################################
meson_check_help = find_program('tools/meson-check-help.sh') check_help = find_program('tools/check-help.sh')
foreach exec : public_programs foreach exec : public_programs
name = exec.full_path().split('/')[-1] name = exec.full_path().split('/')[-1]
if want_tests != 'false' if want_tests != 'false'
test('check-help-' + name, test('check-help-' + name,
meson_check_help, check_help,
args : exec.full_path()) args : exec.full_path())
endif endif
endforeach endforeach
@ -3371,10 +3378,10 @@ if git.found()
endif endif
if git.found() if git.found()
meson_git_contrib_sh = find_program('tools/meson-git-contrib.sh') git_contrib_sh = find_program('tools/git-contrib.sh')
run_target( run_target(
'git-contrib', 'git-contrib',
command : [meson_git_contrib_sh]) command : [git_contrib_sh])
endif endif
if git.found() if git.found()
@ -3398,11 +3405,11 @@ endif
############################################################ ############################################################
meson_check_api_docs_sh = find_program('tools/meson-check-api-docs.sh') check_api_docs_sh = find_program('tools/check-api-docs.sh')
run_target( run_target(
'check-api-docs', 'check-api-docs',
depends : [man, libsystemd, libudev], depends : [man, libsystemd, libudev],
command : [meson_check_api_docs_sh, libsystemd.full_path(), libudev.full_path()]) command : [check_api_docs_sh, libsystemd.full_path(), libudev.full_path()])
############################################################ ############################################################
watchdog_opt = service_watchdog == '' ? 'disabled' : service_watchdog watchdog_opt = service_watchdog == '' ? 'disabled' : service_watchdog

View file

@ -31,6 +31,7 @@ bool hostname_is_set(void) {
char* gethostname_malloc(void) { char* gethostname_malloc(void) {
struct utsname u; struct utsname u;
const char *s;
/* This call tries to return something useful, either the actual hostname /* This call tries to return something useful, either the actual hostname
* or it makes something up. The only reason it might fail is OOM. * or it makes something up. The only reason it might fail is OOM.
@ -38,10 +39,28 @@ char* gethostname_malloc(void) {
assert_se(uname(&u) >= 0); assert_se(uname(&u) >= 0);
if (isempty(u.nodename) || streq(u.nodename, "(none)")) s = u.nodename;
return strdup(FALLBACK_HOSTNAME); if (isempty(s) || streq(s, "(none)"))
s = FALLBACK_HOSTNAME;
return strdup(u.nodename); return strdup(s);
}
char* gethostname_short_malloc(void) {
struct utsname u;
const char *s;
/* Like above, but kills the FQDN part if present. */
assert_se(uname(&u) >= 0);
s = u.nodename;
if (isempty(s) || streq(s, "(none)") || s[0] == '.') {
s = FALLBACK_HOSTNAME;
assert(s[0] != '.');
}
return strndup(s, strcspn(s, "."));
} }
int gethostname_strict(char **ret) { int gethostname_strict(char **ret) {

View file

@ -9,6 +9,7 @@
bool hostname_is_set(void); bool hostname_is_set(void);
char* gethostname_malloc(void); char* gethostname_malloc(void);
char* gethostname_short_malloc(void);
int gethostname_strict(char **ret); int gethostname_strict(char **ret);
bool valid_ldh_char(char c) _const_; bool valid_ldh_char(char c) _const_;

View file

@ -291,6 +291,7 @@ int unit_full_printf(const Unit *u, const char *format, char **ret) {
{ 'm', specifier_machine_id, NULL }, { 'm', specifier_machine_id, NULL },
{ 'H', specifier_host_name, NULL }, { 'H', specifier_host_name, NULL },
{ 'l', specifier_short_host_name, NULL },
{ 'b', specifier_boot_id, NULL }, { 'b', specifier_boot_id, NULL },
{ 'v', specifier_kernel_release, NULL }, { 'v', specifier_kernel_release, NULL },
{} {}

View file

@ -160,6 +160,17 @@ int specifier_host_name(char specifier, const void *data, const void *userdata,
return 0; return 0;
} }
int specifier_short_host_name(char specifier, const void *data, const void *userdata, char **ret) {
char *n;
n = gethostname_short_malloc();
if (!n)
return -ENOMEM;
*ret = n;
return 0;
}
int specifier_kernel_release(char specifier, const void *data, const void *userdata, char **ret) { int specifier_kernel_release(char specifier, const void *data, const void *userdata, char **ret) {
struct utsname uts; struct utsname uts;
char *n; char *n;

View file

@ -18,6 +18,7 @@ int specifier_string(char specifier, const void *data, const void *userdata, cha
int specifier_machine_id(char specifier, const void *data, const void *userdata, char **ret); int specifier_machine_id(char specifier, const void *data, const void *userdata, char **ret);
int specifier_boot_id(char specifier, const void *data, const void *userdata, char **ret); int specifier_boot_id(char specifier, const void *data, const void *userdata, char **ret);
int specifier_host_name(char specifier, const void *data, const void *userdata, char **ret); int specifier_host_name(char specifier, const void *data, const void *userdata, char **ret);
int specifier_short_host_name(char specifier, const void *data, const void *userdata, char **ret);
int specifier_kernel_release(char specifier, const void *data, const void *userdata, char **ret); int specifier_kernel_release(char specifier, const void *data, const void *userdata, char **ret);
int specifier_architecture(char specifier, const void *data, const void *userdata, char **ret); int specifier_architecture(char specifier, const void *data, const void *userdata, char **ret);
int specifier_os_id(char specifier, const void *data, const void *userdata, char **ret); int specifier_os_id(char specifier, const void *data, const void *userdata, char **ret);

View file

@ -1389,17 +1389,18 @@ static bool item_equal(Item *a, Item *b) {
static int parse_line(const char *fname, unsigned line, const char *buffer) { static int parse_line(const char *fname, unsigned line, const char *buffer) {
static const Specifier specifier_table[] = { static const Specifier specifier_table[] = {
{ 'm', specifier_machine_id, NULL }, { 'm', specifier_machine_id, NULL },
{ 'b', specifier_boot_id, NULL }, { 'b', specifier_boot_id, NULL },
{ 'H', specifier_host_name, NULL }, { 'H', specifier_host_name, NULL },
{ 'v', specifier_kernel_release, NULL }, { 'l', specifier_short_host_name, NULL },
{ 'a', specifier_architecture, NULL }, { 'v', specifier_kernel_release, NULL },
{ 'o', specifier_os_id, NULL }, { 'a', specifier_architecture, NULL },
{ 'w', specifier_os_version_id, NULL }, { 'o', specifier_os_id, NULL },
{ 'B', specifier_os_build_id, NULL }, { 'w', specifier_os_version_id, NULL },
{ 'W', specifier_os_variant_id, NULL }, { 'B', specifier_os_build_id, NULL },
{ 'T', specifier_tmp_dir, NULL }, { 'W', specifier_os_variant_id, NULL },
{ 'V', specifier_var_tmp_dir, NULL }, { 'T', specifier_tmp_dir, NULL },
{ 'V', specifier_var_tmp_dir, NULL },
{} {}
}; };

View file

@ -140,6 +140,23 @@ static void test_read_etc_hostname(void) {
unlink(path); unlink(path);
} }
static void test_hostname_malloc(void) {
_cleanup_free_ char *h = NULL, *l = NULL;
assert_se(h = gethostname_malloc());
log_info("hostname_malloc: \"%s\"", h);
assert_se(l = gethostname_short_malloc());
log_info("hostname_short_malloc: \"%s\"", l);
}
static void test_fallback_hostname(void) {
if (!hostname_is_valid(FALLBACK_HOSTNAME, false)) {
log_error("Configured fallback hostname \"%s\" is not valid.", FALLBACK_HOSTNAME);
exit(EXIT_FAILURE);
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
log_parse_environment(); log_parse_environment();
log_open(); log_open();
@ -147,6 +164,9 @@ int main(int argc, char *argv[]) {
test_hostname_is_valid(); test_hostname_is_valid();
test_hostname_cleanup(); test_hostname_cleanup();
test_read_etc_hostname(); test_read_etc_hostname();
test_hostname_malloc();
test_fallback_hostname();
return 0; return 0;
} }

View file

@ -3,6 +3,7 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "log.h" #include "log.h"
#include "specifier.h" #include "specifier.h"
#include "stdio-util.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h" #include "strv.h"
#include "tests.h" #include "tests.h"
@ -15,6 +16,8 @@ static void test_specifier_escape_one(const char *a, const char *b) {
} }
static void test_specifier_escape(void) { static void test_specifier_escape(void) {
log_info("/* %s */", __func__);
test_specifier_escape_one(NULL, NULL); test_specifier_escape_one(NULL, NULL);
test_specifier_escape_one("", ""); test_specifier_escape_one("", "");
test_specifier_escape_one("%", "%%"); test_specifier_escape_one("%", "%%");
@ -31,12 +34,54 @@ static void test_specifier_escape_strv_one(char **a, char **b) {
} }
static void test_specifier_escape_strv(void) { static void test_specifier_escape_strv(void) {
log_info("/* %s */", __func__);
test_specifier_escape_strv_one(NULL, NULL); test_specifier_escape_strv_one(NULL, NULL);
test_specifier_escape_strv_one(STRV_MAKE(NULL), STRV_MAKE(NULL)); test_specifier_escape_strv_one(STRV_MAKE(NULL), STRV_MAKE(NULL));
test_specifier_escape_strv_one(STRV_MAKE(""), STRV_MAKE("")); test_specifier_escape_strv_one(STRV_MAKE(""), STRV_MAKE(""));
test_specifier_escape_strv_one(STRV_MAKE("foo"), STRV_MAKE("foo")); test_specifier_escape_strv_one(STRV_MAKE("foo"), STRV_MAKE("foo"));
test_specifier_escape_strv_one(STRV_MAKE("%"), STRV_MAKE("%%")); test_specifier_escape_strv_one(STRV_MAKE("%"), STRV_MAKE("%%"));
test_specifier_escape_strv_one(STRV_MAKE("foo", "%", "foo%", "%foo", "foo%foo", "quux", "%%%"), STRV_MAKE("foo", "%%", "foo%%", "%%foo", "foo%%foo", "quux", "%%%%%%")); test_specifier_escape_strv_one(STRV_MAKE("foo", "%", "foo%", "%foo", "foo%foo", "quux", "%%%"),
STRV_MAKE("foo", "%%", "foo%%", "%%foo", "foo%%foo", "quux", "%%%%%%"));
}
/* Any specifier functions which don't need an argument. */
static const Specifier specifier_table[] = {
{ 'm', specifier_machine_id, NULL },
{ 'b', specifier_boot_id, NULL },
{ 'H', specifier_host_name, NULL },
{ 'l', specifier_short_host_name, NULL },
{ 'v', specifier_kernel_release, NULL },
{ 'a', specifier_architecture, NULL },
{ 'o', specifier_os_id, NULL },
{ 'w', specifier_os_version_id, NULL },
{ 'B', specifier_os_build_id, NULL },
{ 'W', specifier_os_variant_id, NULL },
{ 'g', specifier_group_name, NULL },
{ 'G', specifier_group_id, NULL },
{ 'U', specifier_user_id, NULL },
{ 'u', specifier_user_name, NULL },
{ 'h', specifier_user_home, NULL },
{ 'T', specifier_tmp_dir, NULL },
{ 'V', specifier_var_tmp_dir, NULL },
{}
};
static void test_specifiers(void) {
log_info("/* %s */", __func__);
for (const Specifier *s = specifier_table; s->specifier; s++) {
char spec[3];
_cleanup_free_ char *resolved = NULL;
xsprintf(spec, "%%%c", s->specifier);
assert_se(specifier_printf(spec, specifier_table, NULL, &resolved) >= 0);
log_info("%%%c → %s", s->specifier, resolved);
}
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -44,6 +89,7 @@ int main(int argc, char *argv[]) {
test_specifier_escape(); test_specifier_escape();
test_specifier_escape_strv(); test_specifier_escape_strv();
test_specifiers();
return 0; return 0;
} }

View file

@ -184,6 +184,7 @@ static const Specifier specifier_table[] = {
{ 'm', specifier_machine_id_safe, NULL }, { 'm', specifier_machine_id_safe, NULL },
{ 'b', specifier_boot_id, NULL }, { 'b', specifier_boot_id, NULL },
{ 'H', specifier_host_name, NULL }, { 'H', specifier_host_name, NULL },
{ 'l', specifier_short_host_name, NULL },
{ 'v', specifier_kernel_release, NULL }, { 'v', specifier_kernel_release, NULL },
{ 'a', specifier_architecture, NULL }, { 'a', specifier_architecture, NULL },
{ 'o', specifier_os_id, NULL }, { 'o', specifier_os_id, NULL },

View file

@ -7,198 +7,6 @@ import re
from xml_helper import xml_parse, xml_print, tree from xml_helper import xml_parse, xml_print, tree
from copy import deepcopy from copy import deepcopy
TEMPLATE = '''\
<refentry id="systemd.directives" conditional="HAVE_PYTHON">
<refentryinfo>
<title>systemd.directives</title>
<productname>systemd</productname>
</refentryinfo>
<refmeta>
<refentrytitle>systemd.directives</refentrytitle>
<manvolnum>7</manvolnum>
</refmeta>
<refnamediv>
<refname>systemd.directives</refname>
<refpurpose>Index of configuration directives</refpurpose>
</refnamediv>
<refsect1>
<title>Unit directives</title>
<para>Directives for configuring units, used in unit
files.</para>
<variablelist id='unit-directives' />
</refsect1>
<refsect1>
<title>Options on the kernel command line</title>
<para>Kernel boot options for configuring the behaviour of the
systemd process.</para>
<variablelist id='kernel-commandline-options' />
</refsect1>
<refsect1>
<title>Environment variables</title>
<para>Environment variables understood by the systemd manager
and other programs and environment variable-compatible settings.</para>
<variablelist id='environment-variables' />
</refsect1>
<refsect1>
<title>EFI variables</title>
<para>EFI variables understood by
<citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>
and other programs.</para>
<variablelist id='efi-variables' />
</refsect1>
<refsect1>
<title>UDEV directives</title>
<para>Directives for configuring systemd units through the
udev database.</para>
<variablelist id='udev-directives' />
</refsect1>
<refsect1>
<title>Network directives</title>
<para>Directives for configuring network links through the
net-setup-link udev builtin and networks through
systemd-networkd.</para>
<variablelist id='network-directives' />
</refsect1>
<refsect1>
<title>Journal fields</title>
<para>Fields in the journal events with a well known meaning.</para>
<variablelist id='journal-directives' />
</refsect1>
<refsect1>
<title>PAM configuration directives</title>
<para>Directives for configuring PAM behaviour.</para>
<variablelist id='pam-directives' />
</refsect1>
<refsect1>
<title><filename>/etc/crypttab</filename> and
<filename>/etc/fstab</filename> options</title>
<para>Options which influence mounted filesystems and
encrypted volumes.</para>
<variablelist id='fstab-options' />
</refsect1>
<refsect1>
<title><citerefentry><refentrytitle>systemd.nspawn</refentrytitle><manvolnum>5</manvolnum></citerefentry>
directives</title>
<para>Directives for configuring systemd-nspawn containers.</para>
<variablelist id='nspawn-directives' />
</refsect1>
<refsect1>
<title>Program configuration options</title>
<para>Directives for configuring the behaviour of the
systemd process and other tools through configuration files.</para>
<variablelist id='config-directives' />
</refsect1>
<refsect1>
<title>Command line options</title>
<para>Command-line options accepted by programs in the
systemd suite.</para>
<variablelist id='options' />
</refsect1>
<refsect1>
<title>Constants</title>
<para>Various constant used and/or defined by systemd.</para>
<variablelist id='constants' />
</refsect1>
<refsect1>
<title>Miscellaneous options and directives</title>
<para>Other configuration elements which don't fit in
any of the above groups.</para>
<variablelist id='miscellaneous' />
</refsect1>
<refsect1>
<title>Files and directories</title>
<para>Paths and file names referred to in the
documentation.</para>
<variablelist id='filenames' />
</refsect1>
<refsect1>
<title>D-Bus interfaces</title>
<para>Interfaces exposed over D-Bus.</para>
<variablelist id='dbus-interface' />
</refsect1>
<refsect1>
<title>D-Bus methods</title>
<para>Methods exposed in the D-Bus interface.</para>
<variablelist id='dbus-method' />
</refsect1>
<refsect1>
<title>D-Bus properties</title>
<para>Properties exposed in the D-Bus interface.</para>
<variablelist id='dbus-property' />
</refsect1>
<refsect1>
<title>D-Bus signals</title>
<para>Signals emitted in the D-Bus interface.</para>
<variablelist id='dbus-signal' />
</refsect1>
<refsect1>
<title>Colophon</title>
<para id='colophon' />
</refsect1>
</refentry>
'''
COLOPHON = '''\ COLOPHON = '''\
This index contains {count} entries in {sections} sections, This index contains {count} entries in {sections} sections,
referring to {pages} individual manual pages. referring to {pages} individual manual pages.
@ -279,6 +87,18 @@ def _extract_directives(directive_groups, formatting, page):
storfile[name.text].append((pagename, section)) storfile[name.text].append((pagename, section))
formatting[name.text] = name formatting[name.text] = name
storfile = directive_groups['specifiers']
for name in t.iterfind(".//table[@class='specifiers']//entry/literal"):
if name.text[0] != '%' or name.getparent().text is not None:
continue
if name.attrib.get('index') == 'false':
continue
storfile[name.text].append((pagename, section))
formatting[name.text] = name
for name in t.iterfind(".//literal[@class='specifiers']"):
storfile[name.text].append((pagename, section))
formatting[name.text] = name
def _make_section(template, name, directives, formatting): def _make_section(template, name, directives, formatting):
varlist = template.find(".//*[@id='{}']".format(name)) varlist = template.find(".//*[@id='{}']".format(name))
for varname, manpages in sorted(directives.items()): for varname, manpages in sorted(directives.items()):
@ -330,9 +150,9 @@ def _make_page(template, directive_groups, formatting):
return template return template
def make_page(*xml_files): def make_page(template_path, xml_files):
"Extract directives from xml_files and return XML index tree." "Extract directives from xml_files and return XML index tree."
template = tree.fromstring(TEMPLATE) template = xml_parse(template_path)
names = [vl.get('id') for vl in template.iterfind('.//variablelist')] names = [vl.get('id') for vl in template.iterfind('.//variablelist')]
directive_groups = {name:collections.defaultdict(list) directive_groups = {name:collections.defaultdict(list)
for name in names} for name in names}
@ -347,4 +167,7 @@ def make_page(*xml_files):
if __name__ == '__main__': if __name__ == '__main__':
with open(sys.argv[1], 'wb') as f: with open(sys.argv[1], 'wb') as f:
f.write(xml_print(make_page(*sys.argv[2:]))) template_path = sys.argv[2]
xml_files = sys.argv[3:]
xml = make_page(template_path, xml_files)
f.write(xml_print(xml))

View file

@ -50,7 +50,7 @@ def mjoin(files):
return ' \\\n\t'.join(sorted(files) or '#') return ' \\\n\t'.join(sorted(files) or '#')
MESON_HEADER = '''\ MESON_HEADER = '''\
# Do not edit. Generated by make-man-rules.py. # Do not edit. Generated by update-man-rules.py.
# Update with: # Update with:
# ninja -C build man/update-man-rules # ninja -C build man/update-man-rules
manpages = [''' manpages = ['''