From abbad04cb46582ff5be0bee7039bb48ce7182ca1 Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Mon, 30 Jan 2023 18:32:32 +1100 Subject: [PATCH] clean the mess and make it working again --- src/include/66/ssexec.h | 4 +- src/lib66/exec/ssexec_help.c | 3 +- src/lib66/exec/ssexec_intree.c | 451 +++++++++++++-------------------- 3 files changed, 185 insertions(+), 273 deletions(-) diff --git a/src/include/66/ssexec.h b/src/include/66/ssexec.h index e1dc6c2c..bb5b7871 100644 --- a/src/include/66/ssexec.h +++ b/src/include/66/ssexec.h @@ -234,9 +234,9 @@ extern char const *help_scandir ; #define OPTS_TREECTL_LEN (sizeof OPTS_TREECTL - 1) #define OPTS_TREE "hco:EDRnadC:S:" #define OPTS_TREE_LEN (sizeof OPTS_TREE - 1) -#define OPTS_INTREE "no:grd:l:" +#define OPTS_INTREE "no:grd:" #define OPTS_INTREE_LEN (sizeof OPTS_INTREE - 1) -#define OPTS_INSERVICE "no:grd:t:p:" +#define OPTS_INSERVICE "no:grd:p:" #define OPTS_INSERVICE_LEN (sizeof OPTS_INSERVICE - 1) #define OPTS_BOOT "hms:e:d:b:l:" #define OPTS_BOOT_LEN (sizeof OPTS_BOOT - 1) diff --git a/src/lib66/exec/ssexec_help.c b/src/lib66/exec/ssexec_help.c index 12ebe70c..e1d2f63f 100644 --- a/src/lib66/exec/ssexec_help.c +++ b/src/lib66/exec/ssexec_help.c @@ -358,8 +358,9 @@ char const *help_tree_status = " depends: displays the list of tree(s) started before\n" " requiredby: displays the list of tree(s) started after\n" " allowed: displays a list of allowed user to use the tree\n" -" symlinks: displays the target of tree's symlinks\n" " contents: displays the contents of the tree\n" +"\n" +"If not trees are provided, it display all trees from the system\n" ; char const *usage_tree_up = "66 tree up [ -h ] [ -f ] tree" ; diff --git a/src/lib66/exec/ssexec_intree.c b/src/lib66/exec/ssexec_intree.c index c6ea85c6..46d0c353 100644 --- a/src/lib66/exec/ssexec_intree.c +++ b/src/lib66/exec/ssexec_intree.c @@ -45,12 +45,6 @@ static unsigned int REVERSE = 0 ; static unsigned int NOFIELD = 1 ; static unsigned int GRAPH = 0 ; -static uid_t OWNER ; -static char OWNERSTR[UID_FMT] ; - -static stralloc base = STRALLOC_ZERO ; -static stralloc live = STRALLOC_ZERO ; -static stralloc src = STRALLOC_ZERO ; static wchar_t const field_suffix[] = L" :" ; static char fields[INFO_NKEY][INFO_FIELD_MAXLEN] = {{ 0 }} ; @@ -61,11 +55,12 @@ static void info_display_init(char const *field,char const *treename) ; static void info_display_depends(char const *field,char const *treename) ; static void info_display_requiredby(char const *field,char const *treename) ; static void info_display_allow(char const *field,char const *treename) ; -static void info_display_symlink(char const *field,char const *treename) ; static void info_display_contents(char const *field,char const *treename) ; static void info_display_groups(char const *field,char const *treename) ; static info_graph_style *T_STYLE = &graph_default ; +static ssexec_t_ref pinfo = 0 ; + info_opts_map_t const opts_tree_table[] = { { .str = "name", .func = &info_display_name, .id = 0 }, @@ -73,15 +68,14 @@ info_opts_map_t const opts_tree_table[] = { .str = "enabled", .func = &info_display_enabled, .id = 2 }, { .str = "init", .func = &info_display_init, .id = 3 }, { .str = "allowed", .func = &info_display_allow, .id = 4 }, - { .str = "symlinks", .func = &info_display_symlink, .id = 5 }, - { .str = "groups", .func = &info_display_groups, .id = 6 }, - { .str = "depends", .func = &info_display_depends, .id = 7 }, - { .str = "requiredby", .func = &info_display_requiredby, .id = 8 }, - { .str = "contents", .func = &info_display_contents, .id = 9 }, + { .str = "groups", .func = &info_display_groups, .id = 5 }, + { .str = "depends", .func = &info_display_depends, .id = 6 }, + { .str = "requiredby", .func = &info_display_requiredby, .id = 7 }, + { .str = "contents", .func = &info_display_contents, .id = 8 }, { .str = 0, .func = 0, .id = -1 } } ; -#define MAXOPTS 11 +#define MAXOPTS 10 #define checkopts(n) if (n >= MAXOPTS) log_die(LOG_EXIT_USER, "too many options") #define DELIM ',' @@ -94,51 +88,135 @@ static void info_display_name(char const *field, char const *treename) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } -static void info_display_init(char const *field,char const *treename) +static void info_display_current(char const *field,char const *treename) { - unsigned int init = 0 ; - int r = set_livedir(&live) ; - if (!r) log_die_nomem("stralloc") ; - if (r == -1) log_die(LOG_EXIT_SYS,"live: ",live.s," must be an absolute path") ; - - init = tree_isinitialized(base.s, treename) ; - if (init == -1) log_dieu(LOG_EXIT_SYS, "resolve file of tree: ", treename) ; + int current = tree_iscurrent(pinfo->base.s, treename) ; + if (current < 0) + log_dieu(LOG_EXIT_ZERO, "read resolve file of: ", treename) ; if (NOFIELD) info_display_field_name(field) ; - if (!bprintf(buffer_1,"%s%s%s",init ? log_color->valid : log_color->warning, init ? "yes":"no",log_color->off)) + if (!bprintf(buffer_1,"%s%s%s", current ? log_color->blink : log_color->warning, current ? "yes":"no",log_color->off)) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") == -1) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; - } -static void info_display_current(char const *field,char const *treename) +static void info_display_enabled(char const *field,char const *treename) { - int current = tree_iscurrent(base.s, treename) ; - if (current < 0) + int enabled = tree_isenabled(pinfo->base.s, treename) ; + if (enabled < 0) log_dieu(LOG_EXIT_ZERO, "read resolve file of: ", treename) ; if (NOFIELD) info_display_field_name(field) ; - if (!bprintf(buffer_1,"%s%s%s", current ? log_color->blink : log_color->warning, current ? "yes":"no",log_color->off)) + if (!bprintf(buffer_1,"%s%s%s",enabled ? log_color->valid : log_color->warning, enabled ? "yes":"no",log_color->off)) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") == -1) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } -static void info_display_enabled(char const *field,char const *treename) +static void info_display_init(char const *field,char const *treename) { - int enabled = tree_isenabled(base.s, treename) ; - if (enabled < 0) - log_dieu(LOG_EXIT_ZERO, "read resolve file of: ", treename) ; + unsigned int init = tree_isinitialized(pinfo->base.s, treename) ; + if (init == -1) log_dieu(LOG_EXIT_SYS, "resolve file of tree: ", treename) ; if (NOFIELD) info_display_field_name(field) ; - if (!bprintf(buffer_1,"%s%s%s",enabled ? log_color->valid : log_color->warning, enabled ? "yes":"no",log_color->off)) + if (!bprintf(buffer_1,"%s%s%s",init ? log_color->valid : log_color->warning, init ? "yes":"no",log_color->off)) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (buffer_putsflush(buffer_1,"\n") == -1) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; + +} + +static void info_display_allow(char const *field, char const *treename) +{ + + stralloc sa = STRALLOC_ZERO ; + resolve_tree_t tres = RESOLVE_TREE_ZERO ; + resolve_wrapper_t_ref wres = resolve_set_struct(DATA_TREE, &tres) ; + + if (!resolve_read_g(wres, pinfo->base.s, treename)) + log_dieusys(LOG_EXIT_SYS,"read resolve file of tree: ", treename) ; + + if (NOFIELD) + info_display_field_name(field) ; + + if (tres.nallow) { + + if (!sastr_clean_string(&sa, tres.sa.s + tres.allow)) + log_dieu(LOG_EXIT_SYS,"clean groups string") ; + + if (!sa.len) + goto empty ; + + size_t len = sa.len, pos = 0 ; + char t[len + 1] ; + + sastr_to_char(t, &sa) ; + + sa.len = 0 ; + + for (; pos < len ; pos += strlen(t + pos) + 1) { + + char *suid = t + pos ; + uid_t uid = 0 ; + if (!uid0_scan(suid, &uid)) + log_dieusys(LOG_EXIT_SYS,"get uid of: ",suid) ; + if (pos) + if (!stralloc_cats(&sa," ")) log_die_nomem("stralloc") ; + if (!get_namebyuid(uid,&sa)) + log_dieusys(LOG_EXIT_SYS, "get name of uid: ", suid) ; + } + + if (!stralloc_0(&sa)) log_die_nomem("stralloc") ; + if (!sastr_rebuild_in_oneline(&sa)) log_dieu(LOG_EXIT_SYS,"rebuild list") ; + + if (!stralloc_0(&sa)) log_die_nomem("stralloc") ; + + info_display_list(field,&sa) ; + + } else { + + empty: + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning,"None",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; + } + + resolve_free(wres) ; + stralloc_free(&sa) ; + +} + +static void info_display_groups(char const *field, char const *treename) +{ + stralloc sa = STRALLOC_ZERO ; + resolve_tree_t tres = RESOLVE_TREE_ZERO ; + resolve_wrapper_t_ref wres = resolve_set_struct(DATA_TREE, &tres) ; + + if (!resolve_read_g(wres, pinfo->base.s, treename)) + log_dieusys(LOG_EXIT_SYS,"read resolve file of: ", treename) ; + + if (NOFIELD) + info_display_field_name(field) ; + + if (tres.ngroups) { + + if (!sastr_clean_string(&sa, tres.sa.s + tres.groups)) + log_dieu(LOG_EXIT_SYS,"clean groups string") ; + + info_display_list(field,&sa) ; + + } else { + + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning,"None",log_color->off)) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; + } + + resolve_free(wres) ; + stralloc_free(&sa) ; + } static void info_display_depends(char const *field, char const *treename) @@ -151,7 +229,7 @@ static void info_display_depends(char const *field, char const *treename) if (NOFIELD) padding = info_display_field_name(field) ; else { field = 0 ; padding = 0 ; } - graph_build_tree(&graph, base.s, E_RESOLVE_TREE_MASTER_CONTENTS) ; + graph_build_tree(&graph, pinfo->base.s, E_RESOLVE_TREE_MASTER_CONTENTS) ; r = graph_matrix_get_edge_g_sorted_sa(&sa, &graph, treename, 0, 0) ; if (r < 0) @@ -161,12 +239,12 @@ static void info_display_depends(char const *field, char const *treename) goto empty ; if (GRAPH) { - if (!bprintf(buffer_1,"%s\n","/")) + if (!bprintf(buffer_1,"%s\n","\\")) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; depth_t d = info_graph_init() ; - if (!info_walk(&graph, treename, treename, &info_graph_display_tree, 0, REVERSE, &d, padding, T_STYLE)) + if (!info_walk(&graph, treename, 0, &info_graph_display_tree, 0, REVERSE, &d, padding, T_STYLE)) log_dieu(LOG_EXIT_SYS,"display the graph dependencies") ; goto freed ; @@ -184,7 +262,7 @@ static void info_display_depends(char const *field, char const *treename) empty: if (GRAPH) { - if (!bprintf(buffer_1,"%s\n","/")) + if (!bprintf(buffer_1,"%s\n","\\")) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", T_STYLE->last, log_color->warning,"None",log_color->off)) @@ -211,7 +289,7 @@ static void info_display_requiredby(char const *field, char const *treename) if (NOFIELD) padding = info_display_field_name(field) ; else { field = 0 ; padding = 0 ; } - graph_build_tree(&graph, base.s, E_RESOLVE_TREE_MASTER_CONTENTS) ; + graph_build_tree(&graph, pinfo->base.s, E_RESOLVE_TREE_MASTER_CONTENTS) ; r = graph_matrix_get_edge_g_sorted_sa(&sa, &graph, treename, 1, 0) ; if (r < 0) @@ -222,12 +300,12 @@ static void info_display_requiredby(char const *field, char const *treename) if (GRAPH) { - if (!bprintf(buffer_1,"%s\n","/")) + if (!bprintf(buffer_1,"%s\n","\\")) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; depth_t d = info_graph_init() ; - if (!info_walk(&graph, treename, treename, &info_graph_display_tree, 1, REVERSE, &d, padding, T_STYLE)) + if (!info_walk(&graph, treename, 0, &info_graph_display_tree, 1, REVERSE, &d, padding, T_STYLE)) log_dieu(LOG_EXIT_SYS,"display the graph dependencies") ; goto freed ; @@ -246,7 +324,7 @@ static void info_display_requiredby(char const *field, char const *treename) empty: if (GRAPH) { - if (!bprintf(buffer_1,"%s\n","/")) + if (!bprintf(buffer_1,"%s\n","\\")) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", T_STYLE->last, log_color->warning,"None",log_color->off)) @@ -263,103 +341,26 @@ static void info_display_requiredby(char const *field, char const *treename) stralloc_free(&sa) ; } -static void info_display_allow(char const *field, char const *treename) -{ - if (NOFIELD) info_display_field_name(field) ; - size_t treenamelen = strlen(treename) , pos ; - stralloc sa = STRALLOC_ZERO ; - stralloc salist = STRALLOC_ZERO ; - char const *exclude[1] = { 0 } ; - - char tmp[src.len + treenamelen + SS_RULES_LEN + 1 ] ; - // force to close the string - auto_strings(tmp,src.s) ; - auto_string_from(tmp,src.len,treename,SS_RULES) ; - - if (!sastr_dir_get(&sa,tmp,exclude,S_IFREG)) - log_dieusys(LOG_EXIT_SYS,"get permissions of tree at: ",tmp) ; - - for (pos = 0 ; pos < sa.len ; pos += strlen(sa.s + pos) + 1) - { - char *suid = sa.s + pos ; - uid_t uid = 0 ; - if (!uid0_scan(suid, &uid)) - log_dieusys(LOG_EXIT_SYS,"get uid of: ",suid) ; - if (pos) - if (!stralloc_cats(&salist," ")) log_die_nomem("stralloc") ; - if (!get_namebyuid(uid,&salist)) - log_dieusys(LOG_EXIT_SYS,"get name of uid: ",suid) ; - } - if (!stralloc_0(&salist)) log_die_nomem("stralloc") ; - if (!sastr_rebuild_in_oneline(&salist)) log_dieu(LOG_EXIT_SYS,"rebuild list: ",salist.s) ; - if (!stralloc_0(&salist)) log_die_nomem("stralloc") ; - info_display_list(field,&salist) ; - - stralloc_free(&sa) ; - stralloc_free(&salist) ; -} - -static void info_display_symlink(char const *field, char const *treename) -{ - /* - if (NOFIELD) info_display_field_name(field) ; - ssexec_t info = SSEXEC_ZERO ; - if (!auto_stra(&info.treename,treename)) log_die_nomem("stralloc") ; - if (!auto_stra(&info.base,base.s)) log_die_nomem("stralloc") ; - int db , svc ; - size_t typelen ; - char type[UINT_FMT] ; - typelen = uint_fmt(type, TYPE_BUNDLE) ; - type[typelen] = 0 ; - - char cmd[typelen + 6 + 1] ; - - auto_strings(cmd,"-t",type," -b") ; - db = backup_cmd_switcher(VERBOSITY,cmd,&info) ; - if (db < 0) log_dieu(LOG_EXIT_SYS,"find realpath of symlink for db of tree: ",info.treename.s) ; - - typelen = uint_fmt(type, TYPE_CLASSIC) ; - type[typelen] = 0 ; - - auto_strings(cmd,"-t",type," -b") ; - svc = backup_cmd_switcher(VERBOSITY,cmd,&info) ; - if (svc < 0) log_dieu(LOG_EXIT_SYS,"find realpath of symlink for svc of tree: ",info.treename.s) ; - - if (!bprintf(buffer_1,"%s%s%s%s%s%s%s%s", "svc->",!svc ? log_color->valid : log_color->warning , !svc ? "source" : "backup",log_color->off, " db->", !db ? log_color->valid : log_color->warning, !db ? "source" : "backup", log_color->off)) - log_dieusys(LOG_EXIT_SYS,"write to stdout") ; - - if (buffer_putsflush(buffer_1,"\n") == -1) - log_dieusys(LOG_EXIT_SYS,"write to stdout") ; - - ssexec_free(&info) ; - */ -} - static void info_display_contents(char const *field, char const *treename) { - size_t padding = 1, treenamelen = strlen(treename) ; + size_t padding = 1 ; graph_t graph = GRAPH_ZERO ; - stralloc sa = STRALLOC_ZERO ; - char tmp[src.len + treenamelen + SS_SVDIRS_LEN + 1] ; + unsigned int areslen = 0 ; + resolve_service_t ares[SS_MAX_SERVICE] ; if (NOFIELD) padding = info_display_field_name(field) ; else { field = 0 ; padding = 0 ; } - auto_strings(tmp, src.s, treename, SS_SVDIRS) ; + graph_build_service(&graph, ares, &areslen, pinfo, STATE_FLAGS_TOPROPAGATE|STATE_FLAGS_WANTUP) ; - if (!graph_build_service_bytree(&graph, tmp, 2, 0)) - log_dieu(LOG_EXIT_SYS,"build the graph dependencies") ; + if (!graph.mlen) + log_die(LOG_EXIT_USER, "services selection is not available -- please make a bug report") ; - if (!graph_matrix_sort_tosa(&sa, &graph)) - log_dieu(LOG_EXIT_SYS, "get the dependencies list") ; - - if (!sa.len) goto empty ; + if (GRAPH) { - if (GRAPH) - { - if (!bprintf(buffer_1,"%s\n","/")) + if (!bprintf(buffer_1,"%s\n","\\")) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; depth_t d = info_graph_init() ; @@ -368,9 +369,17 @@ static void info_display_contents(char const *field, char const *treename) log_dieu(LOG_EXIT_SYS,"display the graph dependencies") ; goto freed ; - } - else - { + + } else { + + stralloc sa = STRALLOC_ZERO ; + + if (!resolve_get_field_tosa_g(&sa, pinfo->base.s, treename, DATA_TREE, E_RESOLVE_TREE_CONTENTS)) + log_dieu(LOG_EXIT_SYS, "get tree services list of: ", treename) ; + + if (!sa.len) + goto empty ; + if (REVERSE) if (!sastr_reverse(&sa)) log_dieu(LOG_EXIT_SYS,"reverse the dependencies list") ; @@ -379,87 +388,39 @@ static void info_display_contents(char const *field, char const *treename) goto freed ; } + empty: - if (GRAPH) - { - if (!bprintf(buffer_1,"%s\n","/")) + + if (GRAPH) { + + if (!bprintf(buffer_1,"%s\n","\\")) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; if (!bprintf(buffer_1,"%*s%s%s%s%s\n",padding, "", T_STYLE->last, log_color->warning,"None",log_color->off)) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; - } - else - { + + } else { + if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning,"None",log_color->off)) log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } freed: graph_free_all(&graph) ; - stralloc_free(&sa) ; -} - -static void info_display_groups(char const *field, char const *treename) -{ - stralloc sa = STRALLOC_ZERO ; - resolve_tree_t tres = RESOLVE_TREE_ZERO ; - resolve_wrapper_t_ref wres = resolve_set_struct(DATA_TREE, &tres) ; - - if (!resolve_read(wres, src.s, treename)) - log_dieusys(LOG_EXIT_SYS,"read resolve file of: ", src.s, "/.resolve/", treename) ; - - if (NOFIELD) - info_display_field_name(field) ; - - if (tres.ngroups) { - - if (!sastr_clean_string(&sa, tres.sa.s + tres.groups)) - log_dieu(LOG_EXIT_SYS,"clean groups string") ; - - info_display_list(field,&sa) ; - - } else { - - if (!bprintf(buffer_1,"%s%s%s\n",log_color->warning,"None",log_color->off)) - log_dieusys(LOG_EXIT_SYS,"write to stdout") ; - } - - resolve_free(wres) ; - stralloc_free(&sa) ; - } static void info_display_all(char const *treename,int *what) { unsigned int i = 0 ; - for (; what[i] >= 0 ; i++) - { + for (; what[i] >= 0 ; i++) { + unsigned int idx = what[i] ; (*opts_tree_table[idx].func)(fields[opts_tree_table[idx].id],treename) ; } } -static void info_sort_enabled_notenabled(stralloc *satree,stralloc *enabled,stralloc *not_enabled) -{ - size_t pos = 0 ; - - FOREACH_SASTR(satree,pos) { - - char *ename = satree->s + pos ; - - if (sastr_cmp(enabled,ename) == -1) - if (!sastr_add_string(not_enabled,ename)) - log_die_nomem("stralloc") ; - } - - if (not_enabled->len) - if (!sastr_sort(not_enabled)) - log_dieu(LOG_EXIT_SYS,"sort not enabled tree list") ; - -} - static void info_parse_options(char const *str,int *what) { size_t pos = 0 ; @@ -492,8 +453,11 @@ int ssexec_intree(int argc, char const *const *argv, ssexec_t *info) { unsigned int legacy = 1 ; - size_t pos, newlen, livelen ; + size_t pos = 0 ; int what[MAXOPTS] = { 0 } ; + stralloc sa = STRALLOC_ZERO ; + + pinfo = info ; char const *treename = 0 ; @@ -507,15 +471,11 @@ int ssexec_intree(int argc, char const *const *argv, ssexec_t *info) "Enabled", "Initialized", "Allowed", - "Symlinks", "Groups", "Depends", "Required by", "Contents" } ; - - stralloc satree = STRALLOC_ZERO ; - { subgetopt l = SUBGETOPT_ZERO ; @@ -531,9 +491,6 @@ int ssexec_intree(int argc, char const *const *argv, ssexec_t *info) case 'g' : GRAPH = 1 ; break ; case 'r' : REVERSE = 1 ; break ; case 'd' : if (!uint0_scan(l.arg, &MAXDEPTH)) log_usage(info->usage, "\n", info->help) ; break ; - case 'l' : if (!stralloc_cats(&live,l.arg)) log_usage(info->usage, "\n", info->help) ; - if (!stralloc_0(&live)) log_usage(info->usage, "\n", info->help) ; - break ; default : log_usage(info->usage, "\n", info->help) ; } } @@ -542,8 +499,8 @@ int ssexec_intree(int argc, char const *const *argv, ssexec_t *info) if (argv[0]) treename = argv[0] ; - if (legacy) - { + if (legacy) { + unsigned int i = 0 ; for (; i < MAXOPTS - 1 ; i++) what[i] = i ; @@ -551,100 +508,57 @@ int ssexec_intree(int argc, char const *const *argv, ssexec_t *info) what[i] = -1 ; } - OWNER = getuid() ; - size_t ownerlen = uid_fmt(OWNERSTR,OWNER) ; - OWNERSTR[ownerlen] = 0 ; info_field_align(buf,fields,field_suffix,MAXOPTS) ; setlocale(LC_ALL, ""); - if(!str_diff(nl_langinfo(CODESET), "UTF-8")) { + if(!str_diff(nl_langinfo(CODESET), "UTF-8")) T_STYLE = &graph_utf8; - } - - if (!set_ownersysdir(&base,OWNER)) log_dieusys(LOG_EXIT_SYS, "set owner directory") ; - if (!stralloc_copy(&src,&base) || - !stralloc_cats(&src,SS_SYSTEM) || - !stralloc_0(&src)) log_die_nomem("stralloc") ; - src.len-- ; - if (!scan_mode(src.s,S_IFDIR)) { - log_info("no tree exist yet") ; - goto freed ; + /** should never happens as long as we have + * a default created */ + char src[info->base.len + SS_SYSTEM_LEN + 1] ; + + auto_strings(src, info->base.s, SS_SYSTEM) ; + + if (!scan_mode(src, S_IFDIR)) { + log_info("no tree exist yet") ; + goto freed ; + } } - if (!stralloc_cats(&src,"/")) log_die_nomem("stralloc") ; + if (treename) { - newlen = src.len ; - livelen = live.len ; + if (!tree_isvalid(info->base.s, treename)) + log_dieusys(LOG_EXIT_SYS, "find tree: ", treename) ; - if (treename) - { + info_display_all(treename, what) ; - if (!auto_stra(&src,treename)) log_die_nomem("stralloc") ; - if (!scan_mode(src.s,S_IFDIR)) log_dieusys(LOG_EXIT_SYS,"find tree: ", src.s) ; - src.len = newlen ; - if (!stralloc_0(&src)) log_die_nomem("stralloc") ; - src.len-- ; - info_display_all(treename,what) ; - } - else - { - char const *exclude[2] = { SS_RESOLVE + 1, 0 } ; - if (!stralloc_0(&src)) log_die_nomem("stralloc") ; - if (!sastr_dir_get(&satree, src.s,exclude, S_IFDIR)) log_dieusys(LOG_EXIT_SYS,"get list of tree at: ",src.s) ; + } else { + graph_t graph = GRAPH_ZERO ; - if (satree.len) { + graph_build_tree(&graph, pinfo->base.s, E_RESOLVE_TREE_MASTER_CONTENTS) ; - stralloc enabled = STRALLOC_ZERO ; - stralloc not_enabled = STRALLOC_ZERO ; + if (!graph_matrix_sort_tosa(&sa, &graph)) + log_dieu(LOG_EXIT_SYS, "get the sorted list of trees") ; - if (!file_readputsa(&enabled,src.s,"state")) - log_dieusys(LOG_EXIT_SYS,"read contents of file: ",src.s,"/state") ; + graph_free_all(&graph) ; - /** May not have enabled tree yet */ - if (enabled.len) { + if (sa.len) { - if (!sastr_split_string_in_nline(&enabled)) - log_dieu(LOG_EXIT_SYS,"rebuild enabled tree list") ; - } + FOREACH_SASTR(&sa, pos) { - info_sort_enabled_notenabled(&satree,&enabled,¬_enabled) ; + info_display_all(sa.s + pos, what) ; - { - pos = 0 ; - FOREACH_SASTR(¬_enabled,pos) { - - src.len = newlen ; - live.len = livelen ; - char *name = not_enabled.s + pos ; - info_display_all(name,what) ; - if (buffer_puts(buffer_1,"\n") == -1) - log_dieusys(LOG_EXIT_SYS,"write to stdout") ; - } + if (buffer_puts(buffer_1,"\n") == -1) + log_dieusys(LOG_EXIT_SYS,"write to stdout") ; } - { - pos = 0 ; - FOREACH_SASTR(&enabled,pos) { - - src.len = newlen ; - live.len = livelen ; - char *name = enabled.s + pos ; - info_display_all(name,what) ; - if (buffer_puts(buffer_1,"\n") == -1) - log_dieusys(LOG_EXIT_SYS,"write to stdout") ; - } - } + } else { - stralloc_free(&enabled) ; - stralloc_free(¬_enabled) ; - } - else - { log_info("no tree exist yet") ; goto freed ; } @@ -655,11 +569,8 @@ int ssexec_intree(int argc, char const *const *argv, ssexec_t *info) freed: - stralloc_free(&base) ; - stralloc_free(&live) ; - stralloc_free(&src) ; - stralloc_free(&satree) ; + stralloc_free(&sa) ; return 0 ; } -- GitLab