summaryrefslogtreecommitdiff
path: root/tests/libostreetest.c
diff options
context:
space:
mode:
authorJonathan Lebon <jlebon@redhat.com>2017-09-28 18:57:33 +0000
committerAtomic Bot <atomic-devel@projectatomic.io>2017-09-30 00:05:07 +0000
commita06bd82cd4dc14b3c2949a421870b6d3067aba34 (patch)
treedfc991209f020098c98611eeb027ac30bbb24694 /tests/libostreetest.c
parent8fe45362578a43260876134d6547ebd0bb2485c3 (diff)
downloadostree-a06bd82cd4dc14b3c2949a421870b6d3067aba34.tar.gz
tests: check for relabeling rather than overlay
Instead of checking for overlayfs, let's explicitly check for our ability to relabel files since we now have a `libtest` function to do this. Also port that logic to `libostreetest`. Note that overlayfs *does* allow manipulating user xattrs. So ideally, we should break down `OSTREE_NO_XATTRS` further to distinguish between tests that use bare repos from other modes. We check the current directory instead of `/` so that developers can just point `TEST_TMPDIR` to a non-overlayfs mount point when hacking from a container. Closes: #1170 Approved by: cgwalters
Diffstat (limited to 'tests/libostreetest.c')
-rw-r--r--tests/libostreetest.c91
1 files changed, 75 insertions, 16 deletions
diff --git a/tests/libostreetest.c b/tests/libostreetest.c
index 6186a73a..496ff740 100644
--- a/tests/libostreetest.c
+++ b/tests/libostreetest.c
@@ -72,6 +72,68 @@ ot_test_setup_repo (GCancellable *cancellable,
return g_steal_pointer (&ret_repo);
}
+/* Determine whether we're able to relabel files. Needed for bare tests. */
+gboolean
+ot_check_relabeling (gboolean *can_relabel,
+ GError **error)
+{
+ g_auto(GLnxTmpfile) tmpf = { 0, };
+ if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, ".", O_RDWR | O_CLOEXEC, &tmpf, error))
+ return FALSE;
+
+ g_autoptr(GError) local_error = NULL;
+ g_autoptr(GBytes) bytes = glnx_fgetxattr_bytes (tmpf.fd, "security.selinux", &local_error);
+ if (!bytes)
+ {
+ /* libglnx preserves errno */
+ if (G_IN_SET (errno, ENOTSUP, ENODATA))
+ {
+ *can_relabel = FALSE;
+ return TRUE;
+ }
+ g_propagate_error (error, g_steal_pointer (&local_error));
+ return FALSE;
+ }
+
+ gsize data_len;
+ const guint8 *data = g_bytes_get_data (bytes, &data_len);
+ if (fsetxattr (tmpf.fd, "security.selinux", data, data_len, 0) < 0)
+ {
+ if (errno == ENOTSUP)
+ {
+ *can_relabel = FALSE;
+ return TRUE;
+ }
+ return glnx_throw_errno_prefix (error, "fsetxattr");
+ }
+
+ *can_relabel = TRUE;
+ return TRUE;
+}
+
+/* Determine whether the filesystem supports getting/setting user xattrs. */
+gboolean
+ot_check_user_xattrs (gboolean *has_user_xattrs,
+ GError **error)
+{
+ g_auto(GLnxTmpfile) tmpf = { 0, };
+ if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, ".", O_RDWR | O_CLOEXEC, &tmpf, error))
+ return FALSE;
+
+ if (fsetxattr (tmpf.fd, "user.test", "novalue", strlen ("novalue"), 0) < 0)
+ {
+ if (errno == ENOTSUP)
+ {
+ *has_user_xattrs = FALSE;
+ return TRUE;
+ }
+ return glnx_throw_errno_prefix (error, "fsetxattr");
+ }
+
+ *has_user_xattrs = TRUE;
+ return TRUE;
+}
+
OstreeSysroot *
ot_test_setup_sysroot (GCancellable *cancellable,
GError **error)
@@ -79,22 +141,19 @@ ot_test_setup_sysroot (GCancellable *cancellable,
if (!ot_test_run_libtest ("setup_os_repository \"archive\" \"syslinux\"", error))
return FALSE;
- struct statfs stbuf;
- { g_autoptr(GString) buf = g_string_new ("mutable-deployments");
- if (statfs ("/", &stbuf) < 0)
- return glnx_null_throw_errno (error);
- /* Keep this in sync with the overlayfs bits in libtest.sh */
-#ifndef OVERLAYFS_SUPER_MAGIC
-#define OVERLAYFS_SUPER_MAGIC 0x794c7630
-#endif
- if (stbuf.f_type == OVERLAYFS_SUPER_MAGIC)
- {
- g_print ("libostreetest: detected overlayfs\n");
- g_string_append (buf, ",no-xattrs");
- }
- /* Make sure deployments are mutable */
- g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE);
- }
+ g_autoptr(GString) buf = g_string_new ("mutable-deployments");
+
+ gboolean can_relabel;
+ if (!ot_check_relabeling (&can_relabel, error))
+ return FALSE;
+ if (!can_relabel)
+ {
+ g_print ("libostreetest: can't relabel, turning off xattrs\n");
+ g_string_append (buf, ",no-xattrs");
+ }
+
+ /* Make sure deployments are mutable */
+ g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE);
g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot");
return ostree_sysroot_new (sysroot_path);