[libglnx] tree-wide: Use our own syscall wrappers or error prefixing



commit 667d8aa7217eefcbc1c701b8f96ecf8cbeff0f8a
Author: Colin Walters <walters verbum org>
Date:   Tue Sep 12 16:00:47 2017 -0400

    tree-wide: Use our own syscall wrappers or error prefixing
    
    Followup to similar commits in the ostree stack recently.

 glnx-dirfd.c    |    5 +++--
 glnx-fdio.c     |   26 ++++++++++++--------------
 glnx-lockfile.c |    7 +++----
 3 files changed, 18 insertions(+), 20 deletions(-)
---
diff --git a/glnx-dirfd.c b/glnx-dirfd.c
index cbc31f9..ea12c8f 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 a257c05..7113aeb 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 c1cfc6b..48f1ea7 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;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]