lib/sysroot: Port a few functions to new style

Not sure why we didn't do this earlier. Just noticed them when looking at the
code for a different reason.

Closes: #1085
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-08-16 15:47:03 -04:00 committed by Atomic Bot
parent 40a64bcfe9
commit 6709aa83a8

View File

@ -1571,6 +1571,7 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot,
return ret; return ret;
} }
/* Deploy a copy of @target_deployment */
static gboolean static gboolean
clone_deployment (OstreeSysroot *sysroot, clone_deployment (OstreeSysroot *sysroot,
OstreeDeployment *target_deployment, OstreeDeployment *target_deployment,
@ -1578,38 +1579,26 @@ clone_deployment (OstreeSysroot *sysroot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
__attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = NULL;
g_autoptr(OstreeDeployment) new_deployment = NULL;
/* Ensure we have a clean slate */ /* Ensure we have a clean slate */
if (!ostree_sysroot_prepare_cleanup (sysroot, cancellable, error)) if (!ostree_sysroot_prepare_cleanup (sysroot, cancellable, error))
{ return glnx_prefix_error (error, "Performing initial cleanup");
g_prefix_error (error, "Performing initial cleanup: ");
goto out;
}
kargs = _ostree_kernel_args_new (); /* Copy the bootloader config options */
OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (merge_deployment);
g_auto(GStrv) previous_args = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1);
__attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = _ostree_kernel_args_new ();
_ostree_kernel_args_append_argv (kargs, previous_args);
{ OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (merge_deployment); /* Deploy the copy */
g_auto(GStrv) previous_args = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1); g_autoptr(OstreeDeployment) new_deployment = NULL;
g_auto(GStrv) kargs_strv = _ostree_kernel_args_to_strv (kargs);
_ostree_kernel_args_append_argv (kargs, previous_args); if (!ostree_sysroot_deploy_tree (sysroot,
} ostree_deployment_get_osname (target_deployment),
ostree_deployment_get_csum (target_deployment),
{ ostree_deployment_get_origin (target_deployment),
g_auto(GStrv) kargs_strv = _ostree_kernel_args_to_strv (kargs); merge_deployment, kargs_strv, &new_deployment,
cancellable, error))
if (!ostree_sysroot_deploy_tree (sysroot, return FALSE;
ostree_deployment_get_osname (target_deployment),
ostree_deployment_get_csum (target_deployment),
ostree_deployment_get_origin (target_deployment),
merge_deployment,
kargs_strv,
&new_deployment,
cancellable, error))
goto out;
}
/* Hotfixes push the deployment as rollback target, so it shouldn't /* Hotfixes push the deployment as rollback target, so it shouldn't
* be the default. * be the default.
@ -1618,11 +1607,9 @@ clone_deployment (OstreeSysroot *sysroot,
new_deployment, merge_deployment, new_deployment, merge_deployment,
OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT, OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT,
cancellable, error)) cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -1647,59 +1634,41 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(OstreeSePolicy) sepolicy = NULL;
OstreeDeploymentUnlockedState current_unlocked =
ostree_deployment_get_unlocked (deployment);
g_autoptr(OstreeDeployment) deployment_clone =
ostree_deployment_clone (deployment);
g_autoptr(OstreeDeployment) merge_deployment = NULL;
GKeyFile *origin_clone = ostree_deployment_get_origin (deployment_clone);
const char hotfix_ovl_options[] = "lowerdir=usr,upperdir=.usr-ovl-upper,workdir=.usr-ovl-work";
const char *ovl_options = NULL;
g_autofree char *deployment_path = NULL;
glnx_fd_close int deployment_dfd = -1;
pid_t mount_child;
/* This function cannot re-lock */ /* This function cannot re-lock */
g_return_val_if_fail (unlocked_state != OSTREE_DEPLOYMENT_UNLOCKED_NONE, FALSE); g_return_val_if_fail (unlocked_state != OSTREE_DEPLOYMENT_UNLOCKED_NONE, FALSE);
OstreeDeploymentUnlockedState current_unlocked = ostree_deployment_get_unlocked (deployment);
if (current_unlocked != OSTREE_DEPLOYMENT_UNLOCKED_NONE) if (current_unlocked != OSTREE_DEPLOYMENT_UNLOCKED_NONE)
{ return glnx_throw (error, "Deployment is already in unlocked state: %s",
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, ostree_deployment_unlocked_state_to_string (current_unlocked));
"Deployment is already in unlocked state: %s",
ostree_deployment_unlocked_state_to_string (current_unlocked));
goto out;
}
merge_deployment = ostree_sysroot_get_merge_deployment (self, ostree_deployment_get_osname (deployment)); g_autoptr(OstreeDeployment) merge_deployment =
ostree_sysroot_get_merge_deployment (self, ostree_deployment_get_osname (deployment));
if (!merge_deployment) if (!merge_deployment)
{ return glnx_throw (error, "No previous deployment to duplicate");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No previous deployment to duplicate");
goto out;
}
/* For hotfixes, we push a rollback target */ /* For hotfixes, we push a rollback target */
if (unlocked_state == OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX) if (unlocked_state == OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX)
{ {
if (!clone_deployment (self, deployment, merge_deployment, cancellable, error)) if (!clone_deployment (self, deployment, merge_deployment, cancellable, error))
goto out; return FALSE;
} }
/* Crack it open */ /* Crack it open */
if (!ostree_sysroot_deployment_set_mutable (self, deployment, TRUE, if (!ostree_sysroot_deployment_set_mutable (self, deployment, TRUE,
cancellable, error)) cancellable, error))
goto out; return FALSE;
deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment);
g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment);
glnx_fd_close int deployment_dfd = -1;
if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &deployment_dfd, error)) if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &deployment_dfd, error))
goto out; return FALSE;
sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error); g_autoptr(OstreeSePolicy) sepolicy = ostree_sepolicy_new_at (deployment_dfd, cancellable, error);
if (!sepolicy) if (!sepolicy)
goto out; return FALSE;
const char *ovl_options = NULL;
switch (unlocked_state) switch (unlocked_state)
{ {
case OSTREE_DEPLOYMENT_UNLOCKED_NONE: case OSTREE_DEPLOYMENT_UNLOCKED_NONE:
@ -1707,14 +1676,15 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
break; break;
case OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX: case OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX:
{ {
const char hotfix_ovl_options[] = "lowerdir=usr,upperdir=.usr-ovl-upper,workdir=.usr-ovl-work";
/* Create the overlayfs directories in the deployment root /* Create the overlayfs directories in the deployment root
* directly for hotfixes. The ostree-prepare-root.c helper * directly for hotfixes. The ostree-prepare-root.c helper
* is also set up to detect and mount these. * is also set up to detect and mount these.
*/ */
if (!glnx_shutil_mkdir_p_at (deployment_dfd, ".usr-ovl-upper", 0755, cancellable, error)) if (!glnx_shutil_mkdir_p_at (deployment_dfd, ".usr-ovl-upper", 0755, cancellable, error))
goto out; return FALSE;
if (!glnx_shutil_mkdir_p_at (deployment_dfd, ".usr-ovl-work", 0755, cancellable, error)) if (!glnx_shutil_mkdir_p_at (deployment_dfd, ".usr-ovl-work", 0755, cancellable, error))
goto out; return FALSE;
ovl_options = hotfix_ovl_options; ovl_options = hotfix_ovl_options;
} }
break; break;
@ -1732,18 +1702,18 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy, if (!_ostree_sepolicy_preparefscreatecon (&con, sepolicy,
"/usr", 0755, error)) "/usr", 0755, error))
goto out; return FALSE;
if (!glnx_mkdtempat (AT_FDCWD, development_ovldir, 0755, error)) if (!glnx_mkdtempat (AT_FDCWD, development_ovldir, 0755, error))
goto out; return FALSE;
} }
development_ovl_upper = glnx_strjoina (development_ovldir, "/upper"); development_ovl_upper = glnx_strjoina (development_ovldir, "/upper");
if (!glnx_shutil_mkdir_p_at (AT_FDCWD, development_ovl_upper, 0755, cancellable, error)) if (!glnx_shutil_mkdir_p_at (AT_FDCWD, development_ovl_upper, 0755, cancellable, error))
goto out; return FALSE;
development_ovl_work = glnx_strjoina (development_ovldir, "/work"); development_ovl_work = glnx_strjoina (development_ovldir, "/work");
if (!glnx_shutil_mkdir_p_at (AT_FDCWD, development_ovl_work, 0755, cancellable, error)) if (!glnx_shutil_mkdir_p_at (AT_FDCWD, development_ovl_work, 0755, cancellable, error))
goto out; return FALSE;
ovl_options = glnx_strjoina ("lowerdir=usr,upperdir=", development_ovl_upper, ovl_options = glnx_strjoina ("lowerdir=usr,upperdir=", development_ovl_upper,
",workdir=", development_ovl_work); ",workdir=", development_ovl_work);
} }
@ -1759,12 +1729,9 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
* threads, etc. * threads, etc.
*/ */
{ {
mount_child = fork (); pid_t mount_child = fork ();
if (mount_child < 0) if (mount_child < 0)
{ return glnx_throw_errno_prefix (error, "fork");
glnx_set_prefix_error_from_errno (error, "%s", "fork");
goto out;
}
else if (mount_child == 0) else if (mount_child == 0)
{ {
/* Child process. Do NOT use any GLib API here. */ /* Child process. Do NOT use any GLib API here. */
@ -1780,18 +1747,15 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
int estatus; int estatus;
if (TEMP_FAILURE_RETRY (waitpid (mount_child, &estatus, 0)) < 0) if (TEMP_FAILURE_RETRY (waitpid (mount_child, &estatus, 0)) < 0)
{ return glnx_throw_errno_prefix (error, "waitpid() on mount helper");
glnx_set_prefix_error_from_errno (error, "%s", "waitpid() on mount helper");
goto out;
}
if (!g_spawn_check_exit_status (estatus, error)) if (!g_spawn_check_exit_status (estatus, error))
{ return glnx_throw_errno_prefix (error, "overlayfs mount helper");
g_prefix_error (error, "overlayfs mount helper: ");
goto out;
}
} }
} }
g_autoptr(OstreeDeployment) deployment_clone = ostree_deployment_clone (deployment);
GKeyFile *origin_clone = ostree_deployment_get_origin (deployment_clone);
/* Now, write out the flag saying what we did */ /* Now, write out the flag saying what we did */
switch (unlocked_state) switch (unlocked_state)
{ {
@ -1803,7 +1767,7 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
ostree_deployment_unlocked_state_to_string (unlocked_state)); ostree_deployment_unlocked_state_to_string (unlocked_state));
if (!ostree_sysroot_write_origin_file (self, deployment, origin_clone, if (!ostree_sysroot_write_origin_file (self, deployment, origin_clone,
cancellable, error)) cancellable, error))
goto out; return FALSE;
break; break;
case OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT: case OSTREE_DEPLOYMENT_UNLOCKED_DEVELOPMENT:
{ {
@ -1811,10 +1775,10 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
g_autofree char *devpath_parent = dirname (g_strdup (devpath)); g_autofree char *devpath_parent = dirname (g_strdup (devpath));
if (!glnx_shutil_mkdir_p_at (AT_FDCWD, devpath_parent, 0755, cancellable, error)) if (!glnx_shutil_mkdir_p_at (AT_FDCWD, devpath_parent, 0755, cancellable, error))
goto out; return FALSE;
if (!g_file_set_contents (devpath, "", 0, error)) if (!g_file_set_contents (devpath, "", 0, error))
goto out; return FALSE;
} }
} }
@ -1824,9 +1788,7 @@ ostree_sysroot_deployment_unlock (OstreeSysroot *self,
* regardless. * regardless.
*/ */
if (!_ostree_sysroot_bump_mtime (self, error)) if (!_ostree_sysroot_bump_mtime (self, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }