Skip to content
Snippets Groups Projects
Commit 06978a20 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

split service_enable_disable to external function

parent 0552f467
No related branches found
No related tags found
No related merge requests found
......@@ -358,6 +358,7 @@ extern int service_resolve_modify_field(resolve_service_t *res, resolve_service_
extern int service_resolve_read_cdb(cdb *c, resolve_service_t *res) ;
extern int service_resolve_write(resolve_service_t *res) ;
extern int service_resolve_write_cdb(cdbmaker *c, resolve_service_t *sres) ;
extern void service_enable_disable(graph_t *g, char const *base, char const *sv, uint8_t action) ;
/** Master */
extern int service_resolve_master_copy(resolve_service_master_t *dst, resolve_service_master_t *mres) ;
......
......@@ -16,39 +16,20 @@
#include <stdint.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
#include <oblibs/sastr.h>
#include <oblibs/types.h>
#include <oblibs/sastr.h>
#include <oblibs/string.h>
#include <skalibs/stralloc.h>
#include <skalibs/sgetopt.h>
#include <skalibs/stralloc.h>
#include <66/graph.h>
#include <66/constants.h>
#include <66/sanitize.h>
#include <66/state.h>
#include <66/service.h>
#include <66/ssexec.h>
typedef enum visit_e visit ;
enum visit_e
{
SS_WHITE = 0,
SS_GRAY,
SS_BLACK
} ;
static void visit_init(visit *v, size_t len)
{
log_flow() ;
size_t pos = 0 ;
for (; pos < len; pos++)
v[pos] = SS_WHITE ;
}
void service_enable_disable(graph_t *g, char const *base, char const *name, uint8_t action) ;
#include <66/graph.h>
#include <66/service.h>
#include <66/config.h>
#include <66/state.h>
#include <66/resolve.h>
static void check_identifier(char const *name)
{
......@@ -61,58 +42,8 @@ static void check_identifier(char const *name)
if (!strcmp(name,"service@")) log_die(LOG_EXIT_USER,"service@ as service name is a reserved name") ;
}
void service_enable_disable_deps(graph_t *g, char const *base, char const *sv, uint8_t action)
{
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 v[len] ;
visit_init(v, len) ;
if (sa.len) {
FOREACH_SASTR(&sa, pos) {
if (v[element] == SS_WHITE) {
char *name = sa.s + pos ;
service_enable_disable(g, base, name, action) ;
v[element] = SS_GRAY ;
}
element++ ;
}
}
stralloc_free(&sa) ;
}
/** @action -> 0 disable
* @action -> 1 enable */
void service_enable_disable(graph_t *g, char const *base, char const *name, uint8_t action)
{
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) ;
service_enable_disable_deps(g, base, name, action) ;
log_info(!action ? "Disabled" : "Enabled"," successfully service: ", name) ;
}
static void parse_it(char const *name, uint8_t force, uint8_t conf, ssexec_t *info)
{
int argc = 4 + (force ? 1 : 0) + (conf ? 1 : 0) ;
int m = 0 ;
char const *prog = PROG ;
......@@ -207,13 +138,7 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
for (n = 0 ; n < argc ; n++) {
service_enable_disable(&graph, info->base.s, argv[n], 1) ;
int aresid = service_resolve_array_search(ares, areslen, argv[n]) ;
if (aresid < 0)
log_die(LOG_EXIT_USER, "service: ", argv[n], " not available -- please make a bug report") ;
char *treename = ares[aresid].sa.s + ares[aresid].treename ;
service_enable_disable(&graph, info->base.s, argv[n], 1) ;
if (!sastr_add_string(&sa, argv[n]))
log_dieu(LOG_EXIT_SYS, "add string") ;
......@@ -221,8 +146,7 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
if (start && sa.len) {
size_t len = sastr_len(&sa) ;
pos = 0 ;
size_t len = sastr_nelement(&sa) ;
int nargc = 1 + len ;
char const *prog = PROG ;
char const *newargv[nargc] ;
......
service_cmp_basedir.o
service_enable_disable.o
service_endof_dir.o
service_frontend_path.o
service_frontend_src.o
......
/*
* service_enable_disable.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 <stdint.h>
#include <oblibs/log.h>
#include <oblibs/graph.h>
#include <oblibs/sastr.h>
#include <skalibs/stralloc.h>
#include <66/service.h>
#include <66/graph.h>
#include <66/state.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)
{
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 (sa.len) {
FOREACH_SASTR(&sa, pos) {
if (v[element] == SS_WHITE) {
char *name = sa.s + pos ;
service_enable_disable(g, base, name, action) ;
v[element] = SS_GRAY ;
}
element++ ;
}
}
stralloc_free(&sa) ;
}
/** @action -> 0 disable
* @action -> 1 enable */
void service_enable_disable(graph_t *g, char const *base, char const *name, uint8_t action)
{
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) ;
service_enable_disable_deps(g, base, name, action) ;
log_info(!action ? "Disabled" : "Enabled"," successfully service: ", name) ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment