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

clean code and remove useless function

parent 0a72621f
No related branches found
No related tags found
No related merge requests found
...@@ -19,23 +19,10 @@ ...@@ -19,23 +19,10 @@
#include <skalibs/genalloc.h> #include <skalibs/genalloc.h>
#include <66/ssexec.h> #include <66/ssexec.h>
extern int db_cmd_master(unsigned int verbosity,char const *cmd) ;
extern int db_update_master(int argc, char const *const *argv) ;
extern int db_bundle_modif(genalloc *bundle,unsigned int verbosity, char const *src, unsigned int action) ;
//extern int db_bundle_contents(graph_t *g, char const *name, char const *src, unsigned int verbosity, unsigned int action) ;
extern int db_write_contents(genalloc *ga, char const *bundle,char const *dir) ;
extern int db_write_master(ssexec_t *info, genalloc *ga, char const *dir,int both) ;
extern int db_compile(char const *workdir, char const *tree, char const *treename,char const *const *envp) ; extern int db_compile(char const *workdir, char const *tree, char const *treename,char const *const *envp) ;
extern int db_find_compiled_state(char const *livetree, char const *treename) ; extern int db_find_compiled_state(char const *livetree, char const *treename) ;
extern int db_get_permissions(stralloc *uid, char const *tree) ;
extern int db_update(char const *newdb, ssexec_t *info,char const *const *envp) ; extern int db_update(char const *newdb, ssexec_t *info,char const *const *envp) ;
extern int db_ok(char const *livetree, char const *treename) ; extern int db_ok(char const *livetree, char const *treename) ;
extern int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) ; extern int db_switch_to(ssexec_t *info, char const *const *envp,unsigned int where) ;
#endif #endif
/*
* db_cmd_start.c
*
* Copyright (c) 2018-2019 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include <66/db.h>
#include <s6-rc/config.h>//S6RC_BINPREFIX
#include <sys/stat.h>
#include <unistd.h>
#include <oblibs/error2.h>
#include <oblibs/string.h>
#include <oblibs/stralist.h>
#include <oblibs/files.h>
#include <oblibs/obgetopt.h>
#include <oblibs/directory.h>
#include <oblibs/strakeyval.h>
#include <skalibs/types.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/djbunix.h>
#include <skalibs/avltree.h>
#include <66/constants.h>
#include <66/parser.h>
#include <66/utils.h>
#include <stdio.h>
//USAGE "db_update_start [ -v verbosity ] [ -a add ] [ -d delete ] [ -c copy to ] [ -B bundle ] [ -D directory ] service"
// -c -> copy the contents file to the given directory, in this case service is not mandatory
int db_update_master(int argc, char const *const *argv)
{
int r ;
unsigned int add, del, copy, verbosity ;
verbosity = 1 ;
add = del = copy = 0 ;
stralloc contents = STRALLOC_ZERO ;
stralloc tocopy = STRALLOC_ZERO ;
genalloc in = GENALLOC_ZERO ;//type stralist
genalloc gargv = GENALLOC_ZERO ;//type stralist
char const *bundle = 0 ;
char const *dir = 0 ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = getopt_args(argc,argv, "v:adc:D:B:", &l) ;
if (opt == -1) break ;
if (opt == -2){ strerr_warnw1x("options must be set first") ; return 0 ; }
switch (opt)
{
case 'v' : if (!uint0_scan(l.arg, &verbosity)) return 0 ; break ;
case 'a' : add = 1 ; if (del) return 0 ; break ;
case 'd' : del = 1 ; if (add) return 0 ; break ;
case 'D' : dir = l.arg ; break ;
case 'B' : bundle = l.arg ; break ;
case 'c' : copy = 1 ;
if(!stralloc_cats(&tocopy,l.arg)) return 0 ;
if(!stralloc_0(&tocopy)) return 0 ;
break ;
default : return 0 ;
}
}
argc -= l.ind ; argv += l.ind ;
}
if (argc < 1 && !copy) return 0 ;
if (!add && !del && !copy) return 0 ;
if (!dir) return 0 ;
if (!bundle) bundle = SS_MASTER ;
if (copy)
if (dir_scan_absopath(tocopy.s) < 0) return 0 ;
size_t dirlen = strlen(dir) ;
size_t bundlen = strlen(bundle) ;
size_t newlen ;
char dst[dirlen + SS_DB_LEN + SS_SRC_LEN + bundlen + 1 + SS_CONTENTS_LEN + 1] ;
if (dir_scan_absopath(dir) < 0) goto err ;
for(;*argv;argv++)
if (!stra_add(&gargv,*argv)) retstralloc(111,"main") ;
memcpy(dst, dir, dirlen) ;
memcpy(dst + dirlen, SS_DB, SS_DB_LEN) ;
memcpy(dst + dirlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ;
dst[dirlen + SS_DB_LEN + SS_SRC_LEN] = '/' ;
memcpy(dst + dirlen + SS_DB_LEN + SS_SRC_LEN + 1, bundle, bundlen) ;
dst[dirlen + SS_DB_LEN + SS_SRC_LEN + 1 + bundlen] = '/' ;
newlen = dirlen + SS_DB_LEN + SS_SRC_LEN + 1 + bundlen + 1 ;
memcpy(dst + newlen, SS_CONTENTS, SS_CONTENTS_LEN) ;
dst[newlen + SS_CONTENTS_LEN] = 0 ;
size_t filesize=file_get_size(dst) ;
r = openreadfileclose(dst,&contents,filesize) ;
if(!r)
{
VERBO3 strerr_warnwu2sys("open: ", dst) ;
goto err ;
}
/** ensure that we have an empty line at the end of the string*/
if (!stralloc_cats(&contents,"\n")) goto err ;
if (!stralloc_0(&contents)) goto err ;
if (!clean_val(&in,contents.s))
{
VERBO3 strerr_warnwu2x("clean: ",contents.s) ;
goto err ;
}
contents = stralloc_zero ;
if (add)
{
for (unsigned int i = 0 ; i < genalloc_len(stralist,&gargv) ; i++)
{
if (!stra_cmp(&in,gaistr(&gargv,i)))
{
if (!stra_add(&in,gaistr(&gargv,i)))
{
VERBO3 strerr_warnwu4x("add: ",gaistr(&gargv,i)," in ",dst) ;
goto err ;
}
}
}
}
if (del)
{
for (unsigned int i = 0 ; i < genalloc_len(stralist,&gargv) ; i++)
{
if (stra_cmp(&in,gaistr(&gargv,i)))
{
if (!stra_remove(&in,gaistr(&gargv,i)))
{
VERBO3 strerr_warnwu4x("remove: ",gaistr(&gargv,i)," in ",dst) ;
goto err ;
}
}
}
}
for (unsigned int i =0 ; i < genalloc_len(stralist,&in); i++)
{
if (!stralloc_cats(&contents,gaistr(&in,i))) goto err ;
if (!stralloc_cats(&contents,"\n")) goto err ;
}
dst[newlen] = 0 ;
r = file_write_unsafe(dst,"contents",contents.s,contents.len) ;
if (!r)
{
VERBO3 strerr_warnwu3sys("write: ",dst,"contents") ;
goto err ;
}
if (copy)
{
r = file_write_unsafe(tocopy.s,"contents",contents.s,contents.len) ;
if (!r)
{
VERBO3 strerr_warnwu3sys("write: ",tocopy.s,"/contents") ;
goto err ;
}
}
stralloc_free(&contents) ;
genalloc_deepfree(stralist,&in,stra_free) ;
genalloc_deepfree(stralist,&gargv,stra_free) ;
return 1 ;
err:
stralloc_free(&contents) ;
genalloc_deepfree(stralist,&in,stra_free) ;
genalloc_deepfree(stralist,&gargv,stra_free) ;
return 0 ;
}
int db_cmd_master(unsigned int verbosity,char const *cmd)
{
int r ;
genalloc opts = GENALLOC_ZERO ;
if (!clean_val(&opts,cmd))
{
VERBO3 strerr_warnwu2x("clean: ",cmd) ;
genalloc_deepfree(stralist,&opts,stra_free) ;
return 0 ;
}
int newopts = 4 + genalloc_len(stralist,&opts) ;
char const *newargv[newopts] ;
unsigned int m = 0 ;
char fmt[UINT_FMT] ;
fmt[uint_fmt(fmt, verbosity)] = 0 ;
newargv[m++] = "update_start" ;
newargv[m++] = "-v" ;
newargv[m++] = fmt ;
for (unsigned int i = 0; i < genalloc_len(stralist,&opts); i++)
newargv[m++] = gaistr(&opts,i) ;
newargv[m++] = 0 ;
r = db_update_master(newopts,newargv) ;
genalloc_deepfree(stralist,&opts,stra_free) ;
return r ;
}
/** action = 0 -> delete, action = 1 -> add, default delete*/
int db_bundle_modif(genalloc *bundle,unsigned int verbosity, char const *src,unsigned int action)
{
unsigned int i = 0 ;
size_t salen ;
stralloc update = STRALLOC_ZERO ;
char *what ;
if (action) what = "-a" ;
else what = "-d" ;
if (!stralloc_cats(&update,what)) return 0 ;
if (!stralloc_cats(&update," -D ")) return 0 ;
if (!stralloc_cats(&update,src)) return 0 ;
if (!stralloc_cats(&update," ")) return 0 ;
salen = update.len ;
for (;i < genalloc_len(strakeyval,bundle) ; i++)
{
update.len = salen ;
char *bname = gaikvkey(bundle,i) ;
char *svname = gaikvval(bundle,i) ;
if (!stralloc_cats(&update,"-B ")) return 0 ;
if (!stralloc_cats(&update,bname)) return 0 ;
if (!stralloc_cats(&update," ")) return 0 ;
if (!stralloc_cats(&update,svname)) return 0 ;
if (!stralloc_0(&update)) return 0 ;
if (!db_cmd_master(verbosity,update.s))
{
strerr_warnwu2x("update contents of bundle: ",bname) ;
return 0 ;
}
}
stralloc_free(&update) ;
return 1 ;
}
/*
int db_bundle_contents(graph_t *g, char const *name, char const *src, unsigned int verbosity, unsigned int action)
{
unsigned int a, b, c ;
int r = 0 ;
genalloc bundle = GENALLOC_ZERO ;
char const *string = g->string ;
for (a = 0 ; a < g->nvertex ; a++)
{
char const *bname = string + genalloc_s(vertex_graph_t,&g->vertex)[a].name ;
if (genalloc_s(vertex_graph_t,&g->vertex)[a].type == BUNDLE)
{
for (b = 0 ; b < genalloc_s(vertex_graph_t,&g->vertex)[a].ndeps; b++)
{
char const *depname = string + genalloc_s(vertex_graph_t,&genalloc_s(vertex_graph_t,&g->vertex)[a].dps)[b].name ;
if(obstr_equal(name,depname))
{
for(c = 0; c < genalloc_len(strakeyval,&bundle) ; c++)
{
r = obstr_equal(depname,gaikvkey(&bundle,c)) ;
if (r) break ;
}
if (!r)
if (!strakv_add(&bundle,bname,name)) return 0 ;
}
}
}
}
if (genalloc_len(strakeyval,&bundle))
{
if (!db_bundle_modif(&bundle,verbosity,src,action))
goto err ;
}
genalloc_free(strakeyval,&bundle) ;
return 1 ;
err:
genalloc_free(strakeyval,&bundle) ;
return 0 ;
}
*/
int db_write_contents(genalloc *ga, char const *bundle,char const *dir)
{
int r ;
stralloc in = STRALLOC_ZERO ;
size_t dirlen = strlen(dir) ;
size_t bundlen = strlen(bundle) ;
char dst[dirlen + SS_DB_LEN + SS_SRC_LEN + 1 + bundlen + 1] ;
memcpy(dst, dir, dirlen) ;
memcpy(dst + dirlen, SS_DB, SS_DB_LEN) ;
memcpy(dst + dirlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ;
dst[dirlen + SS_DB_LEN + SS_SRC_LEN] = '/' ;
memcpy(dst + dirlen + SS_DB_LEN + SS_SRC_LEN + 1, bundle, bundlen) ;
dst[dirlen + SS_DB_LEN + SS_SRC_LEN + 1 + bundlen] = 0 ;
for (unsigned int i = 0 ; i < genalloc_len(stralist,ga); i++)
{
if (!stralloc_cats(&in,gaistr(ga,i))) goto err ;
if (!stralloc_cats(&in,"\n")) goto err ;
}
r = file_write_unsafe(dst,SS_CONTENTS,in.s,in.len) ;
if (!r)
{
VERBO3 strerr_warnwu3sys("write: ",dst,"contents") ;
goto err ;
}
stralloc_free(&in) ;
return 1 ;
err:
stralloc_free(&in) ;
return 0 ;
}
/*
int db_write_master(ssexec_t *info, genalloc *ga, char const *dir,int both)
{
int r ;
char ownerstr[256] ;
size_t ownerlen = uid_fmt(ownerstr,info->owner) ;
ownerstr[ownerlen] = 0 ;
stralloc in = STRALLOC_ZERO ;
stralloc inres = STRALLOC_ZERO ;
ss_resolve_t res = RESOLVE_ZERO ;
size_t dirlen = strlen(dir) ;
char runat[info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN + SS_MASTER_LEN + 1] ;
memcpy(runat,info->livetree.s,info->livetree.len) ;
runat[info->livetree.len] = '/' ;
memcpy(runat + info->livetree.len + 1,info->treename.s,info->treename.len) ;
memcpy(runat + info->livetree.len + 1 + info->treename.len, SS_SVDIRS,SS_SVDIRS_LEN) ;
memcpy(runat + info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN, SS_MASTER, SS_MASTER_LEN) ;
runat[info->livetree.len + 1 + info->treename.len + SS_SVDIRS_LEN + SS_MASTER_LEN] = 0 ;
char dst[dirlen + SS_DB_LEN + SS_SRC_LEN + SS_MASTER_LEN + 1] ;
memcpy(dst, dir, dirlen) ;
memcpy(dst + dirlen, SS_DB, SS_DB_LEN) ;
memcpy(dst + dirlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ;
memcpy(dst + dirlen + SS_DB_LEN + SS_SRC_LEN, SS_MASTER, SS_MASTER_LEN) ;
dst[dirlen + SS_DB_LEN + SS_SRC_LEN + SS_MASTER_LEN] = 0 ;
size_t livelen = info->live.len - 1 ;
char resolve[livelen + SS_STATE_LEN + 1 + ownerlen + 1 + info->treename.len + 1] ;
memcpy(resolve,info->live.s,livelen) ;
memcpy(resolve + livelen, SS_STATE,SS_STATE_LEN) ;
resolve[livelen+ SS_STATE_LEN] = '/' ;
memcpy(resolve + livelen + SS_STATE_LEN + 1,ownerstr,ownerlen) ;
resolve[livelen + SS_STATE_LEN + 1 + ownerlen] = '/' ;
memcpy(resolve + livelen + SS_STATE_LEN + 1 + ownerlen + 1,info->treename.s,info->treename.len) ;
resolve[livelen + SS_STATE_LEN + 1 + ownerlen + 1 + info->treename.len] = 0 ;
for (unsigned int i = 0 ; i < genalloc_len(stralist,ga); i++)
{
if (!stralloc_cats(&in,gaistr(ga,i))) goto err ;
if (!stralloc_cats(&in,"\n")) goto err ;
if (!stralloc_cats(&inres,gaistr(ga,i))) goto err ;
if (!stralloc_cats(&inres," ")) goto err ;
}
if (genalloc_len(stralist,ga)) inres.len--;
if (!stralloc_0(&inres)) goto err ;
r = file_write_unsafe(dst,SS_CONTENTS,in.s,in.len) ;
if (!r)
{
VERBO3 strerr_warnwu3sys("write: ",dst,"contents") ;
goto err ;
}
ss_resolve_init(&res) ;
res.name = ss_resolve_add_string(&res,SS_MASTER+1) ;
res.description = ss_resolve_add_string(&res,"inner bundle - do not use it") ;
res.treename = ss_resolve_add_string(&res,info->treename.s) ;
res.tree = ss_resolve_add_string(&res,info->tree.s) ;
res.live = ss_resolve_add_string(&res,info->live.s) ;
res.type = BUNDLE ;
res.deps = ss_resolve_add_string(&res,inres.s) ;
res.ndeps = genalloc_len(stralist,ga) ;
res.runat = ss_resolve_add_string(&res,runat) ;
res.resolve = ss_resolve_add_string(&res,resolve) ;
res.disen = 1 ;
res.init = 0 ;
res.unsupervise = 0 ;
res.reload = 0 ;
if (!ss_resolve_write(&res,dir,SS_MASTER+1,both)) goto err ;
stralloc_free(&in) ;
stralloc_free(&inres) ;
ss_resolve_free(&res) ;
return 1 ;
err:
ss_resolve_free(&res) ;
stralloc_free(&in) ;
stralloc_free(&inres) ;
return 0 ;
}
*/
/*
* db_get_permissions.c
*
* Copyright (c) 2018-2019 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include <66/utils.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <oblibs/error2.h>
#include <oblibs/directory.h>
#include <oblibs/types.h>
#include <oblibs/stralist.h>
#include <oblibs/files.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/types.h>
#include <66/constants.h>
int db_get_permissions(stralloc *uid, char const *tree)
{
genalloc list = GENALLOC_ZERO ;
size_t treelen = strlen(tree) ;
char tmp[treelen + SS_RULES_LEN + 1] ;
memcpy(tmp,tree,treelen) ;
memcpy(tmp + treelen, SS_RULES, SS_RULES_LEN) ;
tmp[treelen + SS_RULES_LEN] = 0 ;
if (!dir_get(&list,tmp,"",S_IFREG)) return 0 ;
for (unsigned int i = 0; i < genalloc_len(stralist,&list); i++)
{
if (!stralloc_cats(uid,gaistr(&list,i))) retstralloc(0,"set_permissions_db") ;
if (!stralloc_cats(uid,",")) retstralloc(0,"set_permissions_db") ;
}
uid->len-- ;// remove the last ','
if (!stralloc_0(uid)) retstralloc(0,"set_permissions_db") ;
genalloc_deepfree(stralist,&list,stra_free) ;
return 1 ;
}
backup_cmd_switcher.o backup_cmd_switcher.o
backup_make_new.o backup_make_new.o
backup_realpath_sym.o backup_realpath_sym.o
db_cmd_master.o
db_compile.o db_compile.o
db_find_compiled_state.o db_find_compiled_state.o
db_get_permissions.o
db_ok.o db_ok.o
db_switch_to.o db_switch_to.o
db_update.o db_update.o
......
...@@ -71,26 +71,25 @@ int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *se ...@@ -71,26 +71,25 @@ int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *se
{ {
stralloc conf = STRALLOC_ZERO ; stralloc conf = STRALLOC_ZERO ;
size_t svlen = strlen(service) ; size_t svlen = strlen(service) ;
// char svsrc[svlen + 1] ;
// if (!dirname(svsrc,service)) return 0 ;
// size_t srclen = strlen(svsrc) ;
// keep source of the frontend file // keep source of the frontend file
sv_before->src = keep.len ; sv_before->src = keep.len ;
// if (!stralloc_catb(&keep,svsrc,srclen + 1)) return 0 ; if (!stralloc_catb(&keep,service,svlen + 1)) goto err ;
if (!stralloc_catb(&keep,service,svlen + 1)) return 0 ;
// keep source of the configuration file // keep source of the configuration file
if (sv_before->opts[2]) if (sv_before->opts[2])
{ {
if (!env_resolve_conf(&conf,owner)) return 0 ; if (!env_resolve_conf(&conf,owner)) goto err ;
sv_before->srconf = keep.len ; sv_before->srconf = keep.len ;
if (!stralloc_catb(&keep,conf.s,conf.len + 1)) return 0 ; if (!stralloc_catb(&keep,conf.s,conf.len + 1)) goto err ;
} }
// keep service on current list // keep service on current list
if (!stralloc_catb(parsed_list,service,svlen + 1)) return 0 ; if (!stralloc_catb(parsed_list,service,svlen + 1)) goto err ;
if (!genalloc_append(sv_alltype,&gasv,sv_before)) return 0 ; if (!genalloc_append(sv_alltype,&gasv,sv_before)) goto err ;
(*nbsv)++ ; (*nbsv)++ ;
stralloc_free(&conf) ; stralloc_free(&conf) ;
return 1 ; return 1 ;
err:
stralloc_free(&conf) ;
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, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force)
...@@ -100,7 +99,6 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo ...@@ -100,7 +99,6 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo
stralloc newsv = STRALLOC_ZERO ; stralloc newsv = STRALLOC_ZERO ;
if (sv_before->cname.nga) if (sv_before->cname.nga)
{ {
size_t id = sv_before->cname.idga, nid = sv_before->cname.nga ; size_t id = sv_before->cname.idga, nid = sv_before->cname.nga ;
for (;nid; id += strlen(deps.s + id) + 1, nid--) for (;nid; id += strlen(deps.s + id) + 1, nid--)
{ {
...@@ -109,45 +107,21 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo ...@@ -109,45 +107,21 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo
{ {
VERBO3 strerr_warni4x("Service : ",sv, " depends on : ",deps.s+id) ; VERBO3 strerr_warni4x("Service : ",sv, " depends on : ",deps.s+id) ;
}else VERBO3 strerr_warni5x("Bundle : ",sv, " contents : ",deps.s+id," as service") ; }else VERBO3 strerr_warni5x("Bundle : ",sv, " contents : ",deps.s+id," as service") ;
dname = deps.s+id ; dname = deps.s + id ;
if (!ss_resolve_src_path(&newsv,dname,info)) if (!ss_resolve_src_path(&newsv,dname,info))
{ {
VERBO3 strerr_warnwu2x("resolve source path of: ",dname) ; VERBO3 strerr_warnwu2x("resolve source path of: ",dname) ;
stralloc_free(&newsv) ; goto err ;
return 0 ;
}
if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,&exist))
{
stralloc_free(&newsv) ;
return 0 ;
} }
if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,&exist)) goto err ;
} }
/*
for (int i = 0;i < sv_before->cname.nga;i++)
{
newsv.len = 0 ;
if (sv_before->cname.itype != BUNDLE)
{
VERBO3 strerr_warni4x("Service : ",sv, " depends on : ",deps.s+(genalloc_s(unsigned int,&gadeps)[sv_before->cname.idga+i])) ;
}else VERBO3 strerr_warni5x("Bundle : ",sv, " contents : ",deps.s+(genalloc_s(unsigned int,&gadeps)[sv_before->cname.idga+i])," as service") ;
dname = deps.s+(genalloc_s(unsigned int,&gadeps)[sv_before->cname.idga+i]) ;
if (!ss_resolve_src_path(&newsv,dname,info))
{
VERBO3 strerr_warnwu2x("resolve source path of: ",dname) ;
stralloc_free(&newsv) ;
return 0 ;
}
if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,&exist))
{
stralloc_free(&newsv) ;
return 0 ;
}
}*/
} }
else VERBO3 strerr_warni2x(sv,": haven't dependencies") ; else VERBO3 strerr_warni2x(sv,": haven't dependencies") ;
stralloc_free(&newsv) ; stralloc_free(&newsv) ;
return 1 ; return 1 ;
err:
stralloc_free(&newsv) ;
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_before(ssexec_t *info,stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist)
......
...@@ -83,12 +83,7 @@ int ss_state_write(ss_state_t *sta, char const *dst, char const *name) ...@@ -83,12 +83,7 @@ int ss_state_write(ss_state_t *sta, char const *dst, char const *name)
ss_state_pack(pack,sta) ; ss_state_pack(pack,sta) ;
if (!openwritenclose_unsafe(tmp,pack,SS_STATE_SIZE)) return 0 ; if (!openwritenclose_unsafe(tmp,pack,SS_STATE_SIZE)) return 0 ;
/*printf("sta.reload:write:%i\n",sta->reload) ;
printf("sta.init::%i\n",sta->init) ;
printf("sta.unsupervise::%i\n",sta->unsupervise) ;
printf("sta.state::%i\n",sta->state) ;
printf("sta.pid:write:%i\n",sta->pid) ;*/
return 1 ; return 1 ;
} }
...@@ -106,11 +101,7 @@ int ss_state_read(ss_state_t *sta, char const *src, char const *name) ...@@ -106,11 +101,7 @@ int ss_state_read(ss_state_t *sta, char const *src, char const *name)
if (openreadnclose(tmp, pack, SS_STATE_SIZE) < SS_STATE_SIZE) return 0 ; if (openreadnclose(tmp, pack, SS_STATE_SIZE) < SS_STATE_SIZE) return 0 ;
ss_state_unpack(pack, sta) ; ss_state_unpack(pack, sta) ;
/* printf("sta.reload:read:%i\n",sta->reload) ;
printf("sta.init::%i\n",sta->init) ;
printf("sta.unsupervise::%i\n",sta->unsupervise) ;
printf("sta.state::%i\n",sta->state) ;
printf("sta.pid:read:%i\n",sta->pid) ;*/
return 1 ; return 1 ;
} }
......
...@@ -19,10 +19,9 @@ ...@@ -19,10 +19,9 @@
//#include <stdio.h> //#include <stdio.h>
#include <oblibs/error2.h> #include <oblibs/error2.h>
#include <oblibs/stralist.h>
#include <oblibs/string.h> #include <oblibs/string.h>
#include <oblibs/directory.h>
#include <oblibs/types.h> #include <oblibs/types.h>
#include <oblibs/sastr.h>
#include <skalibs/genalloc.h> #include <skalibs/genalloc.h>
#include <skalibs/types.h> #include <skalibs/types.h>
...@@ -41,13 +40,13 @@ ...@@ -41,13 +40,13 @@
int svc_init(ssexec_t *info,char const *src, genalloc *ga) int svc_init(ssexec_t *info,char const *src, genalloc *ga)
{ {
size_t namelen, srclen, svscanlen, tmplen, pos, i ;
ssize_t logname ; ssize_t logname ;
gid_t gid = getgid() ; gid_t gid = getgid() ;
uint16_t id ; uint16_t id ;
ftrigr_t fifo = FTRIGR_ZERO ; ftrigr_t fifo = FTRIGR_ZERO ;
genalloc gadown = GENALLOC_ZERO ; stralloc sadown = STRALLOC_ZERO ;
genalloc ids = GENALLOC_ZERO ; // uint16_t genalloc ids = GENALLOC_ZERO ; // uint16_t
ss_state_t sta = STATE_ZERO ; ss_state_t sta = STATE_ZERO ;
...@@ -60,7 +59,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) ...@@ -60,7 +59,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga)
if (!ss_resolve_create_live(info)) { VERBO1 strerr_warnwu1sys("create live state") ; goto err ; } if (!ss_resolve_create_live(info)) { VERBO1 strerr_warnwu1sys("create live state") ; goto err ; }
for (unsigned int i=0 ; i < genalloc_len(ss_resolve_t,ga); i++) for (i = 0 ; i < genalloc_len(ss_resolve_t,ga); i++)
{ {
logname = 0 ; logname = 0 ;
char *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; char *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ;
...@@ -80,15 +79,14 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) ...@@ -80,15 +79,14 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga)
logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ; logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ;
if (logname > 0) name = string + genalloc_s(ss_resolve_t,ga)[i].logassoc ; if (logname > 0) name = string + genalloc_s(ss_resolve_t,ga)[i].logassoc ;
size_t namelen = strlen(name) ; namelen = strlen(name) ;
size_t srclen = strlen(src) ; srclen = strlen(src) ;
char svsrc[srclen + 1 + namelen + 1] ; char svsrc[srclen + 1 + namelen + 1] ;
memcpy(svsrc,src,srclen) ; memcpy(svsrc,src,srclen) ;
svsrc[srclen] = '/' ; svsrc[srclen] = '/' ;
memcpy(svsrc + srclen + 1,name,namelen) ; memcpy(svsrc + srclen + 1,name,namelen) ;
svsrc[srclen + 1 + namelen] = 0 ; svsrc[srclen + 1 + namelen] = 0 ;
size_t svscanlen ;
if (logname > 0) svscanlen = strlen(string + genalloc_s(ss_resolve_t,ga)[i].runat) - SS_LOG_SUFFIX_LEN ; if (logname > 0) svscanlen = strlen(string + genalloc_s(ss_resolve_t,ga)[i].runat) - SS_LOG_SUFFIX_LEN ;
else svscanlen = strlen(string + genalloc_s(ss_resolve_t,ga)[i].runat) ; else svscanlen = strlen(string + genalloc_s(ss_resolve_t,ga)[i].runat) ;
char svscan[svscanlen + 6 + 1] ; char svscan[svscanlen + 6 + 1] ;
...@@ -116,7 +114,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) ...@@ -116,7 +114,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga)
* check it and create again if doesn't exist */ * check it and create again if doesn't exist */
if (!scan_mode(svscan,S_IFDIR)) if (!scan_mode(svscan,S_IFDIR))
{ {
size_t tmplen = strlen(svsrc) ; tmplen = strlen(svsrc) ;
char tmp[tmplen + 4 + 1] ; char tmp[tmplen + 4 + 1] ;
memcpy(tmp,svsrc,tmplen) ; memcpy(tmp,svsrc,tmplen) ;
memcpy(tmp + tmplen,"/log",4) ; memcpy(tmp + tmplen,"/log",4) ;
...@@ -133,7 +131,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) ...@@ -133,7 +131,7 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga)
if (!genalloc_s(ss_resolve_t,ga)[i].down) if (!genalloc_s(ss_resolve_t,ga)[i].down)
{ {
if (!stra_add(&gadown,svscan)) if (!sastr_add_string(&sadown,svscan))
{ {
VERBO3 strerr_warnwu3x("add: ",svscan," to genalloc") ; VERBO3 strerr_warnwu3x("add: ",svscan," to genalloc") ;
goto err ; goto err ;
...@@ -177,17 +175,17 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) ...@@ -177,17 +175,17 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga)
if (ftrigr_wait_and_g(&fifo, genalloc_s(uint16_t, &ids), genalloc_len(uint16_t, &ids), &deadline) < 0) if (ftrigr_wait_and_g(&fifo, genalloc_s(uint16_t, &ids), genalloc_len(uint16_t, &ids), &deadline) < 0)
goto err ; goto err ;
for (unsigned int i = 0 ; i < genalloc_len(stralist,&gadown) ; i++) for (pos = 0 ; pos < sadown.len; pos += strlen(sadown.s + pos) + 1)
{ {
VERBO3 strerr_warnt2x("Delete down file at: ",gaistr(&gadown,i)) ; VERBO3 strerr_warnt2x("Delete down file at: ",sadown.s + pos) ;
if (unlink(gaistr(&gadown,i)) < 0 && errno != ENOENT) goto err ; if (unlink(sadown.s + pos) < 0 && errno != ENOENT) goto err ;
} }
for (unsigned int i = 0 ; i < genalloc_len(ss_resolve_t,ga) ; i++) for (pos = 0 ; pos < genalloc_len(ss_resolve_t,ga) ; pos++)
{ {
char const *string = genalloc_s(ss_resolve_t,ga)[i].sa.s ; char const *string = genalloc_s(ss_resolve_t,ga)[pos].sa.s ;
char const *name = string + genalloc_s(ss_resolve_t,ga)[i].name ; char const *name = string + genalloc_s(ss_resolve_t,ga)[pos].name ;
char const *state = string + genalloc_s(ss_resolve_t,ga)[i].state ; char const *state = string + genalloc_s(ss_resolve_t,ga)[pos].state ;
VERBO2 strerr_warni2x("Write state file of: ",name) ; VERBO2 strerr_warni2x("Write state file of: ",name) ;
if (!ss_state_write(&sta,state,name)) if (!ss_state_write(&sta,state,name))
...@@ -199,14 +197,14 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga) ...@@ -199,14 +197,14 @@ int svc_init(ssexec_t *info,char const *src, genalloc *ga)
} }
} }
ftrigr_end(&fifo) ; ftrigr_end(&fifo) ;
genalloc_deepfree(stralist,&gadown,stra_free) ; stralloc_free(&sadown) ;
genalloc_free(uint16_t, &ids) ; genalloc_free(uint16_t, &ids) ;
return 1 ; return 1 ;
err: err:
ftrigr_end(&fifo) ; ftrigr_end(&fifo) ;
genalloc_free(uint16_t, &ids) ; genalloc_free(uint16_t, &ids) ;
genalloc_deepfree(stralist,&gadown,stra_free) ; stralloc_free(&sadown) ;
ftrigr_end(&fifo) ; ftrigr_end(&fifo) ;
return 0 ; 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