Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* info_graph_display_tree.c
*
* Copyright (c) 2018-2021 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 <unistd.h>
#include <sys/types.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
#include <skalibs/stralloc.h>
#include <skalibs/lolstdio.h>
#include <skalibs/buffer.h>
#include <66/tree.h>
#include <66/resolve.h>
#include <66/utils.h>
#include <66/constants.h>
#include <66/info.h>
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 = tres.init ;
if (init < 0)
goto freed ;
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 ;
}