lib/deploy: Port various functions to declare-and-initialize
Just noticed this while working on the code. Closes: #1499 Approved by: jlebon
This commit is contained in:
parent
52f7ba1878
commit
d4d193495f
|
|
@ -667,27 +667,21 @@ selinux_relabel_dir (OstreeSysroot *sysroot,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_autoptr(GPtrArray) path_parts = g_ptr_array_new ();
|
|
||||||
g_autoptr(GFileInfo) root_info = NULL;
|
|
||||||
|
|
||||||
root_info = g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO,
|
g_autoptr(GFileInfo) root_info =
|
||||||
|
g_file_query_info (dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
cancellable, error);
|
cancellable, error);
|
||||||
if (!root_info)
|
if (!root_info)
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
|
g_autoptr(GPtrArray) path_parts = g_ptr_array_new ();
|
||||||
g_ptr_array_add (path_parts, (char*)prefix);
|
g_ptr_array_add (path_parts, (char*)prefix);
|
||||||
if (!relabel_recursively (sysroot, sepolicy, dir, root_info, path_parts,
|
if (!relabel_recursively (sysroot, sepolicy, dir, root_info, path_parts,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
return glnx_prefix_error (error, "Relabeling /%s", prefix);
|
||||||
g_prefix_error (error, "Relabeling /%s: ", prefix);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handles SELinux labeling for /var; this is slated to be deleted. See
|
/* Handles SELinux labeling for /var; this is slated to be deleted. See
|
||||||
|
|
@ -766,12 +760,7 @@ merge_configuration (OstreeSysroot *sysroot,
|
||||||
|
|
||||||
if (previous_deployment)
|
if (previous_deployment)
|
||||||
{
|
{
|
||||||
g_autoptr(GFile) previous_path = NULL;
|
OstreeBootconfigParser *previous_bootconfig = ostree_deployment_get_bootconfig (previous_deployment);
|
||||||
OstreeBootconfigParser *previous_bootconfig;
|
|
||||||
|
|
||||||
previous_path = ostree_sysroot_get_deployment_directory (sysroot, previous_deployment);
|
|
||||||
|
|
||||||
previous_bootconfig = ostree_deployment_get_bootconfig (previous_deployment);
|
|
||||||
if (previous_bootconfig)
|
if (previous_bootconfig)
|
||||||
{
|
{
|
||||||
const char *previous_options = ostree_bootconfig_parser_get (previous_bootconfig, "options");
|
const char *previous_options = ostree_bootconfig_parser_get (previous_bootconfig, "options");
|
||||||
|
|
@ -1939,23 +1928,18 @@ deployment_bootconfigs_equal (OstreeDeployment *a,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
{
|
{
|
||||||
OstreeBootconfigParser *a_bootconfig = ostree_deployment_get_bootconfig (a);
|
|
||||||
OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b);
|
|
||||||
const char *a_boot_options = ostree_bootconfig_parser_get (a_bootconfig, "options");
|
|
||||||
const char *b_boot_options = ostree_bootconfig_parser_get (b_bootconfig, "options");
|
|
||||||
g_autoptr(OstreeKernelArgs) a_kargs = NULL;
|
|
||||||
g_autoptr(OstreeKernelArgs) b_kargs = NULL;
|
|
||||||
g_autofree char *a_boot_options_without_ostree = NULL;
|
|
||||||
g_autofree char *b_boot_options_without_ostree = NULL;
|
|
||||||
|
|
||||||
/* We checksum the kernel arguments *except* ostree= */
|
/* We checksum the kernel arguments *except* ostree= */
|
||||||
a_kargs = _ostree_kernel_args_from_string (a_boot_options);
|
OstreeBootconfigParser *a_bootconfig = ostree_deployment_get_bootconfig (a);
|
||||||
|
const char *a_boot_options = ostree_bootconfig_parser_get (a_bootconfig, "options");
|
||||||
|
g_autoptr(OstreeKernelArgs) a_kargs = _ostree_kernel_args_from_string (a_boot_options);
|
||||||
_ostree_kernel_args_replace (a_kargs, "ostree");
|
_ostree_kernel_args_replace (a_kargs, "ostree");
|
||||||
a_boot_options_without_ostree = _ostree_kernel_args_to_string (a_kargs);
|
g_autofree char *a_boot_options_without_ostree = _ostree_kernel_args_to_string (a_kargs);
|
||||||
|
|
||||||
b_kargs = _ostree_kernel_args_from_string (b_boot_options);
|
OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b);
|
||||||
|
const char *b_boot_options = ostree_bootconfig_parser_get (b_bootconfig, "options");
|
||||||
|
g_autoptr(OstreeKernelArgs) b_kargs = _ostree_kernel_args_from_string (b_boot_options);
|
||||||
_ostree_kernel_args_replace (b_kargs, "ostree");
|
_ostree_kernel_args_replace (b_kargs, "ostree");
|
||||||
b_boot_options_without_ostree = _ostree_kernel_args_to_string (b_kargs);
|
g_autofree char *b_boot_options_without_ostree = _ostree_kernel_args_to_string (b_kargs);
|
||||||
|
|
||||||
if (strcmp (a_boot_options_without_ostree, b_boot_options_without_ostree) != 0)
|
if (strcmp (a_boot_options_without_ostree, b_boot_options_without_ostree) != 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
@ -2086,12 +2070,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
guint i;
|
|
||||||
gboolean requires_new_bootversion = FALSE;
|
|
||||||
gboolean found_booted_deployment = FALSE;
|
|
||||||
gboolean bootloader_is_atomic = FALSE;
|
|
||||||
gboolean boot_was_ro_mount = FALSE;
|
gboolean boot_was_ro_mount = FALSE;
|
||||||
SyncStats syncstats = { 0, };
|
|
||||||
g_autoptr(OstreeBootloader) bootloader = NULL;
|
g_autoptr(OstreeBootloader) bootloader = NULL;
|
||||||
|
|
||||||
g_assert (self->loaded);
|
g_assert (self->loaded);
|
||||||
|
|
@ -2105,11 +2084,12 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
|
||||||
* matching bootloader configuration, then we can just swap the
|
* matching bootloader configuration, then we can just swap the
|
||||||
* subbootversion bootlinks.
|
* subbootversion bootlinks.
|
||||||
*/
|
*/
|
||||||
|
gboolean requires_new_bootversion = FALSE;
|
||||||
if (new_deployments->len != self->deployments->len)
|
if (new_deployments->len != self->deployments->len)
|
||||||
requires_new_bootversion = TRUE;
|
requires_new_bootversion = TRUE;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; i < new_deployments->len; i++)
|
for (guint i = 0; i < new_deployments->len; i++)
|
||||||
{
|
{
|
||||||
if (!deployment_bootconfigs_equal (new_deployments->pdata[i],
|
if (!deployment_bootconfigs_equal (new_deployments->pdata[i],
|
||||||
self->deployments->pdata[i]))
|
self->deployments->pdata[i]))
|
||||||
|
|
@ -2120,7 +2100,8 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < new_deployments->len; i++)
|
gboolean found_booted_deployment = FALSE;
|
||||||
|
for (guint i = 0; i < new_deployments->len; i++)
|
||||||
{
|
{
|
||||||
OstreeDeployment *deployment = new_deployments->pdata[i];
|
OstreeDeployment *deployment = new_deployments->pdata[i];
|
||||||
g_autoptr(GFile) deployment_root = NULL;
|
g_autoptr(GFile) deployment_root = NULL;
|
||||||
|
|
@ -2146,6 +2127,8 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean bootloader_is_atomic = FALSE;
|
||||||
|
SyncStats syncstats = { 0, };
|
||||||
if (!requires_new_bootversion)
|
if (!requires_new_bootversion)
|
||||||
{
|
{
|
||||||
if (!create_new_bootlinks (self, self->bootversion,
|
if (!create_new_bootlinks (self, self->bootversion,
|
||||||
|
|
@ -2211,13 +2194,10 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
|
||||||
|
|
||||||
/* Only show the osname in bootloader titles if there are multiple
|
/* Only show the osname in bootloader titles if there are multiple
|
||||||
* osname's among the new deployments. Check for that here. */
|
* osname's among the new deployments. Check for that here. */
|
||||||
for (i = 1; i < new_deployments->len; i++)
|
for (guint i = 1; i < new_deployments->len; i++)
|
||||||
{
|
{
|
||||||
const gchar *osname_0, *osname_i;
|
const char *osname_0 = ostree_deployment_get_osname (new_deployments->pdata[0]);
|
||||||
|
const char *osname_i = ostree_deployment_get_osname (new_deployments->pdata[i]);
|
||||||
osname_0 = ostree_deployment_get_osname (new_deployments->pdata[0]);
|
|
||||||
osname_i = ostree_deployment_get_osname (new_deployments->pdata[i]);
|
|
||||||
|
|
||||||
if (!g_str_equal (osname_0, osname_i))
|
if (!g_str_equal (osname_0, osname_i))
|
||||||
{
|
{
|
||||||
show_osname = TRUE;
|
show_osname = TRUE;
|
||||||
|
|
@ -2225,7 +2205,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < new_deployments->len; i++)
|
for (guint i = 0; i < new_deployments->len; i++)
|
||||||
{
|
{
|
||||||
OstreeDeployment *deployment = new_deployments->pdata[i];
|
OstreeDeployment *deployment = new_deployments->pdata[i];
|
||||||
if (!install_deployment_kernel (self, repo, new_bootversion,
|
if (!install_deployment_kernel (self, repo, new_bootversion,
|
||||||
|
|
|
||||||
|
|
@ -690,30 +690,25 @@ parse_deployment (OstreeSysroot *self,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Given a bootloader config, return the value part of the ostree= kernel
|
||||||
|
* argument.
|
||||||
|
*/
|
||||||
static char *
|
static char *
|
||||||
get_ostree_kernel_arg_from_config (OstreeBootconfigParser *config)
|
get_ostree_kernel_arg_from_config (OstreeBootconfigParser *config)
|
||||||
{
|
{
|
||||||
const char *options;
|
const char *options = ostree_bootconfig_parser_get (config, "options");
|
||||||
char *ret = NULL;
|
|
||||||
char **opts, **iter;
|
|
||||||
|
|
||||||
options = ostree_bootconfig_parser_get (config, "options");
|
|
||||||
if (!options)
|
if (!options)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
opts = g_strsplit (options, " ", -1);
|
g_auto(GStrv) opts = g_strsplit (options, " ", -1);
|
||||||
for (iter = opts; *iter; iter++)
|
for (char **iter = opts; *iter; iter++)
|
||||||
{
|
{
|
||||||
const char *opt = *iter;
|
const char *opt = *iter;
|
||||||
if (g_str_has_prefix (opt, "ostree="))
|
if (g_str_has_prefix (opt, "ostree="))
|
||||||
{
|
return g_strdup (opt + strlen ("ostree="));
|
||||||
ret = g_strdup (opt + strlen ("ostree="));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
g_strfreev (opts);
|
|
||||||
|
|
||||||
return ret;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -963,13 +958,10 @@ ostree_sysroot_get_booted_deployment (OstreeSysroot *self)
|
||||||
GPtrArray *
|
GPtrArray *
|
||||||
ostree_sysroot_get_deployments (OstreeSysroot *self)
|
ostree_sysroot_get_deployments (OstreeSysroot *self)
|
||||||
{
|
{
|
||||||
GPtrArray *copy;
|
|
||||||
guint i;
|
|
||||||
|
|
||||||
g_return_val_if_fail (self->loaded, NULL);
|
g_return_val_if_fail (self->loaded, NULL);
|
||||||
|
|
||||||
copy = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
GPtrArray *copy = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
||||||
for (i = 0; i < self->deployments->len; i++)
|
for (guint i = 0; i < self->deployments->len; i++)
|
||||||
g_ptr_array_add (copy, g_object_ref (self->deployments->pdata[i]));
|
g_ptr_array_add (copy, g_object_ref (self->deployments->pdata[i]));
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
@ -1114,10 +1106,9 @@ char *
|
||||||
_ostree_sysroot_join_lines (GPtrArray *lines)
|
_ostree_sysroot_join_lines (GPtrArray *lines)
|
||||||
{
|
{
|
||||||
GString *buf = g_string_new ("");
|
GString *buf = g_string_new ("");
|
||||||
guint i;
|
|
||||||
gboolean prev_was_empty = FALSE;
|
gboolean prev_was_empty = FALSE;
|
||||||
|
|
||||||
for (i = 0; i < lines->len; i++)
|
for (guint i = 0; i < lines->len; i++)
|
||||||
{
|
{
|
||||||
const char *line = lines->pdata[i];
|
const char *line = lines->pdata[i];
|
||||||
/* Special bit to remove extraneous empty lines */
|
/* Special bit to remove extraneous empty lines */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue