lib/postprocess: Use O_TMPFILE, not O_APPEND for tmpfiles.d writing

The comment here was wrong; we don't rely on `O_APPEND` here for package
layering since we convert on import.  I noticed this while I was doing
a grep for `O_APPEND` in the codebase as part of unified core work.

Fix this by converting to `O_TMPFILE`+`GLNX_LINK_TMPFILE_NOREPLACE`.

Prep for unified core.

Closes: #1009
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-09-25 12:58:44 -04:00 committed by Atomic Bot
parent 57fcd9e1b0
commit 58f8f892fb
2 changed files with 19 additions and 9 deletions

View File

@ -520,15 +520,14 @@ convert_var_to_tmpfiles_d (int src_rootfs_dfd,
} }
} }
/* Append to an existing one for package layering */ /* Convert /var wholesale to tmpfiles.d. Note that with unified core, this
glnx_fd_close int tmpfiles_fd = openat (dest_rootfs_dfd, "usr/lib/tmpfiles.d/rpm-ostree-1-autovar.conf", * code should no longer be necessary as we convert packages on import.
O_WRONLY | O_CREAT | O_APPEND | O_NOCTTY, 0644); */
if (tmpfiles_fd == -1) g_auto(GLnxTmpfile) tmpf = { 0, };
return glnx_throw_errno_prefix (error, "openat"); if (!glnx_open_tmpfile_linkable_at (dest_rootfs_dfd, "usr/lib/tmpfiles.d", O_WRONLY | O_CLOEXEC,
&tmpf, error))
glnx_unref_object GOutputStream *tmpfiles_out = return FALSE;
g_unix_output_stream_new (tmpfiles_fd, FALSE); g_autoptr(GOutputStream) tmpfiles_out = g_unix_output_stream_new (tmpf.fd, FALSE);
if (!tmpfiles_out) if (!tmpfiles_out)
return FALSE; return FALSE;
@ -539,6 +538,11 @@ convert_var_to_tmpfiles_d (int src_rootfs_dfd,
if (!g_output_stream_close (tmpfiles_out, cancellable, error)) if (!g_output_stream_close (tmpfiles_out, cancellable, error))
return FALSE; return FALSE;
if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE,
dest_rootfs_dfd, "usr/lib/tmpfiles.d/rpm-ostree-1-autovar.conf",
error))
return FALSE;
return TRUE; return TRUE;
} }

View File

@ -53,3 +53,9 @@ assert_not_file_has_content ls.txt '__db' 'lock'
ostree --repo=${repobuild} ls -R ${treeref} /usr/etc/selinux > ls.txt ostree --repo=${repobuild} ls -R ${treeref} /usr/etc/selinux > ls.txt
assert_not_file_has_content ls.txt 'LOCK' assert_not_file_has_content ls.txt 'LOCK'
echo "ok no leftover files" echo "ok no leftover files"
ostree --repo=${repobuild} cat ${treeref} /usr/lib/tmpfiles.d/rpm-ostree-1-autovar.conf > autovar.txt
# Picked this one at random as an example of something that won't likely be
# converted to tmpfiles.d upstream. But if it is, we can change this test.
assert_file_has_content_literal autovar.txt 'd /var/cache 0755 0 0 - -'
echo "ok autovar"