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

fix logger creation in case of earlier service, less memory allocation

parent 67ac4c0f
No related branches found
No related tags found
No related merge requests found
......@@ -15,12 +15,14 @@
#include <string.h>
#include <sys/types.h>
#include <unistd.h>//chown
//#include <stdio.h>
#include <stdio.h>
#include <oblibs/error2.h>
#include <oblibs/types.h>//scan_mode
#include <oblibs/stralist.h>
#include <oblibs/directory.h>
#include <oblibs/sastr.h>
#include <oblibs/string.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
......@@ -39,11 +41,10 @@
int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec_t *info)
{
int r, db, classic, earlier ;
genalloc gasvc = GENALLOC_ZERO ; //stralist type
ssize_t i = 0, logname = 0 ;
genalloc gares = GENALLOC_ZERO ; //ss_resolve_t type
stralloc sares = STRALLOC_ZERO ;
stralloc sasvc = STRALLOC_ZERO ;
ss_resolve_t res = RESOLVE_ZERO ;
ss_state_t sta = STATE_ZERO ;
......@@ -67,7 +68,7 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec
r = scandir_ok(info->scandir.s) ;
if (r != 1) earlier = 1 ;
r = scan_mode(info->livetree.s,S_IFDIR) ;
if (r < 0) strerr_dief2x(111,info->livetree.s," conflicted format") ;
if (!r)
......@@ -90,32 +91,30 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec
/** svc already initiated? */
if (classic)
{
size_t i ;
if (!dir_get(&gasvc,svdir,"",S_IFDIR)) strerr_diefu1x(111,"get classic services") ;
if (!genalloc_len(stralist,&gasvc))
if (!sastr_dir_get(&sasvc,svdir,"",S_IFDIR)) strerr_diefu2x(111,"get classic services from: ",svdir) ;
if (!sasvc.len)
{
VERBO1 strerr_warni2x("Initialization aborted -- no classic services into tree: ",info->treename.s) ;
genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ;
genalloc_deepfree(stralist,&gasvc,stra_free) ;
goto follow ;
}
if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC))
strerr_diefu1x(111,"set revolve pointer to source") ;
for (i = 0 ; i < genalloc_len(stralist,&gasvc) ; i++)
for (i = 0;i < sasvc.len; i += strlen(sasvc.s + i) + 1)
{
char *name = gaistr(&gasvc,i) ;
char *name = sasvc.s + i ;
ss_resolve_t tmp = RESOLVE_ZERO ;
if (!ss_resolve_check(sares.s,name)) strerr_dief2sys(110,"unknown service: ",name) ;
if (!ss_resolve_read(&tmp,sares.s,name)) strerr_diefu2sys(111,"read resolve file of: ",name) ;
if (!ss_resolve_add_deps(&gares,&tmp,sares.s)) strerr_diefu2sys(111,"resolve dependencies of: ",name) ;
ss_resolve_free(&tmp) ;
}
/** reverse to start first the logger */
genalloc_reverse(ss_resolve_t,&gares) ;
if (!earlier)
{
/** reverse to start first the logger */
genalloc_reverse(ss_resolve_t,&gares) ;
if (!svc_init(info,svdir,&gares)) strerr_diefu2x(111,"initiate service of tree: ",info->treename.s) ;
}
else
......@@ -123,22 +122,25 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec
if (!ss_resolve_create_live(info)) strerr_diefu1sys(111,"create live state") ;
for (i = 0 ; i < genalloc_len(ss_resolve_t,&gares) ; i++)
{
logname = 0 ;
char *string = genalloc_s(ss_resolve_t,&gares)[i].sa.s ;
char *name = string + genalloc_s(ss_resolve_t,&gares)[i].name ;
size_t namelen = strlen(name) ;
logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ;
if (logname > 0) name = string + genalloc_s(ss_resolve_t,&gares)[i].logassoc ;
char tocopy[dirlen + 1 + namelen + 1] ;
memcpy(tocopy,svdir,dirlen) ;
tocopy[dirlen] = '/' ;
memcpy(tocopy + dirlen + 1, name, namelen) ;
tocopy[dirlen + 1 + namelen] = 0 ;
if (!hiercopy(tocopy,string + genalloc_s(ss_resolve_t,&gares)[i].runat)) strerr_diefu4sys(111,"copy: ",tocopy," to: ",string + genalloc_s(ss_resolve_t,&gares)[i].runat) ;
if (!hiercopy(tocopy,string + genalloc_s(ss_resolve_t,&gares)[i].runat)) strerr_diefu4sys(111,"copy earlier service: ",tocopy," to: ",string + genalloc_s(ss_resolve_t,&gares)[i].runat) ;
ss_state_setflag(&sta,SS_FLAGS_RELOAD,SS_FLAGS_FALSE) ;
ss_state_setflag(&sta,SS_FLAGS_INIT,SS_FLAGS_FALSE) ;
// ss_state_setflag(&sta,SS_FLAGS_UNSUPERVISE,SS_FLAGS_FALSE) ;
ss_state_setflag(&sta,SS_FLAGS_STATE,SS_FLAGS_UNKNOWN) ;
ss_state_setflag(&sta,SS_FLAGS_PID,SS_FLAGS_UNKNOWN) ;
if (!ss_state_write(&sta,string + genalloc_s(ss_resolve_t,&gares)[i].state,name)) strerr_diefu2sys(111,"write state file of: ",name) ;
VERBO1 strerr_warni2x("Initialized successfully: ",name) ;
VERBO1 strerr_warni2x("Initialized successfully: ", logname < 0 ? name : string + genalloc_s(ss_resolve_t,&gares)[i].logreal) ;
}
}
}
......@@ -146,10 +148,10 @@ int ssexec_init(int argc, char const *const *argv,char const *const *envp,ssexec
follow:
stralloc_free(&sares) ;
stralloc_free(&sasvc) ;
ss_resolve_free(&res) ;
genalloc_deepfree(ss_resolve_t,&gares,ss_resolve_free) ;
genalloc_deepfree(stralist,&gasvc,stra_free) ;
/** db already initiated? */
if (db)
{
......
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