Update libglnx, port some uses to newer APIs
authorColin Walters <walters@verbum.org>
Mon, 24 Jul 2017 16:25:07 +0000 (12:25 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 24 Jul 2017 18:43:57 +0000 (18:43 +0000)
Mostly for the latest `-Wmaybe-uninitialized` fix, but while here also port some
places to newer APIs.

Update submodule: libglnx

Closes: #1027
Approved by: jlebon

libglnx
src/libostree/ostree-bootloader-grub2.c
src/libostree/ostree-core.c
src/libostree/ostree-gpg-verifier.c
src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo.c
src/libostree/ostree-sysroot-deploy.c

diff --git a/libglnx b/libglnx
index 607f1775bb1c626cae1875a957a34802daebe81c..ea6df95f22c8f2973714bdbb8b1accc4e37d4d56 160000 (submodule)
--- a/libglnx
+++ b/libglnx
@@ -1 +1 @@
-Subproject commit 607f1775bb1c626cae1875a957a34802daebe81c
+Subproject commit ea6df95f22c8f2973714bdbb8b1accc4e37d4d56
index 63e4b968c6973c8a58e82b6ac049095a2052ce09..86970d36a21c80348631ee0a84e578152afad9c9 100644 (file)
@@ -420,15 +420,13 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader      *bootloader,
     }
 
   /* Now let's fdatasync() for the new file */
