From c6ece9313027ca7150587ba44764f9b38f54d405 Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Mon, 10 Jan 2022 18:51:44 +1100 Subject: [PATCH] add info_graph_display_tree() function --- src/include/66/info.h | 6 ++-- src/lib66/info_utils.c | 74 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/include/66/info.h b/src/include/66/info.h index a0547f8f..af9afdcf 100644 --- a/src/include/66/info.h +++ b/src/include/66/info.h @@ -80,9 +80,9 @@ extern void info_display_list(char const *field, stralloc *list) ; extern void info_display_nline(char const *field,char const *str) ; extern depth_t info_graph_init(void) ; -extern int info_graph_display_service(char const *name, char const *obj) ; -extern int info_graph_display(char const *name, char const *obj, info_graph_func *func, depth_t *depth, int last, int padding, info_graph_style *style) ; - extern int info_walk(graph_t *g, char const *name, char const *obj, info_graph_func *func, uint8_t requiredby, uint8_t reverse, depth_t *depth, int padding, info_graph_style *style) ; +extern int info_graph_display(char const *name, char const *obj, info_graph_func *func, depth_t *depth, int last, int padding, info_graph_style *style) ; +extern int info_graph_display_service(char const *name, char const *obj) ; +extern int info_graph_display_tree(char const *name, char const *obj) ; #endif diff --git a/src/lib66/info_utils.c b/src/lib66/info_utils.c index da8aeff5..1f8d0406 100644 --- a/src/lib66/info_utils.c +++ b/src/lib66/info_utils.c @@ -33,6 +33,8 @@ #include <66/resolve.h> #include <66/state.h> +#include <66/utils.h> +#include <66/constants.h> unsigned int MAXDEPTH = 1 ; @@ -224,13 +226,83 @@ depth_t info_graph_init(void) return d ; } +int info_graph_display_tree(char const *name, char const *obj) +{ + log_flow() ; + + int err = 0 ; + stralloc sa = STRALLOC_ZERO ; + resolve_tree_t tres = RESOLVE_TREE_ZERO ; + resolve_wrapper_t_ref wres = resolve_set_struct(DATA_TREE, &tres) ; + + uid_t owner = getuid() ; + + if (!set_ownersysdir(&sa, owner)) { + log_warnusys("set owner directory") ; + resolve_free(wres) ; + stralloc_free(&sa) ; + return err ; + } + + char base[sa.len + 1] ; + auto_strings(base, sa.s) ; + + if (tree_isvalid(sa.s, name) <= 0) { + log_warn("invalide tree: ", name) ; + goto freed ; + } + + if (!auto_stra(&sa, SS_SYSTEM)) + goto freed ; + + if (!resolve_check(sa.s, name)) + goto freed ; + + if (!resolve_read(wres, sa.s, name)) + goto freed ; + + sa.len = 0 ; + + int r = set_livedir(&sa) ; + if (r <= 0) + goto freed ; + + int init = tree_isinitialized(sa.s, name, owner) ; + + int enabled = tree_isenabled(base, name) ; + if (enabled < 0) + goto freed ; + + if (!bprintf(buffer_1,"(%s%s%s,%s%s%s) %s", \ + + init ? log_color->valid : log_color->warning, \ + init ? "Initialized" : "Unitialized", \ + log_color->off, \ + + enabled ? log_color->valid : log_color->error, \ + enabled ? "Enabled" : "Disabled", \ + log_color->off, \ + + name)) + goto freed ; + + err = 1 ; + + freed: + resolve_free(wres) ; + stralloc_free(&sa) ; + + return err ; + +} + int info_graph_display_service(char const *name, char const *obj) { log_flow() ; stralloc tree = STRALLOC_ZERO ; resolve_service_t res = RESOLVE_SERVICE_ZERO ; - resolve_wrapper_t_ref wres = resolve_set_struct(SERVICE_STRUCT, &res) ; + resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, &res) ; int r = service_intree(&tree, name, obj), err = 0 ; -- GitLab