From fcffefee267f9a76c41182895a2097774cd94b65 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 22 Aug 2016 14:12:31 +0200 Subject: [PATCH] Replace openat() calls from libgsystem --- app/flatpak-builtins-build-finish.c | 5 ++-- common/flatpak-dir.c | 7 ++--- common/flatpak-utils.c | 45 +++++++++++++++++++++++++---- common/flatpak-utils.h | 6 ++++ 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/app/flatpak-builtins-build-finish.c b/app/flatpak-builtins-build-finish.c index e740293f..d2897eae 100644 --- a/app/flatpak-builtins-build-finish.c +++ b/app/flatpak-builtins-build-finish.c @@ -75,9 +75,8 @@ export_dir (int source_parent_fd, } } - if (!gs_file_open_dir_fd_at (destination_parent_fd, destination_name, - &destination_dfd, - cancellable, error)) + if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE, + &destination_dfd, error)) return FALSE; while (TRUE) diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 69909873..d245f07c 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -2153,7 +2153,7 @@ export_desktop_file (const char *app, g_autofree char *escaped_arch = maybe_quote (arch); int i; - if (!gs_file_openat_noatime (parent_fd, name, &desktop_fd, cancellable, error)) + if (!flatpak_openat_noatime (parent_fd, name, &desktop_fd, cancellable, error)) goto out; if (!read_fd (desktop_fd, stat_buf, &data, &data_len, error)) @@ -2418,9 +2418,8 @@ export_dir (int source_parent_fd, } } - if (!gs_file_open_dir_fd_at (destination_parent_fd, destination_name, - &destination_dfd, - cancellable, error)) + if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE, + &destination_dfd, error)) goto out; while (TRUE) diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index b8b87327..3e00220d 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -754,9 +754,8 @@ overlay_symlink_tree_dir (int source_parent_fd, } } - if (!gs_file_open_dir_fd_at (destination_parent_fd, destination_name, - &destination_dfd, - cancellable, error)) + if (!glnx_opendirat (destination_parent_fd, destination_name, TRUE, + &destination_dfd, error)) goto out; while (TRUE) @@ -1422,6 +1421,41 @@ flatpak_file_get_path_cached (GFile *file) return path; } +gboolean +flatpak_openat_noatime (int dfd, + const char *name, + int *ret_fd, + GCancellable *cancellable, + GError **error) +{ + int fd; + int flags = O_RDONLY | O_CLOEXEC; + +#ifdef O_NOATIME + do + fd = openat (dfd, name, flags | O_NOATIME, 0); + while (G_UNLIKELY (fd == -1 && errno == EINTR)); + /* Only the owner or superuser may use O_NOATIME; so we may get + * EPERM. EINVAL may happen if the kernel is really old... + */ + if (fd == -1 && (errno == EPERM || errno == EINVAL)) +#endif + do + fd = openat (dfd, name, flags, 0); + while (G_UNLIKELY (fd == -1 && errno == EINTR)); + + if (fd == -1) + { + glnx_set_error_from_errno (error); + return FALSE; + } + else + { + *ret_fd = fd; + return TRUE; + } +} + gboolean flatpak_cp_a (GFile *src, GFile *dest, @@ -1462,11 +1496,10 @@ flatpak_cp_a (GFile *src, goto out; } - if (!gs_file_open_dir_fd (dest, &dest_dfd, - cancellable, error)) + if (!glnx_opendirat (AT_FDCWD, flatpak_file_get_path_cached (dest), TRUE, + &dest_dfd, error)) goto out; - if (!no_chown) { do diff --git a/common/flatpak-utils.h b/common/flatpak-utils.h index f552d707..0606962e 100644 --- a/common/flatpak-utils.h +++ b/common/flatpak-utils.h @@ -258,6 +258,12 @@ gboolean flatpak_spawnv (GFile *dir, const char *flatpak_file_get_path_cached (GFile *file); +gboolean flatpak_openat_noatime (int dfd, + const char *name, + int *ret_fd, + GCancellable *cancellable, + GError **error); + typedef enum { FLATPAK_CP_FLAGS_NONE = 0, FLATPAK_CP_FLAGS_MERGE = 1<<0,