Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
6
66
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eric Vidal
66
Commits
d5a4c0c5
Commit
d5a4c0c5
authored
1 year ago
by
Eric Vidal
Browse files
Options
Downloads
Patches
Plain Diff
handle logger and module/bundle service
parent
d6e71e59
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib66/service/service_enable_disable.c
+65
-34
65 additions, 34 deletions
src/lib66/service/service_enable_disable.c
with
65 additions
and
34 deletions
src/lib66/service/service_enable_disable.c
+
65
−
34
View file @
d5a4c0c5
...
...
@@ -23,51 +23,33 @@
#include
<66/service.h>
#include
<66/graph.h>
#include
<66/state.h>
#include
<66/utils.h>
#include
<66/enum.h>
typedef
enum
visit_service_e
visit_service_t
;
enum
visit_service_e
{
SS_WHITE
=
0
,
SS_GRAY
,
SS_BLACK
}
;
static
void
visit_init
(
visit_service_t
*
v
,
size_t
len
)
{
log_flow
()
;
size_t
pos
=
0
;
for
(;
pos
<
len
;
pos
++
)
v
[
pos
]
=
SS_WHITE
;
}
static
void
service_enable_disable_deps
(
graph_t
*
g
,
char
const
*
base
,
char
const
*
sv
,
uint8_t
action
)
static
void
service_enable_disable_deps
(
graph_t
*
g
,
resolve_service_t
*
res
,
resolve_service_t
*
ares
,
unsigned
int
areslen
,
uint8_t
action
,
visit_t
*
visit
)
{
log_flow
()
;
size_t
pos
=
0
,
element
=
0
;
stralloc
sa
=
STRALLOC_ZERO
;
if
(
graph_matrix_get_edge_g_sa
(
&
sa
,
g
,
sv
,
action
?
0
:
1
,
0
)
<
0
)
log_dieu
(
LOG_EXIT_SYS
,
"get "
,
action
?
"dependencies"
:
"required by"
,
" of: "
,
sv
)
;
size_t
len
=
sastr_nelement
(
&
sa
)
;
visit_service_t
v
[
len
]
;
visit_init
(
v
,
len
)
;
if
(
graph_matrix_get_edge_g_sa
(
&
sa
,
g
,
res
->
sa
.
s
+
res
->
name
,
action
?
0
:
1
,
0
)
<
0
)
log_dieu
(
LOG_EXIT_SYS
,
"get "
,
action
?
"dependencies"
:
"required by"
,
" of: "
,
res
->
sa
.
s
+
res
->
name
)
;
if
(
sa
.
len
)
{
FOREACH_SASTR
(
&
sa
,
pos
)
{
if
(
v
[
element
]
==
SS
_WHITE
)
{
if
(
v
isit
[
element
]
==
VISIT
_WHITE
)
{
char
*
name
=
sa
.
s
+
pos
;
int
aresid
=
service_resolve_array_search
(
ares
,
areslen
,
name
)
;
if
(
aresid
<
0
)
log_die
(
LOG_EXIT_USER
,
"service: "
,
name
,
" not available -- did you parsed it?"
)
;
service_enable_disable
(
g
,
base
,
name
,
action
)
;
service_enable_disable
(
g
,
&
ares
[
aresid
],
ares
,
areslen
,
action
,
visit
)
;
v
[
element
]
=
SS
_GRAY
;
v
isit
[
element
]
=
VISIT
_GRAY
;
}
element
++
;
}
...
...
@@ -78,15 +60,64 @@ static void service_enable_disable_deps(graph_t *g, char const *base, char const
/** @action -> 0 disable
* @action -> 1 enable */
void
service_enable_disable
(
graph_t
*
g
,
char
const
*
base
,
char
const
*
name
,
uint8_t
action
)
void
service_enable_disable
(
graph_t
*
g
,
resolve_service_t
*
res
,
resolve_service_t
*
ares
,
unsigned
int
areslen
,
uint8_t
action
,
visit_t
*
visit
)
{
log_flow
()
;
if
(
!
state_messenger
(
base
,
name
,
STATE_FLAGS_ISENABLED
,
!
action
?
STATE_FLAGS_FALSE
:
STATE_FLAGS_TRUE
))
log_dieusys
(
LOG_EXIT_SYS
,
"send message to state of: "
,
name
)
;
if
(
!
state_messenger
(
res
,
STATE_FLAGS_ISENABLED
,
!
action
?
STATE_FLAGS_FALSE
:
STATE_FLAGS_TRUE
))
log_dieusys
(
LOG_EXIT_SYS
,
"send message to state of: "
,
res
->
sa
.
s
+
res
->
name
)
;
service_enable_disable_deps
(
g
,
res
,
ares
,
areslen
,
action
,
visit
)
;
/** the logger must be disabled to avoid to start it
* with the 66 tree start <tree> command */
if
(
res
->
logger
.
want
&&
!
action
)
{
char
*
name
=
res
->
sa
.
s
+
res
->
logger
.
name
;
int
aresid
=
service_resolve_array_search
(
ares
,
areslen
,
name
)
;
if
(
aresid
<
0
)
log_die
(
LOG_EXIT_USER
,
"service: "
,
name
,
" not available -- did you parsed it?"
)
;
if
(
!
state_messenger
(
&
ares
[
aresid
],
STATE_FLAGS_ISENABLED
,
!
action
?
STATE_FLAGS_FALSE
:
STATE_FLAGS_TRUE
))
log_dieusys
(
LOG_EXIT_SYS
,
"send message to state of: "
,
name
)
;
log_info
(
"Disabled successfully service: "
,
name
)
;
service_enable_disable_deps
(
g
,
base
,
name
,
action
)
;
}
if
(
res
->
type
==
TYPE_MODULE
||
res
->
type
==
TYPE_BUNDLE
)
{
if
(
res
->
dependencies
.
ncontents
)
{
size_t
pos
=
0
;
stralloc
sa
=
STRALLOC_ZERO
;
visit_t
mvisit
[
SS_MAX_SERVICE
]
;
visit_init
(
mvisit
,
SS_MAX_SERVICE
)
;
if
(
!
sastr_clean_string
(
&
sa
,
res
->
sa
.
s
+
res
->
dependencies
.
contents
))
log_dieu
(
LOG_EXIT_SYS
,
"clean string"
)
;
FOREACH_SASTR
(
&
sa
,
pos
)
{
char
*
name
=
sa
.
s
+
pos
;
int
aresid
=
service_resolve_array_search
(
ares
,
areslen
,
name
)
;
if
(
aresid
<
0
)
log_die
(
LOG_EXIT_USER
,
"service: "
,
name
,
" not available -- did you parsed it?"
)
;
if
(
!
state_messenger
(
&
ares
[
aresid
],
STATE_FLAGS_ISENABLED
,
!
action
?
STATE_FLAGS_FALSE
:
STATE_FLAGS_TRUE
))
log_dieusys
(
LOG_EXIT_SYS
,
"send message to state of: "
,
res
->
sa
.
s
+
res
->
name
)
;
service_enable_disable_deps
(
g
,
&
ares
[
aresid
],
ares
,
areslen
,
action
,
mvisit
)
;
log_info
(
!
action
?
"Disabled"
:
"Enabled"
,
" successfully service: "
,
ares
[
aresid
].
sa
.
s
+
ares
[
aresid
].
name
)
;
}
stralloc_free
(
&
sa
)
;
}
}
log_info
(
!
action
?
"Disabled"
:
"Enabled"
,
" successfully service: "
,
name
)
;
log_info
(
!
action
?
"Disabled"
:
"Enabled"
,
" successfully service: "
,
res
->
sa
.
s
+
res
->
name
)
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment