bbf: check and create a new dmmap file if not there when adding a new section

This commit is contained in:
Amin Ben Ramdhane 2020-10-23 17:33:54 +01:00
parent 6da9750f96
commit 143afb5f2b
2 changed files with 13 additions and 3 deletions

View file

@ -1229,7 +1229,6 @@ void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned i
output = atoi(argv[2]);
cmd = argv[3];
check_create_dmmap_package(DMMAP);
/* GET NAME */
if (strcmp(cmd, "get_name") == 0) {
if (argc < 6) goto invalid_arguments;
@ -1551,7 +1550,6 @@ int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_ve
return -1;
}
check_create_dmmap_package(DMMAP);
dm_ctx_init(&cli_dmctx, dmtype, amd_version, instance_mode);
if (strcmp(argv[2], "get_value") == 0) {
char *param = "";

View file

@ -422,10 +422,22 @@ int dmuci_del_list_value(char *package, char *section, char *option, char *value
char *dmuci_add_section(char *package, char *stype, struct uci_section **s, char **value)
{
struct uci_ptr ptr = {0};
char *val = "";
char *fname, *val = "";
*s = NULL;
dmasprintf(&fname, "%s/%s", uci_ctx->confdir, package);
if (access(fname, F_OK ) == -1 ) {
FILE *fptr = fopen(fname, "w");
dmfree(fname);
if (fptr)
fclose(fptr);
else
return val;
} else {
dmfree(fname);
}
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, NULL, NULL, NULL) == 0
&& uci_add_section(uci_ctx, ptr.p, stype, s) == UCI_OK)
val = dmstrdup((*s)->e.name);