Commit 63fdaa2a authored by Eric Vidal's avatar Eric Vidal 💬

Merge branch 'dev'

parents 9f54978a df8e34c8
......@@ -180,7 +180,7 @@ man: $(ALL_MAN:%.scd=%)
install-man:
for i in 1 5 8 ; do \
install -m755 -d $(DESTDIR)$(mandir)/man$$i; \
install -m644 man/*.$$i $(DESTDIR)$(mandir)/man$$i/ ; \
install -m644 doc/man/*.$$i $(DESTDIR)$(mandir)/man$$i/ ; \
done
.PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include man install-man
......
This diff is collapsed.
......@@ -24,7 +24,7 @@ key = value # comment not valid
Empty _value_ is *not* permitted.
If _val_ begin by a *!* character:
_key=*!*value_
key=*!*value
the _key_ will be removed from the environment after the substitution.
# LIMITS
......
......@@ -40,6 +40,7 @@
#include <66/constants.h>
#include <66/enum.h>
#include <66/resolve.h>
#include <66/environ.h>
#include <s6/s6-supervise.h>//s6_svc_ok
......@@ -606,8 +607,8 @@ int sv_args(int argc, char const *const *argv,char const *const *envp)
stralloc tree = STRALLOC_ZERO ;
genalloc gatree = GENALLOC_ZERO ;
stralloc src = STRALLOC_ZERO ;
stralloc env = STRALLOC_ZERO ;
stralloc conf = STRALLOC_ZERO ;
stralloc env = STRALLOC_ZERO ;
ss_resolve_t res = RESOLVE_ZERO ;
......@@ -651,12 +652,6 @@ int sv_args(int argc, char const *const *argv,char const *const *envp)
size_t newlen ;
/*if (!stralloc_copy(&src,&live)) goto err ;
if (!stralloc_cats(&src,SS_STATE + 1)) goto err ;
if (!stralloc_cats(&src,"/")) goto err ;
if (!stralloc_cats(&src,OWNERSTR)) goto err ;
if (!stralloc_cats(&src,"/")) goto err ;*/
if (!stralloc_copy(&src,&base)) goto err ;
if (!stralloc_cats(&src,SS_SYSTEM)) goto err ;
if (!stralloc_cats(&src,"/")) goto err ;
......@@ -762,26 +757,15 @@ int sv_args(int argc, char const *const *argv,char const *const *envp)
}
}
/** environment */
if(!OWNER)
{
if (!stralloc_cats(&env,SS_SERVICE_SYSCONFDIR)) goto err ;
if (!stralloc_0(&env)) goto err ;
}
else
{
if (!stralloc_cats(&env,base.s)) goto err ;
if (!stralloc_cats(&env,SS_ENVDIR)) goto err ;
if (!stralloc_0(&env)) goto err ;
}
if (dir_search(env.s,svname,S_IFREG))
if (res.srconf)
{
if (!env_resolve_conf(&env,MYUID)) goto err ;
if (!file_readputsa(&conf,env.s,svname)) goto err ;
if (!info_print_title("environment")) goto err ;
if (!bprintf(buffer_1,"%s%s\n","source : ",env.s)) goto err ;
if (!bprintf(buffer_1,"%s",conf.s)) goto err ;
}
/** logger */
if (res.type == CLASSIC || res.type == LONGRUN)
{
......@@ -823,8 +807,8 @@ int sv_args(int argc, char const *const *argv,char const *const *envp)
genalloc_deepfree(stralist,&gatree,stra_free) ;
ss_resolve_free(&res) ;
stralloc_free(&src) ;
stralloc_free(&env) ;
stralloc_free(&conf) ;
stralloc_free(&env) ;
return 1 ;
err:
......@@ -833,8 +817,8 @@ int sv_args(int argc, char const *const *argv,char const *const *envp)
genalloc_deepfree(stralist,&gatree,stra_free) ;
ss_resolve_free(&res) ;
stralloc_free(&src) ;
stralloc_free(&env) ;
stralloc_free(&conf) ;
stralloc_free(&env) ;
return 0 ;
}
......
......@@ -82,7 +82,8 @@ int main(int argc, char const *const *argv,char const *const *envp)
char const *sv ;
char name[4095+1] ;
char srcdir[4095+1] ;
int type, force = 0 ;
int type ;
unsigned int force = 0 , conf = 0 ;
PROG = "66-parser" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
......@@ -153,19 +154,19 @@ int main(int argc, char const *const *argv,char const *const *envp)
switch(type)
{
case CLASSIC:
if (!write_classic(&service, dst.s, force))
if (!write_classic(&service, dst.s, force, conf))
strerr_diefu2x(111,"write: ",name) ;
break ;
case LONGRUN:
if (!write_longrun(&service, dst.s, force))
if (!write_longrun(&service, dst.s, force, conf))
strerr_diefu2x(111,"write: ",name) ;
break ;
case ONESHOT:
if (!write_oneshot(&service, dst.s, force))
if (!write_oneshot(&service, dst.s, conf))
strerr_diefu2x(111,"write: ",name) ;
break ;
case BUNDLE:
if (!write_bundle(&service, dst.s, force))
if (!write_bundle(&service, dst.s))
strerr_diefu2x(111,"write: ",name) ;
break ;
default: break ;
......
......@@ -120,12 +120,14 @@ int sanitize_tree(stralloc *dstree, char const *base, char const *tree,uid_t own
{
if (sanitize_extra(SS_LOGGER_SYSDIR) < 0)
{ VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; }
if (sanitize_extra(SS_SERVICE_PACKDIR) < 0)
{ VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; }
if (sanitize_extra(SS_SERVICE_SYSDIR) < 0)
{ VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; }
{ VERBO3 strerr_warnwu2sys("create directory: ",SS_SERVICE_SYSDIR) ; return -1 ; }
if (sanitize_extra(SS_SERVICE_SYSCONFDIR) < 0)
{ VERBO3 strerr_warnwu2sys("create directory: ",SS_LOGGER_SYSDIR) ; return -1 ; }
{ VERBO3 strerr_warnwu2sys("create directory: ",SS_SERVICE_SYSCONFDIR) ; return -1 ; }
if (sanitize_extra(SS_SERVICE_ADMDIR) < 0)
{ VERBO3 strerr_warnwu2sys("create directory: ",SS_SERVICE_ADMDIR) ; return -1 ; }
if (sanitize_extra(SS_SERVICE_ADMCONFDIR) < 0)
{ VERBO3 strerr_warnwu2sys("create directory: ",SS_SERVICE_ADMCONFDIR) ; return -1 ; }
}
else
{
......
......@@ -43,4 +43,6 @@ extern int env_substitute(char const *key, char const *val,exlsn_t *info, char c
extern int env_addkv (const char *key, const char *val, exlsn_t *info) ;
extern size_t build_env(char const *src,char const *const *envp,char const **newenv, char *tmpenv) ;
extern int env_get_from_src(stralloc *modifs,char const *src) ;
extern int env_resolve_conf(stralloc *env,uid_t owner) ;
extern int env_merge_conf(char const *dst,char const *file,stralloc *srclist,stralloc *modifs,unsigned int force) ;
#endif
......@@ -139,7 +139,12 @@ struct sv_alltype_s
uint32_t hiercopy[24] ; //dir/file to copy
int signal ;//down-signal file
unsigned int pipeline ; //pos in deps
stralloc saenv ; //type diuint32, pos in saenv
stralloc saenv ;
/* path of the environment file, this is only concern the write
* process, the read process could be different if conf/sysadmin/service
* exist */
uint32_t srconf ;
} ;
#define SV_EXEC_ZERO \
......@@ -200,7 +205,8 @@ struct sv_alltype_s
{ 0 } , \
0 , \
0 , \
STRALLOC_ZERO \
STRALLOC_ZERO , \
0 \
}
extern sv_alltype const sv_alltype_zero ;
......@@ -297,9 +303,9 @@ extern void section_free(section_t *sec) ;
extern void freed_parser(void) ;
/** enable phase */
extern int parse_service_get_list(stralloc *result, stralloc *list) ;
extern int parse_service_before(ssexec_t *info, stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,unsigned int force) ;
extern int parse_service_before(ssexec_t *info, stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,unsigned int force,unsigned int exist) ;
extern int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,unsigned int force) ;
extern int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv) ;
extern int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv,uid_t owner) ;
/** utilities */
extern int parse_line(stralloc *src,size_t *pos) ;
extern int parse_quote(stralloc *src,size_t *pos) ;
......@@ -324,17 +330,17 @@ extern int clean_value(stralloc *sa) ;
extern void parse_err(int ierr,int idsec,int idkey) ;
extern int add_pipe(sv_alltype *sv, stralloc *sa) ;
/** write */
extern int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned int force) ;
extern int write_classic(sv_alltype *sv, char const *dst, unsigned int force) ;
extern int write_longrun(sv_alltype *sv,char const *dst, unsigned int force) ;
extern int write_oneshot(sv_alltype *sv,char const *dst, unsigned int force) ;
extern int write_bundle(sv_alltype *sv, char const *dst, unsigned int force) ;
extern int write_common(sv_alltype *sv, char const *dst) ;
extern int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned int force,unsigned int conf) ;
extern int write_classic(sv_alltype *sv, char const *dst, unsigned int force, unsigned int conf) ;
extern int write_longrun(sv_alltype *sv,char const *dst, unsigned int force, unsigned int conf) ;
extern int write_oneshot(sv_alltype *sv,char const *dst, unsigned int conf) ;
extern int write_bundle(sv_alltype *sv, char const *dst) ;
extern int write_common(sv_alltype *sv, char const *dst,unsigned int conf) ;
extern int write_exec(sv_alltype *sv, sv_exec *exec,char const *name,char const *dst,int mode) ;
extern int write_uint(char const *dst, char const *name, uint32_t ui) ;
extern int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *dst, int mode, unsigned int force) ;
extern int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char const *proddst,char const *consdst) ;
extern int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char const *filename, genalloc *ga, unsigned int force) ;
extern int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char const *filename, genalloc *ga) ;
extern int write_env(char const *name,stralloc *sa,char const *dst) ;
#endif
......@@ -47,7 +47,8 @@ struct ss_resolve_s
uint32_t logassoc ;
uint32_t dstlog ;
uint32_t deps ;
uint32_t src ; //etc/service
uint32_t src ; //frontend source
uint32_t srconf ; //configuration file source
uint32_t live ; //run/66
uint32_t runat ; //livetree->longrun,scandir->svc
uint32_t tree ; //var/lib/66/system/tree
......@@ -61,7 +62,7 @@ struct ss_resolve_s
uint32_t down ;
uint32_t disen ;//disable->0,enable->1
} ;
#define RESOLVE_ZERO { 0,STRALLOC_ZERO,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
#define RESOLVE_ZERO { 0,STRALLOC_ZERO,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
/** Graph struct */
typedef struct ss_resolve_graph_ndeps_s ss_resolve_graph_ndeps_t ;
......@@ -115,6 +116,7 @@ extern void ss_resolve_free(ss_resolve_t *res) ;
extern int ss_resolve_pointo(stralloc *sa,ssexec_t *info,unsigned int type, unsigned int where) ;
extern int ss_resolve_src_path(stralloc *sasrc,char const *sv, ssexec_t *info) ;
extern int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,unsigned int *found) ;
extern int ss_resolve_service_isdir(char const *dir, char const *name) ;
extern int ss_resolve_add_uint32(stralloc *sa, uint32_t data) ;
extern uint32_t ss_resolve_add_string(ss_resolve_t *res,char const *data) ;
extern int ss_resolve_pack(stralloc *sa,ss_resolve_t *res) ;
......
......@@ -13,6 +13,8 @@
*/
#include <stddef.h>
#include <string.h>
#include <errno.h>
//#include <stdio.h>
#include <oblibs/string.h>
......@@ -33,6 +35,7 @@
#include <66/environ.h>
#include <66/utils.h>
#include <66/constants.h>
#include <66/config.h>
#include <execline/execline.h>
/* @Return 1 on success
......@@ -146,6 +149,7 @@ int env_split(genalloc *gaenv,stralloc *saenv,stralloc *src)
if (!*line) continue ;
tmp.len = 0 ;
if (!stralloc_cats(&tmp,line)) goto err ;
/** skip commented line or empty line*/
if (env_clean(&tmp) < 0) continue ;
if (!stralloc_0(&tmp)) goto err ;
......@@ -401,3 +405,87 @@ size_t build_env(char const *src,char const *const *envp,char const **newenv, ch
stralloc_free(&modifs) ;
return 0 ;
}
int env_resolve_conf(stralloc *env, uid_t owner)
{
if (!owner)
{
if (!stralloc_cats(env,SS_SERVICE_ADMCONFDIR)) return 0 ;
}
else
{
if (!set_ownerhome(env,owner)) return 0 ;
if (!stralloc_cats(env,SS_SERVICE_USERCONFDIR)) return 0 ;
}
if (!stralloc_0(env)) return 0 ;
env->len-- ;
return 1 ;
}
int env_merge_conf(char const *dst,char const *file,stralloc *srclist,stralloc *modifs,unsigned int force)
{
int found = 0 ;
stralloc newlist = STRALLOC_ZERO ;
// key=value from modifs
genalloc mga = GENALLOC_ZERO ;// diuint32
stralloc msa = STRALLOC_ZERO ;
// key=value from src
genalloc ga = GENALLOC_ZERO ;// diuint32
stralloc sa = STRALLOC_ZERO ;
char *key, *val, *mkey, *mval ;
if (!env_split(&mga,&msa,modifs)) strerr_diefu1x(111,"split key=value pair") ;
if (!env_split(&ga,&sa,srclist)) strerr_diefu3x(111,"split key=value pair of file: ",dst,file) ;
// replace existing key
for (unsigned int i = 0 ; i < genalloc_len(diuint32,&ga) ; i++)
{
found = 0 ;
key = sa.s + genalloc_s(diuint32,&ga)[i].left ;
val = sa.s + genalloc_s(diuint32,&ga)[i].right ;
if (!stralloc_cats(&newlist,key) ||
!stralloc_cats(&newlist,"=")) return 0 ;
for (unsigned int j = 0 ; j < genalloc_len(diuint32,&mga) ; j++)
{
mkey = msa.s + genalloc_s(diuint32,&mga)[j].left ;
mval = msa.s + genalloc_s(diuint32,&mga)[j].right ;
if (obstr_equal(key,mkey) && force)
{
found = 1 ;
if (!stralloc_cats(&newlist,mval)) return 0 ;
break ;
}
}
if (!found) if (!stralloc_cats(&newlist,val)) return 0 ;
if (!stralloc_cats(&newlist,"\n")) return 0 ;
}
// append new key coming from modifs
for (unsigned int i = 0 ; i < genalloc_len(diuint32,&mga) ; i++)
{
found = 0 ;
key = msa.s + genalloc_s(diuint32,&mga)[i].left ;
val = msa.s + genalloc_s(diuint32,&mga)[i].right ;
for (unsigned int j = 0 ; j < genalloc_len(diuint32,&ga) ; j++)
{
mkey = sa.s + genalloc_s(diuint32,&ga)[j].left ;
mval = sa.s + genalloc_s(diuint32,&ga)[j].right ;
if (obstr_equal(key,mkey))
found = 1 ;
}
if (!found)
{
if (!stralloc_cats(&newlist,key) ||
!stralloc_cats(&newlist,"=")) return 0 ;
if (!stralloc_cats(&newlist,val)) return 0 ;
if (!stralloc_cats(&newlist,"\n")) return 0 ;
}
}
if (!file_write_unsafe(dst,file,newlist.s,newlist.len))
strerr_diefu3sys(111,"write: ",dst,file) ;
stralloc_free(&newlist) ;
stralloc_free(&sa) ;
stralloc_free(&msa) ;
genalloc_free(diuint32,&mga) ;
genalloc_free(diuint32,&ga) ;
return 1 ;
}
......@@ -15,6 +15,7 @@
#include <66/parser.h>
#include <string.h>
//#include <stdio.h>
#include <oblibs/string.h>
#include <oblibs/types.h>
......@@ -27,6 +28,7 @@
#include <66/resolve.h>
#include <66/utils.h>
#include <66/constants.h>
#include <66/environ.h>
int parse_service_get_list(stralloc *result, stralloc *list)
{
......@@ -46,23 +48,37 @@ int parse_service_get_list(stralloc *result, stralloc *list)
return 1 ;
}
int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv)
int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv,uid_t owner)
{
stralloc conf = STRALLOC_ZERO ;
size_t svlen = strlen(service) ;
char svsrc[svlen + 1] ;
if (!dirname(svsrc,service)) return 0 ;
size_t srclen = strlen(svsrc) ;
// keep source of the frontend file
sv_before->src = keep.len ;
if (!stralloc_catb(&keep,svsrc,srclen + 1)) retstralloc(0,"parse_add_service") ;
if (!stralloc_catb(parsed_list,service,svlen + 1)) retstralloc(0,"parse_add_service") ;
if (!genalloc_append(sv_alltype,&gasv,sv_before)) retstralloc(0,"parse_add_service") ;
if (!stralloc_catb(&keep,svsrc,srclen + 1)) return 0 ;
// keep source of the configuration file
if (sv_before->opts[2])
{
if (!env_resolve_conf(&conf,owner)) return 0 ;
sv_before->srconf = keep.len ;
if (!stralloc_catb(&keep,conf.s,conf.len + 1)) return 0 ;
}
// keep service on current list
if (!stralloc_catb(parsed_list,service,svlen + 1)) return 0 ;
if (!genalloc_append(sv_alltype,&gasv,sv_before)) return 0 ;
(*nbsv)++ ;
stralloc_free(&conf) ;
return 1 ;
}
int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,unsigned int force)
{
unsigned int exist = 0 ;
char *dname = 0 ;
stralloc newsv = STRALLOC_ZERO ;
if (sv_before->cname.nga)
......@@ -82,7 +98,7 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo
stralloc_free(&newsv) ;
return 0 ;
}
if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force))
if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,exist))
{
stralloc_free(&newsv) ;
return 0 ;
......@@ -94,7 +110,7 @@ int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_befo
return 1 ;
}
int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,unsigned int force)
int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,unsigned int force,unsigned int exist)
{
int r = 0 , insta ;
......@@ -186,9 +202,9 @@ int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,un
if (!parser(&sv_before,sasv,newsv.s)) goto err ;
if (!parse_add_service(parsed_list,&sv_before,svpath,nbsv)) goto err ;
if (!parse_add_service(parsed_list,&sv_before,svpath,nbsv,info->owner)) goto err ;
if (sv_before.cname.itype > CLASSIC)
if ((sv_before.cname.itype > CLASSIC && force > 1) || !exist)
if (!parse_service_deps(info,parsed_list,&sv_before,sv,nbsv,sasv,force)) goto err ;
freed:
......
......@@ -17,6 +17,7 @@
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
//#include <stdio.h>
#include <oblibs/string.h>
#include <oblibs/files.h>
......@@ -36,15 +37,16 @@
#include <66/enum.h>
#include <66/resolve.h>
#include <66/ssexec.h>
#include <66/environ.h>
#include <s6/config.h>//S6_BINPREFIX
#include <execline/config.h>//EXECLINE_BINPREFIX
//#include <stdio.h>
/** @Return 0 on fail
* @Return 1 on success
* @Return 2 if the service is ignored */
int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned int force)
int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned int force, unsigned int conf)
{
int r ;
......@@ -109,7 +111,7 @@ int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned
}
else if (r && !force)
{
VERBO1 strerr_warnw3x("ignoring: ",name," service: already enabled") ;
VERBO1 strerr_warnw3x("Ignoring: ",name," service: already enabled") ;
return 2 ;
}
......@@ -118,14 +120,14 @@ int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned
switch(type)
{
case CLASSIC:
if (!write_classic(sv, wname, force))
if (!write_classic(sv, wname, force, conf))
{
VERBO3 strerr_warnwu2x("write: ",wname) ;
return 0 ;
}
break ;
case LONGRUN:
if (!write_longrun(sv, wname, force))
if (!write_longrun(sv, wname, force, conf))
{
VERBO3 strerr_warnwu2x("write: ",wname) ;
return 0 ;
......@@ -133,7 +135,7 @@ int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned
break ;
case ONESHOT:
if (!write_oneshot(sv, wname, force))
if (!write_oneshot(sv, wname, conf))
{
VERBO3 strerr_warnwu2x("write: ",wname) ;
return 0 ;
......@@ -141,7 +143,7 @@ int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned
break ;
case BUNDLE:
if (!write_bundle(sv, wname, force))
if (!write_bundle(sv, wname))
{
VERBO3 strerr_warnwu2x("write: ",wname) ;
return 0 ;
......@@ -156,10 +158,10 @@ int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, unsigned
return 1 ;
}
int write_classic(sv_alltype *sv, char const *dst, unsigned int force)
int write_classic(sv_alltype *sv, char const *dst, unsigned int force,unsigned int conf)
{
/**notification,timeout, ...*/
if (!write_common(sv, dst))
if (!write_common(sv, dst, conf))
{
VERBO3 strerr_warnwu1x("write common files") ;
return 0 ;
......@@ -193,7 +195,7 @@ int write_classic(sv_alltype *sv, char const *dst, unsigned int force)
return 1 ;
}
int write_longrun(sv_alltype *sv,char const *dst, unsigned force)
int write_longrun(sv_alltype *sv,char const *dst, unsigned int force, unsigned int conf)
{
size_t r ;
char *name = keep.s+sv->cname.name ;
......@@ -203,7 +205,7 @@ int write_longrun(sv_alltype *sv,char const *dst, unsigned force)
char dstlog[dstlen + 1] ;
/**notification,timeout ...*/
if (!write_common(sv, dst))
if (!write_common(sv, dst,conf))
{
VERBO3 strerr_warnwu1x("write common files") ;
return 0 ;
......@@ -250,7 +252,7 @@ int write_longrun(sv_alltype *sv,char const *dst, unsigned force)
}
/** dependencies */
if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies", &gadeps,force))
if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies", &gadeps))
{
VERBO3 strerr_warnwu3x("write: ",dst,"/dependencies") ;
return 0 ;
......@@ -260,10 +262,10 @@ int write_longrun(sv_alltype *sv,char const *dst, unsigned force)
return 1 ;
}
int write_oneshot(sv_alltype *sv,char const *dst, unsigned int force)
int write_oneshot(sv_alltype *sv,char const *dst,unsigned int conf)
{
if (!write_common(sv, dst))
if (!write_common(sv, dst,conf))
{
VERBO3 strerr_warnwu1x("write common files") ;
return 0 ;
......@@ -284,7 +286,7 @@ int write_oneshot(sv_alltype *sv,char const *dst, unsigned int force)
}
}
if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies", &gadeps,force))
if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "dependencies", &gadeps))
{
VERBO3 strerr_warnwu3x("write: ",dst,"/dependencies") ;
return 0 ;
......@@ -293,7 +295,7 @@ int write_oneshot(sv_alltype *sv,char const *dst, unsigned int force)
return 1 ;
}
int write_bundle(sv_alltype *sv, char const *dst, unsigned int force)
int write_bundle(sv_alltype *sv, char const *dst)
{
/** type file*/
if (!file_write_unsafe(dst,"type","bundle",6))
......@@ -302,7 +304,7 @@ int write_bundle(sv_alltype *sv, char const *dst, unsigned int force)
return 0 ;
}
/** contents file*/
if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "contents", &gadeps, force))
if (!write_dependencies(sv->cname.nga,sv->cname.idga, dst, "contents", &gadeps))
{
VERBO3 strerr_warnwu3x("write: ",dst,"/contents") ;
return 0 ;
......@@ -386,7 +388,7 @@ int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *d
/** dependencies*/
if (log->nga)
{
if (!write_dependencies(log->nga,log->idga,ddst.s,"dependencies",&gadeps,force))
if (!write_dependencies(log->nga,log->idga,ddst.s,"dependencies",&gadeps))
{
VERBO3 strerr_warnwu3x("write: ",ddst.s,"/dependencies") ;
return 0 ;
......@@ -600,12 +602,15 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char
return 1 ;
}
int write_common(sv_alltype *sv, char const *dst)
int write_common(sv_alltype *sv, char const *dst,unsigned int conf)
{
int r ;
char *time = NULL ;
char *name = keep.s + sv->cname.name ;
char *src = keep.s + sv->src ;
size_t dstlen = strlen(dst) ;
size_t srclen = strlen(src) ;
size_t namelen = strlen(name) ;
/**down file*/
if (sv->flags[0])
{
......@@ -687,32 +692,48 @@ int write_common(sv_alltype *sv, char const *dst)
/** environment */
if (sv->opts[2])
{
char *dst = 0 ;
uid_t owner = MYUID ;
stralloc home = STRALLOC_ZERO ;
if (!owner) dst = SS_SERVICE_SYSCONFDIR ;
else
// dst is always SS_SERVICE_ADMCONFDIR
char *dst = keep.s + sv->srconf ;
size_t dlen ;
dlen = strlen(SS_SERVICE_ADMCONFDIR) ;
char copy[dlen + namelen + 1] ;
memcpy(copy,SS_SERVICE_ADMCONFDIR,dlen) ;
memcpy(copy + dlen, name,namelen) ;
copy[dlen + namelen] = 0 ;
// copy config file from upstream in sysadmin
r = scan_mode(copy,S_IFREG) ;
if (!r || conf)
{
copy[dlen] = 0 ;
if (!write_env(name,&sv->saenv,copy))
{
VERBO3 strerr_warnwu1x("write environment") ;
return 0 ;
}
}
// we come from upstream, update it
if (!strcmp(src,SS_SERVICE_SYSDIR))
{
if (!set_ownerhome(&home,owner))
{ VERBO3 strerr_warnwu1sys("set home directory") ; return 0 ; }
if (!stralloc_cats(&home,SS_SERVICE_USERCONFDIR)) retstralloc(111,"write_common") ;
if (!stralloc_0(&home)) retstralloc(111,"write_common") ;
home.len-- ;
dst = home.s ;
if (!write_env(name,&sv->saenv,SS_SERVICE_SYSCONFDIR))
{
VERBO3 strerr_warnwu1x("write environment") ;
return 0 ;
}
}
if (!write_env(name,&sv->saenv,dst))
stralloc salist = STRALLOC_ZERO ;
//merge config from upstream to sysadmin
if (!file_readputsa(&salist,SS_SERVICE_ADMCONFDIR,name)) strerr_diefu3sys(111,"read: ",dst,name) ;
if (!env_merge_conf(SS_SERVICE_ADMCONFDIR,name,&salist,&sv->saenv,conf))
{
VERBO3 strerr_warnwu1x("write environment") ;
VERBO3 strerr_warnwu1x("merge environment file") ;
return 0 ;
}
stralloc_free(&home) ;
stralloc_free(&salist) ;
}
/** hierarchy copy */
if (sv->hiercopy[0])
{
int r ;
size_t dstlen = strlen(dst) ;
size_t srclen = strlen(src) ;
for (uint32_t i = 0 ; i < sv->hiercopy[0] ; i++)
{
char *what = keep.s + sv->hiercopy[i+1] ;
......@@ -762,19 +783,6 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in
stralloc runuser = STRALLOC_ZERO ;
stralloc execute = STRALLOC_ZERO ;
char *envdata = 0 ;
if (!owner) envdata = SS_SERVICE_SYSCONFDIR ;
else
{
if (!set_ownerhome(&home,owner))
{ VERBO3 strerr_warnwu1sys("set home directory") ; return 0 ; }
if (!stralloc_cats(&home,SS_SERVICE_USERCONFDIR)) retstralloc(111,"write_exec") ;
if (!stralloc_0(&home)) retstralloc(111,"write_exec") ;
home.len-- ;
envdata = home.s ;
}
switch (exec->build)
{
case AUTO:
......@@ -793,7 +801,8 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in
if (sv->opts[2] && (exec->build == AUTO))
{
if (!stralloc_cats(&env,SS_BINPREFIX "execl-envfile ")) retstralloc(0,"write_exec") ;
if (!stralloc_cats(&env,envdata)) retstralloc(0,"write_exec") ;
if (!env_resolve_conf(&env,owner))
{ VERBO3 strerr_warnwu1sys("get path of service configuration file") ; return 0 ; }
if (!stralloc_cats(&env,name)) retstralloc(0,"write_exec") ;
if (!stralloc_cats(&env,"\n")) retstralloc(0,"write_exec") ;
}
......@@ -872,7 +881,7 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in
return 1 ;
}