summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libostree/libostree.sym1
-rw-r--r--src/libostree/ostree-sysroot-deploy.c8
-rw-r--r--src/libostree/ostree-sysroot-private.h3
-rw-r--r--src/libostree/ostree-sysroot.c93
-rw-r--r--src/libostree/ostree-sysroot.h6
-rw-r--r--src/ostree/ot-admin-builtin-os-init.c44
6 files changed, 107 insertions, 48 deletions
diff --git a/src/libostree/libostree.sym b/src/libostree/libostree.sym
index f86a1ead..03350176 100644
--- a/src/libostree/libostree.sym
+++ b/src/libostree/libostree.sym
@@ -316,4 +316,5 @@ LIBOSTREE_2016.4 {
global:
ostree_repo_get_dfd;
ostree_repo_list_refs_ext;
+ ostree_sysroot_init_osname;
} LIBOSTREE_2016.3;
diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c
index b4f7cd27..1f15ddcf 100644
--- a/src/libostree/ostree-sysroot-deploy.c
+++ b/src/libostree/ostree-sysroot-deploy.c
@@ -1855,12 +1855,8 @@ ostree_sysroot_write_deployments (OstreeSysroot *self,
requires_new_bootversion ? "yes" : "no",
new_deployments->len - self->deployments->len);
- /* Allow other systems to monitor for changes */
- if (utimensat (self->sysroot_fd, "ostree/deploy", NULL, 0) < 0)
- {
- glnx_set_prefix_error_from_errno (error, "%s", "futimens");
- goto out;
- }
+ if (!_ostree_sysroot_bump_mtime (self, error))
+ goto out;
/* Now reload from disk */
if (!ostree_sysroot_load (self, cancellable, error))
diff --git a/src/libostree/ostree-sysroot-private.h b/src/libostree/ostree-sysroot-private.h
index e0dc24fd..356509ad 100644
--- a/src/libostree/ostree-sysroot-private.h
+++ b/src/libostree/ostree-sysroot-private.h
@@ -98,6 +98,9 @@ gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
GCancellable *cancellable,
GError **error);
+gboolean _ostree_sysroot_bump_mtime (OstreeSysroot *sysroot,
+ GError **error);
+
typedef enum {
OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS = 1 << 0,
OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS = 1 << 1,
diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c
index 5ad2713a..eb2b353d 100644
--- a/src/libostree/ostree-sysroot.c
+++ b/src/libostree/ostree-sysroot.c
@@ -229,6 +229,19 @@ ostree_sysroot_get_fd (OstreeSysroot *self)
return self->sysroot_fd;
}
+gboolean
+_ostree_sysroot_bump_mtime (OstreeSysroot *self,
+ GError **error)
+{
+ /* Allow other systems to monitor for changes */
+ if (utimensat (self->sysroot_fd, "ostree/deploy", NULL, 0) < 0)
+ {
+ glnx_set_prefix_error_from_errno (error, "%s", "futimens");
+ return FALSE;
+ }
+ return TRUE;
+}
+
/**
* ostree_sysroot_unload:
* @self: Sysroot
@@ -1338,6 +1351,86 @@ ostree_sysroot_lock_finish (OstreeSysroot *self,
}
/**
+ * ostree_sysroot_init_osname:
+ * @self: Sysroot
+ * @osname: Name group of operating system checkouts
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Initialize the directory structure for an "osname", which is a
+ * group of operating system deployments, with a shared `/var`. One
+ * is required for generating a deployment.
+ */
+gboolean
+ostree_sysroot_init_osname (OstreeSysroot *self,
+ const char *osname,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ const char *deploydir = glnx_strjoina ("ostree/deploy/", osname);
+ glnx_fd_close int dfd = -1;
+
+ if (!ensure_sysroot_fd (self, error))
+ goto out;
+
+ if (mkdirat (self->sysroot_fd, deploydir, 0777) < 0)
+ {
+ glnx_set_prefix_error_from_errno (error, "Creating %s", deploydir);
+ goto out;
+ }
+
+ if (!glnx_opendirat (self->sysroot_fd, deploydir, TRUE, &dfd, error))
+ goto out;
+
+ if (mkdirat (dfd, "var", 0777) < 0)
+ {
+ glnx_set_prefix_error_from_errno (error, "Creating %s", "var");
+ goto out;
+ }
+
+ /* This is a bit of a legacy hack...but we have to keep it around
+ * now. We're ensuring core subdirectories of /var exist.
+ */
+ if (mkdirat (dfd, "var/tmp", 0777) < 0)
+ {
+ glnx_set_prefix_error_from_errno (error, "Creating %s", "var/tmp");
+ goto out;
+ }
+
+ if (fchmodat (dfd, "var/tmp", 01777, 0) < 0)
+ {
+ glnx_set_prefix_error_from_errno (error, "Fchmod %s", "var/tmp");
+ goto out;
+ }
+
+ if (mkdirat (dfd, "var/lib", 0777) < 0)
+ {
+ glnx_set_prefix_error_from_errno (error, "Creating %s", "var/tmp");
+ goto out;
+ }
+
+ if (symlinkat ("../run", dfd, "var/run") < 0)
+ {
+ glnx_set_prefix_error_from_errno (error, "Symlinking %s", "var/run");
+ goto out;
+ }
+
+ if (symlinkat ("../run/lock", dfd, "var/lock") < 0)
+ {
+ glnx_set_prefix_error_from_errno (error, "Symlinking %s", "var/lock");
+ goto out;
+ }
+
+ if (!_ostree_sysroot_bump_mtime (self, error))
+ goto out;
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
+/**
* ostree_sysroot_simple_write_deployment:
* @sysroot: Sysroot
* @osname: (allow-none): OS name
diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h
index bce86985..cab59d0a 100644
--- a/src/libostree/ostree-sysroot.h
+++ b/src/libostree/ostree-sysroot.h
@@ -98,6 +98,12 @@ _OSTREE_PUBLIC
void ostree_sysroot_unlock (OstreeSysroot *self);
_OSTREE_PUBLIC
+gboolean ostree_sysroot_init_osname (OstreeSysroot *self,
+ const char *osname,
+ GCancellable *cancellable,
+ GError **error);
+
+_OSTREE_PUBLIC
gboolean ostree_sysroot_cleanup (OstreeSysroot *self,
GCancellable *cancellable,
GError **error);
diff --git a/src/ostree/ot-admin-builtin-os-init.c b/src/ostree/ot-admin-builtin-os-init.c
index f5b5f64b..fbb04949 100644
--- a/src/ostree/ot-admin-builtin-os-init.c
+++ b/src/ostree/ot-admin-builtin-os-init.c
@@ -40,8 +40,6 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr
glnx_unref_object OstreeSysroot *sysroot = NULL;
gboolean ret = FALSE;
const char *osname = NULL;
- g_autoptr(GFile) deploy_dir = NULL;
- g_autoptr(GFile) dir = NULL;
context = g_option_context_new ("OSNAME - Initialize empty state for given operating system");
@@ -61,48 +59,10 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr
osname = argv[1];
- deploy_dir = ot_gfile_get_child_build_path (ostree_sysroot_get_path (sysroot), "ostree", "deploy", osname, NULL);
-
- /* Ensure core subdirectories of /var exist, since we need them for
- * dracut generation, and the host will want them too.
- */
- g_clear_object (&dir);
- dir = ot_gfile_get_child_build_path (deploy_dir, "var", "tmp", NULL);
- if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
- goto out;
- if (chmod (gs_file_get_path_cached (dir), 01777) < 0)
- {
- gs_set_error_from_errno (error, errno);
- goto out;
- }
-
- g_clear_object (&dir);
- dir = ot_gfile_get_child_build_path (deploy_dir, "var", "lib", NULL);
- if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
+ if (!ostree_sysroot_init_osname (sysroot, osname, cancellable, error))
goto out;
- g_clear_object (&dir);
- dir = ot_gfile_get_child_build_path (deploy_dir, "var", "run", NULL);
- if (!g_file_test (gs_file_get_path_cached (dir), G_FILE_TEST_IS_SYMLINK))
- {
- if (symlink ("../run", gs_file_get_path_cached (dir)) < 0)
- {
- gs_set_error_from_errno (error, errno);
- goto out;
- }
- }
-
- dir = ot_gfile_get_child_build_path (deploy_dir, "var", "lock", NULL);
- if (!g_file_test (gs_file_get_path_cached (dir), G_FILE_TEST_IS_SYMLINK))
- {
- if (symlink ("../run/lock", gs_file_get_path_cached (dir)) < 0)
- {
- gs_set_error_from_errno (error, errno);
- goto out;
- }
- }
-
- g_print ("%s initialized as OSTree root\n", gs_file_get_path_cached (deploy_dir));
+ g_print ("ostree/deploy/%s initialized as OSTree root\n", osname);
ret = TRUE;
out: