Skip to content

Commit

Permalink
Update libglnx, do some porting to new APIs
Browse files Browse the repository at this point in the history
In particular I wanted to start using `GLNX_AUTO_PREFIX_ERROR`.

Update submodule: libglnx

Closes: #893
Approved by: jlebon
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Jul 21, 2017
1 parent 2082b3f commit 5763027
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 46 deletions.
2 changes: 1 addition & 1 deletion libglnx
Submodule libglnx updated from 607f17 to 7d6a31
9 changes: 2 additions & 7 deletions src/app/rpmostree-builtin-start-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/app/rpmostree-dbus-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 5 additions & 8 deletions src/libpriv/rpmostree-bwrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/libpriv/rpmostree-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/libpriv/rpmostree-passwd-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions src/libpriv/rpmostree-postprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/libpriv/rpmostree-unpacker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions src/libpriv/rpmostree-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5763027

Please sign in to comment.