Skip to content

Commit

Permalink
meson: use jinja2 for unit templates
Browse files Browse the repository at this point in the history
We don't need two (and half) templating systems anymore, yay!

I'm keeping the changes minimal, to make the diff manageable. Some enhancements
due to a better templating system might be possible in the future.

For handling of '## ' — see the next commit.
  • Loading branch information
keszybz authored and yuwata committed May 19, 2021
1 parent 6b1aac3 commit 059cc61
Show file tree
Hide file tree
Showing 65 changed files with 133 additions and 160 deletions.
7 changes: 6 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ conf.set_quoted('SYSTEMD_SHUTDOWN_BINARY_PATH', join_paths(rootlib
conf.set_quoted('SYSTEMCTL_BINARY_PATH', join_paths(rootbindir, 'systemctl'))
conf.set_quoted('SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH', join_paths(rootbindir, 'systemd-tty-ask-password-agent'))
conf.set_quoted('SYSTEMD_STDIO_BRIDGE_BINARY_PATH', join_paths(bindir, 'systemd-stdio-bridge'))
conf.set_quoted('ROOTBINDIR', rootbindir)
conf.set_quoted('ROOTPREFIX', rootprefixdir)
conf.set_quoted('ROOTPREFIX_NOSLASH', rootprefixdir_noslash)
conf.set_quoted('RANDOM_SEED_DIR', randomseeddir)
Expand Down Expand Up @@ -842,6 +843,7 @@ substs.set('TTY_GID', tty_gid)

# Ensure provided GID argument is numeric, otherwise fall back to default assignment
users_gid = get_option('users-gid')
conf.set('USERS_GID', users_gid < 0 ? '-' : users_gid)
substs.set('USERS_GID', users_gid < 0 ? '-' : users_gid)

conf.set10('ENABLE_ADM_GROUP', get_option('adm-group'))
Expand Down Expand Up @@ -887,14 +889,17 @@ if localegen_path != ''
writable = ' /usr/lib/locale'
endif
substs.set('SERVICE_LOCALEGEN_WRITABLE', writable)
conf.set_quoted('SERVICE_LOCALEGEN_WRITABLE', writable)
conf.set10('HAVE_LOCALEGEN', have)

conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())

service_watchdog = get_option('service-watchdog')
watchdog_value = service_watchdog == '' ? '' : 'WatchdogSec=' + service_watchdog
substs.set('SERVICE_WATCHDOG', watchdog_value)
conf.set_quoted('SERVICE_WATCHDOG', watchdog_value)

conf.set_quoted('SUSHELL', get_option('debug-shell'))
substs.set('SUSHELL', get_option('debug-shell'))
substs.set('DEBUGTTY', get_option('debug-tty'))
conf.set_quoted('DEBUGTTY', get_option('debug-tty'))
Expand Down Expand Up @@ -3741,7 +3746,7 @@ status = [
'debug shell: @0@ @ @1@'.format(get_option('debug-shell'),
get_option('debug-tty')),
'TTY GID: @0@'.format(tty_gid),
'users GID: @0@'.format(substs.get('USERS_GID')),
'users GID: @0@'.format(conf.get('USERS_GID')),
'system UIDs: <=@0@ (alloc >=@1@)'.format(conf.get('SYSTEM_UID_MAX'),
conf.get('SYSTEM_ALLOC_UID_MIN')),
'system GIDs: <=@0@ (alloc >=@1@)'.format(conf.get('SYSTEM_GID_MAX'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
Description=Console Getty
Documentation=man:agetty(8) man:systemd-getty-generator(8)
After=systemd-user-sessions.service plymouth-quit-wait.service
m4_ifdef(`HAVE_SYSV_COMPAT',
{% if HAVE_SYSV_COMPAT %}
After=rc-local.service getty-pre.target
)m4_dnl
{% endif %}
Before=getty.target

# OCI containers may be run without a console
Expand All @@ -30,9 +30,9 @@ UtmpIdentifier=cons
TTYPath=/dev/console
TTYReset=yes
TTYVHangup=yes
m4_ifdef(`ENABLE_LOGIND',,
{% if not ENABLE_LOGIND %}
KillMode=process
)m4_dnl
{% endif %}
IgnoreSIGPIPE=no
SendSIGHUP=yes

Expand Down
8 changes: 4 additions & 4 deletions units/[email protected] → units/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Description=Container Getty on /dev/pts/%I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=man:machinectl(1)
After=systemd-user-sessions.service plymouth-quit-wait.service
m4_ifdef(`HAVE_SYSV_COMPAT',
{% if HAVE_SYSV_COMPAT %}
After=rc-local.service getty-pre.target
)m4_dnl
{% endif %}
Before=getty.target
IgnoreOnIsolate=yes
ConditionPathExists=/dev/pts/%I
Expand All @@ -36,8 +36,8 @@ UtmpIdentifier=pts/%I
TTYPath=/dev/pts/%I
TTYReset=yes
TTYVHangup=yes
m4_ifdef(`ENABLE_LOGIND',,
{% if not ENABLE_LOGIND %}
KillMode=process
)m4_dnl
{% endif %}
IgnoreSIGPIPE=no
SendSIGHUP=yes
8 changes: 4 additions & 4 deletions units/debug-shell.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
# (at your option) any later version.

[Unit]
Description=Early root shell on @DEBUGTTY@ FOR DEBUGGING ONLY
Description=Early root shell on {{DEBUGTTY}} FOR DEBUGGING ONLY
Documentation=man:systemd-debug-generator(8)
DefaultDependencies=no
IgnoreOnIsolate=yes
ConditionPathExists=@DEBUGTTY@
ConditionPathExists={{DEBUGTTY}}

[Service]
Environment=TERM=linux
ExecStart=@SUSHELL@
ExecStart={{SUSHELL}}
Restart=always
RestartSec=0
StandardInput=tty
TTYPath=@DEBUGTTY@
TTYPath={{DEBUGTTY}}
TTYReset=yes
TTYVHangup=yes
KillMode=process
Expand Down
4 changes: 2 additions & 2 deletions units/emergency.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Before=rescue.service
[Service]
Environment=HOME=/root
WorkingDirectory=-/root
ExecStartPre=-@rootbindir@/plymouth --wait quit
ExecStart=-@rootlibexecdir@/systemd-sulogin-shell emergency
ExecStartPre=-{{ROOTBINDIR}}/plymouth --wait quit
ExecStart=-{{ROOTLIBEXECDIR}}/systemd-sulogin-shell emergency
Type=idle
StandardInput=tty-force
StandardOutput=inherit
Expand Down
8 changes: 4 additions & 4 deletions units/[email protected] → units/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Description=Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
After=systemd-user-sessions.service plymouth-quit-wait.service getty-pre.target
m4_ifdef(`HAVE_SYSV_COMPAT',
{% if HAVE_SYSV_COMPAT %}
After=rc-local.service
)m4_dnl
{% endif %}

# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
Expand Down Expand Up @@ -47,9 +47,9 @@ TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
m4_ifdef(`ENABLE_LOGIND',,
{% if not ENABLE_LOGIND %}
KillMode=process
)m4_dnl
{% endif %}
IgnoreSIGPIPE=no
SendSIGHUP=yes

Expand Down
2 changes: 1 addition & 1 deletion units/kmod-static-nodes.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ConditionFileNotEmpty=/lib/modules/%v/modules.devname
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@KMOD@ static-nodes --format=tmpfiles --output=/run/tmpfiles.d/static-nodes.conf
ExecStart={{KMOD}} static-nodes --format=tmpfiles --output=/run/tmpfiles.d/static-nodes.conf
48 changes: 8 additions & 40 deletions units/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,18 @@ units = [
]

in_units = [
['console-getty.service', ''],
['[email protected]', ''],
['debug-shell.service', ''],
['emergency.service', ''],
['[email protected]', '',
'[email protected]'],
['kmod-static-nodes.service', 'HAVE_KMOD ENABLE_TMPFILES',
'sysinit.target.wants/'],
['quotaon.service', 'ENABLE_QUOTACHECK'],
['rc-local.service', 'HAVE_SYSV_COMPAT'],
['rescue.service', ''],
['[email protected]', ''],
['[email protected]', 'ENABLE_BACKLIGHT'],
['systemd-binfmt.service', 'ENABLE_BINFMT',
'sysinit.target.wants/'],
Expand Down Expand Up @@ -247,14 +252,6 @@ in_units = [
['[email protected]', ''],
]

m4_units = [
['console-getty.service', ''],
['[email protected]', ''],
['[email protected]', '',
'[email protected] '],
['[email protected]', ''],
]

add_wants = []

foreach tuple : in_units
Expand All @@ -265,15 +262,11 @@ foreach tuple : in_units
install = ((conds.get(0, '') == '' or conf.get(conds[0]) == 1) and
(conds.get(1, '') == '' or conf.get(conds[1]) == 1))

gen1 = configure_file(
input : file + '.in',
output : file + '.tmp',
configuration : substs)
gen2 = custom_target(
custom_target(
file,
input : gen1,
input : file + '.in',
output : file,
command : [sed, '/^## /d', '@INPUT@'],
command : [meson_render_jinja2, config_h, '@INPUT@'],
capture : true,
install : install,
install_dir : systemunitdir)
Expand All @@ -285,31 +278,6 @@ foreach tuple : in_units
endif
endforeach

foreach tuple : m4_units
file = tuple[0]
input = tuple.get(3, file + '.m4')

# we do this here because install_data does not accept custom_target output
conds = tuple[1].split(' ')
install = ((conds.get(0, '') == '' or conf.get(conds[0]) == 1) and
(conds.get(1, '') == '' or conf.get(conds[1]) == 1))

custom_target(
file,
input : input,
output: file,
command : [meson_apply_m4, config_h, '@INPUT@'],
capture : true,
install : install,
install_dir : systemunitdir)

if tuple.length() > 2 and install
foreach target : tuple[2].split()
add_wants += [systemunitdir, target, file]
endforeach
endif
endforeach

foreach tuple : units
file = tuple[0]
input = tuple.get(3, file)
Expand Down
4 changes: 2 additions & 2 deletions units/quotaon.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Documentation=man:quotaon(8)
DefaultDependencies=no
After=systemd-quotacheck.service
Before=remote-fs.target shutdown.target
ConditionPathExists=@QUOTAON@
ConditionPathExists={{QUOTAON}}

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@QUOTAON@ -aug
ExecStart={{QUOTAON}} -aug
8 changes: 4 additions & 4 deletions units/rc-local.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
# (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if @RC_LOCAL_PATH@ is executable.
# systemd-rc-local-generator if {{RC_LOCAL_PATH}} is executable.
[Unit]
Description=@RC_LOCAL_PATH@ Compatibility
Description={{RC_LOCAL_PATH}} Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=@RC_LOCAL_PATH@
ConditionFileIsExecutable={{RC_LOCAL_PATH}}
After=network.target

[Service]
Type=forking
ExecStart=@RC_LOCAL_PATH@ start
ExecStart={{RC_LOCAL_PATH}} start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
4 changes: 2 additions & 2 deletions units/rescue.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Before=shutdown.target
[Service]
Environment=HOME=/root
WorkingDirectory=-/root
ExecStartPre=-@rootbindir@/plymouth --wait quit
ExecStart=-@rootlibexecdir@/systemd-sulogin-shell rescue
ExecStartPre=-{{ROOTBINDIR}}/plymouth --wait quit
ExecStart=-{{ROOTLIBEXECDIR}}/systemd-sulogin-shell rescue
Type=idle
StandardInput=tty-force
StandardOutput=inherit
Expand Down
8 changes: 4 additions & 4 deletions units/[email protected] → units/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
BindsTo=dev-%i.device
After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service getty-pre.target
m4_ifdef(`HAVE_SYSV_COMPAT',
{% if HAVE_SYSV_COMPAT %}
After=rc-local.service
)m4_dnl
{% endif %}

# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
Expand All @@ -40,9 +40,9 @@ UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
m4_ifdef(`ENABLE_LOGIND',,
{% if not ENABLE_LOGIND %}
KillMode=process
)m4_dnl
{% endif %}
IgnoreSIGPIPE=no
SendSIGHUP=yes

Expand Down
4 changes: 2 additions & 2 deletions units/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Before=sysinit.target shutdown.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@rootlibexecdir@/systemd-backlight load %i
ExecStop=@rootlibexecdir@/systemd-backlight save %i
ExecStart={{ROOTLIBEXECDIR}}/systemd-backlight load %i
ExecStop={{ROOTLIBEXECDIR}}/systemd-backlight save %i
TimeoutSec=90s
StateDirectory=systemd/backlight
4 changes: 2 additions & 2 deletions units/systemd-binfmt.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ ConditionDirectoryNotEmpty=|/run/binfmt.d
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@rootlibexecdir@/systemd-binfmt
ExecStop=@rootlibexecdir@/systemd-binfmt --unregister
ExecStart={{ROOTLIBEXECDIR}}/systemd-binfmt
ExecStop={{ROOTLIBEXECDIR}}/systemd-binfmt --unregister
TimeoutSec=90s
2 changes: 1 addition & 1 deletion units/systemd-bless-boot.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ Before=shutdown.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@rootlibexecdir@/systemd-bless-boot good
ExecStart={{ROOTLIBEXECDIR}}/systemd-bless-boot good
2 changes: 1 addition & 1 deletion units/systemd-boot-check-no-failures.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Before=shutdown.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@rootlibexecdir@/systemd-boot-check-no-failures
ExecStart={{ROOTLIBEXECDIR}}/systemd-boot-check-no-failures

[Install]
RequiredBy=boot-complete.target
2 changes: 1 addition & 1 deletion units/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Requires=systemd-journald.socket
Before=shutdown.target

[Service]
ExecStart=-@rootlibexecdir@/systemd-coredump
ExecStart=-{{ROOTLIBEXECDIR}}/systemd-coredump
IPAddressDeny=any
LockPersonality=yes
MemoryDenyWriteExecute=yes
Expand Down
2 changes: 1 addition & 1 deletion units/systemd-fsck-root.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ ConditionPathIsReadWrite=!/
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@rootlibexecdir@/systemd-fsck
ExecStart={{ROOTLIBEXECDIR}}/systemd-fsck
TimeoutSec=0
2 changes: 1 addition & 1 deletion units/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Before=systemd-quotacheck.service shutdown.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@rootlibexecdir@/systemd-fsck %f
ExecStart={{ROOTLIBEXECDIR}}/systemd-fsck %f
TimeoutSec=0
2 changes: 1 addition & 1 deletion units/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ AssertPathExists=/etc/initrd-release

[Service]
Type=oneshot
ExecStart=@rootlibexecdir@/systemd-hibernate-resume %f
ExecStart={{ROOTLIBEXECDIR}}/systemd-hibernate-resume %f
2 changes: 1 addition & 1 deletion units/systemd-hibernate.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ After=sleep.target

[Service]
Type=oneshot
ExecStart=@rootlibexecdir@/systemd-sleep hibernate
ExecStart={{ROOTLIBEXECDIR}}/systemd-sleep hibernate
6 changes: 3 additions & 3 deletions units/systemd-homed.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ CapabilityBoundingSet=CAP_SYS_ADMIN CAP_CHOWN CAP_DAC_OVERRIDE CAP_FOWNER CAP_FS
DeviceAllow=/dev/loop-control rw
DeviceAllow=/dev/mapper/control rw
DeviceAllow=block-* rw
ExecStart=@rootlibexecdir@/systemd-homed
ExecStart={{ROOTLIBEXECDIR}}/systemd-homed
IPAddressDeny=any
KillMode=mixed
LimitNOFILE=@HIGH_RLIMIT_NOFILE@
LimitNOFILE={{HIGH_RLIMIT_NOFILE}}
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
Expand All @@ -34,7 +34,7 @@ StateDirectory=systemd/home
SystemCallArchitectures=native
SystemCallErrorNumber=EPERM
SystemCallFilter=@system-service @mount
@SERVICE_WATCHDOG@
{{SERVICE_WATCHDOG}}

[Install]
WantedBy=multi-user.target
Expand Down
Loading

0 comments on commit 059cc61

Please sign in to comment.