Skip to content

Commit

Permalink
lib/deploy: Have internal origin writing API take sepolicy
Browse files Browse the repository at this point in the history
Ensures it's labeled consistently. Prep for staged deployments which reworks the
logic around when the origin file is written.

Closes: #1505
Approved by: jlebon
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Mar 19, 2018
1 parent ce2449a commit 9ca3f76
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/libostree/ostree-sysroot-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ merge_configuration (OstreeSysroot *sysroot,
*/
static gboolean
write_origin_file_internal (OstreeSysroot *sysroot,
OstreeSePolicy *sepolicy,
OstreeDeployment *deployment,
GKeyFile *new_origin,
GLnxFileReplaceFlags flags,
Expand All @@ -849,16 +850,21 @@ write_origin_file_internal (OstreeSysroot *sysroot,

if (origin)
{
g_autofree char *origin_path = NULL;
g_autofree char *contents = NULL;
gsize len;
g_auto(OstreeSepolicyFsCreatecon) con = { 0, };
if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy,
"/etc/ostree/remotes.d/dummy.conf",
0644, error))
return FALSE;

origin_path = g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d.origin",
ostree_deployment_get_osname (deployment),
ostree_deployment_get_csum (deployment),
ostree_deployment_get_deployserial (deployment));
g_autofree char *origin_path =
g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d.origin",
ostree_deployment_get_osname (deployment),
ostree_deployment_get_csum (deployment),
ostree_deployment_get_deployserial (deployment));

contents = g_key_file_to_data (origin, &len, error);

gsize len;
g_autofree char *contents = g_key_file_to_data (origin, &len, error);
if (!contents)
return FALSE;

Expand Down Expand Up @@ -891,7 +897,12 @@ ostree_sysroot_write_origin_file (OstreeSysroot *sysroot,
GCancellable *cancellable,
GError **error)
{
if (!write_origin_file_internal (sysroot, deployment, new_origin,
g_autoptr(GFile) rootfs = g_file_new_for_path ("/");
g_autoptr(OstreeSePolicy) sepolicy = ostree_sepolicy_new (rootfs, cancellable, error);
if (!sepolicy)
return FALSE;

if (!write_origin_file_internal (sysroot, sepolicy, deployment, new_origin,
GLNX_FILE_REPLACE_DATASYNC_NEW,
cancellable, error))
return FALSE;
Expand Down Expand Up @@ -2444,21 +2455,13 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self,
return FALSE;
}

{ g_auto(OstreeSepolicyFsCreatecon) con = { 0, };

if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy,
"/etc/ostree/remotes.d/dummy.conf",
0644, error))
return FALSE;

/* Don't fsync here, as we assume that's all done in
* ostree_sysroot_write_deployments().
*/
if (!write_origin_file_internal (self, new_deployment, NULL,
GLNX_FILE_REPLACE_NODATASYNC,
cancellable, error))
return FALSE;
}
/* Don't fsync here, as we assume that's all done in
* ostree_sysroot_write_deployments().
*/
if (!write_origin_file_internal (self, sepolicy, new_deployment, NULL,
GLNX_FILE_REPLACE_NODATASYNC,
cancellable, error))
return FALSE;

/* After this, install_deployment_kernel() will set the other boot
* options and write it out to disk.
Expand Down

0 comments on commit 9ca3f76

Please sign in to comment.