diff --git a/glnx-dirfd.c b/glnx-dirfd.c index cbc31f9f4cb1bc2be789dd113546234a6bf577e0..ea12c8f9deb852739a72c031006cd2d0430e75e6 100644 --- a/glnx-dirfd.c +++ b/glnx-dirfd.c @@ -23,6 +23,7 @@ #include <string.h> #include <glnx-dirfd.h> +#include <glnx-fdio.h> #include <glnx-errors.h> #include <glnx-local-alloc.h> #include <glnx-shutil.h> @@ -204,8 +205,8 @@ glnx_dirfd_iterator_next_dent_ensure_dtype (GLnxDirFdIterator *dfd_iter, if (ret_dent->d_type == DT_UNKNOWN) { struct stat stbuf; - if (TEMP_FAILURE_RETRY (fstatat (dfd_iter->fd, ret_dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0) - return glnx_throw_errno (error); + if (!glnx_fstatat (dfd_iter->fd, ret_dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error)) + return FALSE; ret_dent->d_type = IFTODT (stbuf.st_mode); } } diff --git a/glnx-fdio.c b/glnx-fdio.c index a257c0569252d64efc5d5d78b0c382b374132aef..7113aebce62a462df9d73f8bb9455a495886cfb6 100644 --- a/glnx-fdio.c +++ b/glnx-fdio.c @@ -112,7 +112,7 @@ rename_file_noreplace_at (int olddirfd, const char *oldpath, return TRUE; } else - return glnx_throw_errno (error); + return glnx_throw_errno_prefix (error, "renameat"); } return TRUE; } @@ -442,8 +442,8 @@ glnx_fd_readall_malloc (int fd, const guint maxreadlen = 4096; struct stat stbuf; - if (TEMP_FAILURE_RETRY (fstat (fd, &stbuf)) < 0) - return glnx_null_throw_errno (error); + if (!glnx_fstat (fd, &stbuf, error)) + return FALSE; gsize buf_allocated; if (S_ISREG (stbuf.st_mode) && stbuf.st_size > 0) @@ -611,7 +611,7 @@ glnx_readlinkat_malloc (int dfd, c = g_malloc (l); n = TEMP_FAILURE_RETRY (readlinkat (dfd, subpath, c, l-1)); if (n < 0) - return glnx_null_throw_errno (error); + return glnx_null_throw_errno_prefix (error, "readlinkat"); if ((size_t) n < l-1) { @@ -658,7 +658,7 @@ copy_symlink_at (int src_dfd, if (TEMP_FAILURE_RETRY (fchownat (dest_dfd, dest_subpath, src_stbuf->st_uid, src_stbuf->st_gid, AT_SYMLINK_NOFOLLOW)) != 0) - return glnx_throw_errno (error); + return glnx_throw_errno_prefix (error, "fchownat"); return TRUE; } @@ -1066,19 +1066,17 @@ glnx_file_replace_contents_with_perms_at (int dfd, return FALSE; if (glnx_loop_write (tmpf.fd, buf, len) < 0) - return glnx_throw_errno (error); + return glnx_throw_errno_prefix (error, "write"); if (!(flags & GLNX_FILE_REPLACE_NODATASYNC)) { struct stat stbuf; gboolean do_sync; - if (fstatat (dfd, subpath, &stbuf, AT_SYMLINK_NOFOLLOW) != 0) - { - if (errno != ENOENT) - return glnx_throw_errno (error); - do_sync = (flags & GLNX_FILE_REPLACE_DATASYNC_NEW) > 0; - } + if (!glnx_fstatat_allow_noent (dfd, subpath, &stbuf, AT_SYMLINK_NOFOLLOW, error)) + return FALSE; + if (errno == ENOENT) + do_sync = (flags & GLNX_FILE_REPLACE_DATASYNC_NEW) > 0; else do_sync = TRUE; @@ -1092,11 +1090,11 @@ glnx_file_replace_contents_with_perms_at (int dfd, if (uid != (uid_t) -1) { if (fchown (tmpf.fd, uid, gid) != 0) - return glnx_throw_errno (error); + return glnx_throw_errno_prefix (error, "fchown"); } if (fchmod (tmpf.fd, mode) != 0) - return glnx_throw_errno (error); + return glnx_throw_errno_prefix (error, "fchmod"); if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_REPLACE, dfd, subpath, error)) diff --git a/glnx-lockfile.c b/glnx-lockfile.c index c1cfc6b286a6e1ec62a9fb45b1f1fe0e740f4a61..48f1ea75af0a964787b59c40b061e636e98e86a2 100644 --- a/glnx-lockfile.c +++ b/glnx-lockfile.c @@ -105,7 +105,7 @@ glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_loc r = flock(fd, operation); if (r < 0) - return glnx_throw_errno(error); + return glnx_throw_errno_prefix (error, "flock"); } /* If we acquired the lock, let's check if the file @@ -114,9 +114,8 @@ glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_loc * it. In such a case our acquired lock is worthless, * hence try again. */ - r = fstat(fd, &st); - if (r < 0) - return glnx_throw_errno(error); + if (!glnx_fstat (fd, &st, error)) + return FALSE; if (st.st_nlink > 0) break;