sysroot: Read the bootloader configuration with fd-relative API
Another piece of the conversion.
This commit is contained in:
parent
a5ffaca9d7
commit
68ce554202
|
|
@ -62,11 +62,22 @@ ostree_bootconfig_parser_clone (OstreeBootconfigParser *self)
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_bootconfig_parser_parse_at:
|
||||||
|
* @self: Parser
|
||||||
|
* @dfd: Directory fd
|
||||||
|
* @path: File path
|
||||||
|
* @cancellable: Cancellable
|
||||||
|
* @error: Error
|
||||||
|
*
|
||||||
|
* Initialize a bootconfig from the given file.
|
||||||
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
ostree_bootconfig_parser_parse (OstreeBootconfigParser *self,
|
ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||||
GFile *path,
|
int dfd,
|
||||||
GCancellable *cancellable,
|
const char *path,
|
||||||
GError **error)
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gs_free char *contents = NULL;
|
gs_free char *contents = NULL;
|
||||||
|
|
@ -75,7 +86,7 @@ ostree_bootconfig_parser_parse (OstreeBootconfigParser *self,
|
||||||
|
|
||||||
g_return_val_if_fail (!self->parsed, FALSE);
|
g_return_val_if_fail (!self->parsed, FALSE);
|
||||||
|
|
||||||
contents = gs_file_load_contents_utf8 (path, cancellable, error);
|
contents = glnx_file_get_contents_utf8_at (dfd, path, NULL, cancellable, error);
|
||||||
if (!contents)
|
if (!contents)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -111,6 +122,16 @@ ostree_bootconfig_parser_parse (OstreeBootconfigParser *self,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
ostree_bootconfig_parser_parse (OstreeBootconfigParser *self,
|
||||||
|
GFile *path,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
return ostree_bootconfig_parser_parse_at (self, AT_FDCWD, gs_file_get_path_cached (path),
|
||||||
|
cancellable, error);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ostree_bootconfig_parser_set (OstreeBootconfigParser *self,
|
ostree_bootconfig_parser_set (OstreeBootconfigParser *self,
|
||||||
const char *key,
|
const char *key,
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,12 @@ gboolean ostree_bootconfig_parser_parse (OstreeBootconfigParser *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gboolean ostree_bootconfig_parser_parse_at (OstreeBootconfigParser *self,
|
||||||
|
int dfd,
|
||||||
|
const char *path,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gboolean ostree_bootconfig_parser_write (OstreeBootconfigParser *self,
|
gboolean ostree_bootconfig_parser_write (OstreeBootconfigParser *self,
|
||||||
GFile *output,
|
GFile *output,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
|
||||||
|
|
@ -360,54 +360,57 @@ _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gs_unref_object GFileEnumerator *dir_enum = NULL;
|
int fd; /* Temporary owned by iterator */
|
||||||
gs_unref_object GFile *loader_entries_dir = NULL;
|
g_autofree char *entries_path = g_strdup_printf ("boot/loader.%d/entries", bootversion);
|
||||||
gs_unref_ptrarray GPtrArray *ret_loader_configs = NULL;
|
gs_unref_ptrarray GPtrArray *ret_loader_configs = NULL;
|
||||||
GError *temp_error = NULL;
|
g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
|
||||||
|
|
||||||
|
if (!ensure_sysroot_fd (self, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
loader_entries_dir = ot_gfile_resolve_path_printf (self->path, "boot/loader.%d/entries",
|
|
||||||
bootversion);
|
|
||||||
ret_loader_configs = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
ret_loader_configs = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
||||||
|
|
||||||
dir_enum = g_file_enumerate_children (loader_entries_dir, OSTREE_GIO_FAST_QUERYINFO,
|
fd = glnx_opendirat_with_errno (self->sysroot_fd, entries_path, TRUE);
|
||||||
0, NULL, &temp_error);
|
if (fd == -1)
|
||||||
if (!dir_enum)
|
|
||||||
{
|
{
|
||||||
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
if (errno == ENOENT)
|
||||||
{
|
goto done;
|
||||||
g_clear_error (&temp_error);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_propagate_error (error, temp_error);
|
glnx_set_error_from_errno (error);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!glnx_dirfd_iterator_init_take_fd (fd, &dfd_iter, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
GFileInfo *file_info;
|
struct dirent *dent;
|
||||||
GFile *child;
|
struct stat stbuf;
|
||||||
const char *name;
|
|
||||||
|
|
||||||
if (!gs_file_enumerator_iterate (dir_enum, &file_info, &child,
|
if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, cancellable, error))
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
goto out;
|
||||||
if (file_info == NULL)
|
|
||||||
|
if (dent == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
name = g_file_info_get_name (file_info);
|
if (fstatat (dfd_iter.fd, dent->d_name, &stbuf, 0) != 0)
|
||||||
|
{
|
||||||
|
glnx_set_error_from_errno (error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (g_str_has_prefix (name, "ostree-") &&
|
if (g_str_has_prefix (dent->d_name, "ostree-") &&
|
||||||
g_str_has_suffix (name, ".conf") &&
|
g_str_has_suffix (dent->d_name, ".conf") &&
|
||||||
g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
|
S_ISREG (stbuf.st_mode))
|
||||||
{
|
{
|
||||||
gs_unref_object OstreeBootconfigParser *config = ostree_bootconfig_parser_new ();
|
gs_unref_object OstreeBootconfigParser *config = ostree_bootconfig_parser_new ();
|
||||||
|
|
||||||
if (!ostree_bootconfig_parser_parse (config, child, cancellable, error))
|
if (!ostree_bootconfig_parser_parse_at (config, dfd_iter.fd, dent->d_name, cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "Parsing %s: ", gs_file_get_path_cached (child));
|
g_prefix_error (error, "Parsing %s: ", dent->d_name);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue