tree: pass NULL to glnx_fstatat_allow_noent when needed

Now that libglnx allows it, we can skip declaring a `struct stat` we
don't actually need just to check if a file exists.

Closes: #1066
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-10-17 20:17:25 +00:00 committed by Atomic Bot
parent 3be6dbae15
commit c107a05b8e
5 changed files with 14 additions and 28 deletions

View File

@ -242,8 +242,7 @@ rpmostree_container_builtin_assemble (int argc,
const char *target_rootdir = glnx_strjoina (name, ".0"); const char *target_rootdir = glnx_strjoina (name, ".0");
struct stat stbuf; if (!glnx_fstatat_allow_noent (rocctx->roots_dfd, target_rootdir, NULL,
if (!glnx_fstatat_allow_noent (rocctx->roots_dfd, target_rootdir, &stbuf,
AT_SYMLINK_NOFOLLOW, error)) AT_SYMLINK_NOFOLLOW, error))
{ {
glnx_set_error_from_errno (error); glnx_set_error_from_errno (error);

View File

@ -587,8 +587,7 @@ replace_usr (OstreeRepo *repo,
const char *name = dent->d_name; const char *name = dent->d_name;
/* Keep track of what entries are in the new /usr */ /* Keep track of what entries are in the new /usr */
g_hash_table_add (seen_new_children, g_strdup (name)); g_hash_table_add (seen_new_children, g_strdup (name));
struct stat stbuf; if (!glnx_fstatat_allow_noent (deployment_usr_dfd, name, NULL, AT_SYMLINK_NOFOLLOW, error))
if (!glnx_fstatat_allow_noent (deployment_usr_dfd, name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE; return FALSE;
if (errno == ENOENT) if (errno == ENOENT)
{ {

View File

@ -744,8 +744,7 @@ checkout_pkg_metadata (RpmOstreeContext *self,
/* give it a .rpm extension so we can fool the libdnf stack */ /* give it a .rpm extension so we can fool the libdnf stack */
g_autofree char *path = get_nevra_relpath (nevra); g_autofree char *path = get_nevra_relpath (nevra);
struct stat stbuf; if (!glnx_fstatat_allow_noent (self->tmpdir.fd, path, NULL, 0, error))
if (!glnx_fstatat_allow_noent (self->tmpdir.fd, path, &stbuf, 0, error))
return FALSE; return FALSE;
/* we may have already written the header out for this one */ /* we may have already written the header out for this one */
if (errno == 0) if (errno == 0)
@ -2158,8 +2157,7 @@ delete_package_from_root (RpmOstreeContext *self,
if (rpmostree_str_has_prefix_in_ptrarray (fn, deleted_dirs)) if (rpmostree_str_has_prefix_in_ptrarray (fn, deleted_dirs))
continue; continue;
struct stat stbuf; if (!glnx_fstatat_allow_noent (rootfs_dfd, fn, NULL, AT_SYMLINK_NOFOLLOW, error))
if (!glnx_fstatat_allow_noent (rootfs_dfd, fn, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE; return FALSE;
if (errno == ENOENT) if (errno == ENOENT)
continue; /* a job well done */ continue; /* a job well done */
@ -2916,8 +2914,7 @@ run_all_transfiletriggers (RpmOstreeContext *self,
/* Triggers from base packages, but only if we already have an rpmdb, /* Triggers from base packages, but only if we already have an rpmdb,
* otherwise librpm will whine on our stderr. * otherwise librpm will whine on our stderr.
*/ */
struct stat stbuf; if (!glnx_fstatat_allow_noent (rootfs_dfd, RPMOSTREE_RPMDB_LOCATION, NULL, AT_SYMLINK_NOFOLLOW, error))
if (!glnx_fstatat_allow_noent (rootfs_dfd, RPMOSTREE_RPMDB_LOCATION, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE; return FALSE;
if (errno == 0) if (errno == 0)
{ {

View File

@ -1008,12 +1008,10 @@ rootfs_has_usrlib_passwd (int rootfs_dfd,
gboolean *out_have_passwd, gboolean *out_have_passwd,
GError **error) GError **error)
{ {
struct stat stbuf;
/* Does this rootfs have a usr/lib/passwd? We might be doing a /* Does this rootfs have a usr/lib/passwd? We might be doing a
* container or something else. * container or something else.
*/ */
if (!glnx_fstatat_allow_noent (rootfs_dfd, "usr/lib/passwd", &stbuf, 0, error)) if (!glnx_fstatat_allow_noent (rootfs_dfd, "usr/lib/passwd", NULL, 0, error))
return FALSE; return FALSE;
*out_have_passwd = (errno == 0); *out_have_passwd = (errno == 0);
return TRUE; return TRUE;
@ -1099,12 +1097,11 @@ rpmostree_passwd_prepare_rpm_layering (int rootfs_dfd,
*/ */
for (guint i = 0; i < G_N_ELEMENTS (pwgrp_shadow_files); i++) for (guint i = 0; i < G_N_ELEMENTS (pwgrp_shadow_files); i++)
{ {
struct stat stbuf;
const char *file = pwgrp_shadow_files[i]; const char *file = pwgrp_shadow_files[i];
const char *src = glnx_strjoina ("usr/etc/", file); const char *src = glnx_strjoina ("usr/etc/", file);
const char *tmp = glnx_strjoina ("usr/etc/", file, ".tmp"); const char *tmp = glnx_strjoina ("usr/etc/", file, ".tmp");
if (!glnx_fstatat_allow_noent (rootfs_dfd, src, &stbuf, AT_SYMLINK_NOFOLLOW, error)) if (!glnx_fstatat_allow_noent (rootfs_dfd, src, NULL, AT_SYMLINK_NOFOLLOW, error))
return FALSE; return FALSE;
if (errno == ENOENT) if (errno == ENOENT)
continue; continue;

View File

@ -61,13 +61,12 @@ run_bwrap_mutably (int rootfs_fd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
struct stat stbuf;
const char *etc_bind; const char *etc_bind;
/* This gets called both by treecompose, where in the non-unified path we just /* This gets called both by treecompose, where in the non-unified path we just
* have /etc, and in kernel postprocessing where we have usr/etc. * have /etc, and in kernel postprocessing where we have usr/etc.
*/ */
if (!glnx_fstatat_allow_noent (rootfs_fd, "etc", &stbuf, 0, error)) if (!glnx_fstatat_allow_noent (rootfs_fd, "etc", NULL, 0, error))
return FALSE; return FALSE;
if (errno == ENOENT) if (errno == ENOENT)
etc_bind = "usr/etc"; etc_bind = "usr/etc";
@ -108,11 +107,10 @@ rename_if_exists (int src_dfd,
const char *to, const char *to,
GError **error) GError **error)
{ {
struct stat stbuf;
const char *errmsg = glnx_strjoina ("renaming ", from); const char *errmsg = glnx_strjoina ("renaming ", from);
GLNX_AUTO_PREFIX_ERROR (errmsg, error); GLNX_AUTO_PREFIX_ERROR (errmsg, error);
if (!glnx_fstatat_allow_noent (src_dfd, from, &stbuf, 0, error)) if (!glnx_fstatat_allow_noent (src_dfd, from, NULL, 0, error))
return FALSE; return FALSE;
if (errno == 0) if (errno == 0)
{ {
@ -642,20 +640,19 @@ rpmostree_prepare_rootfs_get_sepolicy (int dfd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
struct stat stbuf;
const char *policy_path; const char *policy_path;
/* Handle the policy being in both /usr/etc and /etc since /* Handle the policy being in both /usr/etc and /etc since
* this function can be called at different points. * this function can be called at different points.
*/ */
if (!glnx_fstatat_allow_noent (dfd, "usr/etc", &stbuf, 0, error)) if (!glnx_fstatat_allow_noent (dfd, "usr/etc", NULL, 0, error))
return FALSE; return FALSE;
if (errno == ENOENT) if (errno == ENOENT)
policy_path = "etc/selinux"; policy_path = "etc/selinux";
else else
policy_path = "usr/etc/selinux"; policy_path = "usr/etc/selinux";
if (!glnx_fstatat_allow_noent (dfd, policy_path, &stbuf, AT_SYMLINK_NOFOLLOW, error)) if (!glnx_fstatat_allow_noent (dfd, policy_path, NULL, AT_SYMLINK_NOFOLLOW, error))
return FALSE; return FALSE;
if (errno == 0) if (errno == 0)
{ {
@ -779,7 +776,6 @@ postprocess_selinux_policy_store_location (int rootfs_dfd,
glnx_unref_object OstreeSePolicy *sepolicy = NULL; glnx_unref_object OstreeSePolicy *sepolicy = NULL;
const char *var_policy_location = NULL; const char *var_policy_location = NULL;
const char *etc_policy_location = NULL; const char *etc_policy_location = NULL;
struct stat stbuf;
const char *name; const char *name;
glnx_autofd int etc_selinux_dfd = -1; glnx_autofd int etc_selinux_dfd = -1;
@ -792,7 +788,7 @@ postprocess_selinux_policy_store_location (int rootfs_dfd,
var_policy_location = glnx_strjoina ("var/lib/selinux/", name); var_policy_location = glnx_strjoina ("var/lib/selinux/", name);
const char *modules_location = glnx_strjoina (var_policy_location, "/active/modules"); const char *modules_location = glnx_strjoina (var_policy_location, "/active/modules");
if (!glnx_fstatat_allow_noent (rootfs_dfd, modules_location, &stbuf, 0, error)) if (!glnx_fstatat_allow_noent (rootfs_dfd, modules_location, NULL, 0, error))
return FALSE; return FALSE;
if (errno == ENOENT) if (errno == ENOENT)
{ {
@ -1114,8 +1110,7 @@ cleanup_selinux_lockfiles (int rootfs_fd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
struct stat stbuf; if (!glnx_fstatat_allow_noent (rootfs_fd, "usr/etc/selinux", NULL, 0, error))
if (!glnx_fstatat_allow_noent (rootfs_fd, "usr/etc/selinux", &stbuf, 0, error))
return FALSE; return FALSE;
if (errno == ENOENT) if (errno == ENOENT)
@ -1627,8 +1622,7 @@ rpmostree_prepare_rootfs_for_commit (int src_rootfs_dfd,
"bin", "sbin" }; "bin", "sbin" };
for (guint i = 0; i < G_N_ELEMENTS (toplevel_links); i++) for (guint i = 0; i < G_N_ELEMENTS (toplevel_links); i++)
{ {
struct stat stbuf; if (!glnx_fstatat_allow_noent (src_rootfs_dfd, toplevel_links[i], NULL,
if (!glnx_fstatat_allow_noent (src_rootfs_dfd, toplevel_links[i], &stbuf,
AT_SYMLINK_NOFOLLOW, error)) AT_SYMLINK_NOFOLLOW, error))
return FALSE; return FALSE;
if (errno == ENOENT) if (errno == ENOENT)