1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-27 01:57:35 +03:00

Merge pull request #18267 from lucaswerkmeister/truncate

Two StandardOutput=truncate:file improvements
This commit is contained in:
Yu Watanabe 2021-01-19 08:47:39 +09:00 committed by GitHub
commit 4c6dd238b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -2430,8 +2430,19 @@ SystemCallErrorNumber=EPERM</programlisting>
</para>
<para><option>truncate:<replaceable>path</replaceable></option> is similar to
<option>file:<replaceable>path</replaceable></option> above, but it truncates the file when opening it.
</para>
<option>file:<replaceable>path</replaceable></option> above, but it truncates the file when opening
it. For units with multiple command lines, e.g. <varname>Type=oneshot</varname> services with
multiple <varname>ExecStart=</varname>, or services with <varname>ExecCondition=</varname>,
<varname>ExecStartPre=</varname> or <varname>ExecStartPost=</varname>, the output file is reopened
and therefore re-truncated for each command line. If the output file is truncated while another
process still has the file open, e.g. by an <varname>ExecReload=</varname> running concurrently with
an <varname>ExecStart=</varname>, and the other process continues writing to the file without
adjusting its offset, then the space between the file pointers of the two processes may be filled
with <constant>NUL</constant> bytes, producing a sparse file. Thus,
<option>truncate:<replaceable>path</replaceable></option> is typically only useful for units where
only one process runs at a time, such as services with a single <varname>ExecStart=</varname> and no
<varname>ExecStartPost=</varname>, <varname>ExecReload=</varname>, <varname>ExecStop=</varname> or
similar.</para>
<para><option>socket</option> connects standard output to a socket acquired via socket activation. The
semantics are similar to the same option of <varname>StandardInput=</varname>, see above.</para>

View File

@ -8,6 +8,5 @@ StandardInput=data
StandardInputText=hi
StandardOutput=truncate:/tmp/test-exec-standardoutput-output
StandardError=null
ExecStart=cat
ExecStartPost=cmp /tmp/test-exec-standardoutput-output /tmp/test-exec-standardoutput-expected
ExecStart=sh -c 'cat && cmp /tmp/test-exec-standardoutput-output /tmp/test-exec-standardoutput-expected'
Type=oneshot