container/pod id file: truncate instead of throwing an error

Truncate the container and pod ID files instead of throwing an error.
The main motivation is to prevent redundant work when starting systemd
units.  Throwing an error when the file already exists is not preventing
races or file corruptions, so let's leave that to the user which in
almost all cases are generated (and tested) systemd units.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2022-10-24 13:57:37 +02:00
parent 99dfb70950
commit 221cfc6872
11 changed files with 20 additions and 99 deletions

View File

@@ -570,8 +570,6 @@ var _ = Describe("Podman generate systemd", func() {
Expect(session.OutputToString()).To(ContainSubstring("--pod-id-file %t/pod-foo.pod-id"))
Expect(session.OutputToString()).To(ContainSubstring("--exit-policy=stop"))
Expect(session.OutputToString()).To(ContainSubstring("--name foo"))
Expect(session.OutputToString()).To(ContainSubstring("ExecStartPre=/bin/rm"))
Expect(session.OutputToString()).To(ContainSubstring("-f %t/pod-foo.pid %t/pod-foo.pod-id"))
Expect(session.OutputToString()).To(ContainSubstring("pod stop"))
Expect(session.OutputToString()).To(ContainSubstring("--ignore"))
Expect(session.OutputToString()).To(ContainSubstring("--pod-id-file %t/pod-foo.pod-id"))

View File

@@ -192,6 +192,10 @@ echo $rand | 0 | $rand
pidfile=${PODMAN_TMPDIR}/pidfile
cidfile=${PODMAN_TMPDIR}/cidfile
# Write random content to the cidfile to make sure its content is truncated
# on write.
echo "$(random_string 120)" > $cidfile
cname=$(random_string)
run_podman run --name $cname \
--conmon-pidfile=$pidfile \
@@ -218,12 +222,6 @@ echo $rand | 0 | $rand
# All OK. Kill container.
run_podman rm -f $cid
# Podman must not overwrite existing cid file.
# (overwriting conmon-pidfile is OK, so don't test that)
run_podman 125 run --cidfile=$cidfile $IMAGE true
is "$output" "Error: container id file exists. .* delete $cidfile" \
"podman will not overwrite existing cidfile"
}
@test "podman run docker-archive" {