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

add optsdepends features

parent ad9f7c13
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ enum key_enum_e ...@@ -33,6 +33,7 @@ enum key_enum_e
DESCRIPTION , DESCRIPTION ,
CONTENTS , CONTENTS ,
DEPENDS , DEPENDS ,
OPTSDEPS ,
OPTIONS , OPTIONS ,
NOTIFY , NOTIFY ,
USER , USER ,
...@@ -120,6 +121,7 @@ static key_description_t const main_section_list[] = ...@@ -120,6 +121,7 @@ static key_description_t const main_section_list[] =
{ .name = "@name", .expected = LINE, .mandatory = OPTS }, { .name = "@name", .expected = LINE, .mandatory = OPTS },
{ .name = "@description", .expected = QUOTE, .mandatory = OPTS }, { .name = "@description", .expected = QUOTE, .mandatory = OPTS },
{ .name = "@depends", .expected = BRACKET, .mandatory = OPTS }, { .name = "@depends", .expected = BRACKET, .mandatory = OPTS },
{ .name = "@optsdepends", .expected = BRACKET, .mandatory = OPTS },
{ .name = "@contents", .expected = BRACKET, .mandatory = BUNDLE }, { .name = "@contents", .expected = BRACKET, .mandatory = BUNDLE },
{ .name = "@options", .expected = BRACKET, .mandatory = OPTS }, { .name = "@options", .expected = BRACKET, .mandatory = OPTS },
{ .name = "@flags", .expected = BRACKET, .mandatory = OPTS }, { .name = "@flags", .expected = BRACKET, .mandatory = OPTS },
...@@ -166,7 +168,7 @@ static key_description_t const environment_section_list[] = ...@@ -166,7 +168,7 @@ static key_description_t const environment_section_list[] =
{ .name = 0 } { .name = 0 }
} ; } ;
static int const total_list_el[6] = { 17, 5, 5, 12, 2, 0 } ; static int const total_list_el[6] = { 18, 5, 5, 12, 2, 0 } ;
static key_all_t const total_list[] = static key_all_t const total_list[] =
{ {
......
...@@ -104,8 +104,10 @@ struct sv_name_s ...@@ -104,8 +104,10 @@ struct sv_name_s
int itype ;/**int type =30->classic,31->bundle,32->longrun,33->oneshot*/ int itype ;/**int type =30->classic,31->bundle,32->longrun,33->oneshot*/
int name ;//pos in keep int name ;//pos in keep
unsigned int description ;//pos in keep unsigned int description ;//pos in keep
unsigned int idga ; //pos in genalloc gadeps unsigned int idga ; //pos in genalloc gadeps-> depends field
unsigned int nga ; //len of idga in genalloc gadeps unsigned int nga ; //number or deps in genalloc gadeps->depends field
unsigned int idopts ;// pos in genalloc gadeps -> optional depends
unsigned int nopts ; // number of optinal depends in genalloc gadeps->optional depends
unsigned int logname ; //pos in keep unsigned int logname ; //pos in keep
unsigned int dstlog ; //pos in keep unsigned int dstlog ; //pos in keep
} ; } ;
...@@ -253,8 +255,9 @@ extern void freed_parser(void) ; ...@@ -253,8 +255,9 @@ extern void freed_parser(void) ;
/** enable phase */ /** enable phase */
extern int parser(sv_alltype *service,stralloc *src,char const *svname) ; extern int parser(sv_alltype *service,stralloc *src,char const *svname) ;
extern int parse_service_check_enabled(ssexec_t *info, char const *svname,uint8_t force,uint8_t *exist) ; extern int parse_service_check_enabled(ssexec_t *info, char const *svname,uint8_t force,uint8_t *exist) ;
extern int parse_service_before(ssexec_t *info, stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist) ; extern int parse_service_before(ssexec_t *info, stralloc *parsed_list, stralloc *opts_deps_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist) ;
extern int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force) ; extern int parse_service_deps(ssexec_t *info,stralloc *parsed_list, stralloc *opts_deps_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force) ;
extern int parse_service_opts_deps(ssexec_t *info,stralloc *parsed_list,stralloc *opts_deps_list,sv_alltype *sv_before,char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force) ;
extern int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv,uid_t owner) ; extern int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv,uid_t owner) ;
/** split */ /** split */
extern int section_get_range(section_t *sasection,stralloc *src) ; extern int section_get_range(section_t *sasection,stralloc *src) ;
......
...@@ -31,6 +31,7 @@ char const *get_keybyid(key_enum_t key) ...@@ -31,6 +31,7 @@ char const *get_keybyid(key_enum_t key)
(key == DESCRIPTION ) ? "@description" : (key == DESCRIPTION ) ? "@description" :
(key == CONTENTS ) ? "@contents" : (key == CONTENTS ) ? "@contents" :
(key == DEPENDS ) ? "@depends" : (key == DEPENDS ) ? "@depends" :
(key == OPTSDEPS ) ? "@optsdepends" :
(key == OPTIONS ) ? "@options" : (key == OPTIONS ) ? "@options" :
(key == NOTIFY ) ? "@notify" : (key == NOTIFY ) ? "@notify" :
(key == USER ) ? "@user" : (key == USER ) ? "@user" :
......
...@@ -92,7 +92,7 @@ int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *se ...@@ -92,7 +92,7 @@ int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *se
return 0 ; return 0 ;
} }
int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force) int parse_service_deps(ssexec_t *info,stralloc *parsed_list,stralloc *opts_deps_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force)
{ {
uint8_t exist = 0 ; uint8_t exist = 0 ;
char *dname = 0 ; char *dname = 0 ;
...@@ -113,7 +113,7 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo ...@@ -113,7 +113,7 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo
log_warnu("resolve source path of: ",dname) ; log_warnu("resolve source path of: ",dname) ;
goto err ; goto err ;
} }
if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,&exist)) goto err ; if (!parse_service_before(info,parsed_list,opts_deps_list,newsv.s,nbsv,sasv,force,&exist)) goto err ;
} }
} }
else log_trace(sv,": haven't dependencies") ; else log_trace(sv,": haven't dependencies") ;
...@@ -124,7 +124,70 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo ...@@ -124,7 +124,70 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo
return 0 ; return 0 ;
} }
int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist) int parse_service_opts_deps(ssexec_t *info,stralloc *parsed_list,stralloc *opts_deps_list,sv_alltype *sv_before,char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force)
{
stralloc newsv = STRALLOC_ZERO ;
size_t pos = 0 , baselen = strlen(info->base.s) + SS_SYSTEM_LEN ;
uint8_t exist = 0, found = 0 ;
char *optname = 0 ;
char btmp[baselen + 1] ;
auto_strings(btmp,info->base.s,SS_SYSTEM) ;
// only pass here for the first time
if (!opts_deps_list->len)
{
if (!sastr_dir_get(opts_deps_list, btmp,SS_BACKUP + 1, S_IFDIR)) log_warnusys_return(LOG_EXIT_ZERO,"get list of tree at: ",btmp) ;
}
if (sv_before->cname.nopts)
{
// may have no tree yet
if (opts_deps_list->len)
{
size_t id = sv_before->cname.idopts, nid = sv_before->cname.nopts ;
for (;nid; id += strlen(deps.s + id) + 1, nid--)
{
newsv.len = 0 ;
optname = deps.s + id ;
for(pos = 0 ; pos < opts_deps_list->len ; pos += strlen(opts_deps_list->s + pos) +1 )
{
found = 0 ;
char *tree = opts_deps_list->s + pos ;
size_t treelen = strlen(tree) ;
char tmp[baselen + 1 + treelen + SS_SVDIRS_LEN + 1] ;
auto_strings(tmp,btmp,"/",tree,SS_SVDIRS) ;
// already added on a tree
if (ss_resolve_check(tmp,optname))
{
found = 1 ;
log_trace("optional service dependency: ",optname," is already enabled at tree: ",btmp,"/",tree) ;
break ;
}
}
if (!found)
{
if (!ss_resolve_src_path(&newsv,optname,info))
{
log_warnu_return(LOG_EXIT_ZERO,"resolve source path of: ",optname) ;
goto err ;
}
if (!parse_service_before(info,parsed_list,opts_deps_list,newsv.s,nbsv,sasv,force,&exist))
goto err ;
}
}
}
}
stralloc_free(&newsv) ;
return 1 ;
err:
stralloc_free(&newsv) ;
return 0 ;
}
int parse_service_before(ssexec_t *info,stralloc *parsed_list,stralloc *opts_deps_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist)
{ {
int r, insta ; int r, insta ;
...@@ -204,8 +267,10 @@ int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,un ...@@ -204,8 +267,10 @@ int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,un
if (!parse_add_service(parsed_list,&sv_before,svpath,nbsv,info->owner)) return 0 ; if (!parse_add_service(parsed_list,&sv_before,svpath,nbsv,info->owner)) return 0 ;
if ((sv_before.cname.itype > CLASSIC && force > 1) || !(*exist)) if ((sv_before.cname.itype > CLASSIC && force > 1) || !(*exist))
if (!parse_service_deps(info,parsed_list,&sv_before,sv,nbsv,sasv,force)) return 0 ; {
if (!parse_service_deps(info,parsed_list,opts_deps_list,&sv_before,sv,nbsv,sasv,force)) return 0 ;
if (!parse_service_opts_deps(info,parsed_list,opts_deps_list,&sv_before,sv,nbsv,sasv,force)) return 0 ;
}
freed: freed:
return 1 ; return 1 ;
} }
...@@ -634,6 +634,17 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) ...@@ -634,6 +634,17 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
service->cname.nga++ ; service->cname.nga++ ;
} }
break ; break ;
case OPTSDEPS:
if ((service->cname.itype == CLASSIC) || (service->cname.itype == BUNDLE))
log_warn_return(LOG_EXIT_ZERO,"key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ;
if (!get_clean_val(nocheck)) return 0 ;
service->cname.idopts = deps.len ;
for (;pos < *chlen; pos += strlen(chval + pos)+1)
{
if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
service->cname.nopts++ ;
}
break ;
case CONTENTS: case CONTENTS:
if (service->cname.itype != BUNDLE) if (service->cname.itype != BUNDLE)
log_warn_return(LOG_EXIT_ZERO,"key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; log_warn_return(LOG_EXIT_ZERO,"key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ;
......
...@@ -61,7 +61,8 @@ static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv) ...@@ -61,7 +61,8 @@ static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv)
size_t i = 0, len = list->len ; size_t i = 0, len = list->len ;
stralloc sasv = STRALLOC_ZERO ; stralloc sasv = STRALLOC_ZERO ;
stralloc tmp = STRALLOC_ZERO ; stralloc parsed_list = STRALLOC_ZERO ;
stralloc opts_deps_list = STRALLOC_ZERO ;
for (;i < len; i += strlen(list->s + i) + 1) for (;i < len; i += strlen(list->s + i) + 1)
{ {
...@@ -73,11 +74,12 @@ static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv) ...@@ -73,11 +74,12 @@ static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv)
r = parse_service_check_enabled(info,svname,FORCE,&exist) ; r = parse_service_check_enabled(info,svname,FORCE,&exist) ;
if (!r) log_dieu(LOG_EXIT_SYS,"check enabled service: ",svname) ; if (!r) log_dieu(LOG_EXIT_SYS,"check enabled service: ",svname) ;
if (r == 2) continue ; if (r == 2) continue ;
if (!parse_service_before(info,&tmp,name,nbsv,&sasv,FORCE,&exist)) if (!parse_service_before(info,&parsed_list,&opts_deps_list,name,nbsv,&sasv,FORCE,&exist))
log_dieu(LOG_EXIT_SYS,"parse service file: ",svname,": or its dependencies") ; log_dieu(LOG_EXIT_SYS,"parse service file: ",svname,": or its dependencies") ;
} }
stralloc_free(&sasv) ; stralloc_free(&sasv) ;
stralloc_free(&tmp) ; stralloc_free(&parsed_list) ;
stralloc_free(&opts_deps_list) ;
} }
int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssexec_t *info) int ssexec_enable(int argc, char const *const *argv,char const *const *envp,ssexec_t *info)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment