libbe(3)/bectl(8): Provide and use proper alloc/free for property lists

This commit is contained in:
Kyle Evans 2018-07-25 16:00:48 +00:00
parent 4831c931dd
commit 734e362fa1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/bectl/; revision=336715
4 changed files with 19 additions and 3 deletions

View file

@ -67,6 +67,7 @@ const char *be_nextboot_path(libbe_handle_t *);
const char *be_root_path(libbe_handle_t *);
int be_get_bootenv_props(libbe_handle_t *, nvlist_t *);
int be_prop_list_alloc(nvlist_t **be_list);
void be_prop_list_free(nvlist_t *be_list);
int be_activate(libbe_handle_t *, char *, bool);

View file

@ -207,6 +207,13 @@ prop_list_builder(prop_data_t *data)
}
int
be_prop_list_alloc(nvlist_t **be_list)
{
return (nvlist_alloc(be_list, NV_UNIQUE_NAME, KM_SLEEP));
}
/*
* frees property list and its children
*/

View file

@ -129,6 +129,14 @@ of state to be retained, such as errors from previous operations.
.Ft int
.Fn be_add_child "libbe_handle_t *, char *, bool" ;
.Pp
.Ft int
.Fn be_prop_list_alloc "nvlist_t **" ;
.Pp
.Ft int
.Fn be_get_bootenv_props "libbe_handle_t *, nvlist_t *" ;
.Pp
.Ft void
.Fn be_prop_list_free "nvlist_t *" ;
.\" .Ft void
.\" .Fn mp_mfree "MINT *mp" ;
.\" .Bd -ragged -offset indent

View file

@ -28,7 +28,6 @@
#include <sys/param.h>
#include <sys/jail.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <errno.h>
#include <stdbool.h>
@ -418,6 +417,7 @@ bectl_cmd_list(int argc, char *argv[])
int opt;
bool show_all_datasets, show_space, hide_headers, show_snaps;
props = NULL;
show_all_datasets = show_space = hide_headers = show_snaps = false;
while ((opt = getopt(argc, argv, "aDHs")) != -1) {
switch (opt) {
@ -448,7 +448,7 @@ bectl_cmd_list(int argc, char *argv[])
}
if (nvlist_alloc(&props, NV_UNIQUE_NAME, M_WAITOK) != 0) {
if (be_prop_list_alloc(&props) != 0) {
fprintf(stderr, "bectl list: failed to allocate prop nvlist\n");
return (1);
}
@ -459,7 +459,7 @@ bectl_cmd_list(int argc, char *argv[])
}
dump_nvlist(props, 0);
nvlist_free(props);
be_prop_list_free(props);
return (0);
}