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

implement module. Pass to the new enum declaration format,add keep_regex,...

implement module. Pass to the new enum declaration format,add keep_regex, keep_environ function. Change get_mandatory by check_mandatory: more efficient and readable. Implement oneshot logger. Fix @user field parse
parent f923dbad
No related branches found
No related tags found
No related merge requests found
......@@ -221,17 +221,15 @@ int key_get_range(genalloc *ga, section_t *sasection)
pos = 0 ;
keynocheck nocheck = KEYNOCHECK_ZERO ;
nocheck.idsec = i ;
nocheck.idkey = KEY_ENVAL ;
nocheck.idkey = KEY_ENVIRON_ENVAL ;
nocheck.expected = EXPECT_KEYVAL ;
nocheck.mandatory = MANDATORY_OPTS ;
section_setsa(i,&psasection,sasection) ;
if (!stralloc_cats(&nocheck.val,psasection->s+1)) goto err ;//+1 remove the first '\n'
if (!environ_get_clean_env(&nocheck.val)) { log_warnu("parse section: ",get_key_by_enum(ENUM_SECTION,i)) ; goto err ; }
if (!stralloc_cats(&nocheck.val,"\n") ||
!stralloc_0(&nocheck.val)) goto err ;
nocheck.val.len-- ;
if (!genalloc_append(keynocheck,ga,&nocheck)) goto err ;
}
else
......@@ -260,7 +258,6 @@ int key_get_range(genalloc *ga, section_t *sasection)
nocheck.idsec = i ;
nocheck.idkey = list[i].list[j].id ;
nocheck.expected = list[i].list[j].expected ;
nocheck.mandatory = list[i].list[j].mandatory ;
found = 1 ;
switch(list[i].list[j].expected)
{
......@@ -323,178 +320,152 @@ int key_get_range(genalloc *ga, section_t *sasection)
return 0 ;
}
int get_mandatory(genalloc *nocheck,int idsec,int idkey)
int check_mandatory(sv_alltype *service, section_t *sasection)
{
int count, bkey, r, countidsec ;
key_all_t const *list = total_list ;
if (service->cname.description < 0)
log_warn_return(LOG_EXIT_ZERO,"key @description at section [start] must be set") ;
if (!service->user[0])
log_warn_return(LOG_EXIT_ZERO,"key @user at section [start] must be set") ;
stralloc sa = STRALLOC_ZERO ;
/** just warn here about the @version field to let the time to implement
* it inside all already existing service.
* It will be mandatory when 66-backup will be incorporated. */
if (service->cname.version < 0)
log_warn("key @version at section [start] is missing -- it will be mandatory in the near future") ;
r = -1 ;
count = 0 ;
bkey = -1 ;
countidsec = 0 ;
switch(list[idsec].list[idkey].mandatory){
if (service->opts[2] && !sasection->idx[SECTION_ENV])
log_warn_return(LOG_EXIT_ZERO,"options env was asked -- section environment must be set") ;
case MANDATORY_NEED:
for (unsigned int j = 0;j < genalloc_len(keynocheck,nocheck);j++)
{
if (genalloc_s(keynocheck,nocheck)[j].idsec == idsec)
{
countidsec++ ;
if (genalloc_s(keynocheck,nocheck)[j].idkey == get_enum_by_key(*list[idsec].list[idkey].name))
{
count++ ;
break ;
}
}
}
if ((!count) && (countidsec))
log_warn_return(LOG_EXIT_ZERO,"mandatory key: ",*list[idsec].list[idsec].name," not found on section: ",get_key_by_enum(ENUM_SECTION,idsec)) ;
switch (service->cname.itype)
{
case TYPE_BUNDLE:
if (service->cname.idga < 0)
log_warn_return(LOG_EXIT_ZERO,"bundle type detected -- key @contents must be set") ;
break ;
case MANDATORY_CUSTOM:
for (unsigned int j = 0;j < genalloc_len(keynocheck,nocheck);j++)
{
if (genalloc_s(keynocheck,nocheck)[j].idsec == idsec)
{
countidsec++ ;
if (genalloc_s(keynocheck,nocheck)[j].idkey == KEY_BUILD)
{
bkey = j ;
}
if (genalloc_s(keynocheck,nocheck)[j].idkey == get_enum_by_key(*list[idsec].list[idkey].name))
{
count++ ;
break ;
}
}
}
if ((!count) && (countidsec) && bkey>=0)
case TYPE_ONESHOT:
if (service->type.oneshot.up.build < 0)
log_warn_return(LOG_EXIT_ZERO,"key @build at section [start] must be set") ;
if ((service->type.oneshot.up.build == BUILD_CUSTOM) && (service->type.oneshot.up.shebang < 0))
log_warn_return(LOG_EXIT_ZERO,"custom build asked on section [start] -- key @shebang must be set") ;
if (service->type.oneshot.up.exec < 0)
log_warn_return(LOG_EXIT_ZERO,"key @execute at section [start] must be set") ;
if (sasection->idx[SECTION_STOP])
{
if (obstr_equal(genalloc_s(keynocheck,nocheck)[bkey].val.s,get_key_by_enum(ENUM_BUILD,BUILD_CUSTOM)))
log_warn_return(LOG_EXIT_ZERO,"custom build asked on section: ",get_key_by_enum(ENUM_SECTION,idsec)," -- key: ",*list[idsec].list[idkey].name," must be set") ;
if (service->type.oneshot.down.build < 0)
log_warn_return(LOG_EXIT_ZERO,"key @build at section [stop] must be set") ;
if ((service->type.oneshot.down.build == BUILD_CUSTOM) && (service->type.oneshot.down.shebang < 0))
log_warn_return(LOG_EXIT_ZERO,"custom build asked on section [stop] -- key @shebang must be set") ;
if (service->type.oneshot.down.exec < 0)
log_warn_return(LOG_EXIT_ZERO,"key @execute at section [stop] must be set") ;
}
break ;
case MANDATORY_BUNDLE:
for (unsigned int j = 0;j < genalloc_len(keynocheck,nocheck);j++)
{
if (genalloc_s(keynocheck,nocheck)[j].idsec == idsec)
{
countidsec++ ;
if (genalloc_s(keynocheck,nocheck)[j].idkey == KEY_TYPE)
{
bkey = j;
}
if (genalloc_s(keynocheck,nocheck)[j].idkey == get_enum_by_key(*list[idsec].list[idkey].name))
{
count++ ;
}
}
}
if ((!count) && (countidsec) && bkey>=0)
case TYPE_CLASSIC:
case TYPE_LONGRUN:
if (service->type.classic_longrun.run.build < 0)
log_warn_return(LOG_EXIT_ZERO,"key @build at section [start] must be set") ;
if ((service->type.classic_longrun.run.build == BUILD_CUSTOM) && (service->type.classic_longrun.run.shebang < 0))
log_warn_return(LOG_EXIT_ZERO,"custom build asked on section [start] -- key @shebang must be set") ;
if (service->type.classic_longrun.run.exec < 0)
log_warn_return(LOG_EXIT_ZERO,"key @execute at section [start] must be set") ;
if (sasection->idx[SECTION_STOP])
{
if (obstr_equal(genalloc_s(keynocheck,nocheck)[bkey].val.s,get_key_by_enum(ENUM_TYPE,TYPE_BUNDLE)))
log_warn_return(LOG_EXIT_ZERO,"bundle type detected -- key @contents must be set") ;
if (service->type.classic_longrun.finish.build < 0)
log_warn_return(LOG_EXIT_ZERO,"key @build at section [stop] must be set") ;
if ((service->type.classic_longrun.finish.build == BUILD_CUSTOM) && (service->type.classic_longrun.finish.shebang < 0))
log_warn_return(LOG_EXIT_ZERO,"custom build asked on section [stop] -- key @shebang must be set") ;
if (service->type.classic_longrun.finish.exec < 0)
log_warn_return(LOG_EXIT_ZERO,"key @execute at section [stop] must be set") ;
}
break ;
/** only pass through here to check if flags env was asked
* and the corresponding section exist*/
case MANDATORY_OPTS:
for (unsigned int j = 0;j < genalloc_len(keynocheck,nocheck);j++)
if (sasection->idx[SECTION_LOG])
{
if (genalloc_s(keynocheck,nocheck)[j].idsec == SECTION_ENV)
count++ ;
if (genalloc_s(keynocheck,nocheck)[j].idsec == SECTION_MAIN)
if (service->type.classic_longrun.log.run.build < 0)
log_warn_return(LOG_EXIT_ZERO,"key @build at section [logger] must be set") ;
if (service->type.classic_longrun.log.run.build == BUILD_CUSTOM)
{
if (genalloc_s(keynocheck,nocheck)[j].idkey == KEY_OPTIONS)
{
bkey = j;
}
if (service->type.classic_longrun.log.run.shebang < 0)
log_warn_return(LOG_EXIT_ZERO,"custom build asked on section [logger] -- key @shebang must be set") ;
if (service->type.classic_longrun.log.run.exec < 0)
log_warn_return(LOG_EXIT_ZERO,"custom build asked on section [logger] -- key @execute must be set") ;
if (service->type.classic_longrun.log.destination < 0)
log_warn_return(LOG_EXIT_ZERO,"custom build asked on section [logger] -- key @destination must be set") ;
}
}
if (bkey >= 0)
{
if (!sastr_clean_string(&sa,genalloc_s(keynocheck,nocheck)[bkey].val.s))
log_warnu_return(LOG_EXIT_ZERO,"clean value of: ",sa.s) ;
r = sastr_cmp(&sa,get_key_by_enum(ENUM_OPTS,OPTS_ENVIR)) ;
if ((r >= 0) && (!count))
log_warn_return(LOG_EXIT_ZERO,"options env was asked -- section environment must be set") ;
}
}
break ;
case TYPE_MODULE:
/*if (!sasection->idx[SECTION_REGEX])
log_warn_return(LOG_EXIT_ZERO,"section [regex] must be set") ;
if (service->type.module.iddir < 0)
log_warn_return(LOG_EXIT_ZERO,"key @directories at section [regex] must be set") ;
if (service->type.module.idfiles < 0)
log_warn_return(LOG_EXIT_ZERO,"key @files at section [regex] must be set") ;
if (service->type.module.start_infiles < 0)
log_warn_return(LOG_EXIT_ZERO,"key @infiles at section [regex] must be set") ;*/
break ;
/** really nothing to do here */
default: break ;
}
stralloc_free(&sa) ;
return 1 ;
}
int nocheck_toservice(keynocheck *nocheck,int svtype, sv_alltype *service)
{
int p ;
p = svtype ;
int p = svtype ;
int ste = 0 ;
while (ste < 6)
while (ste < 7)
{
unsigned int c = p - 0 ;
unsigned int action = actions[ste][p] ;
unsigned int action = actions[ste][c] ;
ste = states[ste][c] ;
switch (action) {
ste = states[ste][p] ;
switch (action) {
case ACTION_COMMON:
if (!nocheck->idsec)
if (nocheck->idsec == SECTION_MAIN)
if (!keep_common(service,nocheck,svtype))
return 0 ;
break ;
case ACTION_EXECRUN:
if (nocheck->idsec == 1)
if (nocheck->idsec == SECTION_START)
if (!keep_runfinish(&service->type.classic_longrun.run,nocheck))
return 0 ;
break ;
case ACTION_EXECFINISH:
if (nocheck->idsec == 2)
if (nocheck->idsec == SECTION_STOP)
if (!keep_runfinish(&service->type.classic_longrun.finish,nocheck))
return 0 ;
break ;
case ACTION_EXECLOG:
if (nocheck->idsec == 3)
if (nocheck->idsec == SECTION_LOG)
if (!keep_logger(&service->type.classic_longrun.log,nocheck))
return 0 ;
break ;
case ACTION_EXECUP:
if (nocheck->idsec == 1)
if (nocheck->idsec == SECTION_START)
if (!keep_runfinish(&service->type.oneshot.up,nocheck))
return 0 ;
return 0 ;
break ;
case ACTION_EXECDOWN:
if (nocheck->idsec == 2)
if (nocheck->idsec == SECTION_STOP)
if (!keep_runfinish(&service->type.oneshot.down,nocheck))
return 0 ;
break ;
case ACTION_ENVIRON:
if (nocheck->idsec == 4)
if (!keep_common(service,nocheck,svtype))
if (nocheck->idsec == SECTION_ENV)
if (!keep_environ(service,nocheck))
return 0 ;
break ;
case ACTION_REGEX:
if (nocheck->idsec == SECTION_REGEX)
if (!keep_regex(&service->type.module,nocheck))
return 0 ;
break ;
case ACTION_SKIP:
break ;
......@@ -513,28 +484,32 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
int r = 0 ;
size_t pos = 0, *chlen = &nocheck->val.len ;
char *chval = nocheck->val.s ;
switch(nocheck->idkey){
case KEY_TYPE:
case KEY_MAIN_TYPE:
r = get_enum(chval,nocheck) ;
if (r == -1) return 0 ;
service->cname.itype = r ;
break ;
case KEY_NAME:
case KEY_MAIN_NAME:
service->cname.name = keep.len ;
if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
break ;
case KEY_DESCRIPTION:
case KEY_MAIN_DESCRIPTION:
service->cname.description = keep.len ;
if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
break ;
case KEY_OPTIONS:
case KEY_MAIN_VERSION:
service->cname.version = keep.len ;
if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
break ;
case KEY_MAIN_OPTIONS:
if (!get_clean_val(nocheck)) return 0 ;
for (;pos < *chlen; pos += strlen(chval + pos)+1)
{
r = get_enum(chval + pos,nocheck) ;
if (r == -1) return 0 ;
if (svtype == TYPE_CLASSIC || svtype == TYPE_LONGRUN)
if (svtype != TYPE_BUNDLE || svtype != TYPE_MODULE)
{
if (r == OPTS_LOGGER)
service->opts[0] = 1 ;/**0 means not enabled*/
......@@ -545,7 +520,7 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
service->opts[2] = 1 ;
}
break ;
case KEY_FLAGS:
case KEY_MAIN_FLAGS:
if (!get_clean_val(nocheck)) return 0 ;
for (;pos < *chlen; pos += strlen(chval + pos)+1)
{
......@@ -557,14 +532,15 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
service->flags[1] = 1 ;
}
break ;
case KEY_USER:
case KEY_MAIN_USER:
if (!get_clean_val(nocheck)) return 0 ;
{
uid_t owner = MYUID ;
if (!owner)
{
if (sastr_find(&nocheck->val,"root") == -1)
log_warnu_return(LOG_EXIT_ZERO,"use service: ",keep.s+service->cname.name," -- permission denied") ;
log_warnu_return(LOG_EXIT_ZERO,"use the service -- permission denied") ;
}
/** special case, we don't know which user want to use
* the service, we need a general name to allow all user
......@@ -572,7 +548,17 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
ssize_t p = sastr_cmp(&nocheck->val,"user") ;
for (;pos < *chlen; pos += strlen(chval + pos)+1)
{
if (pos == (size_t)p) continue ;
if (pos == (size_t)p)
{
struct passwd *pw = getpwuid(owner);
if (!pw)
{
if (!errno) errno = ESRCH ;
log_warnu_return(LOG_EXIT_ZERO,"get user name") ;
}
scan_uidlist(pw->pw_name,(uid_t *)service->user) ;
continue ;
}
if (!scan_uidlist(chval + pos,(uid_t *)service->user))
{
parse_err(0,nocheck) ;
......@@ -587,11 +573,11 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
if (service->user[i] == owner) e = 1 ;
if (!e)
log_warnu_return(LOG_EXIT_ZERO,"use service: ",keep.s+service->cname.name," -- permission denied") ;
log_warnu_return(LOG_EXIT_ZERO,"use the service -- permission denied") ;
}
}
break ;
case KEY_HIERCOPY:
case KEY_MAIN_HIERCOPY:
if (!get_clean_val(nocheck)) return 0 ;
{
unsigned int idx = 0 ;
......@@ -605,9 +591,9 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
}
}
break ;
case KEY_DEPENDS:
case KEY_MAIN_DEPENDS:
if ((service->cname.itype == TYPE_CLASSIC) || (service->cname.itype == TYPE_BUNDLE))
log_warn_return(LOG_EXIT_ZERO,"key: ",get_key_by_enum(ENUM_KEY,nocheck->idkey),": is not valid for type ",get_key_by_enum(ENUM_TYPE,service->cname.itype)) ;
log_warn_return(LOG_EXIT_ZERO,"key: ",get_key_by_enum(ENUM_KEY_SECTION_MAIN,nocheck->idkey),": is not valid for type ",get_key_by_enum(ENUM_TYPE,service->cname.itype)) ;
if (!get_clean_val(nocheck)) return 0 ;
service->cname.idga = deps.len ;
......@@ -619,9 +605,9 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
service->cname.nga++ ;
}
break ;
case KEY_OPTSDEPS:
case KEY_MAIN_OPTSDEPS:
if ((service->cname.itype == TYPE_CLASSIC) || (service->cname.itype == TYPE_BUNDLE))
log_warn_return(LOG_EXIT_ZERO,"key: ",get_key_by_enum(ENUM_KEY,nocheck->idkey),": is not valid for type ",get_key_by_enum(ENUM_TYPE,service->cname.itype)) ;
log_warn_return(LOG_EXIT_ZERO,"key: ",get_key_by_enum(ENUM_KEY_SECTION_MAIN,nocheck->idkey),": is not valid for type ",get_key_by_enum(ENUM_TYPE,service->cname.itype)) ;
if (!get_clean_val(nocheck)) return 0 ;
service->cname.idopts = deps.len ;
for (;pos < *chlen; pos += strlen(chval + pos)+1)
......@@ -632,9 +618,9 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
service->cname.nopts++ ;
}
break ;
case KEY_EXTDEPS:
case KEY_MAIN_EXTDEPS:
if ((service->cname.itype == TYPE_CLASSIC) || (service->cname.itype == TYPE_BUNDLE))
log_warn_return(LOG_EXIT_ZERO,"key: ",get_key_by_enum(ENUM_KEY,nocheck->idkey),": is not valid for type ",get_key_by_enum(ENUM_TYPE,service->cname.itype)) ;
log_warn_return(LOG_EXIT_ZERO,"key: ",get_key_by_enum(ENUM_KEY_SECTION_MAIN,nocheck->idkey),": is not valid for type ",get_key_by_enum(ENUM_TYPE,service->cname.itype)) ;
if (!get_clean_val(nocheck)) return 0 ;
service->cname.idext = deps.len ;
for (;pos < *chlen; pos += strlen(chval + pos)+1)
......@@ -645,9 +631,9 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
service->cname.next++ ;
}
break ;
case KEY_CONTENTS:
case KEY_MAIN_CONTENTS:
if (service->cname.itype != TYPE_BUNDLE)
log_warn_return(LOG_EXIT_ZERO,"key: ",get_key_by_enum(ENUM_KEY,nocheck->idkey),": is not valid for type ",get_key_by_enum(ENUM_TYPE,service->cname.itype)) ;
log_warn_return(LOG_EXIT_ZERO,"key: ",get_key_by_enum(ENUM_KEY_SECTION_MAIN,nocheck->idkey),": is not valid for type ",get_key_by_enum(ENUM_TYPE,service->cname.itype)) ;
if (!get_clean_val(nocheck)) return 0 ;
service->cname.idga = deps.len ;
......@@ -659,34 +645,26 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype)
service->cname.nga++ ;
}
break ;
case KEY_T_KILL:
case KEY_T_FINISH:
case KEY_T_UP:
case KEY_T_DOWN:
case KEY_MAIN_T_KILL:
case KEY_MAIN_T_FINISH:
case KEY_MAIN_T_UP:
case KEY_MAIN_T_DOWN:
if (!get_timeout(nocheck,(uint32_t *)service->timeout)) return 0 ;
break ;
case KEY_DEATH:
case KEY_MAIN_DEATH:
if (!get_uint(nocheck,&service->death)) return 0 ;
break ;
case KEY_NOTIFY:
case KEY_MAIN_NOTIFY:
if (!get_uint(nocheck,&service->notification)) return 0 ;
break ;
case KEY_ENVAL:
if (!environ_clean_nline(&nocheck->val))
log_warnu_return(LOG_EXIT_ZERO,"clean environment value: ",chval) ;
if (!stralloc_cats(&nocheck->val,"\n")) return 0 ;
if (!stralloc_copy(&service->saenv,&nocheck->val))
log_warnu_return(LOG_EXIT_ZERO,"store environment value: ",chval) ;
break ;
case KEY_SIGNAL:
case KEY_MAIN_SIGNAL:
if (!sig0_scan(chval,&service->signal))
{
parse_err(3,nocheck) ;
return 0 ;
}
break ;
default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_key_by_enum(ENUM_KEY,nocheck->idkey)) ;
default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_key_by_enum(ENUM_KEY_SECTION_MAIN,nocheck->idkey)) ;
}
......@@ -698,20 +676,20 @@ int keep_runfinish(sv_exec *exec,keynocheck *nocheck)
int r = 0 ;
size_t *chlen = &nocheck->val.len ;
char *chval = nocheck->val.s ;
switch(nocheck->idkey)
{
case KEY_BUILD:
case KEY_STARTSTOP_BUILD:
r = get_enum(chval,nocheck) ;
if (r == -1) return 0 ;
exec->build = r ;
break ;
case KEY_RUNAS:
case KEY_STARTSTOP_RUNAS:
if (!check_valid_runas(nocheck)) return 0 ;
exec->runas = keep.len ;
if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
break ;
case KEY_SHEBANG:
case KEY_STARTSTOP_SHEBANG:
if (chval[0] != '/')
{
parse_err(4,nocheck) ;
......@@ -720,11 +698,11 @@ int keep_runfinish(sv_exec *exec,keynocheck *nocheck)
exec->shebang = keep.len ;
if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
break ;
case KEY_EXEC:
case KEY_STARTSTOP_EXEC:
exec->exec = keep.len ;
if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
break ;
default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_key_by_enum(ENUM_KEY,nocheck->idkey)) ;
default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_key_by_enum(ENUM_KEY_SECTION_STARTSTOP,nocheck->idkey)) ;
}
return 1 ;
}
......@@ -736,13 +714,13 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck)
char *chval = nocheck->val.s ;
switch(nocheck->idkey){
case KEY_BUILD:
case KEY_LOGGER_BUILD:
if (!keep_runfinish(&log->run,nocheck)) return 0 ;
break ;
case KEY_RUNAS:
case KEY_LOGGER_RUNAS:
if (!keep_runfinish(&log->run,nocheck)) return 0 ;
break ;
case KEY_DEPENDS:
case KEY_LOGGER_DEPENDS:
if (!get_clean_val(nocheck)) return 0 ;
log->idga = deps.len ;
for (;pos < *chlen; pos += strlen(chval + pos) + 1)
......@@ -751,17 +729,17 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck)
log->nga++ ;
}
break ;
case KEY_SHEBANG:
case KEY_LOGGER_SHEBANG:
if (!keep_runfinish(&log->run,nocheck)) return 0 ;
break ;
case KEY_EXEC:
case KEY_LOGGER_EXEC:
if (!keep_runfinish(&log->run,nocheck)) return 0 ;
break ;
case KEY_T_KILL:
case KEY_T_FINISH:
case KEY_LOGGER_T_KILL:
case KEY_LOGGER_T_FINISH:
if (!get_timeout(nocheck,(uint32_t *)log->timeout)) return 0 ;
break ;
case KEY_DESTINATION:
case KEY_LOGGER_DESTINATION:
if (chval[0] != '/')
{
parse_err(4,nocheck) ;
......@@ -770,18 +748,91 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck)
log->destination = keep.len ;
if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
break ;
case KEY_BACKUP:
case KEY_LOGGER_BACKUP:
if (!get_uint(nocheck,&log->backup)) return 0 ;
break ;
case KEY_MAXSIZE:
case KEY_LOGGER_MAXSIZE:
if (!get_uint(nocheck,&log->maxsize)) return 0 ;
break ;
case KEY_TIMESTP:
case KEY_LOGGER_TIMESTP:
r = get_enum(chval,nocheck) ;
if (r == -1) return 0 ;
log->timestamp = r ;
break ;
default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_key_by_enum(ENUM_KEY,nocheck->idkey)) ;
default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_key_by_enum(ENUM_KEY_SECTION_LOGGER,nocheck->idkey)) ;
}
return 1 ;
}
int keep_environ(sv_alltype *service,keynocheck *nocheck)
{
char *chval = nocheck->val.s ;
switch(nocheck->idkey){
case KEY_ENVIRON_ENVAL:
if (!environ_clean_nline(&nocheck->val))
log_warnu_return(LOG_EXIT_ZERO,"clean environment value: ",chval) ;
if (!stralloc_cats(&nocheck->val,"\n")) return 0 ;
if (!stralloc_copy(&service->saenv,&nocheck->val))
log_warnu_return(LOG_EXIT_ZERO,"store environment value: ",chval) ;
break ;
default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_key_by_enum(ENUM_KEY_SECTION_ENVIRON,nocheck->idkey)) ;
}
return 1 ;
}
int keep_regex(sv_module *module,keynocheck *nocheck)
{
size_t pos = 0, *chlen = &nocheck->val.len ;
char *chval = nocheck->val.s ;
switch(nocheck->idkey){
case KEY_REGEX_CONFIGURE:
module->configure = keep.len ;
if (!stralloc_catb(&keep,chval,*chlen + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
break ;
case KEY_REGEX_DIRECTORIES:
if (!get_clean_val(nocheck)) return 0 ;
module->iddir = keep.len ;
for (;pos < *chlen; pos += strlen(chval + pos) + 1)
{
/* allow to comment a service */
if (chval[pos] == '#') continue ;
if (!stralloc_catb(&keep,chval + pos,strlen(chval + pos) + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
module->ndir++ ;
}
break ;
case KEY_REGEX_FILES:
if (!get_clean_val(nocheck)) return 0 ;
module->idfiles = keep.len ;
for (;pos < *chlen; pos += strlen(chval + pos) + 1)
{
/* allow to comment a service */
if (chval[pos] == '#') continue ;
if (!stralloc_catb(&keep,chval + pos,strlen(chval + pos) + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
module->nfiles++ ;
}
break ;
case KEY_REGEX_INFILES:
if (!environ_get_clean_env(&nocheck->val))
log_warnu_return(LOG_EXIT_ZERO,"clean key ",get_key_by_enum(ENUM_KEY_SECTION_REGEX,nocheck->idkey)," field") ;
if (!environ_clean_nline(&nocheck->val))
log_warnu_return(LOG_EXIT_ZERO,"clean lines of key ",get_key_by_enum(ENUM_KEY_SECTION_REGEX,nocheck->idkey)," field") ;
if (!stralloc_0(&nocheck->val))
log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
if (!sastr_split_string_in_nline(&nocheck->val))
log_warnu_return(LOG_EXIT_SYS,"split lines of key ",get_key_by_enum(ENUM_KEY_SECTION_REGEX,nocheck->idkey)," field") ;
module->start_infiles = keep.len ;
for (;pos < *chlen; pos += strlen(chval + pos) + 1)
if (!stralloc_catb(&keep,chval + pos,strlen(chval + pos) + 1))
log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
module->end_infiles = keep.len ;
break ;
default: log_warn_return(LOG_EXIT_ZERO,"unknown key: ",get_key_by_enum(ENUM_KEY_SECTION_REGEX,nocheck->idkey)) ;
}
return 1 ;
}
......@@ -801,7 +852,7 @@ int read_svfile(stralloc *sasv,char const *name,char const *src)
memcpy(svtmp + srclen + 1, name, namelen) ;
svtmp[srclen + 1 + namelen] = 0 ;
log_trace("Read service file of : ",name," from: ",src) ;
log_trace("Read service file of: ",src,name) ;
size_t filesize=file_get_size(svtmp) ;
if (!filesize)
......@@ -880,6 +931,7 @@ void section_setsa(int id, stralloc_ref *p,section_t *sa)
case SECTION_STOP: *p = &sa->stop ; break ;
case SECTION_LOG: *p = &sa->logger ; break ;
case SECTION_ENV: *p = &sa->environment ; break ;
case SECTION_REGEX: *p = &sa->regex ; break ;
default: break ;
}
}
......@@ -979,10 +1031,10 @@ int get_enum(char const *str, keynocheck *ch)
int get_timeout(keynocheck *ch,uint32_t *ui)
{
int time = 0 ;
if (ch->idkey == KEY_T_KILL) time = 0 ;
else if (ch->idkey == KEY_T_FINISH) time = 1 ;
else if (ch->idkey == KEY_T_UP) time = 2 ;
else if (ch->idkey == KEY_T_DOWN) time = 3 ;
if ((ch->idkey == KEY_MAIN_T_KILL) || (ch->idkey == KEY_LOGGER_T_KILL)) time = 0 ;
else if ((ch->idkey == KEY_MAIN_T_FINISH) || (ch->idkey == KEY_LOGGER_T_FINISH)) time = 1 ;
else if (ch->idkey == KEY_MAIN_T_UP) time = 2 ;
else if (ch->idkey == KEY_MAIN_T_DOWN) time = 3 ;
if (scan_timeout(ch->val.s,ui,time) == -1)
{
parse_err(3,ch) ;
......@@ -1018,7 +1070,10 @@ void parse_err(int ierr,keynocheck *check)
int idsec = check->idsec ;
int idkey = check->idkey ;
char const *section = get_key_by_enum(ENUM_SECTION,idsec) ;
char const *key = get_key_by_enum(ENUM_KEY,idkey) ;
/* start stop enum are the same, enum_all must increase by one to match
* the correct list */
char const *key = get_key_by_enum(idsec < 2 ? idsec + 1 : idsec,idkey) ;
switch(ierr)
{
case 0:
......@@ -1056,3 +1111,23 @@ void parse_err(int ierr,keynocheck *check)
break ;
}
}
int get_svtype(sv_alltype *sv_before, char const *contents)
{
stralloc sa = STRALLOC_ZERO ;
if (!auto_stra(&sa,contents)) goto err ;
if (!environ_get_val_of_key(&sa,get_key_by_enum(ENUM_KEY_SECTION_MAIN,KEY_MAIN_TYPE))) goto err ;
if (!sastr_clean_element(&sa)) goto err ;
sv_before->cname.itype = get_enum_by_key(sa.s) ;
if (sv_before->cname.itype == -1) goto err ;
stralloc_free(&sa) ;
return 1 ;
err:
stralloc_free(&sa) ;
return 0 ;
}
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