tree-wide: Update to new libglnx fd APIs

This ends up a lot better IMO.  This commit is *mostly* just
`s/glnx_close_fd/glnx_autofd`, but there's also a number of hunks like:

```
-  if (self->sysroot_fd != -1)
-    {
-      (void) close (self->sysroot_fd);
-      self->sysroot_fd = -1;
-    }
+  glnx_close_fd (&self->sysroot_fd);
```

Update submodule: libglnx

Closes: #1259
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-10-11 09:41:31 -04:00 committed by Atomic Bot
parent 3e3d28632d
commit 1825f03fe7
29 changed files with 116 additions and 137 deletions

@ -1 +1 @@
Subproject commit e30154431d7eea6397e5502b175ba3b50330140f Subproject commit 5362f6bc3ff3e30f379e767b203d15c9e56d6f08

View File

@ -416,7 +416,7 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
} }
/* Now let's fdatasync() for the new file */ /* Now let's fdatasync() for the new file */
{ glnx_fd_close int new_config_fd = -1; { glnx_autofd int new_config_fd = -1;
if (!glnx_openat_rdonly (AT_FDCWD, gs_file_get_path_cached (new_config_path), TRUE, &new_config_fd, error)) if (!glnx_openat_rdonly (AT_FDCWD, gs_file_get_path_cached (new_config_path), TRUE, &new_config_fd, error))
return FALSE; return FALSE;

View File

@ -73,7 +73,7 @@ append_system_uenv (OstreeBootloaderUboot *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int uenv_fd = -1; glnx_autofd int uenv_fd = -1;
__attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = NULL; __attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = NULL;
const char *uenv_path = NULL; const char *uenv_path = NULL;
const char *ostree_arg = NULL; const char *ostree_arg = NULL;

View File

@ -670,7 +670,7 @@ ostree_content_file_parse_at (gboolean compressed,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!glnx_openat_rdonly (parent_dfd, path, TRUE, &fd, error)) if (!glnx_openat_rdonly (parent_dfd, path, TRUE, &fd, error))
return FALSE; return FALSE;

View File

@ -177,7 +177,7 @@ _ostree_gpg_verifier_check_signature (OstreeGpgVerifier *self,
for (guint i = 0; i < self->key_ascii_files->len; i++) for (guint i = 0; i < self->key_ascii_files->len; i++)
{ {
const char *path = self->key_ascii_files->pdata[i]; const char *path = self->key_ascii_files->pdata[i];
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
g_auto(gpgme_data_t) kdata = NULL; g_auto(gpgme_data_t) kdata = NULL;
if (!glnx_openat_rdonly (AT_FDCWD, path, TRUE, &fd, error)) if (!glnx_openat_rdonly (AT_FDCWD, path, TRUE, &fd, error))
@ -355,7 +355,7 @@ _ostree_gpg_verifier_add_keyring_dir_at (OstreeGpgVerifier *self,
if (g_str_equal (name, "secring.gpg")) if (g_str_equal (name, "secring.gpg"))
continue; continue;
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!glnx_openat_rdonly (dfd_iter.fd, dent->d_name, TRUE, &fd, error)) if (!glnx_openat_rdonly (dfd_iter.fd, dent->d_name, TRUE, &fd, error))
return FALSE; return FALSE;

View File

@ -164,7 +164,7 @@ _ostree_impl_system_generator (const char *ostree_cmdline,
/* Prepare to write to the output unit dir; we use the "normal" dir /* Prepare to write to the output unit dir; we use the "normal" dir
* that overrides /usr, but not /etc. * that overrides /usr, but not /etc.
*/ */
glnx_fd_close int normal_dir_dfd = -1; glnx_autofd int normal_dir_dfd = -1;
if (!glnx_opendirat (AT_FDCWD, normal_dir, TRUE, &normal_dir_dfd, error)) if (!glnx_opendirat (AT_FDCWD, normal_dir, TRUE, &normal_dir_dfd, error))
return FALSE; return FALSE;

View File

@ -782,7 +782,7 @@ checkout_tree_at_recurse (OstreeRepo *self,
} }
} }
glnx_fd_close int destination_dfd = -1; glnx_autofd int destination_dfd = -1;
if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE, if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE,
&destination_dfd, error)) &destination_dfd, error))
return FALSE; return FALSE;
@ -947,7 +947,7 @@ checkout_tree_at (OstreeRepo *self,
* exists. * exists.
*/ */
int destination_dfd = destination_parent_fd; int destination_dfd = destination_parent_fd;
glnx_fd_close int destination_dfd_owned = -1; glnx_autofd int destination_dfd_owned = -1;
if (strcmp (destination_name, ".") != 0) if (strcmp (destination_name, ".") != 0)
{ {
if (mkdirat (destination_parent_fd, destination_name, 0700) < 0 if (mkdirat (destination_parent_fd, destination_name, 0700) < 0

View File

@ -1229,7 +1229,7 @@ rename_pending_loose_objects (OstreeRepo *self,
/* Ensure that in the case of a power cut all the directory metadata that /* Ensure that in the case of a power cut all the directory metadata that
we want has reached the disk. In particular, we want this before we we want has reached the disk. In particular, we want this before we
update the refs to point to these objects. */ update the refs to point to these objects. */
glnx_fd_close int target_dir_fd = -1; glnx_autofd int target_dir_fd = -1;
loose_objpath[2] = 0; loose_objpath[2] = 0;
@ -2221,7 +2221,7 @@ ostree_repo_read_commit_detached_metadata (OstreeRepo *self,
if (self->commit_stagedir.initialized) if (self->commit_stagedir.initialized)
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!ot_openat_ignore_enoent (self->commit_stagedir.fd, buf, &fd, error)) if (!ot_openat_ignore_enoent (self->commit_stagedir.fd, buf, &fd, error))
return FALSE; return FALSE;
if (fd != -1) if (fd != -1)
@ -2229,7 +2229,7 @@ ostree_repo_read_commit_detached_metadata (OstreeRepo *self,
out_metadata, error); out_metadata, error);
} }
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!ot_openat_ignore_enoent (self->objects_dir_fd, buf, &fd, error)) if (!ot_openat_ignore_enoent (self->objects_dir_fd, buf, &fd, error))
return FALSE; return FALSE;
if (fd != -1) if (fd != -1)
@ -3404,7 +3404,7 @@ import_one_object_direct (OstreeRepo *dest_repo,
* that basically just optionally does chown(). Perhaps * that basically just optionally does chown(). Perhaps
* in the future we should add flags for those things? * in the future we should add flags for those things?
*/ */
glnx_fd_close int src_fd = -1; glnx_autofd int src_fd = -1;
if (!glnx_openat_rdonly (src_repo->objects_dir_fd, loose_path_buf, if (!glnx_openat_rdonly (src_repo->objects_dir_fd, loose_path_buf,
FALSE, &src_fd, error)) FALSE, &src_fd, error))
return FALSE; return FALSE;

View File

@ -328,9 +328,9 @@ ostree_repo_finder_mount_resolve_async (OstreeRepoFinder *finde
g_autofree gchar *mount_name = NULL; g_autofree gchar *mount_name = NULL;
g_autoptr(GFile) mount_root = NULL; g_autoptr(GFile) mount_root = NULL;
g_autofree gchar *mount_root_path = NULL; g_autofree gchar *mount_root_path = NULL;
glnx_fd_close int mount_root_dfd = -1; glnx_autofd int mount_root_dfd = -1;
struct stat mount_root_stbuf; struct stat mount_root_stbuf;
glnx_fd_close int repos_dfd = -1; glnx_autofd int repos_dfd = -1;
gsize i; gsize i;
g_autoptr(GHashTable) repo_to_refs = NULL; /* (element-type UriAndKeyring GHashTable) */ g_autoptr(GHashTable) repo_to_refs = NULL; /* (element-type UriAndKeyring GHashTable) */
GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */ GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */

View File

@ -547,7 +547,7 @@ write_commitpartial_for (OtPullData *pull_data,
GError **error) GError **error)
{ {
g_autofree char *commitpartial_path = _ostree_get_commitpartial_path (checksum); g_autofree char *commitpartial_path = _ostree_get_commitpartial_path (checksum);
glnx_fd_close int fd = openat (pull_data->repo->repo_dir_fd, commitpartial_path, O_EXCL | O_CREAT | O_WRONLY | O_CLOEXEC | O_NOCTTY, 0644); glnx_autofd int fd = openat (pull_data->repo->repo_dir_fd, commitpartial_path, O_EXCL | O_CREAT | O_WRONLY | O_CLOEXEC | O_NOCTTY, 0644);
if (fd == -1) if (fd == -1)
{ {
if (errno != EEXIST) if (errno != EEXIST)
@ -2495,7 +2495,7 @@ _ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self,
return TRUE; return TRUE;
const char *summary_cache_sig_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig"); const char *summary_cache_sig_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig");
glnx_fd_close int prev_fd = -1; glnx_autofd int prev_fd = -1;
if (!ot_openat_ignore_enoent (self->cache_dir_fd, summary_cache_sig_file, &prev_fd, error)) if (!ot_openat_ignore_enoent (self->cache_dir_fd, summary_cache_sig_file, &prev_fd, error))
return FALSE; return FALSE;
if (prev_fd < 0) if (prev_fd < 0)
@ -2508,7 +2508,7 @@ _ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self,
if (g_bytes_compare (old_sig_contents, summary_sig) == 0) if (g_bytes_compare (old_sig_contents, summary_sig) == 0)
{ {
const char *summary_cache_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote); const char *summary_cache_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote);
glnx_fd_close int summary_fd = -1; glnx_autofd int summary_fd = -1;
GBytes *summary_data; GBytes *summary_data;

View File

@ -150,7 +150,7 @@ find_ref_in_remotes (OstreeRepo *self,
GError **error) GError **error)
{ {
g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
glnx_fd_close int ret_fd = -1; glnx_autofd int ret_fd = -1;
if (!glnx_dirfd_iterator_init_at (self->repo_dir_fd, "refs/remotes", TRUE, &dfd_iter, error)) if (!glnx_dirfd_iterator_init_at (self->repo_dir_fd, "refs/remotes", TRUE, &dfd_iter, error))
return FALSE; return FALSE;
@ -158,7 +158,7 @@ find_ref_in_remotes (OstreeRepo *self,
while (TRUE) while (TRUE)
{ {
struct dirent *dent = NULL; struct dirent *dent = NULL;
glnx_fd_close int remote_dfd = -1; glnx_autofd int remote_dfd = -1;
if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, NULL, error)) if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, NULL, error))
return FALSE; return FALSE;
@ -234,7 +234,7 @@ resolve_refspec (OstreeRepo *self,
{ {
__attribute__((unused)) GCancellable *cancellable = NULL; __attribute__((unused)) GCancellable *cancellable = NULL;
g_autofree char *ret_rev = NULL; g_autofree char *ret_rev = NULL;
glnx_fd_close int target_fd = -1; glnx_autofd int target_fd = -1;
g_return_val_if_fail (ref != NULL, FALSE); g_return_val_if_fail (ref != NULL, FALSE);
@ -637,7 +637,7 @@ _ostree_repo_list_refs_internal (OstreeRepo *self,
{ {
if (S_ISDIR (stbuf.st_mode)) if (S_ISDIR (stbuf.st_mode))
{ {
glnx_fd_close int base_fd = -1; glnx_autofd int base_fd = -1;
g_autoptr(GString) base_path = g_string_new (""); g_autoptr(GString) base_path = g_string_new ("");
if (!cut_prefix) if (!cut_prefix)
g_string_printf (base_path, "%s/", ref_prefix); g_string_printf (base_path, "%s/", ref_prefix);
@ -652,7 +652,7 @@ _ostree_repo_list_refs_internal (OstreeRepo *self,
} }
else else
{ {
glnx_fd_close int prefix_dfd = -1; glnx_autofd int prefix_dfd = -1;
if (!glnx_opendirat (self->repo_dir_fd, prefix_path, TRUE, &prefix_dfd, error)) if (!glnx_opendirat (self->repo_dir_fd, prefix_path, TRUE, &prefix_dfd, error))
return FALSE; return FALSE;
@ -667,7 +667,7 @@ _ostree_repo_list_refs_internal (OstreeRepo *self,
{ {
g_auto(GLnxDirFdIterator) dfd_iter = { 0, }; g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
g_autoptr(GString) base_path = g_string_new (""); g_autoptr(GString) base_path = g_string_new ("");
glnx_fd_close int refs_heads_dfd = -1; glnx_autofd int refs_heads_dfd = -1;
if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE, &refs_heads_dfd, error)) if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE, &refs_heads_dfd, error))
return FALSE; return FALSE;
@ -687,7 +687,7 @@ _ostree_repo_list_refs_internal (OstreeRepo *self,
while (TRUE) while (TRUE)
{ {
struct dirent *dent; struct dirent *dent;
glnx_fd_close int remote_dfd = -1; glnx_autofd int remote_dfd = -1;
if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error)) if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error))
return FALSE; return FALSE;
@ -992,7 +992,7 @@ _ostree_repo_write_ref (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int dfd = -1; glnx_autofd int dfd = -1;
g_return_val_if_fail (remote == NULL || ref->collection_id == NULL, FALSE); g_return_val_if_fail (remote == NULL || ref->collection_id == NULL, FALSE);
g_return_val_if_fail (!(rev != NULL && alias != NULL), FALSE); g_return_val_if_fail (!(rev != NULL && alias != NULL), FALSE);
@ -1016,7 +1016,7 @@ _ostree_repo_write_ref (OstreeRepo *self,
} }
else if (remote == NULL && ref->collection_id != NULL) else if (remote == NULL && ref->collection_id != NULL)
{ {
glnx_fd_close int refs_mirrors_dfd = -1; glnx_autofd int refs_mirrors_dfd = -1;
/* refs/mirrors might not exist in older repositories, so create it. */ /* refs/mirrors might not exist in older repositories, so create it. */
if (!glnx_shutil_mkdir_p_at_open (self->repo_dir_fd, "refs/mirrors", 0777, if (!glnx_shutil_mkdir_p_at_open (self->repo_dir_fd, "refs/mirrors", 0777,
@ -1039,7 +1039,7 @@ _ostree_repo_write_ref (OstreeRepo *self,
} }
else else
{ {
glnx_fd_close int refs_remotes_dfd = -1; glnx_autofd int refs_remotes_dfd = -1;
if (!glnx_opendirat (self->repo_dir_fd, "refs/remotes", TRUE, if (!glnx_opendirat (self->repo_dir_fd, "refs/remotes", TRUE,
&refs_remotes_dfd, error)) &refs_remotes_dfd, error))
@ -1212,7 +1212,7 @@ ostree_repo_list_collection_refs (OstreeRepo *self,
if (main_collection_id != NULL && if (main_collection_id != NULL &&
(match_collection_id == NULL || g_strcmp0 (match_collection_id, main_collection_id) == 0)) (match_collection_id == NULL || g_strcmp0 (match_collection_id, main_collection_id) == 0))
{ {
glnx_fd_close int refs_heads_dfd = -1; glnx_autofd int refs_heads_dfd = -1;
if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE, &refs_heads_dfd, error)) if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE, &refs_heads_dfd, error))
return FALSE; return FALSE;
@ -1237,7 +1237,7 @@ ostree_repo_list_collection_refs (OstreeRepo *self,
while (refs_dir_exists) while (refs_dir_exists)
{ {
struct dirent *dent; struct dirent *dent;
glnx_fd_close int subdir_fd = -1; glnx_autofd int subdir_fd = -1;
const gchar *current_collection_id; const gchar *current_collection_id;
g_autofree gchar *remote_collection_id = NULL; g_autofree gchar *remote_collection_id = NULL;

View File

@ -1209,12 +1209,12 @@ ostree_repo_static_delta_generate (OstreeRepo *self,
g_autoptr(GVariant) to_commit = NULL; g_autoptr(GVariant) to_commit = NULL;
const char *opt_filename; const char *opt_filename;
g_autofree char *descriptor_name = NULL; g_autofree char *descriptor_name = NULL;
glnx_fd_close int descriptor_dfd = -1; glnx_autofd int descriptor_dfd = -1;
g_autoptr(GVariant) fallback_headers = NULL; g_autoptr(GVariant) fallback_headers = NULL;
g_autoptr(GVariant) detached = NULL; g_autoptr(GVariant) detached = NULL;
gboolean inline_parts; gboolean inline_parts;
guint endianness = G_BYTE_ORDER; guint endianness = G_BYTE_ORDER;
glnx_fd_close int tmp_dfd = -1; glnx_autofd int tmp_dfd = -1;
builder.parts = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_static_delta_part_builder_unref); builder.parts = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_static_delta_part_builder_unref);
builder.fallback_objects = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); builder.fallback_objects = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref);

View File

@ -224,7 +224,7 @@ ostree_repo_static_delta_execute_offline (OstreeRepo *self,
const char *dir_or_file_path = gs_file_get_path_cached (dir_or_file); const char *dir_or_file_path = gs_file_get_path_cached (dir_or_file);
/* First, try opening it as a directory */ /* First, try opening it as a directory */
glnx_fd_close int dfd = glnx_opendirat_with_errno (AT_FDCWD, dir_or_file_path, TRUE); glnx_autofd int dfd = glnx_opendirat_with_errno (AT_FDCWD, dir_or_file_path, TRUE);
if (dfd < 0) if (dfd < 0)
{ {
if (errno != ENOTDIR) if (errno != ENOTDIR)
@ -241,7 +241,7 @@ ostree_repo_static_delta_execute_offline (OstreeRepo *self,
else else
basename = g_strdup ("superblock"); basename = g_strdup ("superblock");
glnx_fd_close int meta_fd = openat (dfd, basename, O_RDONLY | O_CLOEXEC); glnx_autofd int meta_fd = openat (dfd, basename, O_RDONLY | O_CLOEXEC);
if (meta_fd < 0) if (meta_fd < 0)
return glnx_throw_errno_prefix (error, "openat(%s)", basename); return glnx_throw_errno_prefix (error, "openat(%s)", basename);
@ -377,7 +377,7 @@ ostree_repo_static_delta_execute_offline (OstreeRepo *self,
else else
{ {
g_autofree char *relpath = g_strdup_printf ("%u", i); /* TODO avoid malloc here */ g_autofree char *relpath = g_strdup_printf ("%u", i); /* TODO avoid malloc here */
glnx_fd_close int part_fd = openat (dfd, relpath, O_RDONLY | O_CLOEXEC); glnx_autofd int part_fd = openat (dfd, relpath, O_RDONLY | O_CLOEXEC);
if (part_fd < 0) if (part_fd < 0)
return glnx_throw_errno_prefix (error, "Opening deltapart '%s'", relpath); return glnx_throw_errno_prefix (error, "Opening deltapart '%s'", relpath);
@ -525,7 +525,7 @@ show_one_part (OstreeRepo *self,
g_print ("PartMeta%u: nobjects=%u size=%" G_GUINT64_FORMAT " usize=%" G_GUINT64_FORMAT "\n", g_print ("PartMeta%u: nobjects=%u size=%" G_GUINT64_FORMAT " usize=%" G_GUINT64_FORMAT "\n",
i, (guint)(g_variant_get_size (objects) / OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN), size, usize); i, (guint)(g_variant_get_size (objects) / OSTREE_STATIC_DELTA_OBJTYPE_CSUM_LEN), size, usize);
glnx_fd_close gint part_fd = openat (self->repo_dir_fd, part_path, O_RDONLY | O_CLOEXEC); glnx_autofd int part_fd = openat (self->repo_dir_fd, part_path, O_RDONLY | O_CLOEXEC);
if (part_fd < 0) if (part_fd < 0)
return glnx_throw_errno_prefix (error, "openat(%s)", part_path); return glnx_throw_errno_prefix (error, "openat(%s)", part_path);
g_autoptr(GInputStream) part_in = g_unix_input_stream_new (part_fd, FALSE); g_autoptr(GInputStream) part_in = g_unix_input_stream_new (part_fd, FALSE);
@ -767,7 +767,7 @@ _ostree_repo_static_delta_dump (OstreeRepo *self,
superblock_path = _ostree_get_relative_static_delta_superblock_path (from, to); superblock_path = _ostree_get_relative_static_delta_superblock_path (from, to);
glnx_fd_close int superblock_fd = -1; glnx_autofd int superblock_fd = -1;
if (!glnx_openat_rdonly (self->repo_dir_fd, superblock_path, TRUE, &superblock_fd, error)) if (!glnx_openat_rdonly (self->repo_dir_fd, superblock_path, TRUE, &superblock_fd, error))
return FALSE; return FALSE;
if (!ot_variant_read_fd (superblock_fd, 0, if (!ot_variant_read_fd (superblock_fd, 0,

View File

@ -762,11 +762,7 @@ dispatch_set_read_source (OstreeRepo *repo,
GLNX_AUTO_PREFIX_ERROR("opcode set-read-source", error); GLNX_AUTO_PREFIX_ERROR("opcode set-read-source", error);
guint64 source_offset; guint64 source_offset;
if (state->read_source_fd != -1) glnx_close_fd (&state->read_source_fd);
{
(void) close (state->read_source_fd);
state->read_source_fd = -1;
}
if (!read_varuint64 (state, &source_offset, error)) if (!read_varuint64 (state, &source_offset, error))
return FALSE; return FALSE;
@ -799,12 +795,7 @@ dispatch_unset_read_source (OstreeRepo *repo,
if (state->stats_only) if (state->stats_only)
return TRUE; /* Early return */ return TRUE; /* Early return */
if (state->read_source_fd != -1) glnx_close_fd (&state->read_source_fd);
{
(void) close (state->read_source_fd);
state->read_source_fd = -1;
}
g_clear_pointer (&state->read_source_object, g_free); g_clear_pointer (&state->read_source_object, g_free);
return TRUE; return TRUE;

View File

@ -488,18 +488,13 @@ ostree_repo_finalize (GObject *object)
g_free (self->stagedir_prefix); g_free (self->stagedir_prefix);
g_clear_object (&self->repodir_fdrel); g_clear_object (&self->repodir_fdrel);
g_clear_object (&self->repodir); g_clear_object (&self->repodir);
if (self->repo_dir_fd != -1) glnx_close_fd (&self->repo_dir_fd);
(void) close (self->repo_dir_fd);
glnx_tmpdir_unset (&self->commit_stagedir); glnx_tmpdir_unset (&self->commit_stagedir);
glnx_release_lock_file (&self->commit_stagedir_lock); glnx_release_lock_file (&self->commit_stagedir_lock);
if (self->tmp_dir_fd != -1) glnx_close_fd (&self->tmp_dir_fd);
(void) close (self->tmp_dir_fd); glnx_close_fd (&self->cache_dir_fd);
if (self->cache_dir_fd != -1) glnx_close_fd (&self->objects_dir_fd);
(void) close (self->cache_dir_fd); glnx_close_fd (&self->uncompressed_objects_dir_fd);
if (self->objects_dir_fd != -1)
(void) close (self->objects_dir_fd);
if (self->uncompressed_objects_dir_fd != -1)
(void) close (self->uncompressed_objects_dir_fd);
g_clear_object (&self->sysroot_dir); g_clear_object (&self->sysroot_dir);
g_weak_ref_clear (&self->sysroot); g_weak_ref_clear (&self->sysroot);
g_free (self->remotes_config_dir); g_free (self->remotes_config_dir);
@ -734,7 +729,7 @@ ostree_repo_open_at (int dfd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int repo_dfd = -1; glnx_autofd int repo_dfd = -1;
if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error)) if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error))
return NULL; return NULL;
@ -1463,7 +1458,7 @@ ostree_repo_remote_gpg_import (OstreeRepo *self,
gpgme_import_status_t import_status; gpgme_import_status_t import_status;
g_autofree char *source_tmp_dir = NULL; g_autofree char *source_tmp_dir = NULL;
g_autofree char *target_tmp_dir = NULL; g_autofree char *target_tmp_dir = NULL;
glnx_fd_close int target_temp_fd = -1; glnx_autofd int target_temp_fd = -1;
g_autoptr(GPtrArray) keys = NULL; g_autoptr(GPtrArray) keys = NULL;
struct stat stbuf; struct stat stbuf;
gpgme_error_t gpg_error; gpgme_error_t gpg_error;
@ -1596,7 +1591,7 @@ ostree_repo_remote_gpg_import (OstreeRepo *self,
} }
else if (errno == ENOENT) else if (errno == ENOENT)
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
/* Create an empty pubring.gpg file prior to importing keys. This /* Create an empty pubring.gpg file prior to importing keys. This
* prevents gpg2 from creating a pubring.kbx file in the new keybox * prevents gpg2 from creating a pubring.kbx file in the new keybox
@ -1815,7 +1810,7 @@ repo_create_at_internal (int dfd,
return FALSE; return FALSE;
if (errno == 0) if (errno == 0)
{ {
glnx_fd_close int repo_dfd = -1; glnx_autofd int repo_dfd = -1;
if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error)) if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error))
return FALSE; return FALSE;
@ -1831,7 +1826,7 @@ repo_create_at_internal (int dfd,
return glnx_throw_errno_prefix (error, "mkdirat"); return glnx_throw_errno_prefix (error, "mkdirat");
} }
glnx_fd_close int repo_dfd = -1; glnx_autofd int repo_dfd = -1;
if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error)) if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error))
return FALSE; return FALSE;
@ -1922,7 +1917,7 @@ ostree_repo_create (OstreeRepo *self,
g_variant_builder_add (builder, "{s@v}", "collection-id", g_variant_builder_add (builder, "{s@v}", "collection-id",
g_variant_new_variant (g_variant_new_string (self->collection_id))); g_variant_new_variant (g_variant_new_string (self->collection_id)));
glnx_fd_close int repo_dir_fd = -1; glnx_autofd int repo_dir_fd = -1;
if (!repo_create_at_internal (AT_FDCWD, repopath, mode, if (!repo_create_at_internal (AT_FDCWD, repopath, mode,
g_variant_builder_end (builder), g_variant_builder_end (builder),
&repo_dir_fd, &repo_dir_fd,
@ -1966,7 +1961,7 @@ ostree_repo_create_at (int dfd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int repo_dfd = -1; glnx_autofd int repo_dfd = -1;
if (!repo_create_at_internal (dfd, path, mode, options, &repo_dfd, if (!repo_create_at_internal (dfd, path, mode, options, &repo_dfd,
cancellable, error)) cancellable, error))
return NULL; return NULL;
@ -2531,14 +2526,12 @@ ostree_repo_set_cache_dir (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
int fd; glnx_autofd int fd = -1;
if (!glnx_opendirat (dfd, path, TRUE, &fd, error)) if (!glnx_opendirat (dfd, path, TRUE, &fd, error))
return FALSE; return FALSE;
if (self->cache_dir_fd != -1) glnx_close_fd (&self->cache_dir_fd);
close (self->cache_dir_fd); self->cache_dir_fd = glnx_steal_fd (&fd);
self->cache_dir_fd = fd;
return TRUE; return TRUE;
} }
@ -2814,7 +2807,7 @@ load_metadata_internal (OstreeRepo *self,
GError **error) GError **error)
{ {
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
g_autoptr(GInputStream) ret_stream = NULL; g_autoptr(GInputStream) ret_stream = NULL;
g_autoptr(GVariant) ret_variant = NULL; g_autoptr(GVariant) ret_variant = NULL;
@ -2932,7 +2925,7 @@ repo_load_file_archive (OstreeRepo *self,
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
_ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, self->mode); _ostree_loose_path (loose_path_buf, checksum, OSTREE_OBJECT_TYPE_FILE, self->mode);
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd, if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd,
error)) error))
return FALSE; return FALSE;
@ -2988,7 +2981,7 @@ _ostree_repo_load_file_bare (OstreeRepo *self,
} }
struct stat stbuf; struct stat stbuf;
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
g_autofree char *ret_symlink = NULL; g_autofree char *ret_symlink = NULL;
g_autoptr(GVariant) ret_xattrs = NULL; g_autoptr(GVariant) ret_xattrs = NULL;
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX]; char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
@ -3062,7 +3055,7 @@ _ostree_repo_load_file_bare (OstreeRepo *self,
ret_symlink = g_strndup (targetbuf, target_size); ret_symlink = g_strndup (targetbuf, target_size);
} }
/* In the symlink case, we don't want to return the bare-user fd */ /* In the symlink case, we don't want to return the bare-user fd */
(void) close (glnx_steal_fd (&fd)); glnx_close_fd (&fd);
} }
} }
else if (self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY) else if (self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY)
@ -3138,7 +3131,7 @@ ostree_repo_load_file (OstreeRepo *self,
cancellable, error); cancellable, error);
else else
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
struct stat stbuf; struct stat stbuf;
g_autofree char *symlink_target = NULL; g_autofree char *symlink_target = NULL;
g_autoptr(GVariant) ret_xattrs = NULL; g_autoptr(GVariant) ret_xattrs = NULL;
@ -4182,14 +4175,14 @@ ostree_repo_add_gpg_signature_summary (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!glnx_openat_rdonly (self->repo_dir_fd, "summary", TRUE, &fd, error)) if (!glnx_openat_rdonly (self->repo_dir_fd, "summary", TRUE, &fd, error))
return FALSE; return FALSE;
g_autoptr(GBytes) summary_data = ot_fd_readall_or_mmap (fd, 0, error); g_autoptr(GBytes) summary_data = ot_fd_readall_or_mmap (fd, 0, error);
if (!summary_data) if (!summary_data)
return FALSE; return FALSE;
/* Note that fd is reused below */ /* Note that fd is reused below */
(void) close (glnx_steal_fd (&fd)); glnx_close_fd (&fd);
g_autoptr(GVariant) existing_signatures = NULL; g_autoptr(GVariant) existing_signatures = NULL;
if (!ot_openat_ignore_enoent (self->repo_dir_fd, "summary.sig", &fd, error)) if (!ot_openat_ignore_enoent (self->repo_dir_fd, "summary.sig", &fd, error))
@ -4239,7 +4232,7 @@ find_keyring (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!ot_openat_ignore_enoent (self->repo_dir_fd, remote->keyring, &fd, error)) if (!ot_openat_ignore_enoent (self->repo_dir_fd, remote->keyring, &fd, error))
return FALSE; return FALSE;
@ -4748,7 +4741,7 @@ ostree_repo_regenerate_summary (OstreeRepo *self,
return FALSE; return FALSE;
g_autofree char *superblock = _ostree_get_relative_static_delta_superblock_path ((from && from[0]) ? from : NULL, to); g_autofree char *superblock = _ostree_get_relative_static_delta_superblock_path ((from && from[0]) ? from : NULL, to);
glnx_fd_close int superblock_file_fd = -1; glnx_autofd int superblock_file_fd = -1;
if (!glnx_openat_rdonly (self->repo_dir_fd, superblock, TRUE, &superblock_file_fd, error)) if (!glnx_openat_rdonly (self->repo_dir_fd, superblock, TRUE, &superblock_file_fd, error))
return FALSE; return FALSE;
@ -4965,7 +4958,7 @@ _ostree_repo_allocate_tmpdir (int tmpdir_dfd,
dent->d_type != DT_DIR) dent->d_type != DT_DIR)
continue; continue;
glnx_fd_close int target_dfd = -1; glnx_autofd int target_dfd = -1;
if (!glnx_opendirat (dfd_iter.fd, dent->d_name, FALSE, if (!glnx_opendirat (dfd_iter.fd, dent->d_name, FALSE,
&target_dfd, &local_error)) &target_dfd, &local_error))
{ {

View File

@ -203,7 +203,7 @@ get_policy_checksum (char **out_csum,
g_autofree char *best_policy = NULL; g_autofree char *best_policy = NULL;
int best_version = 0; int best_version = 0;
glnx_fd_close int bindir_dfd = -1; glnx_autofd int bindir_dfd = -1;
if (!glnx_opendirat (AT_FDCWD, bindir_path, TRUE, &bindir_dfd, error)) if (!glnx_opendirat (AT_FDCWD, bindir_path, TRUE, &bindir_dfd, error))
return FALSE; return FALSE;

View File

@ -282,7 +282,7 @@ cleanup_old_deployments (OstreeSysroot *self,
if (!g_hash_table_lookup (active_deployment_dirs, deployment_path)) if (!g_hash_table_lookup (active_deployment_dirs, deployment_path))
{ {
struct stat stbuf; struct stat stbuf;
glnx_fd_close int deployment_fd = -1; glnx_autofd int deployment_fd = -1;
if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE,
&deployment_fd, error)) &deployment_fd, error))

View File

@ -164,7 +164,7 @@ copy_dir_recurse (int src_parent_dfd,
GError **error) GError **error)
{ {
g_auto(GLnxDirFdIterator) src_dfd_iter = { 0, }; g_auto(GLnxDirFdIterator) src_dfd_iter = { 0, };
glnx_fd_close int dest_dfd = -1; glnx_autofd int dest_dfd = -1;
struct dirent *dent; struct dirent *dent;
if (!glnx_dirfd_iterator_init_at (src_parent_dfd, name, TRUE, &src_dfd_iter, error)) if (!glnx_dirfd_iterator_init_at (src_parent_dfd, name, TRUE, &src_dfd_iter, error))
@ -226,8 +226,8 @@ ensure_directory_from_template (int orig_etc_fd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int src_dfd = -1; glnx_autofd int src_dfd = -1;
glnx_fd_close int target_dfd = -1; glnx_autofd int target_dfd = -1;
g_assert (path != NULL); g_assert (path != NULL);
g_assert (*path != '/' && *path != '\0'); g_assert (*path != '/' && *path != '\0');
@ -297,7 +297,7 @@ copy_modified_config_file (int orig_etc_fd,
if (!glnx_fstatat (modified_etc_fd, path, &modified_stbuf, AT_SYMLINK_NOFOLLOW, error)) if (!glnx_fstatat (modified_etc_fd, path, &modified_stbuf, AT_SYMLINK_NOFOLLOW, error))
return glnx_prefix_error (error, "Reading modified config file"); return glnx_prefix_error (error, "Reading modified config file");
glnx_fd_close int dest_parent_dfd = -1; glnx_autofd int dest_parent_dfd = -1;
if (strchr (path, '/') != NULL) if (strchr (path, '/') != NULL)
{ {
g_autofree char *parent = g_path_get_dirname (path); g_autofree char *parent = g_path_get_dirname (path);
@ -393,7 +393,7 @@ merge_configuration_from (OstreeSysroot *sysroot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int owned_merge_deployment_dfd = -1; glnx_autofd int owned_merge_deployment_dfd = -1;
const OstreeSysrootDebugFlags flags = sysroot->debug_flags; const OstreeSysrootDebugFlags flags = sysroot->debug_flags;
g_assert (merge_deployment != NULL && new_deployment != NULL); g_assert (merge_deployment != NULL && new_deployment != NULL);
@ -443,13 +443,13 @@ merge_configuration_from (OstreeSysroot *sysroot,
_ostree_sysroot_emit_journal_msg (sysroot, msg); _ostree_sysroot_emit_journal_msg (sysroot, msg);
} }
glnx_fd_close int orig_etc_fd = -1; glnx_autofd int orig_etc_fd = -1;
if (!glnx_opendirat (merge_deployment_dfd, "usr/etc", TRUE, &orig_etc_fd, error)) if (!glnx_opendirat (merge_deployment_dfd, "usr/etc", TRUE, &orig_etc_fd, error))
return FALSE; return FALSE;
glnx_fd_close int modified_etc_fd = -1; glnx_autofd int modified_etc_fd = -1;
if (!glnx_opendirat (merge_deployment_dfd, "etc", TRUE, &modified_etc_fd, error)) if (!glnx_opendirat (merge_deployment_dfd, "etc", TRUE, &modified_etc_fd, error))
return FALSE; return FALSE;
glnx_fd_close int new_etc_fd = -1; glnx_autofd int new_etc_fd = -1;
if (!glnx_opendirat (new_deployment_dfd, "etc", TRUE, &new_etc_fd, error)) if (!glnx_opendirat (new_deployment_dfd, "etc", TRUE, &new_etc_fd, error))
return FALSE; return FALSE;
@ -508,7 +508,7 @@ checkout_deployment_tree (OstreeSysroot *sysroot,
const char *csum = ostree_deployment_get_csum (deployment); const char *csum = ostree_deployment_get_csum (deployment);
g_autofree char *checkout_target_name = NULL; g_autofree char *checkout_target_name = NULL;
g_autofree char *osdeploy_path = NULL; g_autofree char *osdeploy_path = NULL;
glnx_fd_close int osdeploy_dfd = -1; glnx_autofd int osdeploy_dfd = -1;
int ret_fd; int ret_fd;
osdeploy_path = g_strconcat ("ostree/deploy/", ostree_deployment_get_osname (deployment), "/deploy", NULL); osdeploy_path = g_strconcat ("ostree/deploy/", ostree_deployment_get_osname (deployment), "/deploy", NULL);
@ -899,8 +899,7 @@ typedef struct {
static void static void
_ostree_kernel_layout_free (OstreeKernelLayout *layout) _ostree_kernel_layout_free (OstreeKernelLayout *layout)
{ {
if (layout->boot_dfd != -1) glnx_close_fd (&layout->boot_dfd);
(void) close (layout->boot_dfd);
g_free (layout->kernel_srcpath); g_free (layout->kernel_srcpath);
g_free (layout->kernel_namever); g_free (layout->kernel_namever);
g_free (layout->initramfs_srcpath); g_free (layout->initramfs_srcpath);
@ -991,7 +990,7 @@ get_kernel_from_tree_usrlib_modules (int deployment_dfd,
/* We found a module directory, compute the checksum */ /* We found a module directory, compute the checksum */
g_auto(OtChecksum) checksum = { 0, }; g_auto(OtChecksum) checksum = { 0, };
ot_checksum_init (&checksum); ot_checksum_init (&checksum);
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
/* Checksum the kernel */ /* Checksum the kernel */
if (!glnx_openat_rdonly (ret_layout->boot_dfd, "vmlinuz", TRUE, &fd, error)) if (!glnx_openat_rdonly (ret_layout->boot_dfd, "vmlinuz", TRUE, &fd, error))
return FALSE; return FALSE;
@ -999,7 +998,7 @@ get_kernel_from_tree_usrlib_modules (int deployment_dfd,
if (!ot_gio_splice_update_checksum (NULL, in, &checksum, cancellable, error)) if (!ot_gio_splice_update_checksum (NULL, in, &checksum, cancellable, error))
return FALSE; return FALSE;
g_clear_object (&in); g_clear_object (&in);
(void) close (fd); fd = -1; glnx_close_fd (&fd);
/* Look for an initramfs, but it's optional; since there wasn't any precedent /* Look for an initramfs, but it's optional; since there wasn't any precedent
* for this, let's be a bit conservative and support both `initramfs.img` and * for this, let's be a bit conservative and support both `initramfs.img` and
@ -1238,8 +1237,8 @@ fsfreeze_thaw_cycle (OstreeSysroot *self,
int sockpair[2]; int sockpair[2];
if (socketpair (AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sockpair) < 0) if (socketpair (AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sockpair) < 0)
return glnx_throw_errno_prefix (error, "socketpair"); return glnx_throw_errno_prefix (error, "socketpair");
glnx_fd_close int sock_parent = sockpair[0]; glnx_autofd int sock_parent = sockpair[0];
glnx_fd_close int sock_watchdog = sockpair[1]; glnx_autofd int sock_watchdog = sockpair[1];
pid_t pid = fork (); pid_t pid = fork ();
if (pid < 0) if (pid < 0)
@ -1249,7 +1248,7 @@ fsfreeze_thaw_cycle (OstreeSysroot *self,
char c = '!'; char c = '!';
if (pid == 0) /* Child watchdog/unfreezer process. */ if (pid == 0) /* Child watchdog/unfreezer process. */
{ {
(void) close (glnx_steal_fd (&sock_parent)); glnx_close_fd (&sock_parent);
/* Daemonize, and mask SIGINT/SIGTERM, so we're likely to survive e.g. /* Daemonize, and mask SIGINT/SIGTERM, so we're likely to survive e.g.
* someone doing a `systemctl restart rpm-ostreed` or a Ctrl-C of * someone doing a `systemctl restart rpm-ostreed` or a Ctrl-C of
* `ostree admin upgrade`. We don't daemonize though if testing so * `ostree admin upgrade`. We don't daemonize though if testing so
@ -1306,7 +1305,7 @@ fsfreeze_thaw_cycle (OstreeSysroot *self,
} }
else /* Parent process. */ else /* Parent process. */
{ {
(void) close (glnx_steal_fd (&sock_watchdog)); glnx_close_fd (&sock_watchdog);
/* Wait for the watchdog to say it's set up; mainly that it's /* Wait for the watchdog to say it's set up; mainly that it's
* masked SIGTERM successfully. * masked SIGTERM successfully.
*/ */
@ -1390,7 +1389,7 @@ full_system_sync (OstreeSysroot *self,
out_stats->root_syncfs_msec = (end_msec - start_msec); out_stats->root_syncfs_msec = (end_msec - start_msec);
start_msec = g_get_monotonic_time () / 1000; start_msec = g_get_monotonic_time () / 1000;
glnx_fd_close int boot_dfd = -1; glnx_autofd int boot_dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, "boot", TRUE, &boot_dfd, error)) if (!glnx_opendirat (self->sysroot_fd, "boot", TRUE, &boot_dfd, error))
return FALSE; return FALSE;
if (!fsfreeze_thaw_cycle (self, boot_dfd, cancellable, error)) if (!fsfreeze_thaw_cycle (self, boot_dfd, cancellable, error))
@ -1425,7 +1424,7 @@ create_new_bootlinks (OstreeSysroot *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int ostree_dfd = -1; glnx_autofd int ostree_dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, "ostree", TRUE, &ostree_dfd, error)) if (!glnx_opendirat (self->sysroot_fd, "ostree", TRUE, &ostree_dfd, error))
return FALSE; return FALSE;
@ -1450,7 +1449,7 @@ create_new_bootlinks (OstreeSysroot *self,
if (!glnx_shutil_mkdir_p_at (ostree_dfd, ostree_subbootdir_name, 0755, cancellable, error)) if (!glnx_shutil_mkdir_p_at (ostree_dfd, ostree_subbootdir_name, 0755, cancellable, error))
return FALSE; return FALSE;
glnx_fd_close int ostree_subbootdir_dfd = -1; glnx_autofd int ostree_subbootdir_dfd = -1;
if (!glnx_opendirat (ostree_dfd, ostree_subbootdir_name, FALSE, &ostree_subbootdir_dfd, error)) if (!glnx_opendirat (ostree_dfd, ostree_subbootdir_name, FALSE, &ostree_subbootdir_dfd, error))
return FALSE; return FALSE;
@ -1487,7 +1486,7 @@ swap_bootlinks (OstreeSysroot *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int ostree_dfd = -1; glnx_autofd int ostree_dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, "ostree", TRUE, &ostree_dfd, error)) if (!glnx_opendirat (self->sysroot_fd, "ostree", TRUE, &ostree_dfd, error))
return FALSE; return FALSE;
@ -1558,7 +1557,7 @@ install_deployment_kernel (OstreeSysroot *sysroot,
{ {
OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (deployment); OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (deployment);
g_autofree char *deployment_dirpath = ostree_sysroot_get_deployment_dirpath (sysroot, deployment); g_autofree char *deployment_dirpath = ostree_sysroot_get_deployment_dirpath (sysroot, deployment);
glnx_fd_close int deployment_dfd = -1; glnx_autofd int deployment_dfd = -1;
if (!glnx_opendirat (sysroot->sysroot_fd, deployment_dirpath, FALSE, if (!glnx_opendirat (sysroot->sysroot_fd, deployment_dirpath, FALSE,
&deployment_dfd, error)) &deployment_dfd, error))
return FALSE; return FALSE;
@ -1569,7 +1568,7 @@ install_deployment_kernel (OstreeSysroot *sysroot,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
glnx_fd_close int boot_dfd = -1; glnx_autofd int boot_dfd = -1;
if (!glnx_opendirat (sysroot->sysroot_fd, "boot", TRUE, &boot_dfd, error)) if (!glnx_opendirat (sysroot->sysroot_fd, "boot", TRUE, &boot_dfd, error))
return FALSE; return FALSE;
@ -1583,7 +1582,7 @@ install_deployment_kernel (OstreeSysroot *sysroot,
if (!glnx_shutil_mkdir_p_at (boot_dfd, bootcsumdir, 0775, cancellable, error)) if (!glnx_shutil_mkdir_p_at (boot_dfd, bootcsumdir, 0775, cancellable, error))
return FALSE; return FALSE;
glnx_fd_close int bootcsum_dfd = -1; glnx_autofd int bootcsum_dfd = -1;
if (!glnx_opendirat (boot_dfd, bootcsumdir, TRUE, &bootcsum_dfd, error)) if (!glnx_opendirat (boot_dfd, bootcsumdir, TRUE, &bootcsum_dfd, error))
return FALSE; return FALSE;
@ -1714,7 +1713,7 @@ install_deployment_kernel (OstreeSysroot *sysroot,
g_autofree char *options_key = _ostree_kernel_args_to_string (kargs); g_autofree char *options_key = _ostree_kernel_args_to_string (kargs);
ostree_bootconfig_parser_set (bootconfig, "options", options_key); ostree_bootconfig_parser_set (bootconfig, "options", options_key);
glnx_fd_close int bootconf_dfd = -1; glnx_autofd int bootconf_dfd = -1;
if (!glnx_opendirat (boot_dfd, bootconfdir, TRUE, &bootconf_dfd, error)) if (!glnx_opendirat (boot_dfd, bootconfdir, TRUE, &bootconf_dfd, error))
return FALSE; return FALSE;
@ -1759,7 +1758,7 @@ swap_bootloader (OstreeSysroot *sysroot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int boot_dfd = -1; glnx_autofd int boot_dfd = -1;
g_assert ((current_bootversion == 0 && new_bootversion == 1) || g_assert ((current_bootversion == 0 && new_bootversion == 1) ||
(current_bootversion == 1 && new_bootversion == 0)); (current_bootversion == 1 && new_bootversion == 0));
@ -2254,7 +2253,7 @@ allocate_deployserial (OstreeSysroot *self,
g_autoptr(GPtrArray) tmp_current_deployments = g_autoptr(GPtrArray) tmp_current_deployments =
g_ptr_array_new_with_free_func (g_object_unref); g_ptr_array_new_with_free_func (g_object_unref);
glnx_fd_close int deploy_dfd = -1; glnx_autofd int deploy_dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, "ostree/deploy", TRUE, &deploy_dfd, error)) if (!glnx_opendirat (self->sysroot_fd, "ostree/deploy", TRUE, &deploy_dfd, error))
return FALSE; return FALSE;
@ -2309,7 +2308,7 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self,
osname = ostree_deployment_get_osname (self->booted_deployment); osname = ostree_deployment_get_osname (self->booted_deployment);
const char *osdeploypath = glnx_strjoina ("ostree/deploy/", osname); const char *osdeploypath = glnx_strjoina ("ostree/deploy/", osname);
glnx_fd_close int os_deploy_dfd = -1; glnx_autofd int os_deploy_dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, osdeploypath, TRUE, &os_deploy_dfd, error)) if (!glnx_opendirat (self->sysroot_fd, osdeploypath, TRUE, &os_deploy_dfd, error))
return FALSE; return FALSE;
@ -2330,7 +2329,7 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self,
ostree_deployment_set_origin (new_deployment, origin); ostree_deployment_set_origin (new_deployment, origin);
/* Check out the userspace tree onto the filesystem */ /* Check out the userspace tree onto the filesystem */
glnx_fd_close int deployment_dfd = -1; glnx_autofd int deployment_dfd = -1;
if (!checkout_deployment_tree (self, repo, new_deployment, &deployment_dfd, if (!checkout_deployment_tree (self, repo, new_deployment, &deployment_dfd,
cancellable, error)) cancellable, error))
{ {
@ -2476,7 +2475,7 @@ ostree_sysroot_deployment_set_mutable (OstreeSysroot *self,
return FALSE; return FALSE;
g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment); g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment);
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &fd, error)) if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &fd, error))
return FALSE; return FALSE;

View File

@ -296,11 +296,7 @@ _ostree_sysroot_bump_mtime (OstreeSysroot *self,
void void
ostree_sysroot_unload (OstreeSysroot *self) ostree_sysroot_unload (OstreeSysroot *self)
{ {
if (self->sysroot_fd != -1) glnx_close_fd (&self->sysroot_fd);
{
(void) close (self->sysroot_fd);
self->sysroot_fd = -1;
}
} }
/** /**
@ -638,7 +634,7 @@ parse_deployment (OstreeSysroot *self,
&treecsum, &deployserial, error)) &treecsum, &deployserial, error))
return FALSE; return FALSE;
glnx_fd_close int deployment_dfd = -1; glnx_autofd int deployment_dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, relative_boot_link, TRUE, if (!glnx_opendirat (self->sysroot_fd, relative_boot_link, TRUE,
&deployment_dfd, error)) &deployment_dfd, error))
return FALSE; return FALSE;
@ -1438,7 +1434,7 @@ ostree_sysroot_init_osname (OstreeSysroot *self,
if (mkdirat (self->sysroot_fd, deploydir, 0777) < 0) if (mkdirat (self->sysroot_fd, deploydir, 0777) < 0)
return glnx_throw_errno_prefix (error, "Creating %s", deploydir); return glnx_throw_errno_prefix (error, "Creating %s", deploydir);
glnx_fd_close int dfd = -1; glnx_autofd int dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, deploydir, TRUE, &dfd, error)) if (!glnx_opendirat (self->sysroot_fd, deploydir, TRUE, &dfd, error))
return FALSE; return FALSE;
@ -1694,7 +1690,7 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
return FALSE; return FALSE;
g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment); g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment);
glnx_fd_close int deployment_dfd = -1; glnx_autofd int deployment_dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &deployment_dfd, error)) if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &deployment_dfd, error))
return FALSE; return FALSE;

View File

@ -79,7 +79,7 @@ ot_openat_read_stream (int dfd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!glnx_openat_rdonly (dfd, path, follow, &fd, error)) if (!glnx_openat_rdonly (dfd, path, follow, &fd, error))
return FALSE; return FALSE;
*out_istream = g_unix_input_stream_new (glnx_steal_fd (&fd), TRUE); *out_istream = g_unix_input_stream_new (glnx_steal_fd (&fd), TRUE);
@ -127,7 +127,7 @@ ot_dfd_iter_init_allow_noent (int dfd,
gboolean *out_exists, gboolean *out_exists,
GError **error) GError **error)
{ {
glnx_fd_close int fd = glnx_opendirat_with_errno (dfd, path, TRUE); glnx_autofd int fd = glnx_opendirat_with_errno (dfd, path, TRUE);
if (fd < 0) if (fd < 0)
{ {
if (errno != ENOENT) if (errno != ENOENT)

View File

@ -353,7 +353,7 @@ do_get (OtTrivialHttpd *self,
if (msg->method == SOUP_METHOD_GET) if (msg->method == SOUP_METHOD_GET)
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
g_autoptr(GMappedFile) mapping = NULL; g_autoptr(GMappedFile) mapping = NULL;
gsize buffer_length, file_size; gsize buffer_length, file_size;
SoupRange *ranges; SoupRange *ranges;

View File

@ -57,7 +57,7 @@ ot_admin_builtin_init_fs (int argc, char **argv, GCancellable *cancellable, GErr
const char *sysroot_path = argv[1]; const char *sysroot_path = argv[1];
glnx_fd_close int root_dfd = -1; glnx_autofd int root_dfd = -1;
if (!glnx_opendirat (AT_FDCWD, sysroot_path, TRUE, &root_dfd, error)) if (!glnx_opendirat (AT_FDCWD, sysroot_path, TRUE, &root_dfd, error))
return FALSE; return FALSE;

View File

@ -501,7 +501,7 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError
&filter_data, NULL); &filter_data, NULL);
if (opt_selinux_policy) if (opt_selinux_policy)
{ {
glnx_fd_close int rootfs_dfd = -1; glnx_autofd int rootfs_dfd = -1;
if (!glnx_opendirat (AT_FDCWD, opt_selinux_policy, TRUE, &rootfs_dfd, error)) if (!glnx_opendirat (AT_FDCWD, opt_selinux_policy, TRUE, &rootfs_dfd, error))
{ {
g_prefix_error (error, "selinux-policy: "); g_prefix_error (error, "selinux-policy: ");

View File

@ -80,7 +80,7 @@ ostree_builtin_create_usb (int argc,
const char *mount_root_path = argv[1]; const char *mount_root_path = argv[1];
struct stat mount_root_stbuf; struct stat mount_root_stbuf;
glnx_fd_close int mount_root_dfd = -1; glnx_autofd int mount_root_dfd = -1;
if (!glnx_opendirat (AT_FDCWD, mount_root_path, TRUE, &mount_root_dfd, error)) if (!glnx_opendirat (AT_FDCWD, mount_root_path, TRUE, &mount_root_dfd, error))
return FALSE; return FALSE;
if (!glnx_fstat (mount_root_dfd, &mount_root_stbuf, error)) if (!glnx_fstat (mount_root_dfd, &mount_root_stbuf, error))

View File

@ -58,7 +58,7 @@ do_print_variant_generic (const GVariantType *type,
{ {
g_autoptr(GVariant) variant = NULL; g_autoptr(GVariant) variant = NULL;
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!glnx_openat_rdonly (AT_FDCWD, filename, TRUE, &fd, error)) if (!glnx_openat_rdonly (AT_FDCWD, filename, TRUE, &fd, error))
return FALSE; return FALSE;
if (!ot_variant_read_fd (fd, 0, type, FALSE, &variant, error)) if (!ot_variant_read_fd (fd, 0, type, FALSE, &variant, error))

View File

@ -217,7 +217,7 @@ ostree_builtin_summary (int argc, char **argv, GCancellable *cancellable, GError
if (opt_raw) if (opt_raw)
flags |= OSTREE_DUMP_RAW; flags |= OSTREE_DUMP_RAW;
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
if (!glnx_openat_rdonly (repo->repo_dir_fd, "summary", TRUE, &fd, error)) if (!glnx_openat_rdonly (repo->repo_dir_fd, "summary", TRUE, &fd, error))
return FALSE; return FALSE;
summary_data = ot_fd_readall_or_mmap (fd, 0, error); summary_data = ot_fd_readall_or_mmap (fd, 0, error);

View File

@ -79,7 +79,7 @@ ot_parse_cookies_at (int dfd, const char *path,
{ {
OtCookieParser *parser; OtCookieParser *parser;
g_autofree char *cookies_content = NULL; g_autofree char *cookies_content = NULL;
glnx_fd_close int infd = -1; glnx_autofd int infd = -1;
infd = openat (dfd, path, O_RDONLY | O_CLOEXEC); infd = openat (dfd, path, O_RDONLY | O_CLOEXEC);
if (infd < 0) if (infd < 0)
@ -143,7 +143,7 @@ ot_add_cookie_at (int dfd, const char *jar_path,
const char *name, const char *value, const char *name, const char *value,
GError **error) GError **error)
{ {
glnx_fd_close int fd = openat (dfd, jar_path, O_WRONLY | O_APPEND | O_CREAT, 0644); glnx_autofd int fd = openat (dfd, jar_path, O_WRONLY | O_APPEND | O_CREAT, 0644);
if (fd < 0) if (fd < 0)
return glnx_throw_errno_prefix (error, "open(%s)", jar_path); return glnx_throw_errno_prefix (error, "open(%s)", jar_path);

View File

@ -268,7 +268,7 @@ callback_chown (const char *path, uid_t uid, gid_t gid)
static int static int
callback_truncate (const char *path, off_t size) callback_truncate (const char *path, off_t size)
{ {
glnx_fd_close int fd = -1; glnx_autofd int fd = -1;
path = ENSURE_RELPATH (path); path = ENSURE_RELPATH (path);
VERIFY_WRITE(path); VERIFY_WRITE(path);

View File

@ -154,7 +154,7 @@ assert_create_repos_dir (Fixture *fixture,
int *out_repos_dfd, int *out_repos_dfd,
GMount **out_mount) GMount **out_mount)
{ {
glnx_fd_close int repos_dfd = -1; glnx_autofd int repos_dfd = -1;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autofree gchar *path = g_build_filename (mount_root_name, ".ostree", "repos.d", NULL); g_autofree gchar *path = g_build_filename (mount_root_name, ".ostree", "repos.d", NULL);
@ -242,7 +242,7 @@ assert_create_repo_dir (Fixture *fixture,
gchar **out_uri, gchar **out_uri,
...) ...)
{ {
glnx_fd_close int ref_dfd = -1; glnx_autofd int ref_dfd = -1;
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
va_list args; va_list args;
@ -318,9 +318,9 @@ test_repo_finder_mount_mixed_mounts (Fixture *fixture,
g_autoptr(GMount) repo1_mount = NULL; g_autoptr(GMount) repo1_mount = NULL;
g_autoptr(GMount) repo2_mount = NULL; g_autoptr(GMount) repo2_mount = NULL;
g_autoptr(GFile) non_removable_root = NULL; g_autoptr(GFile) non_removable_root = NULL;
glnx_fd_close int no_repos_repos = -1; glnx_autofd int no_repos_repos = -1;
glnx_fd_close int repo1_repos = -1; glnx_autofd int repo1_repos = -1;
glnx_fd_close int repo2_repos = -1; glnx_autofd int repo2_repos = -1;
g_autoptr(OstreeRepo) repo1_repo_a = NULL, repo1_repo_b = NULL; g_autoptr(OstreeRepo) repo1_repo_a = NULL, repo1_repo_b = NULL;
g_autoptr(OstreeRepo) repo2_repo_a = NULL; g_autoptr(OstreeRepo) repo2_repo_a = NULL;
g_autofree gchar *repo1_repo_a_uri = NULL, *repo1_repo_b_uri = NULL; g_autofree gchar *repo1_repo_a_uri = NULL, *repo1_repo_b_uri = NULL;
@ -464,7 +464,7 @@ test_repo_finder_mount_well_known (Fixture *fixture,
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autoptr(GList) mounts = NULL; /* (element-type OstreeMockMount) */ g_autoptr(GList) mounts = NULL; /* (element-type OstreeMockMount) */
g_autoptr(GMount) mount = NULL; g_autoptr(GMount) mount = NULL;
glnx_fd_close int repos = -1; glnx_autofd int repos = -1;
g_autoptr(OstreeRepo) repo_a = NULL, repo_b = NULL; g_autoptr(OstreeRepo) repo_a = NULL, repo_b = NULL;
g_autofree gchar *repo_a_uri = NULL, *repo_b_uri = NULL; g_autofree gchar *repo_a_uri = NULL, *repo_b_uri = NULL;
g_autofree gchar *ref_a_checksum = NULL, *ref_b_checksum = NULL; g_autofree gchar *ref_a_checksum = NULL, *ref_b_checksum = NULL;