Commit 640c3161 authored by Eric Vidal's avatar Eric Vidal 💬

update and follow change

parent 8775404a
......@@ -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 ;
......
......@@ -13,7 +13,8 @@
*/
#include <string.h>
#include <stdio.h>
//#include <stdio.h>
#include <stdlib.h>//getenv
#include <oblibs/obgetopt.h>
#include <oblibs/error2.h>
......@@ -24,6 +25,7 @@
#include <skalibs/genalloc.h>
#include <skalibs/buffer.h>
#include <skalibs/diuint32.h>
#include <skalibs/djbunix.h>
#include <66/ssexec.h>
#include <66/utils.h>
......@@ -33,20 +35,20 @@
int ssexec_env(int argc, char const *const *argv,char const *const *envp,ssexec_t *info)
{
int list = 0, replace = 0 ;
int list = 0, replace = 0 , edit = 0 ;
stralloc conf = STRALLOC_ZERO ;
stralloc var = STRALLOC_ZERO ;
stralloc salist = STRALLOC_ZERO ;
stralloc sasrc = STRALLOC_ZERO ;
char const *sv = 0, *src = 0 ;
char const *sv = 0, *src = 0, *editor ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
int opt = getopt_args(argc,argv, ">Ld:r:", &l) ;
int opt = getopt_args(argc,argv, ">Ld:r:e", &l) ;
if (opt == -1) break ;
if (opt == -2) strerr_dief1x(110,"options must be set first") ;
switch (opt)
......@@ -54,17 +56,20 @@ int ssexec_env(int argc, char const *const *argv,char const *const *envp,ssexec_
case 'L' : if (replace) exitusage(usage_env) ; list = 1 ; break ;
case 'd' : src = l.arg ; break ;
case 'r' : if (!stralloc_cats(&var,l.arg) ||
!stralloc_cats(&var,"\n") ||
!stralloc_0(&var)) retstralloc(111,"main") ;
replace = 1 ; break ;
case 'e' : if (replace) exitusage(usage_env) ;
edit = 1 ;
break ;
default : exitusage(usage_env) ;
}
}
argc -= l.ind ; argv += l.ind ;
}
if (argc < 1) exitusage(usage_env) ;
sv = argv[0] ;
if (!env_resolve_conf(&sasrc,sv,info->owner)) strerr_diefu1sys(111,"get path of the configuration file") ;
if (!env_resolve_conf(&sasrc,info->owner)) strerr_diefu1sys(111,"get path of the configuration file") ;
if (!src) src = sasrc.s ;
if (!file_readputsa(&salist,src,sv)) strerr_diefu3sys(111,"read: ",src,sv) ;
if (list)
......@@ -75,39 +80,20 @@ int ssexec_env(int argc, char const *const *argv,char const *const *envp,ssexec_
}
else if (replace)
{
stralloc newlist = STRALLOC_ZERO ;
// key=value from cmdline
genalloc mga = GENALLOC_ZERO ;// diuint32
stralloc msa = STRALLOC_ZERO ;
// key=value from file
genalloc ga = GENALLOC_ZERO ;// diuint32
stralloc sa = STRALLOC_ZERO ;
char *key, *val, *mkey, *mval ;
if (!env_clean(&var)) strerr_diefu1x(111,"clean key=value pair") ;
if (!env_split_one(var.s,&mga,&msa)) strerr_diefu1x(111,"split key=value pair") ;
mkey = msa.s + genalloc_s(diuint32,&mga)[0].left ;
mval = msa.s + genalloc_s(diuint32,&mga)[0].right ;
if (!env_split(&ga,&sa,&salist)) strerr_diefu3x(111,"split key=value pair of file: ",src,sv) ;
for (unsigned int i = 0 ; i < genalloc_len(diuint32,&ga) ; i++)
{
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,"=")) retstralloc(111,"replace") ;
if (obstr_equal(key,mkey)) {
if (!stralloc_cats(&newlist,mval)) retstralloc(111,"replace") ;
}else if (!stralloc_cats(&newlist,val)) retstralloc(111,"replace") ;
if (!stralloc_cats(&newlist,"\n")) retstralloc(111,"replace") ;
}
if (!file_write_unsafe(src,sv,newlist.s,newlist.len))
strerr_diefu3sys(111,"write: ",src,sv) ;
stralloc_free(&newlist) ;
stralloc_free(&sa) ;
stralloc_free(&msa) ;
genalloc_free(diuint32,&mga) ;
genalloc_free(diuint32,&ga) ;
if (!env_merge_conf(src,sv,&salist,&var,replace))
strerr_diefu2x(111,"merge environment file with: ",var.s) ;
}
else if (edit)
{
size_t svlen = strlen(sv) ;
char t[sasrc.len + svlen + 1] ;
editor = getenv("EDITOR") ;
if (!editor) strerr_diefu1sys(111,"get EDITOR") ;
memcpy(t,sasrc.s,sasrc.len) ;
memcpy(t + sasrc.len,sv,svlen) ;
t[sasrc.len + svlen] = 0 ;
char const *const newarg[3] = { editor, t, 0 } ;
xpathexec_run (newarg[0],newarg,envp) ;
}
freed:
stralloc_free(&conf) ;
......
......@@ -14,7 +14,7 @@
#include <66/ssexec.h>
char const *usage_enable = "66-enable [ -h help ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f ] [ -S ] service(s)" ;
char const *usage_enable = "66-enable [ -h help ] [ -v verbosity ] [ - l live ] [ -t tree ] [ -f ] [ -F ] [ -o ] [ -S ] service(s)" ;
char const *help_enable =
"66-enable <options> service(s)\n"
......@@ -24,7 +24,9 @@ char const *help_enable =
" -v: increase/decrease verbosity\n"
" -l: live directory\n"
" -t: name of the tree to use\n"
" -f: overwrite service(s)\n"
" -f: force to overwrite the service(s)\n"
" -F: force to overwrite the service(s) and it dependencies\n"
" -o: force to overwrite the configuration file\n"
" -S: enable and start the service\n"
;
......@@ -131,4 +133,5 @@ char const *help_env =
" -L: list environment variable of service\n"
" -d: directory of configuration service file\n"
" -r: replace the value of the key \n"
" -e: edit the file with EDITOR \n"
;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment