tree-wide: Some more misc libglnx porting

More use of the `glnx_unlinkat()`, `glnx_fstatat()`, and `glnx_renameat()`
wrappers.

Closes: #1027
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-10-01 10:12:51 -07:00 committed by Atomic Bot
parent 2cf87ba897
commit acbbda8214
2 changed files with 19 additions and 22 deletions

View File

@ -1793,8 +1793,8 @@ import_one_package (RpmOstreeContext *self,
*/ */
if (!pkg_is_local (pkg)) if (!pkg_is_local (pkg))
{ {
if (TEMP_FAILURE_RETRY (unlinkat (AT_FDCWD, pkg_path, 0)) < 0) if (!glnx_unlinkat (AT_FDCWD, pkg_path, 0, error))
return glnx_throw_errno_prefix (error, "Deleting %s", pkg_path); return FALSE;
} }
if (!rpmostree_unpacker_unpack_to_ostree (unpacker, ostreerepo, sepolicy, if (!rpmostree_unpacker_unpack_to_ostree (unpacker, ostreerepo, sepolicy,
@ -3096,9 +3096,9 @@ rpmostree_context_assemble_tmprootfs (RpmOstreeContext *self,
if (have_systemctl) if (have_systemctl)
{ {
if (renameat (tmprootfs_dfd, "usr/bin/systemctl.rpmostreesave", if (!glnx_renameat (tmprootfs_dfd, "usr/bin/systemctl.rpmostreesave",
tmprootfs_dfd, "usr/bin/systemctl") < 0) tmprootfs_dfd, "usr/bin/systemctl", error))
return glnx_throw_errno_prefix (error, "renameat(usr/bin/systemctl)"); return FALSE;
} }
if (have_passwd) if (have_passwd)

View File

@ -119,8 +119,8 @@ rename_if_exists (int src_dfd,
/* Handle empty directory in legacy location */ /* Handle empty directory in legacy location */
if (errno == EEXIST) if (errno == EEXIST)
{ {
if (unlinkat (src_dfd, from, AT_REMOVEDIR) < 0) if (!glnx_unlinkat (src_dfd, from, AT_REMOVEDIR, error))
return glnx_throw_errno_prefix (error, "rmdirat(%s)", from); return FALSE;
} }
else else
return glnx_throw_errno_prefix (error, "renameat(%s)", to); return glnx_throw_errno_prefix (error, "renameat(%s)", to);
@ -466,8 +466,8 @@ convert_var_to_tmpfiles_d_recurse (GOutputStream *tmpfiles_out,
if (filetype_c == 'd') if (filetype_c == 'd')
{ {
struct stat stbuf; struct stat stbuf;
if (TEMP_FAILURE_RETRY (fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0) if (!glnx_fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return glnx_throw_errno_prefix (error, "fstatat"); return FALSE;
g_string_append_printf (tmpfiles_d_buf, " 0%02o", stbuf.st_mode & ~S_IFMT); g_string_append_printf (tmpfiles_d_buf, " 0%02o", stbuf.st_mode & ~S_IFMT);
g_string_append_printf (tmpfiles_d_buf, " %d %d - -", stbuf.st_uid, stbuf.st_gid); g_string_append_printf (tmpfiles_d_buf, " %d %d - -", stbuf.st_uid, stbuf.st_gid);
@ -618,8 +618,8 @@ workaround_selinux_cross_labeling_recurse (int dfd,
const char *lastdot; const char *lastdot;
g_autofree char *nonbin_name = NULL; g_autofree char *nonbin_name = NULL;
if (TEMP_FAILURE_RETRY (fstatat (dfd_iter.fd, name, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0) if (!glnx_fstatat (dfd_iter.fd, name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return glnx_throw_errno_prefix (error, "fstat"); return FALSE;
lastdot = strrchr (name, '.'); lastdot = strrchr (name, '.');
g_assert (lastdot); g_assert (lastdot);
@ -1062,8 +1062,8 @@ rpmostree_rootfs_symlink_emptydir_at (int rootfs_fd,
make_symlink = FALSE; make_symlink = FALSE;
else if (S_ISDIR (stbuf.st_mode)) else if (S_ISDIR (stbuf.st_mode))
{ {
if (unlinkat (rootfs_fd, src, AT_REMOVEDIR) < 0) if (!glnx_unlinkat (rootfs_fd, src, AT_REMOVEDIR, error))
return glnx_throw_errno_prefix (error, "Removing %s", src); return FALSE;
} }
} }
@ -1138,8 +1138,8 @@ cleanup_leftover_files (int rootfs_fd,
if (!in_files && !has_prefix) if (!in_files && !has_prefix)
continue; continue;
if (unlinkat (dfd_iter.fd, name, 0) < 0) if (!glnx_unlinkat (dfd_iter.fd, name, 0, error))
return glnx_throw_errno_prefix (error, "Unlinking %s: ", name); return FALSE;
} }
return TRUE; return TRUE;
@ -1609,8 +1609,8 @@ rpmostree_treefile_postprocessing (int rootfs_fd,
return glnx_prefix_error (error, "While executing postprocessing script '%s'", bn); return glnx_prefix_error (error, "While executing postprocessing script '%s'", bn);
} }
if (unlinkat (rootfs_fd, target_binpath, 0) < 0) if (!glnx_unlinkat (rootfs_fd, target_binpath, 0, error))
return glnx_throw_errno_prefix (error, "unlinkat(%s)", target_binpath); return FALSE;
g_print ("Finished postprocessing script '%s'\n", bn); g_print ("Finished postprocessing script '%s'\n", bn);
} }
@ -1779,11 +1779,8 @@ count_filesizes (int dfd,
{ {
struct stat stbuf; struct stat stbuf;
if (fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW) != 0) if (!glnx_fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
{
glnx_set_prefix_error_from_errno (error, "%s", "fstatat");
return FALSE; return FALSE;
}
(*out_n_bytes) += stbuf.st_size; (*out_n_bytes) += stbuf.st_size;
} }