diff --git a/src/66/66-all.c b/src/66/66-all.c index 6b2e604df7efd21fee78beab1fba188bb3c25fa1..1f402a34812766bc45f310908c7aa309c365b906 100644 --- a/src/66/66-all.c +++ b/src/66/66-all.c @@ -183,7 +183,7 @@ int main(int argc, char const *const *argv,char const *const *envp) stralloc contents = STRALLOC_ZERO ; genalloc in = GENALLOC_ZERO ; //stralist - what = -1 ; + what = 1 ; PROG = "66-all" ; { diff --git a/src/66/66-disable.c b/src/66/66-disable.c index 2ba8a193335027d0eea15804f23e7a942bed1eb3..d7e13d17a25bfd99885477d03483c748e08fe6ba 100644 --- a/src/66/66-disable.c +++ b/src/66/66-disable.c @@ -357,8 +357,15 @@ int main(int argc, char const *const *argv,char const *const *envp) /** retrieve dependencies */ { if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,0,SS_RESOLVE_SRC)) + { + cleanup(workdir.s) ; strerr_diefu1x(111,"set revolve pointer to source") ; - if (!make_depends_graph(saresolve.s)) strerr_diefu1x(111,"make dependencies graph") ; + } + if (!make_depends_graph(saresolve.s)) + { + cleanup(workdir.s) ; + strerr_diefu1x(111,"make dependencies graph") ; + } } { @@ -367,8 +374,10 @@ int main(int argc, char const *const *argv,char const *const *envp) for(;*argv;argv++) { if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,0,SS_RESOLVE_SRC)) + { + cleanup(workdir.s) ; strerr_diefu1x(111,"set revolve pointer to source") ; - + } /*rb = resolve_read(&type,saresolve.s,*argv,"remove") ; if (rb < -1) strerr_dief2x(111,"invalid .resolve directory: ",saresolve.s) ; if (rb >= 1) @@ -402,10 +411,16 @@ int main(int argc, char const *const *argv,char const *const *envp) char *name = gaistr(&ganclassic,i) ; VERBO2 strerr_warni1x("remove svc services ... ") ; if (!remove_sv(workdir.s,name,CLASSIC,&gadepstoremove)) + { + cleanup(workdir.s) ; strerr_diefu2x(111,"disable: ",name) ; + } /** modify the resolve file for 66-stop*/ - if (!resolve_write(workdir.s,gaistr(&ganclassic,i),"remove","",1)) + if (!resolve_write(workdir.s,gaistr(&ganclassic,i),"remove","",1)) + { + cleanup(workdir.s) ; strerr_diefu2sys(111,"write resolve file: remove for service: ",gaistr(&ganclassic,i)) ; + } } r = backup_cmd_switcher(VERBOSITY,"-t30 -b",treename) ; @@ -446,12 +461,17 @@ int main(int argc, char const *const *argv,char const *const *envp) { char *name = gaistr(&ganlong,i) ; if (!remove_sv(workdir.s,name,LONGRUN,&gadepstoremove)) + { + cleanup(workdir.s) ; strerr_diefu2x(111,"disable: ",name) ; + } if (!stralloc_cats(&newupdate," ")) retstralloc(111,"main") ; if (!stralloc_cats(&newupdate,name)) retstralloc(111,"main") ; - if (!resolve_write(workdir.s,gaistr(&ganlong,i),"remove","",1)) + if (!resolve_write(workdir.s,gaistr(&ganlong,i),"remove","",1)) + { + cleanup(workdir.s) ; strerr_diefu2sys(111,"write resolve file: remove for service: ",gaistr(&ganlong,i)) ; - + } } for (unsigned int i = 0 ; i < genalloc_len(stralist,&gadepstoremove) ; i++ ) { @@ -459,8 +479,11 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!stralloc_cats(&newupdate,gaistr(&gadepstoremove,i))) retstralloc(111,"main") ; /** modify the resolve file for 66-stop*/ - if (!resolve_write(workdir.s,gaistr(&gadepstoremove,i),"remove","",1)) + if (!resolve_write(workdir.s,gaistr(&gadepstoremove,i),"remove","",1)) + { + cleanup(workdir.s) ; strerr_diefu2sys(111,"write resolve file: remove for service: ",gaistr(&gadepstoremove,i)) ; + } } if (!stralloc_0(&newupdate)) retstralloc(111,"main") ; @@ -480,8 +503,8 @@ int main(int argc, char const *const *argv,char const *const *envp) /** this is an important part, we call s6-rc-update here */ if (!db_switch_to(base.s,livetree.s,tree.s,treename,envp,SS_SWBACK)) { - VERBO3 strerr_warnwu3x("switch ",treename," to backup") ; - return 0 ; + cleanup(workdir.s) ; + strerr_diefu3x(111,"switch ",treename," to backup") ; } } @@ -500,10 +523,15 @@ int main(int argc, char const *const *argv,char const *const *envp) if (rm_rf(svdir) < 0) { if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,CLASSIC,SS_RESOLVE_SRC)) + { + cleanup(workdir.s) ; strerr_diefu1x(111,"set revolve pointer to source") ; - + } if (!resolve_pointo(&swap,base.s,live.s,tree.s,treename,CLASSIC,SS_RESOLVE_BACK)) + { + cleanup(workdir.s) ; strerr_diefu1x(111,"set revolve pointer to source") ; + } if (!hiercopy(swap.s,saresolve.s)) { cleanup(workdir.s) ; @@ -520,10 +548,15 @@ int main(int argc, char const *const *argv,char const *const *envp) if (rm_rf(svdir) < 0) { if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,LONGRUN,SS_RESOLVE_SRC)) + { + cleanup(workdir.s) ; strerr_diefu1x(111,"set revolve pointer to source") ; - + } if (!resolve_pointo(&swap,base.s,live.s,tree.s,treename,LONGRUN,SS_RESOLVE_BACK)) + { + cleanup(workdir.s) ; strerr_diefu1x(111,"set revolve pointer to source") ; + } if (!hiercopy(swap.s,saresolve.s)) { cleanup(workdir.s) ; @@ -551,10 +584,15 @@ int main(int argc, char const *const *argv,char const *const *envp) if (!hiercopy(workdir.s,svdir)) { if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,0,SS_RESOLVE_SRC)) + { + cleanup(workdir.s) ; strerr_diefu1x(111,"set revolve pointer to source") ; - + } if (!resolve_pointo(&swap,base.s,live.s,tree.s,treename,0,SS_RESOLVE_BACK)) + { + cleanup(workdir.s) ; strerr_diefu1x(111,"set revolve pointer to source") ; + } if (!hiercopy(swap.s,saresolve.s)) { cleanup(workdir.s) ; diff --git a/src/66/66-enable.c b/src/66/66-enable.c index 2a01d0bb32a465d8f6db095d77f4d5b89957a0fa..93afd4d8ad93ba58a1d5cb452654b173a335dbbc 100644 --- a/src/66/66-enable.c +++ b/src/66/66-enable.c @@ -47,7 +47,7 @@ unsigned int VERBOSITY = 1 ; stralloc saresolve = STRALLOC_ZERO ; -#define USAGE "66-enable [ -h help ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f force ] [ -d directory ] service(s)" +#define USAGE "66-enable [ -h help ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f force ] [ -d directory ] [ -I instance ] service(s)" static inline void info_help (void) { @@ -61,6 +61,7 @@ static inline void info_help (void) " -t: name of the tree to use\n" " -f: owerwrite service(s)\n" " -d: enable an entire directory\n" +" -I: create an instance of service\n" ; if (buffer_putsflush(buffer_1, help) < 0) @@ -74,13 +75,97 @@ static void cleanup(char const *dst) errno = e ; } +int start_parser(char const *src,char const *svname,char const *tree, stralloc *keep, unsigned int *nbsv) +{ + stralloc sasv = STRALLOC_ZERO ; + + if (!parse_service_before(src,svname,tree,keep, nbsv, &sasv)) strerr_dief4x(111,"invalid service file: ",src,"/",svname) ; + + stralloc_free(&sasv) ; + + return 1 ; +} + +int insta_replace(stralloc *sa,char const *src,char const *cpy) +{ + + int curr, count ; + + if (!src || !*src) return 0; + + size_t len = strlen(src) ; + size_t clen= strlen(cpy) ; + + curr = count = 0 ; + for(int i = 0; (size_t)i < len;i++) + if (src[i] == '@') + count++ ; + + size_t resultlen = len + (clen * count) ; + char result[resultlen + 1 ] ; + + for(int i = 0; (size_t)i < len;i++) + { + if (src[i] == '@') + { + + if (((size_t)i + 1) == len) break ; + if (src[i + 1] == 'I') + { + memcpy(result + curr,cpy,clen) ; + curr = curr + clen; + i = i + 2 ; + } + } + result[curr++] = src[i] ; + + } + result[curr] = 0 ; + + return stralloc_obreplace(sa,result) ; +} +int insta_create(char const *src,char const *instasrc, char const *instacopy, char const *tree,stralloc *keep,unsigned int *nbsv) +{ + + stralloc sa = STRALLOC_ZERO ; + stralloc tmp = STRALLOC_ZERO ; + + if (get_len_until(instasrc,'@') < 0) + strerr_dief2x(111,"unvalid instance service file: ",instasrc) ; + + if (!dir_create_tmp(&tmp,"/tmp",instacopy)) + strerr_diefu1x(111,"create instance tmp dir") ; + + if (!file_readputsa(&sa,src,instasrc)) + strerr_diefu4sys(111,"open: ",tmp.s,"/",instasrc) ; + + if (!insta_replace(&sa,sa.s,instacopy)) + strerr_diefu2x(111,"replace instance character at: ",sa.s) ; + + if (!file_write_unsafe(tmp.s,instacopy,sa.s,sa.len)) + strerr_diefu4sys(111,"create instance service file: ",src,"/",instacopy) ; + + start_parser(tmp.s,instacopy,tree,keep,nbsv) ; + + if (rm_rf(tmp.s) < 0) + VERBO3 strerr_warnwu2x("remove tmp directory: ",tmp.s) ; + + stralloc_free(&sa) ; + stralloc_free(&tmp) ; + + return 1 ; +} + int main(int argc, char const *const *argv,char const *const *envp) { int r ; - unsigned int nbsv, nlongrun, nclassic ; + unsigned int nbsv, nlongrun, nclassic, insta ; uid_t owner ; + char const *instasrc = NULL ; + char const *instacopy = NULL ; + stralloc base = STRALLOC_ZERO ;//SS_SYSTEM stralloc tree = STRALLOC_ZERO ;//-t options stralloc dir = STRALLOC_ZERO ; //-d options @@ -93,7 +178,7 @@ int main(int argc, char const *const *argv,char const *const *envp) genalloc ganlong = GENALLOC_ZERO ; // type stralist genalloc ganclassic = GENALLOC_ZERO ; // name of classic service, type stralist - r = nbsv = nclassic = nlongrun = 0 ; + r = nbsv = nclassic = nlongrun = insta = 0 ; PROG = "66-enable" ; { @@ -101,7 +186,7 @@ int main(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, ">hv:l:t:fd:", &l) ; + int opt = getopt_args(argc,argv, ">hv:l:t:fd:I:", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) @@ -119,6 +204,10 @@ int main(int argc, char const *const *argv,char const *const *envp) if(!stralloc_0(&dir)) retstralloc(111,"main") ; MULTI = 1 ; break ; + case 'I' : if (MULTI) exitusage() ; + instacopy = l.arg ; + insta = 1 ; + break ; default : exitusage() ; } } @@ -127,7 +216,7 @@ int main(int argc, char const *const *argv,char const *const *envp) if (argc < 1) exitusage() ; /**only name of the service to enable is allowed with -d options*/ - if (argc > 1 && MULTI) exitusage() ; + if ((argc > 1 && MULTI) || (argc > 1 && insta)) exitusage() ; owner = MYUID ; if (!set_ownersysdir(&base,owner)) strerr_diefu1sys(111, "set owner directory") ; @@ -173,26 +262,28 @@ int main(int argc, char const *const *argv,char const *const *envp) } stralloc_free(&dir) ; - /** get all service on sv_src directory*/ - if (MULTI){ - if (!file_get_fromdir(&gargv,sv_src.s)) strerr_diefu2sys(111,"get services from directory: ",sv_src.s) ; - MSTART = *argv ; - } - else{ - for(;*argv;argv++) - if (!stra_add(&gargv,*argv)) retstralloc(111,"main") ; - } - - /** parse all the files*/ + if (!insta) { - stralloc sasv = STRALLOC_ZERO ; - for(unsigned int i=0;i<genalloc_len(stralist,&gargv);i++) + + /** get all service on sv_src directory*/ + if (MULTI){ + if (!file_get_fromdir(&gargv,sv_src.s)) strerr_diefu2sys(111,"get services from directory: ",sv_src.s) ; + MSTART = *argv ; + for (unsigned int i = 0; i < genalloc_len(stralist,&gasv); i++) + start_parser(sv_src.s,gaistr(&gasv,i),tree.s,&keep,&nbsv) ; + } + else { - if (!parse_service_before(sv_src.s, gaistr(&gargv,i),tree.s,&keep, &nbsv, &sasv)) strerr_dief4x(111,"invalid service file: ",sv_src.s,"/",gaistr(&gargv,i)) ; + for(;*argv;argv++) + start_parser(sv_src.s,*argv,tree.s,&keep,&nbsv) ; } - stralloc_free(&sasv) ; } - + else + { + instasrc = argv[0] ; + if (!insta_create(sv_src.s,instasrc,instacopy,tree.s,&keep,&nbsv)) strerr_diefu4x(111,"make instance from: ",instasrc," to: ",instacopy) ; + } + sv_alltype svblob[nbsv] ; diff --git a/src/66/66-info.c b/src/66/66-info.c index 3451dad9949c07d241210d622abdd3e4d60a7027..732f50ea60848fedadf5c9ef72cb18beed5ad4af 100644 --- a/src/66/66-info.c +++ b/src/66/66-info.c @@ -22,6 +22,7 @@ #include <oblibs/stralist.h> #include <oblibs/string.h> #include <oblibs/files.h> +#include <oblibs/directory.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> @@ -43,7 +44,6 @@ unsigned int VERBOSITY = 1 ; static stralloc base = STRALLOC_ZERO ; static stralloc live = STRALLOC_ZERO ; -static stralloc saresolve = STRALLOC_ZERO ; static stralloc SCANDIR = STRALLOC_ZERO ; // upper case to avoid conflicts with dirent.h static uid_t owner ; @@ -53,9 +53,10 @@ static uid_t owner ; #define USAGE "66-info [ -h help ] [ -T tree ] [ -S service ] sub-options (use -h as sub-options for futher informations)" -#define TREE_USAGE "66-info -T [ -help ] [ -L list] [ -t tree ]" + +#define TREE_USAGE "66-info -T [ -help ] tree " #define exit_tree_usage() strerr_dieusage(100, TREE_USAGE) -#define SV_USAGE "66-info -S [ -help ] [ -t tree ] [ -l live ] [ -p n lines ] service" +#define SV_USAGE "66-info -S [ -help ] [ -l live ] [ -p n lines ] service" #define exit_sv_usage() strerr_dieusage(100, SV_USAGE) /* @@ -106,12 +107,10 @@ static inline void info_help (void) static inline void tree_help (void) { static char const *help = -"66-info -T <options> \n" +"66-info -T <options> tree\n" "\n" "options :\n" " -h: print this help\n" -" -L: list available tree\n" -" -t: get informations about the given tree\n" ; if (buffer_putsflush(buffer_1, help) < 0) @@ -125,14 +124,14 @@ static inline void sv_help (void) "\n" "options :\n" " -h: print this help\n" -" -t: tree to use\n" " -l: live directory\n" -" -p: print n last lines of the associated logger\n" +" -p: print n last lines of the associated log file\n" ; if (buffer_putsflush(buffer_1, help) < 0) strerr_diefu1sys(111, "write to stdout") ; } + char *print_nlog(char *str, int n) { int r = 0 ; @@ -279,13 +278,11 @@ int print_status(char const *svname,char const *type,char const *treename, char int tree_args(int argc, char const *const *argv) { - int r, list, comma, master ; + int r, comma, master ; - genalloc galist = GENALLOC_ZERO ; + genalloc gatree = GENALLOC_ZERO ;// stralist, all tree stralloc tree = STRALLOC_ZERO ; stralloc sacurrent = STRALLOC_ZERO ; - - char treename[MAXSIZE] ; char current[MAXSIZE] ; r = tree_find_current(&sacurrent,base.s) ; @@ -297,56 +294,45 @@ int tree_args(int argc, char const *const *argv) currnamelen-- ; current[currnamelen] = 0 ; } - + size_t baselen = base.len - 1 ; char src[baselen + SS_SYSTEM_LEN + 1] ; memcpy(src,base.s,baselen) ; memcpy(src + baselen,SS_SYSTEM, SS_SYSTEM_LEN) ; src[baselen + SS_SYSTEM_LEN] = 0 ; - list = comma = master = 0 ; - + comma = master = 0 ; + //without args see all tree available, if arg = tree, -s to specify see service { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - int opt = getopt_args(argc,argv, ">hLt:", &l) ; + int opt = getopt_args(argc,argv, ">h", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) { case 'h' : tree_help(); return 0 ; - case 'L' : list = 1 ; break ; - case 't' : if(!stralloc_cats(&tree,l.arg)) retstralloc(111,"main") ; - if(!stralloc_0(&tree)) retstralloc(111,"main") ; - memcpy(treename,l.arg,strlen(l.arg)) ; - treename[strlen(l.arg)] = 0 ; - break ; default : exit_tree_usage() ; } } argc -= l.ind ; argv += l.ind ; } + if (argc > 1) exit_tree_usage(); - if (tree.len) - { - r = tree_sethome(&tree,base.s) ; - if (!r) strerr_diefu2sys(111,"find tree: ", tree.s) ; - } - - if (list) + if (!argv[0]) { - if (!get_fromdir(&galist, src, S_IFDIR)) return 0 ; - if (genalloc_len(stralist,&galist)) + if (!get_fromdir(&gatree, src, S_IFDIR)) return 0 ; + if (!bprintf(buffer_1,"%s\n","[Available tree]")) return 0 ; + if (genalloc_len(stralist,&gatree)) { - if (!bprintf(buffer_1,"%s\n","[Available tree]")) return 0 ; - for (unsigned int i = 0 ; i < genalloc_len(stralist,&galist) ; i++) + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) { - int enabled = tree_cmd_state(VERBOSITY,"-s",gaistr(&galist,i)) ; - if (!bprintf(buffer_1," %s : ",gaistr(&galist,i))) return 0 ; - if (obstr_equal(gaistr(&galist,i),current)) + int enabled = tree_cmd_state(VERBOSITY,"-s",gaistr(&gatree,i)) ; + if (!bprintf(buffer_1," %s : ",gaistr(&gatree,i))) return 0 ; + if (obstr_equal(gaistr(&gatree,i),current)) { if (!bprintf(buffer_1, "%s","current")) return 0 ; comma = 1 ; } if (enabled) { @@ -356,63 +342,79 @@ int tree_args(int argc, char const *const *argv) if (buffer_putflush(buffer_1,"\n",1) < 0) return 0 ; comma = 0 ; } - galist = genalloc_zero ; + gatree = genalloc_zero ; + } + else + { + if (!bprintf(buffer_1," %s ","nothing to display")) return 0 ; + if (buffer_putflush(buffer_1,"\n",1) < 0) return 0 ; } + return 1 ; } - if (tree.len) - { - size_t treelen = tree.len - 1 ; - size_t newlen ; - char what[treelen + SS_SVDIRS_LEN + SS_DB_LEN + SS_SRC_LEN + 1] ; - memcpy(what,tree.s,treelen) ; - memcpy(what + treelen, SS_SVDIRS,SS_SVDIRS_LEN) ; - newlen = treelen + SS_SVDIRS_LEN ; - - if (!bprintf(buffer_1,"%s%s%s\n","[Service on tree: ",treename,"]")) return 0 ; + if(!stralloc_cats(&tree,argv[0])) retstralloc(111,"main") ; + if(!stralloc_0(&tree)) retstralloc(111,"main") ; + + r = tree_sethome(&tree,base.s) ; + if (r < 0) strerr_diefu1x(110,"find the current tree. You must use -t options") ; + if (!r) strerr_diefu2sys(111,"find tree: ", tree.s) ; - /** classic */ - memcpy(what + newlen, SS_SVC, SS_SVC_LEN) ; - what[newlen + SS_SVC_LEN] = 0 ; + size_t treelen = get_rlen_until(tree.s,'/',tree.len - 1) ; + size_t treenamelen = (tree.len - 1) - treelen ; + char treename[treenamelen + 1] ; + memcpy(treename, tree.s + treelen + 1,treenamelen) ; + treenamelen-- ; + treename[treenamelen] = 0 ; + + size_t satreelen = tree.len - 1 ; + size_t newlen ; + char what[satreelen + SS_SVDIRS_LEN + SS_DB_LEN + SS_SRC_LEN + 1] ; + memcpy(what,tree.s,satreelen) ; + memcpy(what + satreelen, SS_SVDIRS,SS_SVDIRS_LEN) ; + newlen = satreelen + SS_SVDIRS_LEN ; + + if (!bprintf(buffer_1,"%s%s%s\n","[Service on tree: ",treename,"]")) return 0 ; + + /** classic */ + memcpy(what + newlen, SS_SVC, SS_SVC_LEN) ; + what[newlen + SS_SVC_LEN] = 0 ; + + if (!bprintf(buffer_1," %s","classic :")) ; + if (!get_fromdir(&gatree,what,S_IFDIR)) return 0 ; + if (genalloc_len(stralist,&gatree)) + { + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) + if (!bprintf(buffer_1," %s ",gaistr(&gatree,i))) return 0 ; - if (!bprintf(buffer_1," %s","classic :")) ; - if (!get_fromdir(&galist,what,S_IFDIR)) return 0 ; - if (genalloc_len(stralist,&galist)) - { - for (unsigned int i = 0 ; i < genalloc_len(stralist,&galist) ; i++) - if (!bprintf(buffer_1," %s ",gaistr(&galist,i))) return 0 ; - - galist = genalloc_zero ; - } - else if (!bprintf(buffer_1," %s ","nothing to display")) return 0 ; - if (buffer_putflush(buffer_1,"\n",1) < 0) return 0 ; - - /** rc */ - memcpy(what + newlen, SS_DB, SS_DB_LEN) ; - memcpy(what + newlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ; - what[newlen + SS_DB_LEN + SS_SRC_LEN] = 0 ; - - if (!bprintf(buffer_1," %s","rc :")) ; - if (!get_fromdir(&galist,what,S_IFDIR)) return 0 ; - if (genalloc_len(stralist,&galist) > 1) //only pass if Master is not alone + gatree = genalloc_zero ; + } + else if (!bprintf(buffer_1," %s ","nothing to display")) return 1 ; + if (buffer_putflush(buffer_1,"\n",1) < 0) return 1 ; + + /** rc */ + memcpy(what + newlen, SS_DB, SS_DB_LEN) ; + memcpy(what + newlen + SS_DB_LEN, SS_SRC, SS_SRC_LEN) ; + what[newlen + SS_DB_LEN + SS_SRC_LEN] = 0 ; + + if (!bprintf(buffer_1," %s","rc :")) ; + if (!get_fromdir(&gatree,what,S_IFDIR)) return 0 ; + if (genalloc_len(stralist,&gatree) > 1) //only pass if Master is not alone + { + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) { - for (unsigned int i = 0 ; i < genalloc_len(stralist,&galist) ; i++) - { - if (!str_diff(gaistr(&galist,i),SS_MASTER+1)) - continue ; - if (!bprintf(buffer_1," %s ",gaistr(&galist,i))) return 0 ; - } - galist = genalloc_zero ; + if (!str_diff(gaistr(&gatree,i),SS_MASTER+1)) + continue ; + if (!bprintf(buffer_1," %s ",gaistr(&gatree,i))) return 0 ; } - else if (!bprintf(buffer_1," %s ","nothing to display")) return 0 ; - if (buffer_putflush(buffer_1,"\n",1) < 0) return 0 ; - - + gatree = genalloc_zero ; } + else if (!bprintf(buffer_1," %s ","nothing to display")) return 0 ; + if (buffer_putflush(buffer_1,"\n",1) < 0) return 0 ; + stralloc_free(&tree) ; stralloc_free(&sacurrent) ; - genalloc_deepfree(stralist,&galist,stra_free) ; + genalloc_deepfree(stralist,&gatree,stra_free) ; return 1 ; } @@ -424,10 +426,12 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) stralloc tree = STRALLOC_ZERO ; stralloc what = STRALLOC_ZERO ; - genalloc gawhat = GENALLOC_ZERO ; stralloc type = STRALLOC_ZERO ; + genalloc gawhat = GENALLOC_ZERO ;//stralist + genalloc gatree = GENALLOC_ZERO ; char const *svname = NULL ; + char const *treename = NULL ; r = 0 ; @@ -436,15 +440,12 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) for (;;) { - int opt = getopt_args(argc,argv, ">hl:t:p:", &l) ; + int opt = getopt_args(argc,argv, ">hl:p:", &l) ; if (opt == -1) break ; if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) { case 'h' : sv_help(); return 0 ; - case 't' : if(!stralloc_cats(&tree,l.arg)) retstralloc(111,"main") ; - if(!stralloc_0(&tree)) retstralloc(111,"main") ; - break ; case 'l' : if (!stralloc_cats(&live,l.arg)) retstralloc(111,"main") ; if (!stralloc_0(&live)) retstralloc(111,"main") ; break ; @@ -455,30 +456,64 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) argc -= l.ind ; argv += l.ind ; } if (argc > 1 || !argc) exit_sv_usage() ; + svname = *argv ; r = set_livedir(&live) ; if (!r) retstralloc(111,"main") ; if (r < 0 ) strerr_dief3x(111,"live: ",live.s," must be an absolute path") ; + size_t baselen = base.len - 1 ; + size_t newlen ; + char src[MAXSIZE] ; + memcpy(src,base.s,baselen) ; + memcpy(src + baselen,SS_SYSTEM, SS_SYSTEM_LEN) ; + baselen = baselen + SS_SYSTEM_LEN ; + src[baselen] = 0 ; + + { + if (!get_fromdir(&gatree, src, S_IFDIR)) return 0 ; + + if (genalloc_len(stralist,&gatree)) + { + for (unsigned int i = 0 ; i < genalloc_len(stralist,&gatree) ; i++) + { + treename = gaistr(&gatree,i) ; + size_t treelen = gaistrlen(&gatree,i) ; + src[baselen] = '/' ; + memcpy(src + baselen + 1,treename,treelen) ; + memcpy(src + baselen + 1 + treelen,SS_SVDIRS,SS_SVDIRS_LEN) ; + newlen = baselen + 1 + treelen + SS_SVDIRS_LEN ; + memcpy(src + baselen + 1 + treelen + SS_SVDIRS_LEN,SS_RESOLVE,SS_RESOLVE_LEN) ; + src[baselen + 1 + treelen + SS_SVDIRS_LEN + SS_RESOLVE_LEN] = 0 ; + if (dir_search(src,svname,S_IFDIR)) + { + if(!stralloc_cats(&tree,treename)) retstralloc(111,"main") ; + if(!stralloc_0(&tree)) retstralloc(111,"main") ; + src[newlen] = 0 ; + break ; + } + } + + } + else + { + if (!bprintf(buffer_1," %s ","nothing to display")) return 0 ; + if (buffer_putflush(buffer_1,"\n",1) < 0) return 0 ; + return 1 ; + } + } + r = tree_sethome(&tree,base.s) ; if (r < 0) strerr_diefu1x(110,"find the current tree. You must use -t options") ; if (!r) strerr_diefu2sys(111,"find tree: ", tree.s) ; - size_t treelen = get_rlen_until(tree.s,'/',tree.len - 1) ; - size_t treenamelen = (tree.len - 1) - treelen ; - char treename[treenamelen + 1] ; - memcpy(treename, tree.s + treelen + 1,treenamelen) ; - treenamelen-- ; - treename[treenamelen] = 0 ; - if (!bprintf(buffer_1,"%s%s%s\n","[",svname,"]")) return 0 ; + if (!bprintf(buffer_1,"%s%s\n","tree : ",treename)) return 0 ; - if (!resolve_pointo(&saresolve,base.s,live.s,tree.s,treename,0,SS_RESOLVE_SRC)) - strerr_diefu1x(111,"set revolve pointer to source") ; /** retrieve type but do not print it*/ - r = resolve_read(&type,saresolve.s,svname,"type") ; - if (r < -1) strerr_dief2sys(111,"invalid .resolve directory: ",saresolve.s) ; + r = resolve_read(&type,src,svname,"type") ; + if (r < -1) strerr_dief2sys(111,"invalid .resolve directory: ",src) ; if (r <= 0) strerr_diefu2x(111,"read type of: ",svname) ; /** status */ @@ -489,8 +524,8 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) if (!bprintf(buffer_1,"%s %s\n","type :",type.s)) return 0 ; /** description */ - r = resolve_read(&what,saresolve.s,svname,"description") ; - if (r < -1) strerr_dief2sys(111,"invalid .resolve directory: ",saresolve.s) ; + r = resolve_read(&what,src,svname,"description") ; + if (r < -1) strerr_dief2sys(111,"invalid .resolve directory: ",src) ; if (r <= 0) strerr_diefu2x(111,"read description of: ",svname) ; if (!bprintf(buffer_1,"%s %s\n","description :",what.s)) return 0 ; @@ -502,7 +537,7 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) if (!bprintf(buffer_1,"%s\n","contents :")) return 0 ; } else if (!bprintf(buffer_1,"%s\n","depends on :")) return 0 ; - r = resolve_read(&what,saresolve.s,svname,"deps") ; + r = resolve_read(&what,src,svname,"deps") ; if (what.len) { if (!clean_val(&gawhat,what.s)) return 0 ; @@ -520,16 +555,16 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) if (get_enumbyid(type.s,key_enum_el) == CLASSIC || get_enumbyid(type.s,key_enum_el) == LONGRUN) { if (!bprintf(buffer_1,"%s ","logger at :")) return 0 ; - r = resolve_read(&what,saresolve.s,svname,"logger") ; - if (r < -1) strerr_dief2sys(111,"invalid .resolve directory: ",saresolve.s) ; + r = resolve_read(&what,src,svname,"logger") ; + if (r < -1) strerr_dief2sys(111,"invalid .resolve directory: ",src) ; if (r <= 0) { if (!bprintf(buffer_1,"%s \n","apparently not")) return 0 ; } else { - r = resolve_read(&what,saresolve.s,svname,"dstlog") ; - if (r < -1) strerr_dief2sys(111,"invalid .resolve directory: ",saresolve.s) ; + r = resolve_read(&what,src,svname,"dstlog") ; + if (r < -1) strerr_dief2sys(111,"invalid .resolve directory: ",src) ; if (r <= 0) { if (!bprintf(buffer_1,"%s \n","unset")) return 0 ; @@ -553,6 +588,7 @@ int sv_args(int argc, char const *const *argv,char const *const *envp) stralloc_free(&what) ; stralloc_free(&type) ; genalloc_deepfree(stralist,&gawhat,stra_free) ; + genalloc_deepfree(stralist,&gatree,stra_free) ; return 0 ; } @@ -600,6 +636,6 @@ int main(int argc, char const *const *argv, char const *const *envp) stralloc_free(&base) ; stralloc_free(&live) ; stralloc_free(&SCANDIR) ; - stralloc_free(&saresolve) ; + return 0 ; } diff --git a/src/lib66/parser.c b/src/lib66/parser.c index 180a89f8906d9753abe48486571e2bdc192e3518..70b8cb658f456c65874f9633b6978cba2730988e 100644 --- a/src/lib66/parser.c +++ b/src/lib66/parser.c @@ -53,6 +53,7 @@ void freed_parser(void) stralloc_free(&ganame) ; genalloc_free(unsigned int,&gadeps) ; genalloc_free(sv_alltype,&gasv) ; + avltree_free(&deps_map) ; } static void *sv_toadd (unsigned int d, void *x) diff --git a/src/lib66/parser_write.c b/src/lib66/parser_write.c index 3051e43d6f5899d103eff076a3823b55bffb9386..09fff6f9669bc315dca221089916dce03f326163 100644 --- a/src/lib66/parser_write.c +++ b/src/lib66/parser_write.c @@ -143,7 +143,7 @@ int write_services(sv_alltype *sv, char const *workdir, unsigned int force) break ; default: VERBO3 strerr_warni2x("unkown type: ", get_keybyid(sv->cname.itype)) ; - break ; + return 0 ; } //VERBO2 strerr_warnt4x("write resolve file ", workdir,SS_RESOLVE,"/type ...") ;