postprocess: Some porting to new style
Not all of it, but I did a few things since the GLnxTmpfile bit let us port one of the functions. Closes: #800 Approved by: jlebon
This commit is contained in:
parent
0ea649d80b
commit
51ae1e080e
@ -149,17 +149,14 @@ do_kernel_prep (int rootfs_dfd,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
g_autoptr(GVariant) kernelstate = rpmostree_find_kernel (rootfs_dfd, cancellable, error);
|
||||||
g_autoptr(GVariant) kernelstate = NULL;
|
if (!kernelstate)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
const char* kernel_path;
|
const char* kernel_path;
|
||||||
const char* initramfs_path;
|
const char* initramfs_path;
|
||||||
const char *kver;
|
const char *kver;
|
||||||
const char *bootdir;
|
const char *bootdir;
|
||||||
g_auto(GLnxTmpfile) initramfs_tmpf = { 0, };
|
|
||||||
|
|
||||||
kernelstate = rpmostree_find_kernel (rootfs_dfd, cancellable, error);
|
|
||||||
if (!kernelstate)
|
|
||||||
goto out;
|
|
||||||
g_variant_get (kernelstate, "(&s&s&sm&s)",
|
g_variant_get (kernelstate, "(&s&s&sm&s)",
|
||||||
&kver, &bootdir,
|
&kver, &bootdir,
|
||||||
&kernel_path, &initramfs_path);
|
&kernel_path, &initramfs_path);
|
||||||
@ -168,17 +165,17 @@ do_kernel_prep (int rootfs_dfd,
|
|||||||
{
|
{
|
||||||
g_print ("Removing RPM-generated '%s'\n", initramfs_path);
|
g_print ("Removing RPM-generated '%s'\n", initramfs_path);
|
||||||
if (!glnx_shutil_rm_rf_at (rootfs_dfd, initramfs_path, cancellable, error))
|
if (!glnx_shutil_rm_rf_at (rootfs_dfd, initramfs_path, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* OSTree needs to own this */
|
/* OSTree needs to own this */
|
||||||
if (!glnx_shutil_rm_rf_at (rootfs_dfd, "boot/loader", cancellable, error))
|
if (!glnx_shutil_rm_rf_at (rootfs_dfd, "boot/loader", cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
{
|
{
|
||||||
char *child_argv[] = { "depmod", (char*)kver, NULL };
|
char *child_argv[] = { "depmod", (char*)kver, NULL };
|
||||||
if (!run_bwrap_mutably (rootfs_dfd, "depmod", child_argv, error))
|
if (!run_bwrap_mutably (rootfs_dfd, "depmod", child_argv, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure the /etc/machine-id file is present and empty. Apparently systemd
|
/* Ensure the /etc/machine-id file is present and empty. Apparently systemd
|
||||||
@ -188,45 +185,41 @@ do_kernel_prep (int rootfs_dfd,
|
|||||||
if (!glnx_file_replace_contents_at (rootfs_dfd, "etc/machine-id", (guint8*)"", 0,
|
if (!glnx_file_replace_contents_at (rootfs_dfd, "etc/machine-id", (guint8*)"", 0,
|
||||||
GLNX_FILE_REPLACE_NODATASYNC,
|
GLNX_FILE_REPLACE_NODATASYNC,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
{
|
g_autoptr(GPtrArray) dracut_argv = g_ptr_array_new ();
|
||||||
g_autoptr(GPtrArray) dracut_argv = g_ptr_array_new ();
|
if (json_object_has_member (treefile, "initramfs-args"))
|
||||||
|
{
|
||||||
|
guint i, len;
|
||||||
|
JsonArray *initramfs_args;
|
||||||
|
|
||||||
if (json_object_has_member (treefile, "initramfs-args"))
|
initramfs_args = json_object_get_array_member (treefile, "initramfs-args");
|
||||||
{
|
len = json_array_get_length (initramfs_args);
|
||||||
guint i, len;
|
|
||||||
JsonArray *initramfs_args;
|
|
||||||
|
|
||||||
initramfs_args = json_object_get_array_member (treefile, "initramfs-args");
|
for (i = 0; i < len; i++)
|
||||||
len = json_array_get_length (initramfs_args);
|
{
|
||||||
|
const char *arg = _rpmostree_jsonutil_array_require_string_element (initramfs_args, i, error);
|
||||||
|
if (!arg)
|
||||||
|
return FALSE;
|
||||||
|
g_ptr_array_add (dracut_argv, (char*)arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_ptr_array_add (dracut_argv, NULL);
|
||||||
|
|
||||||
for (i = 0; i < len; i++)
|
g_auto(GLnxTmpfile) initramfs_tmpf = { 0, };
|
||||||
{
|
if (!rpmostree_run_dracut (rootfs_dfd,
|
||||||
const char *arg = _rpmostree_jsonutil_array_require_string_element (initramfs_args, i, error);
|
(const char *const*)dracut_argv->pdata, kver,
|
||||||
if (!arg)
|
NULL, &initramfs_tmpf,
|
||||||
goto out;
|
cancellable, error))
|
||||||
g_ptr_array_add (dracut_argv, (char*)arg);
|
return FALSE;
|
||||||
}
|
|
||||||
}
|
|
||||||
g_ptr_array_add (dracut_argv, NULL);
|
|
||||||
|
|
||||||
if (!rpmostree_run_dracut (rootfs_dfd,
|
|
||||||
(const char *const*)dracut_argv->pdata, kver,
|
|
||||||
NULL, &initramfs_tmpf,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rpmostree_finalize_kernel (rootfs_dfd, bootdir, kver,
|
if (!rpmostree_finalize_kernel (rootfs_dfd, bootdir, kver,
|
||||||
kernel_path,
|
kernel_path,
|
||||||
&initramfs_tmpf,
|
&initramfs_tmpf,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -395,11 +388,9 @@ workaround_selinux_cross_labeling_recurse (int dfd,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
|
g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
|
||||||
|
|
||||||
if (!glnx_dirfd_iterator_init_at (dfd, path, TRUE, &dfd_iter, error))
|
if (!glnx_dirfd_iterator_init_at (dfd, path, TRUE, &dfd_iter, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
@ -407,7 +398,7 @@ workaround_selinux_cross_labeling_recurse (int dfd,
|
|||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error))
|
if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (!dent)
|
if (!dent)
|
||||||
break;
|
break;
|
||||||
@ -417,7 +408,7 @@ workaround_selinux_cross_labeling_recurse (int dfd,
|
|||||||
if (dent->d_type == DT_DIR)
|
if (dent->d_type == DT_DIR)
|
||||||
{
|
{
|
||||||
if (!workaround_selinux_cross_labeling_recurse (dfd_iter.fd, name, cancellable, error))
|
if (!workaround_selinux_cross_labeling_recurse (dfd_iter.fd, name, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else if (g_str_has_suffix (name, ".bin"))
|
else if (g_str_has_suffix (name, ".bin"))
|
||||||
{
|
{
|
||||||
@ -426,10 +417,7 @@ workaround_selinux_cross_labeling_recurse (int dfd,
|
|||||||
g_autofree char *nonbin_name = NULL;
|
g_autofree char *nonbin_name = NULL;
|
||||||
|
|
||||||
if (TEMP_FAILURE_RETRY (fstatat (dfd_iter.fd, name, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0)
|
if (TEMP_FAILURE_RETRY (fstatat (dfd_iter.fd, name, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0)
|
||||||
{
|
return glnx_throw_errno_prefix (error, "fstat");
|
||||||
glnx_set_error_from_errno (error);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastdot = strrchr (name, '.');
|
lastdot = strrchr (name, '.');
|
||||||
g_assert (lastdot);
|
g_assert (lastdot);
|
||||||
@ -437,16 +425,11 @@ workaround_selinux_cross_labeling_recurse (int dfd,
|
|||||||
nonbin_name = g_strndup (name, lastdot - name);
|
nonbin_name = g_strndup (name, lastdot - name);
|
||||||
|
|
||||||
if (TEMP_FAILURE_RETRY (utimensat (dfd_iter.fd, nonbin_name, NULL, 0)) == -1)
|
if (TEMP_FAILURE_RETRY (utimensat (dfd_iter.fd, nonbin_name, NULL, 0)) == -1)
|
||||||
{
|
return glnx_throw_errno_prefix (error, "utimensat");
|
||||||
glnx_set_error_from_errno (error);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -455,8 +438,6 @@ rpmostree_prepare_rootfs_get_sepolicy (int dfd,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
glnx_unref_object OstreeSePolicy *ret_sepolicy = NULL;
|
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
const char *policy_path;
|
const char *policy_path;
|
||||||
|
|
||||||
@ -466,10 +447,7 @@ rpmostree_prepare_rootfs_get_sepolicy (int dfd,
|
|||||||
if (fstatat (dfd, "usr/etc", &stbuf, 0) < 0)
|
if (fstatat (dfd, "usr/etc", &stbuf, 0) < 0)
|
||||||
{
|
{
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
{
|
return glnx_throw_errno_prefix (error, "fstatat");
|
||||||
glnx_set_error_from_errno (error);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
policy_path = "etc/selinux";
|
policy_path = "etc/selinux";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -478,26 +456,21 @@ rpmostree_prepare_rootfs_get_sepolicy (int dfd,
|
|||||||
if (TEMP_FAILURE_RETRY (fstatat (dfd, policy_path, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0)
|
if (TEMP_FAILURE_RETRY (fstatat (dfd, policy_path, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0)
|
||||||
{
|
{
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
{
|
return glnx_throw_errno_prefix (error, "fstatat");
|
||||||
glnx_set_error_from_errno (error);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!workaround_selinux_cross_labeling_recurse (dfd, policy_path,
|
if (!workaround_selinux_cross_labeling_recurse (dfd, policy_path,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_sepolicy = ostree_sepolicy_new_at (dfd, cancellable, error);
|
g_autoptr(OstreeSePolicy) ret_sepolicy = ostree_sepolicy_new_at (dfd, cancellable, error);
|
||||||
if (ret_sepolicy == NULL)
|
if (ret_sepolicy == NULL)
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
*out_sepolicy = g_steal_pointer (&ret_sepolicy);
|
*out_sepolicy = g_steal_pointer (&ret_sepolicy);
|
||||||
out:
|
return TRUE;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
Loading…
Reference in New Issue
Block a user