Skip to content
Snippets Groups Projects
Commit f845397b authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

Use new environment function

parent 1ca1e839
No related branches found
No related tags found
No related merge requests found
......@@ -31,41 +31,15 @@ int tree_seed_parse_file(tree_seed_t *seed, char const *seedpath)
{
log_flow() ;
int r, e = 0 ;
stralloc sa = STRALLOC_ZERO ;
int r ;
size_t pos = 0 ;
_alloc_sa_(sa) ;
size_t filesize=file_get_size(seedpath) ;
if (!filesize) {
log_warn(seedpath," is empty") ;
goto err ;
}
r = openreadfileclose(seedpath, &sa, filesize) ;
if(!r) {
log_warnusys("open ", seedpath) ;
goto err ;
}
/** ensure that we have an empty line at the end of the string*/
if (!auto_stra(&sa,"\n"))
log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
if (!environ_get_clean_env(&sa)) {
log_warnu("clean seed file: ", seedpath) ;
goto err ;
}
if (!sastr_split_string_in_nline(&sa))
goto err ;
if (!environ_merge_file(&sa, seedpath))
log_warn_return(LOG_EXIT_ZERO, "merge seed file: ", seedpath) ;
FOREACH_SASTR(&sa, pos) {
char *line = sa.s + pos, *key = 0, *val = 0 ;
size_t len = strlen(line) ;
......@@ -76,7 +50,7 @@ int tree_seed_parse_file(tree_seed_t *seed, char const *seedpath)
/** should never happens */
if (r == -1) {
log_warn("invalid format of key: ",line," -- please make a bug report") ;
goto err ;
return 0 ;
}
key = tmp ;
......@@ -90,7 +64,7 @@ int tree_seed_parse_file(tree_seed_t *seed, char const *seedpath)
seed->depends = seed->sa.len ;
if (!sastr_add_string(&seed->sa, val))
goto err ;
return 0 ;
seed->nopts++ ;
......@@ -100,7 +74,7 @@ int tree_seed_parse_file(tree_seed_t *seed, char const *seedpath)
seed->requiredby = seed->sa.len ;
if (!sastr_add_string(&seed->sa, val))
goto err ;
return 0 ;
seed->nopts++ ;
......@@ -119,7 +93,7 @@ int tree_seed_parse_file(tree_seed_t *seed, char const *seedpath)
seed->allow = seed->sa.len ;
if (!sastr_add_string(&seed->sa, val))
goto err ;
return 0 ;
seed->nopts++ ;
......@@ -129,7 +103,7 @@ int tree_seed_parse_file(tree_seed_t *seed, char const *seedpath)
seed->deny = seed->sa.len ;
if (!sastr_add_string(&seed->sa, val))
goto err ;
return 0 ;
seed->nopts++ ;
......@@ -149,12 +123,12 @@ int tree_seed_parse_file(tree_seed_t *seed, char const *seedpath)
if (strcmp(val,TREE_GROUPS_BOOT) && strcmp(val,TREE_GROUPS_ADM) && strcmp(val,TREE_GROUPS_USER)) {
log_warn("invalid group: ", val) ;
goto err ;
return 0 ;
}
seed->groups = seed->sa.len ;
if (!sastr_add_string(&seed->sa, val))
goto err ;
return 0 ;
seed->nopts++ ;
......@@ -163,13 +137,10 @@ int tree_seed_parse_file(tree_seed_t *seed, char const *seedpath)
default :
log_warn("unknown key: ", key, " -- ignoring") ;
goto err ;
return 0 ;
}
}
e = 1 ;
err:
stralloc_free(&sa) ;
return e ;
return 1 ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment