From 5763027b5f50933dc0a27bc9f8756e227f501795 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 21 Jul 2017 16:25:56 -0400 Subject: [PATCH] Update libglnx, do some porting to new APIs In particular I wanted to start using `GLNX_AUTO_PREFIX_ERROR`. Update submodule: libglnx Closes: #893 Approved by: jlebon --- libglnx | 2 +- src/app/rpmostree-builtin-start-daemon.c | 9 ++------- src/app/rpmostree-dbus-helpers.c | 6 +++--- src/libpriv/rpmostree-bwrap.c | 13 +++++-------- src/libpriv/rpmostree-core.c | 12 ++++++------ src/libpriv/rpmostree-passwd-util.c | 14 +++++++------- src/libpriv/rpmostree-postprocess.c | 7 ++----- src/libpriv/rpmostree-unpacker.c | 6 +++--- src/libpriv/rpmostree-util.c | 8 ++------ 9 files changed, 31 insertions(+), 46 deletions(-) diff --git a/libglnx b/libglnx index 607f1775..7d6a31fb 160000 --- a/libglnx +++ b/libglnx @@ -1 +1 @@ -Subproject commit 607f1775bb1c626cae1875a957a34802daebe81c +Subproject commit 7d6a31fb9316ec85d462c26b84fb8fe9ca04ef2b diff --git a/src/app/rpmostree-builtin-start-daemon.c b/src/app/rpmostree-builtin-start-daemon.c index eded3672..c637385a 100644 --- a/src/app/rpmostree-builtin-start-daemon.c +++ b/src/app/rpmostree-builtin-start-daemon.c @@ -78,18 +78,13 @@ static gboolean start_daemon (GDBusConnection *connection, GError **error) { + GLNX_AUTO_PREFIX_ERROR ("Couldn't start daemon", error); rpm_ostree_daemon = g_initable_new (RPMOSTREED_TYPE_DAEMON, NULL, error, "connection", connection, "sysroot-path", opt_sysroot, NULL); - if (!rpm_ostree_daemon) - { - g_prefix_error (error, "Couldn't start daemon: "); - return FALSE; - } - - return TRUE; + return rpm_ostree_daemon != NULL; } static void diff --git a/src/app/rpmostree-dbus-helpers.c b/src/app/rpmostree-dbus-helpers.c index 8ac0d0e7..a4b82ce1 100644 --- a/src/app/rpmostree-dbus-helpers.c +++ b/src/app/rpmostree-dbus-helpers.c @@ -790,9 +790,9 @@ rpmostree_sort_pkgs_strv (const char *const* pkgs, g_ptr_array_add (repo_pkgs, g_strdup (*pkg)); else { - glnx_fd_close int fd = open (*pkg, O_RDONLY | O_CLOEXEC); - if (fd < 0) - return glnx_throw_errno_prefix (error, "can't open '%s'", *pkg); + glnx_fd_close int fd = -1; + if (!glnx_openat_rdonly (AT_FDCWD, *pkg, TRUE, &fd, error)) + return FALSE; int idx = g_unix_fd_list_append (fd_list, fd, error); if (idx < 0) diff --git a/src/libpriv/rpmostree-bwrap.c b/src/libpriv/rpmostree-bwrap.c index a9acdd7a..260196d8 100644 --- a/src/libpriv/rpmostree-bwrap.c +++ b/src/libpriv/rpmostree-bwrap.c @@ -326,18 +326,15 @@ rpmostree_bwrap_run (RpmOstreeBwrap *bwrap, /* Add the final NULL */ g_ptr_array_add (bwrap->argv, NULL); + const char *errmsg = glnx_strjoina ("Executing bwrap(", bwrap->child_argv0, ")"); + GLNX_AUTO_PREFIX_ERROR (errmsg, error); + if (!g_spawn_sync (NULL, (char**)bwrap->argv->pdata, (char**) bwrap_env, G_SPAWN_SEARCH_PATH, bwrap_child_setup, bwrap, NULL, NULL, &estatus, error)) - { - g_prefix_error (error, "Executing bwrap(%s): ", bwrap->child_argv0); - return FALSE; - } + return FALSE; if (!g_spawn_check_exit_status (estatus, error)) - { - g_prefix_error (error, "Executing bwrap(%s): ", bwrap->child_argv0); - return FALSE; - } + return FALSE; } return TRUE; diff --git a/src/libpriv/rpmostree-core.c b/src/libpriv/rpmostree-core.c index a872aefb..7d980c0f 100644 --- a/src/libpriv/rpmostree-core.c +++ b/src/libpriv/rpmostree-core.c @@ -1973,8 +1973,8 @@ break_single_hardlink_at (int dfd, { struct stat stbuf; - if (fstatat (dfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) != 0) - return glnx_throw_errno_prefix (error, "fstatat"); + if (!glnx_fstatat (dfd, path, &stbuf, AT_SYMLINK_NOFOLLOW, error)) + return FALSE; if (!S_ISLNK (stbuf.st_mode) && !S_ISREG (stbuf.st_mode)) return glnx_throw (error, "Unsupported type for entry '%s'", path); @@ -2011,8 +2011,8 @@ break_single_hardlink_at (int dfd, return FALSE; } - if (renameat (dfd, path_tmp, dfd, path) != 0) - return glnx_throw_errno_prefix (error, "rename(%s)", path); + if (!glnx_renameat (dfd, path_tmp, dfd, path, error)) + return FALSE; } return TRUE; @@ -2394,8 +2394,8 @@ get_package_metainfo (RpmOstreeContext *self, GError **error) { glnx_fd_close int metadata_fd = -1; - if ((metadata_fd = openat (self->tmpdir_fd, path, O_RDONLY | O_CLOEXEC)) < 0) - return glnx_throw_errno_prefix (error, "open(%s)", path); + if (!glnx_openat_rdonly (self->tmpdir_fd, path, TRUE, &metadata_fd, error)) + return FALSE; return rpmostree_unpacker_read_metainfo (metadata_fd, out_header, NULL, out_fi, error); diff --git a/src/libpriv/rpmostree-passwd-util.c b/src/libpriv/rpmostree-passwd-util.c index c24e285b..48deca8c 100644 --- a/src/libpriv/rpmostree-passwd-util.c +++ b/src/libpriv/rpmostree-passwd-util.c @@ -1095,9 +1095,9 @@ rpmostree_passwd_prepare_rpm_layering (int rootfs_dfd, const char *usrlibfiletmp = glnx_strjoina ("usr/lib/", file, ".tmp"); /* Retain the current copies in /etc as backups */ - if (renameat (rootfs_dfd, usretcfile, rootfs_dfd, - glnx_strjoina (usretcfile, ".rpmostreesave")) < 0) - return glnx_throw_errno_prefix (error, "renameat"); + if (!glnx_renameat (rootfs_dfd, usretcfile, rootfs_dfd, + glnx_strjoina (usretcfile, ".rpmostreesave"), error)) + return FALSE; /* Copy /usr/lib/{passwd,group} -> /usr/etc (breaking hardlinks) */ if (!glnx_file_copy_at (rootfs_dfd, usrlibfile, NULL, @@ -1111,8 +1111,8 @@ rpmostree_passwd_prepare_rpm_layering (int rootfs_dfd, GLNX_FILE_COPY_OVERWRITE, cancellable, error)) return FALSE; - if (renameat (rootfs_dfd, usrlibfiletmp, rootfs_dfd, usrlibfile) < 0) - return glnx_throw_errno_prefix (error, "renameat"); + if (!glnx_renameat (rootfs_dfd, usrlibfiletmp, rootfs_dfd, usrlibfile, error)) + return FALSE; } /* And break hardlinks for the shadow files, since we don't have @@ -1136,8 +1136,8 @@ rpmostree_passwd_prepare_rpm_layering (int rootfs_dfd, rootfs_dfd, tmp, GLNX_FILE_COPY_OVERWRITE, cancellable, error)) return FALSE; - if (renameat (rootfs_dfd, tmp, rootfs_dfd, src) < 0) - return glnx_throw_errno_prefix (error, "renameat"); + if (!glnx_renameat (rootfs_dfd, tmp, rootfs_dfd, src, error)) + return FALSE; } return TRUE; diff --git a/src/libpriv/rpmostree-postprocess.c b/src/libpriv/rpmostree-postprocess.c index c2a9f111..8f1beb9b 100644 --- a/src/libpriv/rpmostree-postprocess.c +++ b/src/libpriv/rpmostree-postprocess.c @@ -681,11 +681,8 @@ hardlink_recurse (int src_dfd, if (!dent) break; - if (fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW) < 0) - { - glnx_set_error_from_errno (error); - return FALSE; - } + if (!glnx_fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error)) + return FALSE; if (dent->d_type == DT_DIR) { diff --git a/src/libpriv/rpmostree-unpacker.c b/src/libpriv/rpmostree-unpacker.c index 5aee5166..888f7f10 100644 --- a/src/libpriv/rpmostree-unpacker.c +++ b/src/libpriv/rpmostree-unpacker.c @@ -336,9 +336,9 @@ rpmostree_unpacker_new_at (int dfd, const char *path, RpmOstreeUnpackerFlags flags, GError **error) { - glnx_fd_close int fd = openat (dfd, path, O_RDONLY | O_CLOEXEC | O_NOCTTY); - if (fd < 0) - return glnx_null_throw_errno_prefix (error, "openat(%s)", path); + glnx_fd_close int fd = -1; + if (!glnx_openat_rdonly (dfd, path, TRUE, &fd, error)) + return FALSE; RpmOstreeUnpacker *ret = rpmostree_unpacker_new_fd (fd, pkg, flags, error); if (ret == NULL) diff --git a/src/libpriv/rpmostree-util.c b/src/libpriv/rpmostree-util.c index 5baeb2bf..990554b1 100644 --- a/src/libpriv/rpmostree-util.c +++ b/src/libpriv/rpmostree-util.c @@ -159,12 +159,8 @@ _rpmostree_util_update_checksum_from_file (GChecksum *checksum, glnx_fd_close int fd = -1; g_autoptr(GMappedFile) mfile = NULL; - fd = openat (dfd, path, O_RDONLY | O_CLOEXEC); - if (fd < 0) - { - glnx_set_error_from_errno (error); - return FALSE; - } + if (!glnx_openat_rdonly (dfd, path, TRUE, &fd, error)) + return FALSE; mfile = g_mapped_file_new_from_fd (fd, FALSE, error); if (!mfile)