sysroot: Update some code to use fstatat_allow_noent API

It's much easier to read and use correctly.  Making this change
since I saw an unprefixed error in an issue.

Closes: #1757
Approved by: jlebon
This commit is contained in:
Colin Walters 2018-10-17 16:06:50 +00:00 committed by Atomic Bot
parent e242033fe7
commit 5183c8f35e
1 changed files with 12 additions and 12 deletions

View File

@ -376,12 +376,11 @@ _ostree_sysroot_read_current_subbootversion (OstreeSysroot *self,
g_autofree char *ostree_bootdir_name = g_strdup_printf ("ostree/boot.%d", bootversion); g_autofree char *ostree_bootdir_name = g_strdup_printf ("ostree/boot.%d", bootversion);
struct stat stbuf; struct stat stbuf;
if (fstatat (self->sysroot_fd, ostree_bootdir_name, &stbuf, AT_SYMLINK_NOFOLLOW) != 0) if (!glnx_fstatat_allow_noent (self->sysroot_fd, ostree_bootdir_name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE;
if (errno == ENOENT)
{ {
if (errno == ENOENT) *out_subbootversion = 0;
*out_subbootversion = 0;
else
return glnx_throw_errno (error);
} }
else else
{ {
@ -499,10 +498,10 @@ read_current_bootversion (OstreeSysroot *self,
int ret_bootversion; int ret_bootversion;
struct stat stbuf; struct stat stbuf;
if (fstatat (self->sysroot_fd, "boot/loader", &stbuf, AT_SYMLINK_NOFOLLOW) != 0) if (!glnx_fstatat_allow_noent (self->sysroot_fd, "boot/loader", &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE;
if (errno == ENOENT)
{ {
if (errno != ENOENT)
return glnx_throw_errno (error);
ret_bootversion = 0; ret_bootversion = 0;
} }
else else
@ -976,11 +975,12 @@ ostree_sysroot_load_if_changed (OstreeSysroot *self,
/* Otherwise - check for /sysroot which should only exist in a deployment, /* Otherwise - check for /sysroot which should only exist in a deployment,
* not in ${sysroot} (a metavariable for the real physical root). * not in ${sysroot} (a metavariable for the real physical root).
*/ */
else if (fstatat (self->sysroot_fd, "sysroot", &stbuf, 0) < 0) else
{ {
if (errno != ENOENT) if (!glnx_fstatat_allow_noent (self->sysroot_fd, "sysroot", &stbuf, 0, error))
return glnx_throw_errno_prefix (error, "fstatat"); return FALSE;
self->is_physical = TRUE; if (errno == ENOENT)
self->is_physical = TRUE;
} }
/* Otherwise, the default is FALSE */ /* Otherwise, the default is FALSE */
} }