-  { glnx_fd_close int new_config_fd = open (gs_file_get_path_cached (new_config_path), O_RDONLY | O_CLOEXEC);
-    if (new_config_fd < 0)
-      {
-        glnx_set_prefix_error_from_errno (error, "Opening %s", gs_file_get_path_cached (new_config_path));
-        goto out;
-      }
+  { glnx_fd_close int new_config_fd = -1;
+    if (!glnx_openat_rdonly (AT_FDCWD, gs_file_get_path_cached (new_config_path), TRUE, &new_config_fd, error))
+      goto out;
+
     if (fdatasync (new_config_fd) < 0)
       {
-        glnx_set_error_from_errno (error);
+        (void)glnx_throw_errno_prefix (error, "fdatasync");
         goto out;
       }
   }
index 116f376f2bd3e5797a6c679f2573d1383d8d5edf..c13d2f2eef3eccc6fbdbdcb58faac057c16972d2 100644 (file)
@@ -775,9 +775,9 @@ ostree_content_file_parse_at (gboolean                compressed,
                               GCancellable           *cancellable,
                               GError                **error)
 {
-  int glnx_fd_close fd = openat (parent_dfd, path, O_RDONLY | O_CLOEXEC);
-  if (fd < 0)
-    return glnx_throw_errno_prefix (error, "open(%s)", path);
+  glnx_fd_close int fd = -1;
+  if (!glnx_openat_rdonly (parent_dfd, path, TRUE, &fd, error))
+    return FALSE;
 
   struct stat stbuf;
   if (!glnx_fstat (fd, &stbuf, error))
index c008bdaf46de8294eb3561962c075d130b9051ec..77594d9b0f452640eff42b0eea9692164dc0f9c4 100644 (file)
@@ -167,12 +167,8 @@ _ostree_gpg_verifier_check_signature (OstreeGpgVerifier  *self,
           glnx_fd_close int fd = -1;
           ot_auto_gpgme_data gpgme_data_t kdata = NULL;
 
-          fd = openat (AT_FDCWD, path, O_RDONLY | O_CLOEXEC) ;
-          if (fd < 0)
-            {
-              glnx_set_prefix_error_from_errno (error, "Opening %s", path);
-              goto out;
-            }
+          if (!glnx_openat_rdonly (AT_FDCWD, path, TRUE, &fd, error))
+            goto out;
 
           gpg_error = gpgme_data_new_from_fd (&kdata, fd);
           if (gpg_error != GPG_ERR_NO_ERROR)
index bcd9c2d91ed9531b5f609ae063ffd0a332545235..1d3d6840e2e72c3690ad2c679e8f9067586277aa 100644 (file)
@@ -2824,18 +2824,16 @@ write_dfd_iter_to_mtree_internal (OstreeRepo                  *self,
   while (TRUE)
     {
       struct dirent *dent;
-      struct stat stbuf;
-      g_autoptr(GFileInfo) child_info = NULL;
-      const char *loose_checksum;
       if (!glnx_dirfd_iterator_next_dent (src_dfd_iter, &dent, cancellable, error))
         return FALSE;
       if (dent == NULL)
         break;
 
-      if (fstatat (src_dfd_iter->fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW) == -1)
-        return glnx_throw_errno (error);
+      struct stat stbuf;
+      if (!glnx_fstatat (src_dfd_iter->fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
+        return FALSE;
 
-      loose_checksum = devino_cache_lookup (self, modifier, stbuf.st_dev, stbuf.st_ino);
+      const char *loose_checksum = devino_cache_lookup (self, modifier, stbuf.st_dev, stbuf.st_ino);
       if (loose_checksum)
         {
           if (!ostree_mutable_tree_replace_file (mtree, dent->d_name, loose_checksum,
@@ -2845,7 +2843,7 @@ write_dfd_iter_to_mtree_internal (OstreeRepo                  *self,
           continue;
         }
 
-      child_info = _ostree_stbuf_to_gfileinfo (&stbuf);
+      g_autoptr(GFileInfo) child_info = _ostree_stbuf_to_gfileinfo (&stbuf);
       g_file_info_set_name (child_info, dent->d_name);
 
       if (S_ISREG (stbuf.st_mode))
index 33ea489c3bdda09a59e4761ea31dd4fcd6c5242b..1c0f79ea77f7511242eabd3a249a0f425583fe2f 100644 (file)
@@ -1229,12 +1229,8 @@ meta_fetch_on_complete (GObject           *object,
   if (objtype == OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT)
     goto out;
 
-  fd = openat (_ostree_fetcher_get_dfd (fetcher), tmp_unlinker.path, O_RDONLY | O_CLOEXEC);
-  if (fd == -1)
-    {
-      glnx_set_error_from_errno (error);
-      goto out;
-    }
+  if (!glnx_openat_rdonly (_ostree_fetcher_get_dfd (fetcher), tmp_unlinker.path, TRUE, &fd, error))
+    goto out;
 
   /* Now delete it, keeping the fd open as the last reference; see comment in
    * corresponding content fetch path.
@@ -1342,12 +1338,8 @@ static_deltapart_fetch_on_complete (GObject           *object,
   if (!_ostree_fetcher_request_to_tmpfile_finish (fetcher, result, &temp_path, error))
     goto out;
 
-  fd = openat (_ostree_fetcher_get_dfd (fetcher), temp_path, O_RDONLY | O_CLOEXEC);
-  if (fd == -1)
-    {
-      glnx_set_error_from_errno (error);
-      goto out;
-    }
+  if (!glnx_openat_rdonly (_ostree_fetcher_get_dfd (fetcher), temp_path, TRUE, &fd, error))
+    goto out;
 
   /* From here on, if we fail to apply the delta, we'll re-fetch it */
   if (unlinkat (_ostree_fetcher_get_dfd (fetcher), temp_path, 0) < 0)
index a009f1c82c39c7c7d3ed51bd3cd02a00ae062849..896c57bc20ae8baafbfe4ea3111305417e327e7f 100644 (file)
@@ -4718,9 +4718,10 @@ ostree_repo_regenerate_summary (OstreeRepo     *self,
           return FALSE;
 
         g_autofree char *superblock = _ostree_get_relative_static_delta_superblock_path ((from && from[0]) ? from : NULL, to);
-        glnx_fd_close int superblock_file_fd = openat (self->repo_dir_fd, superblock, O_RDONLY | O_CLOEXEC);
-        if (superblock_file_fd == -1)
-          return glnx_throw_errno (error);
+        glnx_fd_close int superblock_file_fd = -1;
+
+        if (!glnx_openat_rdonly (self->repo_dir_fd, superblock, TRUE, &superblock_file_fd, error))
+          return FALSE;
 
         g_autoptr(GInputStream) in_stream = g_unix_input_stream_new (superblock_file_fd, FALSE);
         if (!in_stream)
index bf4424a92f1ffdadb3b642f94106d5f9f347f824..b2b46b362682f3e1be9dac906618727bd1747e8c 100644 (file)
@@ -178,9 +178,9 @@ copy_dir_recurse (int              src_parent_dfd,
       if (dent == NULL)
         break;
 
-      if (fstatat (src_dfd_iter.fd, dent->d_name, &child_stbuf,
-                   AT_SYMLINK_NOFOLLOW) != 0)
-        return glnx_throw_errno (error);
+      if (!glnx_fstatat (src_dfd_iter.fd, dent->d_name, &child_stbuf,
+                         AT_SYMLINK_NOFOLLOW, error))
+        return FALSE;
 
       if (S_ISDIR (child_stbuf.st_mode))
         {