diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a63e558466eea542545c8285a10edb1b56e20ad5..480889d641ceb31166570779fe7e878305e9cd27 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,5 +14,8 @@ build: - make -j9 man - make -j9 install DESTDIR=gitlab-ci - make -j9 install-man DESTDIR=gitlab-ci - + + only: + refs: + - master diff --git a/package/deps.mak b/package/deps.mak index 125324257bca9c0138f320c24af8d3714bddad14..c158030e6a44e2ce04603a3f2a6483e7fca0d3d3 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -14,7 +14,7 @@ src/include/66/svc.h: src/include/66/resolve.h src/include/66/ssexec.h src/include/66/tree.h: src/include/66/ssexec.h src/include/66/utils.h: src/include/66/resolve.h src/include/66/ssexec.h src/66/66-all.o src/66/66-all.lo: src/66/66-all.c src/include/66/config.h src/include/66/constants.h src/include/66/tree.h src/include/66/utils.h -src/66/66-boot.o src/66/66-boot.lo: src/66/66-boot.c src/include/66/config.h src/include/66/constants.h src/include/66/environ.h +src/66/66-boot.o src/66/66-boot.lo: src/66/66-boot.c src/include/66/config.h src/include/66/constants.h src/66/66-dbctl.o src/66/66-dbctl.lo: src/66/66-dbctl.c src/include/66/ssexec.h src/66/66-disable.o src/66/66-disable.lo: src/66/66-disable.c src/include/66/ssexec.h src/66/66-enable.o src/66/66-enable.lo: src/66/66-enable.c src/include/66/ssexec.h @@ -22,11 +22,11 @@ src/66/66-env.o src/66/66-env.lo: src/66/66-env.c src/include/66/ssexec.h src/66/66-hpr.o src/66/66-hpr.lo: src/66/66-hpr.c src/include/66/config.h src/include/66/hpr.h src/66/66-info.o src/66/66-info.lo: src/66/66-info.c src/include/66/constants.h src/include/66/enum.h src/include/66/environ.h src/include/66/resolve.h src/include/66/tree.h src/include/66/utils.h src/66/66-init.o src/66/66-init.lo: src/66/66-init.c src/include/66/ssexec.h -src/66/66-parser.o src/66/66-parser.lo: src/66/66-parser.c src/include/66/parser.h src/include/66/utils.h +src/66/66-parser.o src/66/66-parser.lo: src/66/66-parser.c src/include/66/constants.h src/include/66/parser.h src/include/66/utils.h src/66/66-scanctl.o src/66/66-scanctl.lo: src/66/66-scanctl.c src/include/66/utils.h src/66/66-scandir.o src/66/66-scandir.lo: src/66/66-scandir.c src/include/66/config.h src/include/66/constants.h src/include/66/environ.h src/include/66/utils.h src/66/66-shutdown.o src/66/66-shutdown.lo: src/66/66-shutdown.c src/include/66/config.h src/include/66/hpr.h -src/66/66-shutdownd.o src/66/66-shutdownd.lo: src/66/66-shutdownd.c src/include/66/config.h src/include/66/constants.h src/include/66/environ.h +src/66/66-shutdownd.o src/66/66-shutdownd.lo: src/66/66-shutdownd.c src/include/66/config.h src/include/66/constants.h src/66/66-start.o src/66/66-start.lo: src/66/66-start.c src/include/66/ssexec.h src/66/66-stop.o src/66/66-stop.lo: src/66/66-stop.c src/include/66/ssexec.h src/66/66-svctl.o src/66/66-svctl.lo: src/66/66-svctl.c src/include/66/ssexec.h @@ -39,8 +39,8 @@ src/extra-tools/66-umountall.o src/extra-tools/66-umountall.lo: src/extra-tools/ src/extra-tools/66-which.o src/extra-tools/66-which.lo: src/extra-tools/66-which.c src/extra-tools/66-writenv.o src/extra-tools/66-writenv.lo: src/extra-tools/66-writenv.c src/extra-tools/execl-cmdline.o src/extra-tools/execl-cmdline.lo: src/extra-tools/execl-cmdline.c -src/extra-tools/execl-envfile.o src/extra-tools/execl-envfile.lo: src/extra-tools/execl-envfile.c src/include/66/constants.h src/include/66/environ.h src/include/66/parser.h -src/extra-tools/execl-subuidgid.o src/extra-tools/execl-subuidgid.lo: src/extra-tools/execl-subuidgid.c src/include/66/environ.h src/include/66/utils.h +src/extra-tools/execl-envfile.o src/extra-tools/execl-envfile.lo: src/extra-tools/execl-envfile.c +src/extra-tools/execl-subuidgid.o src/extra-tools/execl-subuidgid.lo: src/extra-tools/execl-subuidgid.c src/extra-tools/execl-testncreate.o src/extra-tools/execl-testncreate.lo: src/extra-tools/execl-testncreate.c src/lib66/backup_cmd_switcher.o src/lib66/backup_cmd_switcher.lo: src/lib66/backup_cmd_switcher.c src/include/66/constants.h src/include/66/enum.h src/include/66/ssexec.h src/include/66/utils.h src/lib66/backup_make_new.o src/lib66/backup_make_new.lo: src/lib66/backup_make_new.c src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/tree.h src/include/66/utils.h @@ -52,16 +52,16 @@ src/lib66/db_get_permissions.o src/lib66/db_get_permissions.lo: src/lib66/db_get src/lib66/db_ok.o src/lib66/db_ok.lo: src/lib66/db_ok.c src/include/66/constants.h src/lib66/db_switch_to.o src/lib66/db_switch_to.lo: src/lib66/db_switch_to.c src/include/66/backup.h src/include/66/constants.h src/include/66/db.h src/include/66/enum.h src/include/66/ssexec.h src/include/66/utils.h src/lib66/db_update.o src/lib66/db_update.lo: src/lib66/db_update.c src/include/66/constants.h src/include/66/db.h src/include/66/ssexec.h src/include/66/utils.h -src/lib66/environ.o src/lib66/environ.lo: src/lib66/environ.c src/include/66/config.h src/include/66/constants.h src/include/66/environ.h src/include/66/parser.h src/include/66/utils.h +src/lib66/environ.o src/lib66/environ.lo: src/lib66/environ.c src/include/66/constants.h src/include/66/utils.h src/lib66/get_enum.o src/lib66/get_enum.lo: src/lib66/get_enum.c src/include/66/enum.h src/lib66/get_uidgid.o src/lib66/get_uidgid.lo: src/lib66/get_uidgid.c src/lib66/get_userhome.o src/lib66/get_userhome.lo: src/lib66/get_userhome.c src/include/66/utils.h src/lib66/hpr_shutdown.o src/lib66/hpr_shutdown.lo: src/lib66/hpr_shutdown.c src/include/66/hpr.h src/lib66/hpr_wall.o src/lib66/hpr_wall.lo: src/lib66/hpr_wall.c src/include/66/hpr.h -src/lib66/instance.o src/lib66/instance.lo: src/lib66/instance.c src/include/66/utils.h +src/lib66/instance.o src/lib66/instance.lo: src/lib66/instance.c src/include/66/enum.h src/include/66/utils.h src/lib66/parser.o src/lib66/parser.lo: src/lib66/parser.c src/include/66/enum.h src/include/66/parser.h src/include/66/utils.h src/lib66/parser_enabled.o src/lib66/parser_enabled.lo: src/lib66/parser_enabled.c src/include/66/constants.h src/include/66/environ.h src/include/66/parser.h src/include/66/resolve.h src/include/66/utils.h -src/lib66/parser_utils.o src/lib66/parser_utils.lo: src/lib66/parser_utils.c src/include/66/config.h src/include/66/constants.h src/include/66/enum.h src/include/66/environ.h src/include/66/parser.h src/include/66/utils.h +src/lib66/parser_utils.o src/lib66/parser_utils.lo: src/lib66/parser_utils.c src/include/66/config.h src/include/66/constants.h src/include/66/enum.h src/include/66/parser.h src/include/66/utils.h src/lib66/parser_write.o src/lib66/parser_write.lo: src/lib66/parser_write.c src/include/66/constants.h src/include/66/enum.h src/include/66/environ.h src/include/66/parser.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/utils.h src/lib66/rc_init.o src/lib66/rc_init.lo: src/lib66/rc_init.c src/include/66/constants.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/state.h src/include/66/utils.h src/lib66/rc_manage.o src/lib66/rc_manage.lo: src/lib66/rc_manage.c src/include/66/constants.h src/include/66/db.h src/include/66/rc.h src/include/66/resolve.h src/include/66/ssexec.h src/include/66/state.h src/include/66/utils.h @@ -158,9 +158,9 @@ src/lib66/tree_switch_current.o src/lib66/tree_switch_current.lo: src/lib66/tree execl-cmdline: EXTRA_LIBS := execl-cmdline: src/extra-tools/execl-cmdline.o -lexecline -loblibs -lskarnet execl-envfile: EXTRA_LIBS := -execl-envfile: src/extra-tools/execl-envfile.o ${LIB66} -lexecline -loblibs -lskarnet ${LIBEXECLINE} +execl-envfile: src/extra-tools/execl-envfile.o ${LIB66} ${LIBEXECLINE} -loblibs -lexecline -lskarnet execl-subuidgid: EXTRA_LIBS := -execl-subuidgid: src/extra-tools/execl-subuidgid.o ${LIB66} -lexecline -loblibs -lskarnet ${LIBEXECLINE} +execl-subuidgid: src/extra-tools/execl-subuidgid.o ${LIB66} -loblibs -lexecline -lskarnet ${LIBEXECLINE} ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),) lib66.a.xyzzy: src/lib66/backup_cmd_switcher.o src/lib66/backup_make_new.o src/lib66/backup_realpath_sym.o src/lib66/db_cmd_master.o src/lib66/db_compile.o src/lib66/db_find_compiled_state.o src/lib66/db_get_permissions.o src/lib66/db_ok.o src/lib66/db_switch_to.o src/lib66/db_update.o src/lib66/environ.o src/lib66/get_enum.o src/lib66/get_uidgid.o src/lib66/get_userhome.o src/lib66/hpr_shutdown.o src/lib66/hpr_wall.o src/lib66/instance.o src/lib66/parser.o src/lib66/parser_enabled.o src/lib66/parser_utils.o src/lib66/parser_write.o src/lib66/rc_init.o src/lib66/rc_manage.o src/lib66/rc_send.o src/lib66/rc_unsupervise.o src/lib66/resolve.o src/lib66/resolve_graph.o src/lib66/scandir_ok.o src/lib66/scandir_send_signal.o src/lib66/set_livedir.o src/lib66/set_livescan.o src/lib66/set_livestate.o src/lib66/set_livetree.o src/lib66/set_ownerhome.o src/lib66/set_ownersysdir.o src/lib66/ss_utils.o src/lib66/ssexec_dbctl.o src/lib66/ssexec_enable.o src/lib66/ssexec_env.o src/lib66/ssexec_disable.o src/lib66/ssexec_free.o src/lib66/ssexec_help.o src/lib66/ssexec_init.o src/lib66/ssexec_main.o src/lib66/ssexec_start.o src/lib66/ssexec_stop.o src/lib66/ssexec_svctl.o src/lib66/state.o src/lib66/sv_alltype_zero.o src/lib66/svc_init.o src/lib66/svc_init_pipe.o src/lib66/svc_send.o src/lib66/svc_switch_to.o src/lib66/svc_unsupervise.o src/lib66/tree_cmd_state.o src/lib66/tree_copy.o src/lib66/tree_copy_tmp.o src/lib66/tree_find_current.o src/lib66/tree_get_permissions.o src/lib66/tree_sethome.o src/lib66/tree_setname.o src/lib66/tree_switch_current.o else diff --git a/src/66/66-boot.c b/src/66/66-boot.c index 1e40f5fce82354d2eb228160b333d107c9ca11e6..1f73d7acdcc39ab3bf8cee8fbd91d562a138b646 100644 --- a/src/66/66-boot.c +++ b/src/66/66-boot.c @@ -19,21 +19,21 @@ #include <errno.h> #include <sys/stat.h> #include <sys/mount.h> +#include <sys/reboot.h> #include <oblibs/error2.h> #include <oblibs/files.h> #include <oblibs/string.h> #include <oblibs/obgetopt.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <skalibs/buffer.h> #include <skalibs/djbunix.h> -#include <skalibs/diuint32.h> -#include <skalibs/genalloc.h> #include <skalibs/stralloc.h> #include <skalibs/types.h> #include <66/config.h> -#include <66/environ.h> #include <66/constants.h> unsigned int VERBOSITY = 1 ; @@ -68,7 +68,7 @@ static void sulogin(char const *msg,char const *arg) fd_close(0) ; if (dup2(fdin,0) == -1) strerr_diefu1x(111,"duplicate stdin -- you are on your own") ; fd_close(fdin) ; - if (*msg) strerr_warnwu2sys(msg,arg) ; + if (*msg) strerr_warnwu2x(msg,arg) ; pid = child_spawn0(newarg[0],newarg,genv) ; if (waitpid_nointr(pid,&wstat, 0) < 0) strerr_diefu1sys(111,"wait for sulogin -- you are on your own") ; @@ -101,10 +101,9 @@ static void parse_conf(void) static char const *valid[] = { "VERBOSITY", "PATH", "LIVE", "TREE", "RCINIT", "UMASK", "RESCAN", 0 } ; int r ; - unsigned int i = 0, j = 0 ; + unsigned int j = 0 ; stralloc src = STRALLOC_ZERO ; - stralloc saconf = STRALLOC_ZERO ; - genalloc gaconf = GENALLOC_ZERO ; + stralloc val = STRALLOC_ZERO ; if (skel[0] != '/') sulogin("skeleton directory must be an aboslute path: ",skel) ; size_t skelen = strlen(skel) ; memcpy(confile,skel,skelen) ; @@ -114,51 +113,44 @@ static void parse_conf(void) size_t filesize=file_get_size(confile) ; r = openreadfileclose(confile,&src,filesize) ; if(!r) sulogin("open configuration file: ",confile) ; - if (!stralloc_0(&src)) sulogin("append stralloc configuration file","") ; + if (!stralloc_0(&src)) sulogin("append stralloc of file: ",confile) ; - r = env_split(&gaconf,&saconf,&src) ; - if (!r) sulogin("parse configuration file: ",confile) ; - - for (;i < genalloc_len(diuint32,&gaconf) ; i++) + for (char const *const *p = valid;*p;p++,j++) { - char *key = saconf.s + genalloc_s(diuint32,&gaconf)[i].left ; - char *val = saconf.s + genalloc_s(diuint32,&gaconf)[i].right ; - j = 0 ; - for (char const *const *p = valid;*p;p++,j++) + if (!stralloc_copy(&val,&src)) sulogin("copy stralloc of file: ",confile) ; + if (!environ_get_val_of_key(&val,*p)) continue ; + sastr_clean_element(&val) ; + if (!val.len) strerr_warnwu3x("get value of: ",*p," -- keeps the default") ; + + switch (j) { - if (!strcmp(*p,key)) - { - switch (j) - { - case 0: if (!uint0_scan(val, &VERBOSITY)) sulogin("invalid VERBOSITY value: ","") ; - break ; - case 1: memcpy(tpath,val,strlen(val)) ; - tpath[strlen(val)] = 0 ; - path = tpath ; - break ; - case 2: memcpy(tlive,val,strlen(val)) ; - tlive[strlen(val)] = 0 ; - live = tlive ; - if (live[0] != '/') sulogin ("LIVE must be an absolute path","") ; - break ; - case 3: memcpy(ttree,val,strlen(val)) ; - ttree[strlen(val)] = 0 ; - tree = ttree ; - break ; - case 4: memcpy(trcinit,val,strlen(val)) ; - trcinit[strlen(val)] = 0 ; - rcinit = trcinit ; - if (rcinit[0] != '/') sulogin ("RCINIT must be an absolute path","") ; - break ; - case 5: if (!uint0_oscan(val, &mask)) sulogin("invalid MASK value","") ; break ; - case 6: if (!uint0_scan(val, &rescan)) sulogin("invalid RESCAN value","") ; break ; - default: break ; - } - } + case 0: if (!uint0_scan(val.s, &VERBOSITY)) sulogin("parse VERBOSITY value: ",val.s) ; + break ; + case 1: memcpy(tpath,val.s,val.len) ; + tpath[val.len] = 0 ; + path = tpath ; + break ; + case 2: memcpy(tlive,val.s,val.len) ; + tlive[val.len] = 0 ; + live = tlive ; + if (live[0] != '/') sulogin ("LIVE must be an absolute path: ",val.s) ; + break ; + case 3: memcpy(ttree,val.s,val.len) ; + ttree[val.len] = 0 ; + tree = ttree ; + break ; + case 4: memcpy(trcinit,val.s,val.len) ; + trcinit[val.len] = 0 ; + rcinit = trcinit ; + if (rcinit[0] != '/') sulogin ("RCINIT must be an absolute path: ",val.s) ; + break ; + case 5: if (!uint0_oscan(val.s, &mask)) sulogin("invalid MASK value: ",val.s) ; break ; + case 6: if (!uint0_scan(val.s, &rescan)) sulogin("invalid RESCAN value: ",val.s) ; break ; + default: break ; } + } - genalloc_free(diuint32,&gaconf) ; - stralloc_free(&saconf) ; + stralloc_free(&val) ; stralloc_free(&src) ; } @@ -330,8 +322,10 @@ int main(int argc, char const *const *argv,char const *const *envp) make_cmdline(SS_EXTBINPREFIX "66-init",t,3,"initiate earlier service of tree: ",tree,envp) ; } - if (envdir) - if (!env_get_from_src(&envmodifs,envdir)) sulogin("get environment from: ",envdir) ; + if (envdir) { + int e = environ_get_envfile(&envmodifs,envdir) ; + if (e <= 0){ environ_get_envfile_error(e,envdir) ; sulogin("","") ; } + } { strerr_warni3x("Starts boot logger at: ",live,"/log/0") ; @@ -360,6 +354,7 @@ int main(int argc, char const *const *argv,char const *const *envp) pid = fork() ; if (pid == -1) sulogin("fork: ",rcinit) ; if (!pid) run_stage2(newenvp, 2, envmodifs.s,envmodifs.len) ; + if (reboot(RB_DISABLE_CAD) == -1) sulogin("trap ctrl-alt-del","") ; if (fd_copy(2, 1) == -1) sulogin("copy stderr to stdout","") ; fd_close(fdin) ; xpathexec_r(newargv, newenvp, 2, envmodifs.s, envmodifs.len) ; diff --git a/src/66/66-parser.c b/src/66/66-parser.c index 846bdc65fa3420a54a3d94721cb84bed4c6c5c15..0efef9d9b55098fff44d0c10198a3493dd95ff4b 100644 --- a/src/66/66-parser.c +++ b/src/66/66-parser.c @@ -16,6 +16,7 @@ #include <stdlib.h> #include <stdio.h> #include <errno.h> +#include <stdint.h> #include <oblibs/error2.h> #include <oblibs/files.h> @@ -30,6 +31,7 @@ #include <66/utils.h> #include <66/parser.h> +#include <66/constants.h> #define USAGE "66-parser [ -h ] [ -v verbosity ] [ -f ] [ -c|C ] service destination" @@ -50,7 +52,7 @@ static inline void info_help (void) strerr_diefu1sys(111, "write to stdout") ; } -static void check_dir(char const *dir,int force,int main) +static void check_dir(char const *dir,uint8_t force,int main) { int r ; size_t dirlen = strlen(dir) ; @@ -85,7 +87,7 @@ int main(int argc, char const *const *argv,char const *const *envp) char name[4095+1] ; char srcdir[4095+1] ; int type ; - unsigned int force = 0 , conf = 0 ; + uint8_t force = 0 , conf = 0 ; PROG = "66-parser" ; { subgetopt_t l = SUBGETOPT_ZERO ; @@ -131,11 +133,11 @@ int main(int argc, char const *const *argv,char const *const *envp) check_dir(dir,force,0) ; if (!stralloc_cats(&insta,name) || !stralloc_0(&insta)) retstralloc(111,"main") ; - r = insta_check(insta.s) ; + r = instance_check(insta.s) ; if (!r) strerr_dief2x(111,"invalid instance name: ",insta.s) ; if (r > 0) { - if (!insta_create(&src,&insta,srcdir,r)) + if (!instance_create(&src,insta.s,SS_INSTANCE,srcdir,r)) strerr_diefu2x(111,"create instance service: ",name) ; memcpy(name,insta.s,insta.len) ; name[insta.len] = 0 ; diff --git a/src/66/66-scandir.c b/src/66/66-scandir.c index 390f8ec034eea0abe333f06c246fd315b5fd62cb..5db01545bfee9e542034c20f840caf61f9384755 100644 --- a/src/66/66-scandir.c +++ b/src/66/66-scandir.c @@ -25,6 +25,7 @@ #include <oblibs/types.h> #include <oblibs/files.h> #include <oblibs/string.h> +#include <oblibs/environ.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> @@ -549,7 +550,7 @@ int main(int argc, char const *const *argv, char const *const *envp) if (envdir.s[0] != '/') strerr_dief3x(110,"environment: ",envdir.s," must be an absolute path") ; - if (!build_env(envdir.s,envp,newenv,TMPENV)) strerr_diefu2x(111,"build environment with: ",envdir.s) ; + if (!environ_get_envfile_n_merge(envdir.s,envp,newenv,TMPENV)) strerr_diefu2x(111,"build environment with: ",envdir.s) ; genv = newenv ; } else genv = envp ; diff --git a/src/66/66-shutdownd.c b/src/66/66-shutdownd.c index 49b7a155ed74af3b1a80ee5d8fb34aa087500848..b35cc5f0dc35b260a3feecbc7654f341d5e9d5dc 100644 --- a/src/66/66-shutdownd.c +++ b/src/66/66-shutdownd.c @@ -26,6 +26,8 @@ #include <stdio.h> #include <sys/wait.h> +#include <oblibs/environ.h> + #include <skalibs/posixplz.h> #include <skalibs/uint32.h> #include <skalibs/types.h> @@ -40,7 +42,6 @@ #include <skalibs/djbunix.h> #include <skalibs/iopause.h> #include <skalibs/skamisc.h> -#include <skalibs/diuint32.h> #include <execline/config.h> @@ -48,7 +49,6 @@ #include <66/config.h> #include <66/constants.h> -#include <66/environ.h> #define STAGE4_FILE "stage4" #define DOTPREFIX ".66-shutdownd:" @@ -107,29 +107,16 @@ ssize_t file_get_size(const char* filename) static void parse_conf(char const *confile,char *rcshut,size_t filesize) { int r ; - unsigned int i = 0 ; stralloc src = STRALLOC_ZERO ; - stralloc saconf = STRALLOC_ZERO ; - genalloc gaconf = GENALLOC_ZERO ; r = openreadfileclose(confile,&src,filesize) ; if(!r) strerr_diefu2sys(111,"open configuration file: ",confile) ; if (!stralloc_0(&src)) strerr_diefu1sys(111,"append stralloc configuration file") ; - r = env_split(&gaconf,&saconf,&src) ; - if (!r) strerr_diefu2sys(111,"parse configuration file: ",confile) ; - - for (;i < genalloc_len(diuint32,&gaconf) ; i++) + if (environ_get_val_of_key(&src,"RCSHUTDOWN")) { - char *key = saconf.s + genalloc_s(diuint32,&gaconf)[i].left ; - char *val = saconf.s + genalloc_s(diuint32,&gaconf)[i].right ; - if (!strcmp(key,"RCSHUTDOWN")) - { - memcpy(rcshut,val,strlen(val)) ; - rcshut[strlen(val)] = 0 ; - } + memcpy(rcshut,src.s,src.len) ; + rcshut[src.len] = 0 ; } - genalloc_free(diuint32,&gaconf) ; - stralloc_free(&saconf) ; stralloc_free(&src) ; } diff --git a/src/extra-tools/deps-exe/execl-envfile b/src/extra-tools/deps-exe/execl-envfile index 77b1d97fdc3b7efce73a9a3efb7a8691bb92c0ea..e25e157e5b437887daf1cd5a5675f86440db6e37 100644 --- a/src/extra-tools/deps-exe/execl-envfile +++ b/src/extra-tools/deps-exe/execl-envfile @@ -1,5 +1,6 @@ ${LIB66} --lexecline +${LIBEXECLINE} -loblibs +-lexecline -lskarnet -${LIBEXECLINE} + diff --git a/src/extra-tools/deps-exe/execl-subuidgid b/src/extra-tools/deps-exe/execl-subuidgid index 77b1d97fdc3b7efce73a9a3efb7a8691bb92c0ea..84a128c2c444222aa2d2803ee5682450abb82aa8 100644 --- a/src/extra-tools/deps-exe/execl-subuidgid +++ b/src/extra-tools/deps-exe/execl-subuidgid @@ -1,5 +1,5 @@ ${LIB66} --lexecline -loblibs +-lexecline -lskarnet ${LIBEXECLINE} diff --git a/src/extra-tools/execl-envfile.c b/src/extra-tools/execl-envfile.c index f50afcaaa36868266d71ebd81460dcb4aac7ffbf..682f6d9b8b0d20426cc21d04aeba071d6cb66ee5 100644 --- a/src/extra-tools/execl-envfile.c +++ b/src/extra-tools/execl-envfile.c @@ -21,28 +21,20 @@ #include <oblibs/stralist.h> #include <oblibs/error2.h> #include <oblibs/types.h> -#include <oblibs/obgetopt.h> #include <oblibs/directory.h> #include <oblibs/files.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <skalibs/bytestr.h> #include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> #include <skalibs/env.h> #include <skalibs/djbunix.h> -#include <skalibs/diuint32.h> #include <skalibs/env.h> #include <skalibs/sgetopt.h> #include <execline/execline.h> -#include <66/parser.h> -#include <66/environ.h> -#include <66/constants.h> - -static stralloc SAENV = STRALLOC_ZERO ; -static genalloc GAENV = GENALLOC_ZERO ; //diuint32, pos in senv - #define USAGE "execl-envfile [ -h help ] [ -l ] src prog" static inline void info_help (void) @@ -60,43 +52,36 @@ static inline void info_help (void) strerr_diefu1sys(111, "write to stdout") ; } -int loop_stra(stralloc *sa,char const *search) +void clean_n_unexport(stralloc *modifs, stralloc *dst, stralloc *src) { - size_t i = 0, len = sa->len ; - for (;i < len; i += strlen(sa->s + i) + 1) - if (!strcmp(sa->s+i,search)) return 1 ; - - return 0 ; + if (!environ_clean_envfile(modifs,src)) strerr_diefu2sys(111,"prepare modified environment of: ",src->s) ; + if (!sastr_split_string_in_nline(modifs)) strerr_diefu2sys(111,"build environment line of: ",src->s) ; ; + if (!stralloc_cats(dst,src->s)) exitstralloc("clean_n_unexport") ; } int main (int argc, char const *const *argv, char const *const *envp) { - int r, unexport ; - int insist = 1 ; - size_t pathlen, i ; - char const *path = 0 ; - char const *file = 0 ; - char tpath[MAXENV + 1] ; - char tfile[MAXENV+1] ; + int r = 0, unexport = 0, insist = 1, nfile = 0, nvar = 0 ; + size_t pos = 0, pathlen = 0 ; + char const *path = 0, *file = 0 ; + char tpath[MAXENV + 1], tfile[MAXENV+1] ; stralloc src = STRALLOC_ZERO ; stralloc modifs = STRALLOC_ZERO ; stralloc dst = STRALLOC_ZERO ; - genalloc toparse = GENALLOC_ZERO ; //stralist + stralloc toparse = STRALLOC_ZERO ; + stralloc key = STRALLOC_ZERO ; + stralloc val = STRALLOC_ZERO ; exlsn_t info = EXLSN_ZERO ; - - r = i = unexport = 0 ; - insist = 1 ; - + PROG = "execl-envfile" ; { subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc,argv, ">hlf:", &l) ; + int opt = subgetopt_r(argc,argv, "hlf:", &l) ; if (opt == -1) break ; - if (opt == -2) strerr_dief1x(110,"options must be set first") ; switch (opt) { case 'h' : info_help(); return 0 ; @@ -107,7 +92,6 @@ int main (int argc, char const *const *argv, char const *const *envp) } argc -= l.ind ; argv += l.ind ; } - if (argc < 2) exitusage(USAGE) ; path = *argv ; @@ -123,11 +107,11 @@ int main (int argc, char const *const *argv, char const *const *envp) else { r = scan_mode(path,S_IFREG) ; - if (!r) strerr_diefu2sys(111,"find: ",path) ; + if (!r && insist) strerr_diefu2sys(111,"find: ",path) ; if (r < 0) { r = scan_mode(path,S_IFDIR) ; - if (!r) strerr_diefu2sys(111,"find: ",path) ; + if (!r && insist) strerr_diefu2sys(111,"find: ",path) ; if (r < 0) strerr_dief2x(111,"invalid format of: ", path) ; if (path[0] == '.') { @@ -152,16 +136,15 @@ int main (int argc, char const *const *argv, char const *const *envp) } } - r = dir_get(&toparse,path,"",S_IFREG) ; + r = sastr_dir_get(&toparse,path,"",S_IFREG) ; if (!r && insist) strerr_diefu2sys(111,"get file from: ",path) ; - else if ((!r && !insist) || !genalloc_len(stralist,&toparse)) + else if ((!r && !insist) || !toparse.len) { xpathexec_run(argv[0],argv,envp) ; } - if (file) { - r = stra_findidx(&toparse,file) ; + ssize_t r = sastr_cmp(&toparse,file) ; if (r < 0) { if (insist) strerr_diefu2x(111,"find: ",file) ; @@ -170,27 +153,23 @@ int main (int argc, char const *const *argv, char const *const *envp) xpathexec_run(argv[0],argv,envp) ; } } - if (!file_readputsa(&src,path,file)) strerr_diefu4sys(111,"read file: ",path,"/",file) ; - if (!env_parsenclean(&modifs,&src)) strerr_diefu4x(111,"parse and clean environment of: ",path,"/",file) ; - if (!env_split(&GAENV,&SAENV,&src)) strerr_diefu4x(111,"split environment of: ",path,"/",file) ; - if (genalloc_len(diuint32,&GAENV) > MAXVAR) strerr_dief4x(111,"to many variables in file: ",path,"/",file) ; + clean_n_unexport(&modifs,&dst,&src) ; } else { - for (i = 0 ; i < genalloc_len(stralist,&toparse) ; i++) + for (;pos < toparse.len; pos += strlen(toparse.s + pos) + 1) { + nfile++; src.len = 0 ; - size_t n = genalloc_len(diuint32,&GAENV) + MAXVAR ; - if (i > MAXFILE) strerr_dief2x(111,"to many file to parse in: ",path) ; - if (!file_readputsa(&src,path,gaistr(&toparse,i))) strerr_diefu4sys(111,"read file: ",path,"/",gaistr(&toparse,i)) ; - if (!env_parsenclean(&modifs,&src)) strerr_diefu4x(111,"parse and clean environment of: ",path,"/",gaistr(&toparse,i)) ; - if (!env_split(&GAENV,&SAENV,&src)) strerr_diefu4x(111,"split environment of: ",path,"/",gaistr(&toparse,i)) ; - if (genalloc_len(diuint32,&GAENV) > n) strerr_dief4x(111,"to many variables in file: ",path,"/",gaistr(&toparse,i)) ; + if (nfile > MAXFILE) strerr_dief2x(111,"to many file to parse in: ",path) ; + if (!file_readputsa(&src,path,toparse.s+pos)) strerr_diefu4sys(111,"read file: ",path,"/",toparse.s+pos) ; + clean_n_unexport(&modifs,&dst,&src) ; + nvar = environ_get_num_of_line(&src) ; + if (nvar == -1) strerr_diefu4sys(111,"get number of line of:",path,"/",toparse.s+pos) ; + if (nvar > MAXVAR) strerr_dief4x(111,"to many variables in file: ",path,"/",toparse.s+pos) ; } } - - genalloc_deepfree(stralist,&toparse,stra_free) ; stralloc_free(&src) ; /** be able to freed the stralloc before existing */ @@ -203,35 +182,45 @@ int main (int argc, char const *const *argv, char const *const *envp) char const *newenv[n + 1] ; if (!env_merge (newenv, n ,envp,env_len(envp),tmp, modifs.len)) strerr_diefu1sys(111,"build environment") ; - for (i = 0 ; i < genalloc_len(diuint32,&GAENV) ; i++) - { - unexport = 0 ; - int key = genalloc_s(diuint32,&GAENV)[i].left ; - int val = genalloc_s(diuint32,&GAENV)[i].right ; - if ((SAENV.s+val)[0] == SS_VAR_UNEXPORT) - { - val++ ; - unexport = 1 ; - } - if(!loop_stra(&info.vars,SAENV.s + key)) - if (!env_substitute(SAENV.s + key,SAENV.s + val,&info,newenv,unexport)) - strerr_diefu4x(111,"substitute value of: ",SAENV.s + key," by: ",SAENV.s + val) ; + if (!sastr_split_string_in_nline(&dst)) strerr_diefu1x(111,"split line") ; + pos = 0 ; + while (pos < dst.len) + { + unexport = 0 ; + key.len = val.len = 0 ; + if (!stralloc_copy(&key,&dst) || + !stralloc_copy(&val,&dst)) retstralloc(111,"main") ; + + if (!environ_get_key_nclean(&key,&pos)) strerr_diefu2x(111,"get key from line: ",key.s) ; + pos-- ;// retrieve the '=' character + if (!environ_get_val(&val,&pos)) strerr_diefu2x(111,"get value from line: ",val.s) ; + + char *uval = val.s ; + if (val.s[0] == VAR_UNEXPORT) + { + uval = val.s+1 ; + unexport = 1 ; + } + if(sastr_cmp(&info.vars,key.s) == -1) + if (!environ_substitute(key.s,uval,&info,newenv,unexport)) + strerr_diefu4x(111,"substitute value of: ",key.s," by: ",uval) ; } - genalloc_free(diuint32,&GAENV) ; - stralloc_free(&SAENV) ; + stralloc_free(&key) ; + stralloc_free(&val) ; + stralloc_free(&dst) ; + stralloc_free(&modifs) ; - modifs.len = 0 ; if (!env_string (&modifs, argv, (unsigned int) argc)) strerr_diefu1x(111,"make environment string") ; - r = el_substitute (&dst, modifs.s, modifs.len, info.vars.s, info.values.s, genalloc_s (elsubst_t const, &info.data),genalloc_len (elsubst_t const, &info.data)) ; if (r < 0) strerr_diefu1sys(111,"el_substitute") ; else if (!r) _exit(0) ; - + stralloc_free(&modifs) ; - + char const *v[r + 1] ; if (!env_make (v, r ,dst.s, dst.len)) strerr_diefu1sys(111,"make environment") ; v[r] = 0 ; + pathexec_r (v, newenv, env_len(newenv),info.modifs.s,info.modifs.len) ; } diff --git a/src/extra-tools/execl-subuidgid.c b/src/extra-tools/execl-subuidgid.c index 8eb60e834be597c43808b637e23e2956041daedc..50a35602c0c9fe284dc2e8eb0a94349a067e68c1 100644 --- a/src/extra-tools/execl-subuidgid.c +++ b/src/extra-tools/execl-subuidgid.c @@ -15,7 +15,11 @@ #include <unistd.h> #include <sys/types.h> #include <stdio.h> +#include <errno.h> +#include <pwd.h> + #include <oblibs/error2.h> +#include <oblibs/environ.h> #include <skalibs/types.h> #include <skalibs/buffer.h> @@ -26,8 +30,6 @@ #include <skalibs/djbunix.h> #include <execline/execline.h> -#include <66/environ.h> -#include <66/utils.h> #define USAGE "execl-subuidgid [ -h ] [ -o owner ] prog..." @@ -45,6 +47,40 @@ static inline void info_help (void) strerr_diefu1sys(111, "write to stdout") ; } +/** Implement again this function coming from + * 66. This is avoid the dependency from it*/ +static int youruid(uid_t *passto,char const *owner) +{ + int e ; + e = errno ; + errno = 0 ; + struct passwd *st ; + if (!(st = getpwnam(owner)) || errno) + { + if (!errno) errno = EINVAL ; + return 0 ; + } + *passto = st->pw_uid ; + errno = e ; + return 1 ; +} + +static int yourgid(gid_t *passto,uid_t owner) +{ + int e ; + e = errno ; + errno = 0 ; + struct passwd *st ; + if (!(st = getpwuid(owner)) || errno) + { + if (!errno) errno = EINVAL ; + return 0 ; + } + *passto = st->pw_gid ; + errno = e ; + return 1 ; +} + int main (int argc, char const **argv, char const *const *envp) { uid_t uid ; @@ -83,8 +119,8 @@ int main (int argc, char const **argv, char const *const *envp) cuid[uid_fmt(cuid,uid)] = 0 ; cgid[gid_fmt(cgid,gid)] = 0 ; - if (!env_addkv("UID",cuid,&info)) strerr_diefu1sys(111,"set UID") ; - if (!env_addkv("GID",cgid,&info)) strerr_diefu1sys(111,"set GID") ; + if (!environ_add_key_val("UID",cuid,&info)) strerr_diefu1sys(111,"set UID") ; + if (!environ_add_key_val("GID",cgid,&info)) strerr_diefu1sys(111,"set GID") ; if (!env_string(&sa,argv,(unsigned int) argc)) strerr_diefu1sys(111,"environment string") ; diff --git a/src/include/66/backup.h b/src/include/66/backup.h index d9421af80e7758633187c44e36ffc0cdef9009a2..397f163b95996b4e13a8df301c44a19abb2d1f94 100644 --- a/src/include/66/backup.h +++ b/src/include/66/backup.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef BACKUP_H -#define BACKUP_H +#ifndef SS_BACKUP_H +#define SS_BACKUP_H #include <skalibs/stralloc.h> diff --git a/src/include/66/constants.h b/src/include/66/constants.h index 95aad7a75c61166c84224bbc0f88fbc215fe477b..b54d921a53daa6d1154412bbbb8612ed73ecaa08 100644 --- a/src/include/66/constants.h +++ b/src/include/66/constants.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef CONSTANTS_H -#define CONSTANTS_H +#ifndef SS_CONSTANTS_H +#define SS_CONSTANTS_H #include <66/config.h> @@ -94,7 +94,7 @@ #define SS_BOOT_CONF_LEN (sizeof SS_BOOT_CONF - 1) #define SS_BOOT_PATH "/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin" #define SS_BOOT_PATH_LEN (sizeof SS_BOOT_PATH - 1) -#define SS_BOOT_TREE "init" +#define SS_BOOT_TREE "boot" #define SS_BOOT_TREE_LEN (sizeof SS_BOOT_TREE - 1) #define SS_BOOT_RCINIT "rc.init" #define SS_BOOT_RCINIT_LEN (sizeof SS_BOOT_RCINIT - 1) @@ -106,4 +106,7 @@ #define SS_BOOT_LOGFIFO_LEN (sizeof SS_BOOT_LOGFIFO - 1) #define SS_BOOT_SHUTDOWND "66-shutdownd" #define SS_BOOT_SHUTDOWND_LEN (sizeof SS_BOOT_SHUTDOWND - 1) + +/** Instance */ +#define SS_INSTANCE "@I" #endif diff --git a/src/include/66/db.h b/src/include/66/db.h index de55f840d4f19190353126513e6c1b037b9f43b8..81a5ac02282d04a165644f07dcc75e98794b4bf2 100644 --- a/src/include/66/db.h +++ b/src/include/66/db.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef DB_H -#define DB_H +#ifndef SS_DB_H +#define SS_DB_H #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> diff --git a/src/include/66/enum.h b/src/include/66/enum.h index 2388db0a319f44ba67610127d25414902dd6a29f..022cd2d76a49d57f5d6bfab9069b8272e323c572 100644 --- a/src/include/66/enum.h +++ b/src/include/66/enum.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef ENUM_H -#define ENUM_H +#ifndef SS_ENUM_H +#define SS_ENUM_H #include <sys/types.h> @@ -117,7 +117,7 @@ struct key_all_s static key_description_t const main_section_list[] = { { .name = "@type", .expected = LINE, .mandatory = NEED }, - { .name = "@name", .expected = LINE, .mandatory = NEED }, + { .name = "@name", .expected = LINE, .mandatory = OPTS }, { .name = "@description", .expected = QUOTE, .mandatory = OPTS }, { .name = "@depends", .expected = BRACKET, .mandatory = OPTS }, { .name = "@contents", .expected = BRACKET, .mandatory = BUNDLE }, diff --git a/src/include/66/environ.h b/src/include/66/environ.h index 00216352692caf79f0989d01ac7110a00d67bde7..7c57b9387086fda2bc38ce8d7ecfc7e563b976a8 100644 --- a/src/include/66/environ.h +++ b/src/include/66/environ.h @@ -12,37 +12,14 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef ENVIRON_H -#define ENVIRON_H +#ifndef SS_ENVIRON_H +#define SS_ENVIRON_H -#include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> - -#define MAXVAR 50 -#define MAXFILE 100 -#define MAXENV 4095 - -typedef struct exlsn_s exlsn_t, *exlsn_t_ref ; -struct exlsn_s -{ - stralloc vars ; - stralloc values ; - genalloc data ; // array of elsubst - stralloc modifs ; -} ; - -#define EXLSN_ZERO { .vars = STRALLOC_ZERO, .values = STRALLOC_ZERO, .data = GENALLOC_ZERO, .modifs = STRALLOC_ZERO } +#include <sys/types.h> +#include <skalibs/stralloc.h> -extern int env_clean(stralloc *src) ; -extern int env_split_one(char *line,genalloc *ga,stralloc *sa) ; -extern int env_split(genalloc *gaenv,stralloc *saenv,stralloc *src) ; -extern int env_parsenclean(stralloc *modifs,stralloc *src) ; -extern int make_env_from_line(char const **v,stralloc *sa) ; -extern int env_substitute(char const *key, char const *val,exlsn_t *info, char const *const *envp,int unexport) ; -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 diff --git a/src/include/66/hpr.h b/src/include/66/hpr.h index 816eef0cabe39630460a25b502bc0e7b5273a851..f53a212abe5622d687cdf80d56cbad6383962b17 100644 --- a/src/include/66/hpr.h +++ b/src/include/66/hpr.h @@ -16,8 +16,8 @@ * All credits goes to Laurent Bercot <ska-remove-this-if-you-are-not-a-bot@skarnet.org> * */ -#ifndef HPR_H -#define HPR_H +#ifndef SS_HPR_H +#define SS_HPR_H #include <stddef.h> diff --git a/src/include/66/parser.h b/src/include/66/parser.h index 62f05c484cb5fa59a7bf69a2888da52b079c7292..00a7c83a83ec2dc58d828d63f5c9fe505591fedb 100644 --- a/src/include/66/parser.h +++ b/src/include/66/parser.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef PARSER_H -#define PARSER_H +#ifndef SS_PARSER_H +#define SS_PARSER_H #include <66/enum.h> @@ -22,6 +22,8 @@ #include <oblibs/oblist.h> #include <oblibs/stralist.h> +#include <oblibs/mill.h> + #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> @@ -244,101 +246,52 @@ struct section_s .idx = { 0 } , \ .file = 0 } - -typedef struct parse_mill_inner_s parse_mill_inner_t, *parse_mill_inner_t_ref ; -struct parse_mill_inner_s -{ - char curr ; - uint32_t nline ; - uint8_t nopen ; //number of open found - uint8_t nclose ; //number of close found - uint8_t jumped ;//jump was made or not 1->no,0->yes - uint8_t flushed ;//flush was made or not 1->no,0->yes - -} ; -#define PARSE_MILL_INNER_ZERO { .curr = 0, \ - .nline = 1, \ - .nopen = 0, \ - .nclose = 0, \ - .jumped = 0, \ - .flushed = 0 } - -typedef struct parse_mill_s parse_mill_t,*parse_mill_t_ref ; -struct parse_mill_s -{ - char const open ; - char const close ; - uint8_t force ; //1 -> only one open and close - char const *skip ; - size_t skiplen ; - char const *end ; - size_t endlen ; - char const *jump ;//skip the complete line - size_t jumplen ; - uint8_t check ;//check if nopen == openclose, 0 -> no,1->yes - uint8_t flush ;//set nopen,nclose,sa.len to 0 at every new line - uint8_t forceskip ;//force to skip even if nopen is positive - parse_mill_inner_t inner ; -} ; - -typedef enum parse_enum_e parse_enum_t,*parse_enum_t_ref ; -enum parse_enum_e -{ - IGN = 0 , - KEEP , - JUMP , - EXIT , - END -} ; - -/** Main */ -extern int parser(sv_alltype *service,stralloc *src,char const *file) ; -extern int parse_config(parse_mill_t *p,char const *file, stralloc *src, stralloc *kp,size_t *pos) ; -extern char next(stralloc *s,size_t *pos) ; -extern uint8_t cclass (parse_mill_t *p) ; /** freed */ extern void sv_alltype_free(sv_alltype *sv) ; extern void keynocheck_free(keynocheck *nocheck) ; 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,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 parser(sv_alltype *service,stralloc *src,char const *svname) ; +extern int parse_service_check_enabled(ssexec_t *info, char const *svname,uint8_t force,uint8_t *exist) ; +extern int parse_service_before(ssexec_t *info, stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist) ; +extern int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force) ; extern int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv,uid_t owner) ; -/** utilities */ +/** mill utilities +extern parse_mill_t MILL_FIRST_BRACKET ; +extern parse_mill_t MILL_GET_AROBASE_KEY ; +extern parse_mill_t MILL_GET_COMMENTED_KEY ; +extern parse_mill_t MILL_GET_SECTION_NAME ; */ +/** utilities extern int parse_line(stralloc *src,size_t *pos) ; -extern int parse_quote(stralloc *src,size_t *pos) ; -extern int parse_bracket(stralloc *src,size_t *pos) ; -extern int parse_env(stralloc *src,size_t *pos) ; +extern int parse_bracket(stralloc *src,size_t *pos) ; */ /** split */ -extern int get_section_range(section_t *sasection,stralloc *src) ; -extern int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtype) ; +extern int section_get_range(section_t *sasection,stralloc *src) ; +extern int key_get_range(genalloc *ga, section_t *sasection,int *svtype) ; extern int get_mandatory(genalloc *nocheck,int idsec,int idkey) ; extern int nocheck_toservice(keynocheck *nocheck,int svtype, sv_alltype *service) ; /** store */ extern int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) ; extern int keep_runfinish(sv_exec *exec,keynocheck *nocheck) ; extern int keep_logger(sv_execlog *log,keynocheck *nocheck) ; -/** helper */ -extern int read_svfile(stralloc *sasv,char const *name,char const *src) ; -extern ssize_t get_sep_before (char const *line, char const sepstart, char const sepend) ; +/** helper extern void section_setsa(int id, stralloc_ref *p,section_t *sa) ; -extern int section_skip(char const *s,size_t pos,int nline) ; -extern int section_valid(int id, uint32_t nline, size_t pos,stralloc *src, char const *file) ; -extern int clean_value(stralloc *sa) ; -extern void parse_err(int ierr,int idsec,int idkey) ; +extern int section_get_skip(char const *s,size_t pos,int nline) ; +extern int section_get_id(stralloc *secname, char const *string,size_t *pos,int *id) ; +extern int key_get_next_id(stralloc *sa, char const *string,size_t *pos) ; +extern void parse_err(int ierr,int idsec,int idkey) ; */ +extern int read_svfile(stralloc *sasv,char const *name,char const *src) ; 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,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_services(ssexec_t *info,sv_alltype *sv, char const *workdir, uint8_t force,uint8_t conf) ; +extern int write_classic(sv_alltype *sv, char const *dst, uint8_t force, uint8_t conf) ; +extern int write_longrun(sv_alltype *sv,char const *dst, uint8_t force, uint8_t conf) ; +extern int write_oneshot(sv_alltype *sv,char const *dst, uint8_t 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_common(sv_alltype *sv, char const *dst,uint8_t 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_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *dst, int mode, uint8_t 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) ; extern int write_env(char const *name,stralloc *sa,char const *dst) ; diff --git a/src/include/66/rc.h b/src/include/66/rc.h index 1485c4fc6b53ca9ed202ad8118d3a21e6325f8ee..0be2cbeac44ec742fff1b7fc16b7d54d6eb14e35 100644 --- a/src/include/66/rc.h +++ b/src/include/66/rc.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef RC_H -#define RC_H +#ifndef SS_RC_H +#define SS_RC_H #include <66/ssexec.h> diff --git a/src/include/66/resolve.h b/src/include/66/resolve.h index c02bb62b34b1bce4af4297694e29de96e4118ffa..40c03e1544e7359573aedf09e7b4ad757e0ca108 100644 --- a/src/include/66/resolve.h +++ b/src/include/66/resolve.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef SSRESOLVE_H -#define SSRESOLVE_H +#ifndef SS_RESOLVE_H +#define SS_RESOLVE_H #include <stddef.h> diff --git a/src/include/66/ssexec.h b/src/include/66/ssexec.h index 92c1c8bc277c21bc6a07769182abbfcc0206f22b..7a7b32266c1c382d923376b5f07a6921630acbb8 100644 --- a/src/include/66/ssexec.h +++ b/src/include/66/ssexec.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef SSEXEC_H -#define SSEXEC_H +#ifndef SS_SSEXEC_H +#define SS_SSEXEC_H #include <skalibs/stralloc.h> #include <skalibs/types.h> diff --git a/src/include/66/state.h b/src/include/66/state.h index 77048dbb11d85f0b74e46a0398a11ed61d62b429..a7b126c010e72c64cad5dc749bdd8f42c211d513 100644 --- a/src/include/66/state.h +++ b/src/include/66/state.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef SSSTATE_H -#define SSSTATE_H +#ifndef SS_STATE_H +#define SS_STATE_H #include <stddef.h> diff --git a/src/include/66/svc.h b/src/include/66/svc.h index d9fa724cf13999b696334febb0bb631140b312e1..8b1005a991cb62cba7d521fb1eed99d5c5fcb3ca 100644 --- a/src/include/66/svc.h +++ b/src/include/66/svc.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef SVC_H -#define SVC_H +#ifndef SS_SVC_H +#define SS_SVC_H #include <skalibs/tai.h> #include <skalibs/stralloc.h> diff --git a/src/include/66/tree.h b/src/include/66/tree.h index ac5d7f0e0e0ca812ac7b18bd11f305181ca0c3a0..6268c9133d63c52c3dd5dfc20a9037ac7f1d7701 100644 --- a/src/include/66/tree.h +++ b/src/include/66/tree.h @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef TREE_H -#define TREE_H +#ifndef SS_TREE_H +#define SS_TREE_H #include <sys/types.h> diff --git a/src/include/66/utils.h b/src/include/66/utils.h index d46ec1d357c41256a67bfa2bd1ce8115f64c7eff..1b9b87ad1c5e6b9290cc0be4f6fd7c688f4ea06b 100644 --- a/src/include/66/utils.h +++ b/src/include/66/utils.h @@ -12,14 +12,15 @@ * except according to the terms contained in the LICENSE file./ */ -#ifndef UTILS_H -#define UTILS_H +#ifndef SS_UTILS_H +#define SS_UTILS_H #include <sys/types.h> #include <unistd.h> //getuid #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> +#include <skalibs/gccattributes.h> #include <66/ssexec.h> #include <66/resolve.h> @@ -47,10 +48,13 @@ extern int set_livedir(stralloc *live) ; extern int set_livescan(stralloc *live,uid_t owner) ; extern int set_livetree(stralloc *live,uid_t owner) ; extern int set_livestate(stralloc *live,uid_t owner) ; -extern int insta_check(char const *svname) ; -extern int insta_create(stralloc *sasv,stralloc *sv, char const *src, int len) ; -extern int insta_splitname(stralloc *sa,char const *name,int len,int what) ; -extern int insta_replace(stralloc *sa,char const *src,char const *cpy) ; +extern int insta_check(char const *svname) gccattr_deprecated ; +extern int insta_create(stralloc *sasv,stralloc *sv, char const *src, int len) gccattr_deprecated ; +extern int insta_splitname(stralloc *sa,char const *name,int len,int what) gccattr_deprecated ; +extern int insta_replace(stralloc *sa,char const *src,char const *cpy) gccattr_deprecated ; extern int read_svfile(stralloc *sasv,char const *name,char const *src) ; - +extern int instance_check(char const *svname) ; +extern int instance_splitname(stralloc *sa,char const *name,int len,int what) ; +//extern int instance_change_name(stralloc *sa,char const *template,char const *copy) ; +extern int instance_create(stralloc *sasv,char const *svname, char const *regex, char const *src, int len) ; #endif diff --git a/src/lib66/environ.c b/src/lib66/environ.c index b45f01a4667a0abb5b71d6e7185e947a89fa0069..d2a664cf1268843938ed8d683cac7db1c32b0c8e 100644 --- a/src/lib66/environ.c +++ b/src/lib66/environ.c @@ -11,397 +11,19 @@ * This file may not be copied, modified, propagated, or distributed * except according to the terms contained in the LICENSE file./ */ - -#include <stddef.h> -#include <string.h> -#include <errno.h> + //#include <stdio.h> +#include <sys/types.h> +#include <string.h> -#include <oblibs/string.h> -#include <oblibs/stralist.h> -#include <oblibs/directory.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <oblibs/files.h> -#include <oblibs/types.h> #include <skalibs/stralloc.h> -#include <skalibs/genalloc.h> -#include <skalibs/diuint32.h> -#include <skalibs/env.h> -#include <skalibs/strerr2.h> -#include <skalibs/djbunix.h> -#include <skalibs/bytestr.h> -#include <66/parser.h> -#include <66/environ.h> -#include <66/utils.h> #include <66/constants.h> -#include <66/config.h> - -#include <execline/execline.h> -/* @Return 1 on success - * @Return 0 on fail - * @Return -1 for empty line */ -int env_clean(stralloc *src) -{ - int r, e = 1 ; - unsigned int i ; - genalloc gatmp =GENALLOC_ZERO ;//stralist - stralloc kp = STRALLOC_ZERO ; - stralloc tmp = STRALLOC_ZERO ; - - size_t pos = 0 ; - char const *file = "env_clean" ; - parse_mill_t line = { .open = '@', .close = '=', \ - .skip = " \t\r", .skiplen = 3, \ - .end = "\n", .endlen = 1, \ - .jump = "#", .jumplen = 1,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - parse_mill_t line_end = { .open = '@', .close = '\n', \ - .skip = " \t\r", .skiplen = 3, \ - .end = "\n", .endlen = 1, \ - .jump = "#", .jumplen = 1,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - size_t blen = src->len, n = 0 ; - if (!stralloc_inserts(src,0,"@")) goto err ; - while(pos < (blen+n) && n < 2) - { - kp.len = 0 ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - line.inner.nopen = line.inner.nclose = 0 ; - r = parse_config(!n?&line:&line_end,file,src,&kp,&pos) ; - if (!r) goto err ; - if (r < 0 && !n){ e = -1 ; goto freed ; } - if (!stralloc_0(&kp)) goto err ; - if (!clean_val(&gatmp,kp.s)) goto err ; - for (i = 0 ; i < genalloc_len(stralist,&gatmp) ; i++) - { - if ((i+1) < genalloc_len(stralist,&gatmp)) - { - if (!stralloc_cats(&tmp,gaistr(&gatmp,i))) goto err ; - if (!stralloc_cats(&tmp," ")) goto err ; - } - else if (!stralloc_cats(&tmp,gaistr(&gatmp,i))) goto err ; - } - if (!n) if (!stralloc_cats(&tmp,"=")) goto err ; - if (!stralloc_inserts(src,pos,"@")) goto err ; - n++; - } - - if (!stralloc_0(&tmp)) goto err ; - if (!stralloc_copy(src,&tmp)) goto err ; - - freed: - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - return e ; - - err: - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - return 0 ; -} - -int env_split_one(char *line,genalloc *ga,stralloc *sa) -{ - size_t slen = strlen(line) ; - char s[slen + 1] ; - memcpy(s,line,slen) ; - s[slen] = 0 ; - - char *k = 0 ; - char *v = 0 ; - diuint32 tmp = DIUINT32_ZERO ; - k = s ; - v = s ; - obstr_sep(&v,"=") ; - /** TODO, for the moment we just ignore un key with an empty - * value, this is clearely not a good way, it must be handled - * correctly. By the way the parser is currently re written and - * the env_** will changes. Just be functionnal here*/ - if (!*v) return -1 ; - tmp.left = sa->len ; - if(!stralloc_catb(sa,k,strlen(k)+1)) return 0 ; - if (!obstr_trim(v,'\n')) return 0 ; - tmp.right = sa->len ; - if(!stralloc_catb(sa,v,strlen(v)+1)) return 0 ; - if (!genalloc_append(diuint32,ga,&tmp)) return 0 ; - return 1 ; -} - -int env_split(genalloc *gaenv,stralloc *saenv,stralloc *src) -{ - int nbline = 0, i = 0 ; - genalloc gatmp = GENALLOC_ZERO ;//stralist - stralloc tmp = STRALLOC_ZERO ; - nbline = get_nbline_ga(src->s,src->len,&gatmp) ; - for (; i < nbline ; i++) - { - char *line = gaistr(&gatmp,i) ; - 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 ; - if (!env_split_one(tmp.s,gaenv,saenv)) goto err ; - } - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&tmp) ; - return 1 ; - err: - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&tmp) ; - return 0 ; -} - -int env_parsenclean(stralloc *modifs,stralloc *src) -{ - int nbline = 0, i = 0 ; - size_t pos = 0 ; - genalloc gatmp = GENALLOC_ZERO ;//stralist - stralloc tmp = STRALLOC_ZERO ; - nbline = get_nbline_ga(src->s,src->len,&gatmp) ; - - for (; i < nbline ; i++) - { - tmp.len = 0 ; - if (!gaistrlen(&gatmp,i)) break ; - if (!stralloc_cats(&tmp,gaistr(&gatmp,i))) goto err ; - if (!parse_env(&tmp,&pos)) goto err ; - if (!env_clean(&tmp)) goto err ; - tmp.len--;//remove '0' - int r = get_len_until(tmp.s,'=') ; - if (tmp.s[r+1] == SS_VAR_UNEXPORT){ - r++ ; - char t[tmp.len+1] ; - memcpy(t,tmp.s,r) ; - memcpy(t+r,tmp.s+r+1,tmp.len-(r+1)) ; - tmp.len--; - t[tmp.len] = 0 ; - if (!stralloc_catb(modifs,t,tmp.len + 1)) goto err ; - }else if (!stralloc_catb(modifs,tmp.s,tmp.len + 1)) goto err ;// || - } - - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&tmp) ; - return 1 ; - err: - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&tmp) ; - return 0 ; -} - -int make_env_from_line(char const **v,stralloc *sa) -{ - genalloc gatmp = GENALLOC_ZERO ; - stralloc copy = STRALLOC_ZERO ; - unsigned int i = 0 ; - if (!sa->len) goto err ; - if (!clean_val(&gatmp,sa->s)) goto err ; - for (;i < genalloc_len(stralist,&gatmp) ; i++) - { - char *line = gaistr(&gatmp,i) ; - if (!stralloc_catb(©,line,gaistrlen(&gatmp,i) + 1)) goto err ; - } - stralloc_copy(sa,©) ; - stralloc_free(©) ; - if (!env_make(v,i,sa->s,sa->len)) goto err ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - return i ; - err: - stralloc_free(©) ; - genalloc_deepfree(stralist,&gatmp,stra_free) ; - return 0 ; -} - -int env_substitute(char const *key, char const *val,exlsn_t *info, char const *const *envp,int unexport) -{ - char const *defaultval = "" ; - char const *x ; - int insist = 0 ; - - eltransforminfo_t si = ELTRANSFORMINFO_ZERO ; - elsubst_t blah ; - - blah.var = info->vars.len ; - blah.value = info->values.len ; - - if (el_vardupl(key, info->vars.s, info->vars.len)) { strerr_warnwu1x("el_vardupl") ; goto err ; } - if (!stralloc_catb(&info->vars,key, strlen(key) + 1)) { strerr_warnwu1x("append stralloc of env_substitute") ; goto err ; } - - x = env_get2(envp, key) ; - if (!x) - { - if (insist) { strerr_warnw2x(key,": is not set") ; goto err ; } - x = defaultval ; - } - else if (unexport) - { - if (!stralloc_catb(&info->modifs, key, strlen(key) + 1)) goto err ; - } - if (!x) blah.n = 0 ; - else - { - int r ; - if (!stralloc_cats(&info->values, x)) goto err ; - r = el_transform(&info->values, blah.value, &si) ; - if (r < 0) goto err ; - blah.n = r ; - } - - if (!genalloc_append(elsubst_t, &info->data, &blah)) goto err ; - - return 1 ; - - err: - info->vars.len = blah.var ; - info->values.len = blah.value ; - return 0 ; -} - -int env_addkv (const char *key, const char *val, exlsn_t *info) -{ - int r ; - eltransforminfo_t si = ELTRANSFORMINFO_ZERO ; - elsubst_t blah ; - - blah.var = info->vars.len ; - blah.value = info->values.len ; - - if (el_vardupl (key, info->vars.s, info->vars.len)) goto err ; - if (!stralloc_catb (&info->vars, key, strlen(key) + 1)) goto err ; - if (!stralloc_cats (&info->values, val)) goto err ; - - r = el_transform (&info->values, blah.value, &si) ; - if (r < 0) goto err; - blah.n = r ; - - if (!genalloc_append (elsubst_t, &info->data, &blah)) goto err ; - - return 1 ; - err: - info->vars.len = blah.var ; - info->values.len = blah.value ; - return 0 ; -} - -int env_get_from_src(stralloc *modifs,char const *src) -{ - int r ; - size_t filesize ; - unsigned int i ; - stralloc sa = STRALLOC_ZERO ; - genalloc toparse = GENALLOC_ZERO ; - r = scan_mode(src,S_IFDIR) ; - if (r < 0) - { - r = scan_mode(src,S_IFREG) ; - if (!r || r < 0) - { - VERBO3 strerr_warnw2sys("invalid environment: ",src) ; - goto err ; - } - filesize=file_get_size(src) ; - if (filesize > MAXENV) - { - VERBO3 strerr_warnw2x("environment too long: ",src) ; - goto err ; - } - if (!openreadfileclose(src,&sa,filesize)) - { - VERBO3 strerr_warnwu2sys("open: ",src ) ; - goto err ; - } - if (!env_parsenclean(modifs,&sa)) - { - VERBO3 strerr_warnwu2x("parse and clean environment of: ",sa.s) ; - goto err ; - } - } - else if (!r) - { - VERBO3 strerr_warnw2sys("invalid environment: ",src) ; - goto err ; - } - /** we parse all file of the directory*/ - else - { - r = dir_get(&toparse,src,"",S_IFREG) ; - if (!r) - { - VERBO3 strerr_warnwu2sys("get file from: ",src) ; - goto err ; - } - for (i = 0 ; i < genalloc_len(stralist,&toparse) ; i++) - { - sa.len = 0 ; - if (i > MAXFILE) - { - VERBO3 strerr_warnw2x("to many file to parse in: ",src) ; - goto err ; - } - if (!file_readputsa(&sa,src,gaistr(&toparse,i))) - { - VERBO3 strerr_warnw4x("read file: ",src,"/",gaistr(&toparse,i)) ; - goto err ; - } - if (!env_parsenclean(modifs,&sa)) - { - VERBO3 strerr_warnw4x("parse and clean environment of: ",src,"/",gaistr(&toparse,i)) ; - goto err ; - } - } - } - genalloc_deepfree(stralist,&toparse,stra_free) ; - stralloc_free(&sa) ; - return 1 ; - err: - genalloc_deepfree(stralist,&toparse,stra_free) ; - stralloc_free(&sa) ; - return 0 ; -} - -size_t build_env(char const *src,char const *const *envp,char const **newenv, char *tmpenv) -{ - - stralloc modifs = STRALLOC_ZERO ; - size_t envlen = env_len(envp) ; - - if (!env_get_from_src(&modifs,src)) - { - VERBO3 strerr_warnw2x("get environment file from: ",src) ; - goto err ; - } - size_t n = env_len(envp) + 1 + byte_count(modifs.s,modifs.len,'\0') ; - size_t mlen = modifs.len ; - if (mlen > MAXENV) - { - VERBO3 strerr_warnw2x("environment too long: ",src) ; - goto err ; - } - memcpy(tmpenv,modifs.s,mlen) ; - tmpenv[mlen] = 0 ; - - if (!env_merge(newenv, n, envp, envlen, tmpenv, mlen)) - { - VERBO3 strerr_warnwu2x("merge environment from: ",src) ; - goto err ; - } - - stralloc_free(&modifs) ; - - return 1 ; - err: - stralloc_free(&modifs) ; - return 0 ; -} +#include <66/utils.h> int env_resolve_conf(stralloc *env, uid_t owner) { @@ -421,68 +43,57 @@ int env_resolve_conf(stralloc *env, uid_t owner) 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++) + int r ; + size_t pos = 0, fakepos = 0 ; + stralloc result = STRALLOC_ZERO ; + stralloc skey = STRALLOC_ZERO ; + stralloc sval = STRALLOC_ZERO ; + stralloc mkey = STRALLOC_ZERO ; + stralloc mval = STRALLOC_ZERO ; + if (!environ_get_clean_env(srclist) || + !environ_get_clean_env(modifs) || + !environ_clean_nline(srclist) || + !environ_clean_nline(modifs) || + !stralloc_copy(&result,srclist)) goto err ; + result.len-- ; //remove 0 + if (!sastr_split_string_in_nline(modifs)) goto err ; + if (!sastr_split_string_in_nline(srclist)) goto err ; + for (;pos < modifs->len; pos += strlen(modifs->s + pos) + 1) + { + fakepos = pos ; + skey.len = sval.len = mkey.len = mval.len = 0 ; + if (!stralloc_copy(&mkey,modifs) || + !stralloc_copy(&mval,modifs) || + !stralloc_copy(&skey,srclist) || + !stralloc_copy(&sval,srclist)) goto err ; + if(!environ_get_key_nclean(&mkey,&pos)) goto err ; + r = sastr_find(srclist,mkey.s) ; + if (r >= 0) { - mkey = msa.s + genalloc_s(diuint32,&mga)[j].left ; - mval = msa.s + genalloc_s(diuint32,&mga)[j].right ; - if (obstr_equal(key,mkey) && force) + if (force) { - found = 1 ; - if (!stralloc_cats(&newlist,mval)) return 0 ; - break ; + if (!environ_get_val_of_key(&sval,mkey.s) || + !environ_get_val_of_key(&mval,mkey.s) || + !sastr_replace(&result,sval.s,mval.s)) goto err ; + result.len-- ; } } - 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) + else { - 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 (!stralloc_cats(&result,modifs->s+fakepos) || + !stralloc_cats(&result,"\n")) goto err ; } } - if (!file_write_unsafe(dst,file,newlist.s,newlist.len)) - strerr_diefu3sys(111,"write: ",dst,file) ; + if (!stralloc_cats(&result,"\n")) goto err ; + if (!file_write_unsafe(dst,file,result.s,result.len)) goto err ; - stralloc_free(&newlist) ; - stralloc_free(&sa) ; - stralloc_free(&msa) ; - genalloc_free(diuint32,&mga) ; - genalloc_free(diuint32,&ga) ; + stralloc_free(&result) ; stralloc_free(&skey) ; + stralloc_free(&sval) ; stralloc_free(&mkey) ; + stralloc_free(&mval) ; return 1 ; + err: + stralloc_free(&result) ; stralloc_free(&skey) ; + stralloc_free(&sval) ; stralloc_free(&mkey) ; + stralloc_free(&mval) ; + return 0 ; } diff --git a/src/lib66/instance.c b/src/lib66/instance.c index 06f56e1f698a7100acc2885eb5fe8c071a0b7139..d71cee973b5e647f967b49c74b438f0fa5539003 100644 --- a/src/lib66/instance.c +++ b/src/lib66/instance.c @@ -21,10 +21,102 @@ #include <oblibs/string.h> #include <oblibs/stralist.h> #include <oblibs/directory.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> +#include <66/enum.h> + +/** New functions */ + +int instance_check(char const *svname) +{ + int r ; + r = get_len_until(svname,'@') ; + // avoid empty value after the instance template name + if (strlen(svname+r) <= 1 && r > 0) return 0 ; + + return r ; +} + +int instance_splitname(stralloc *sa,char const *name,int len,int what) +{ + char const *copy ; + size_t tlen = len + 1 ; + + char template[tlen + 1] ; + memcpy(template,name,tlen) ; + template[tlen] = 0 ; + + copy = name + tlen ; + + if (!what) + return stralloc_obreplace(sa,template) ; + else + return stralloc_obreplace(sa,copy) ; +} +/* +int instance_change_name(stralloc *sa,char const *template,char const *copy) +{ + stralloc tmp = STRALLOC_ZERO ; + stralloc iname = STRALLOC_ZERO ; + + if (!stralloc_cats(&iname,template) || + !stralloc_cats(&iname,copy) || + !stralloc_0(&iname) || + !stralloc_copy(&tmp,sa) || + !environ_get_val_of_key(&tmp,get_keybyid(NAME)) || + !sastr_replace(sa,tmp.s,iname.s)) goto err ; + + stralloc_free(&tmp) ; + stralloc_free(&iname) ; + return 1 ; + err: + stralloc_free(&tmp) ; + stralloc_free(&iname) ; + return 0 ; +} +*/ + +int instance_create(stralloc *sasv,char const *svname, char const *regex, char const *src, int len) +{ + char const *copy ; + size_t tlen = len + 1 ; + + stralloc tmp = STRALLOC_ZERO ; + + char template[tlen + 1] ; + memcpy(template,svname,tlen) ; + template[tlen] = 0 ; + + copy = svname + tlen ; + + if (!file_readputsa(&tmp,src,template)) { + VERBO3 strerr_warnwu3sys("open: ",src,template) ; + goto err ; + } +/* if (!instance_change_name(&tmp,template,copy)) { + VERBO3 strerr_warnwu3x("replace instance name at: ",src,template) ; + goto err ; + }*/ + if (!sastr_replace_all(&tmp,regex,copy)){ + VERBO3 strerr_warnwu3x("replace instance character at: ",src,template) ; + goto err ; + } + if (!stralloc_copy(sasv,&tmp)) goto err ; + stralloc_free(&tmp) ; + return 1 ; + err: + stralloc_free(&tmp) ; + return 0 ; +} + +/********************* + * Deprecated function + * *******************/ + int insta_replace(stralloc *sa,char const *src,char const *cpy) { diff --git a/src/lib66/parser.c b/src/lib66/parser.c index 98c6d4513d11ac98f30e4f7436b6431b7552f74e..78e34a30a43c2871ce89eda477d180478fd2bd89 100644 --- a/src/lib66/parser.c +++ b/src/lib66/parser.c @@ -13,6 +13,8 @@ */ #include <string.h> +#include <stdint.h> +#include <stdint.h> //#include <stdio.h> #include <oblibs/error2.h> @@ -20,6 +22,7 @@ #include <oblibs/files.h> #include <oblibs/stralist.h> #include <oblibs/obgetopt.h> +#include <oblibs/mill.h> #include <skalibs/buffer.h> #include <skalibs/stralloc.h> @@ -31,186 +34,57 @@ #include <66/utils.h> #include <66/parser.h> -inline uint8_t cclass (parse_mill_t *p) -{ - size_t i = 0 ; - - if (!p->inner.curr) return 0 ; - else if (p->inner.curr == '\n') - { - if (p->flush) p->inner.flushed = 1 ; - p->inner.jumped = 0 ; - p->inner.nline++ ; - } - for (; i < p->jumplen ; i++) - { - if (p->inner.curr == p->jump[i]) - { - p->inner.jumped = 1 ; - return 2 ; - } - } - for (i = 0 ; i < p->endlen ; i++) - { - if (p->inner.curr == p->end[i]) - { - if (p->inner.curr == p->close) p->inner.nclose++ ; - return 3 ; - } - } - for (i = 0 ; i < p->skiplen ; i++) - { - if (p->inner.curr == p->skip[i]) - { - if (p->open && !p->forceskip) return 1 ; - return 0 ; - } - } - /* close and open can be the same, in this case - * we skip open if it already found */ - if (p->inner.curr == p->open && !p->inner.nopen) - { - p->inner.nopen++ ; - return 0 ; - } - - if (p->inner.curr == p->close) - { - p->inner.nclose++ ; - if (p->force) return 3 ; - return 0 ; - } - - return 1 ; -} -inline char next(stralloc *s,size_t *pos) +int parser(sv_alltype *service,stralloc *src,char const *svname) { - char c ; - if (*pos >= s->len) return -1 ; - c = s->s[*pos] ; - (*pos) += 1 ; - return c ; -} -/** @Return 1 on sucess - * @Return 0 on fail - * @Return 2 for end of file - * @Return -1 if close was not found */ -inline int parse_config(parse_mill_t *p,char const *file, stralloc *src, stralloc *kp,size_t *pos) -{ - uint8_t what = 0 ; - static uint8_t const table[5] = { IGN, KEEP, JUMP, EXIT, END } ; - uint8_t state = 1, end = 0 ; - char j = 0 ; - while (state) - { - p->inner.curr = next(src, pos) ; - what = table[cclass(p)] ; - // end of file - if (p->inner.curr == -1) what = END ; - if (p->inner.flushed) - { - kp->len = 0 ; - p->inner.nopen = 0 ; - p->inner.nclose = 0 ; - p->inner.flushed = 0 ; - what = SKIP ; - } - switch(what) - { - case KEEP: - if (p->inner.nopen && !p->inner.jumped) - if (!stralloc_catb(kp,&p->inner.curr,1)) return 0 ; - break ; - case JUMP: - if (!p->inner.nopen) - { - while (j != '\n') - { - j = next(src,pos) ; - if (j < 0) break ;//end of string - } - p->inner.jumped = 0 ; - p->inner.nline++ ; - } - break ; - case IGN: - break ; - case EXIT: - state = 0 ; - break ; - case END: - state = 0 ; - end = 1 ; - break ; - default: break ; - } - } - - if (p->check && p->inner.nopen != p->inner.nclose) - { - char fmt[UINT_FMT] ; - fmt[uint_fmt(fmt, p->inner.nline-1)] = 0 ; - char sepopen[2] = { p->open,0 } ; - char sepclose[2] = { p->close,0 } ; - strerr_warnw6x("umatched ",(p->inner.nopen > p->inner.nclose) ? sepopen : sepclose," in: ",file," at line: ",fmt) ; - return 0 ; - } - if (!p->inner.nclose) return -1 ; - if (end) return 2 ; - return 1 ; -} - -int parser(sv_alltype *service,stralloc *src,char const *file) -{ - int r ; - int svtype = -1 ; + int r , svtype = -1 ; + size_t i = 0 ; section_t sasection = SECTION_ZERO ; genalloc ganocheck = GENALLOC_ZERO ; - sasection.file = file ; + sasection.file = svname ; - r = get_section_range(&sasection,src) ; + r = section_get_range(&sasection,src) ; if (r <= 0){ - strerr_warnwu2x("parse section of service file: ",file) ; + strerr_warnwu2x("parse section of service file: ",svname) ; goto err ; } if (!sasection.idx[MAIN]) { - VERBO1 strerr_warnw2x("missing section [main] in service file: ", file) ; + VERBO1 strerr_warnw2x("missing section [main] in service file: ", svname) ; goto err ; } - if (!get_key_range(&ganocheck,&sasection,file,&svtype)) goto err ; + if (!key_get_range(&ganocheck,&sasection,&svtype)) goto err ; if (svtype < 0) { - VERBO1 strerr_warnw2x("invalid value for key: @type in service file: ",file) ; + VERBO1 strerr_warnw4x("invalid value for key: ",get_keybyid(TYPE)," in service file: ",svname) ; goto err ; } if (svtype != BUNDLE && !sasection.idx[START]) { - VERBO1 strerr_warnw2x("missing section [start] in service file: ", file) ; + VERBO1 strerr_warnw2x("missing section [start] in service file: ", svname) ; goto err ; } if (!genalloc_len(keynocheck,&ganocheck)){ - VERBO1 strerr_warnw2x("empty service file: ",file) ; + VERBO1 strerr_warnw2x("empty service file: ",svname) ; goto err ; } - for (unsigned int i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) + for (i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) { uint32_t idsec = genalloc_s(keynocheck,&ganocheck)[i].idsec ; - for (int j = 0;j < total_list_el[idsec] && total_list[idsec].list > 0;j++) + for (unsigned int j = 0;j < total_list_el[idsec] && total_list[idsec].list > 0;j++) { if (!get_mandatory(&ganocheck,idsec,j)) { - VERBO1 strerr_warnw2x("mandatory key is missing in service file: ",file) ; + VERBO1 strerr_warnw2x("mandatory key is missing in service file: ",svname) ; goto err ; } } } - for (unsigned int i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) + for (i = 0;i < genalloc_len(keynocheck,&ganocheck);i++) { if (!nocheck_toservice(&(genalloc_s(keynocheck,&ganocheck)[i]),svtype,service)) { - VERBO1 strerr_warnwu2x("keep information of service file: ",file) ; + VERBO1 strerr_warnwu2x("keep information of service file: ",svname) ; goto err ; } } diff --git a/src/lib66/parser_enabled.c b/src/lib66/parser_enabled.c index 0918f6a22471a55e9c1f019cec1254629840ec7c..939d59ab79cfa774b456a8dc76a38e3dc3eff717 100644 --- a/src/lib66/parser_enabled.c +++ b/src/lib66/parser_enabled.c @@ -15,7 +15,7 @@ #include <66/parser.h> #include <string.h> -//#include <stdio.h> +#include <stdio.h> #include <oblibs/string.h> #include <oblibs/types.h> @@ -30,22 +30,47 @@ #include <66/constants.h> #include <66/environ.h> -int parse_service_get_list(stralloc *result, stralloc *list) +int parse_service_check_enabled(ssexec_t *info, char const *svname,uint8_t force,uint8_t *exist) { - int found ; - size_t i = 0, len = list->len ; - for (;i < len; i += strlen(list->s + i) + 1) + int rc, rl, ret = 1 ; + stralloc tmp = STRALLOC_ZERO ; + if (!set_ownerhome(&tmp,info->owner)) { - found = 0 ; - char *name = list->s+i ; - size_t svlen = strlen(name) ; - char svname[svlen + 1] ; - char svsrc[svlen + 1] ; - if (!basename(svname,name)) return 0 ; - if (!dirname(svsrc,name)) return 0 ; - if (ss_resolve_src(result,svname,svsrc,&found) <= 0) return 0 ; + VERBO3 strerr_warnwu1sys("set home directory") ; + goto err ; } - return 1 ; + if (!ss_resolve_pointo(&tmp,info,LONGRUN,SS_RESOLVE_SRC)) { + VERBO3 strerr_warnwu1sys("set revolve pointer to source") ; + goto err ; + } + tmp.len-- ; + if (!stralloc_cats(&tmp,SS_SRC) || + !stralloc_0(&tmp)) retstralloc(0,"parse_service_check_enabled") ; + rl = dir_search(tmp.s,svname,S_IFDIR) ; + if (!ss_resolve_pointo(&tmp,info,CLASSIC,SS_RESOLVE_SRC)) { + VERBO3 strerr_warnwu1sys("set revolve pointer to source") ; + goto err ; + } + rc = dir_search(tmp.s,svname,S_IFDIR) ; + if (rc == 1 || rl == 1) { + (*exist) = 1 ; + if (!force) { + VERBO2 strerr_warni2x("already added: ",svname) ; + ret = 2 ; + goto freed ; + } + } + else if (rc == -1 || rl == -1) + { + VERBO3 strerr_warnw3x("Conflicting format type for ",svname," service file") ; + goto err ; + } + freed: + stralloc_free(&tmp) ; + return ret ; + err: + stralloc_free(&tmp) ; + return 0 ; } int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *service,unsigned int *nbsv,uid_t owner) @@ -71,14 +96,11 @@ int parse_add_service(stralloc *parsed_list,sv_alltype *sv_before,char const *se (*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) +int parse_service_deps(ssexec_t *info,stralloc *parsed_list, sv_alltype *sv_before, char const *sv,unsigned int *nbsv,stralloc *sasv,uint8_t force) { - unsigned int exist = 0 ; + uint8_t exist = 0 ; char *dname = 0 ; stralloc newsv = STRALLOC_ZERO ; if (sv_before->cname.nga) @@ -98,7 +120,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,exist)) + if (!parse_service_before(info,parsed_list,newsv.s,nbsv,sasv,force,&exist)) { stralloc_free(&newsv) ; return 0 ; @@ -110,87 +132,43 @@ 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,unsigned int exist) +int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,unsigned int *nbsv, stralloc *sasv,uint8_t force,uint8_t *exist) { - int r = 0 , insta ; - size_t svlen = strlen(sv), svsrclen ; - - char svname[svlen + 1] ; - char svsrc[svlen + 1] ; - char svpath[svlen + 1] ; + int r, insta ; + size_t svlen = strlen(sv), svsrclen, svnamelen ; + char svname[svlen + 1], svsrc[svlen + 1], svpath[svlen + 1] ; if (!basename(svname,sv)) return 0 ; if (!dirname(svsrc,sv)) return 0 ; svsrclen = strlen(svsrc) ; + svnamelen = strlen(svname) ; if (scan_mode(sv,S_IFDIR) == 1) return 1 ; - - stralloc newsv = STRALLOC_ZERO ; - stralloc tmp = STRALLOC_ZERO ; - - { - if (!set_ownerhome(&tmp,info->owner)) - { - VERBO3 strerr_warnwu1sys("set home directory") ; - goto err ; - } - if (!stralloc_cats(&tmp,info->tree.s)) retstralloc(0,"parse_service_before") ; - if (!stralloc_cats(&tmp,SS_SVDIRS)) retstralloc(0,"parse_service_before") ; - if (!stralloc_cats(&tmp,SS_DB)) retstralloc(0,"parse_service_before") ; - if (!stralloc_cats(&tmp,SS_SRC)) retstralloc(0,"parse_service_before") ; - if (!stralloc_0(&tmp)) retstralloc(0,"parse_service_before") ; - - insta = insta_check(svname) ; - if (!insta) - { - VERBO3 strerr_warnw2x("invalid instance name: ",svname) ; - goto err ; - } - if (insta > 0) - { - if (!insta_splitname(&newsv,svname,insta,1)) - { - VERBO3 strerr_warnwu2x("split copy name of instance: ",svname) ; - goto err ; - } - } - else if (!stralloc_cats(&newsv,svname)) retstralloc(0,"parse_service_before") ; - if (!stralloc_0(&newsv)) goto err ; - r = dir_search(tmp.s,newsv.s,S_IFDIR) ; - if (r && !force) { - VERBO2 strerr_warni2x(newsv.s,": already added") ; - goto freed ; - } - else if (r < 0) - { - VERBO3 strerr_warnw3x("Conflicting format type for ",newsv.s," service file") ; - goto err ; - } - newsv.len = 0 ; - } - if (!stralloc_cats(&newsv,svname)) goto err ; - if (!stralloc_0(&newsv)) goto err ; + r = parse_service_check_enabled(info,svname,force,exist) ; + if (r == 2) goto freed ; + else if (!r) return 0 ; sv_alltype sv_before = SV_ALLTYPE_ZERO ; - insta = insta_check(newsv.s) ; + insta = instance_check(svname) ; if (!insta) { - VERBO3 strerr_warnw2x("invalid instance name: ",newsv.s) ; - goto err ; + VERBO3 strerr_warnw2x("invalid instance name: ",svname) ; + return 0 ; } if (insta > 0) { - - if (!insta_create(sasv,&newsv,svsrc,insta)) + if (!instance_create(sasv,svname,SS_INSTANCE,svsrc,insta)) { - VERBO3 strerr_warnwu2x("create instance service: ",newsv.s) ; - goto err ; + VERBO3 strerr_warnwu2x("create instance service: ",svname) ; + return 0 ; } - - }else if (!read_svfile(sasv,newsv.s,svsrc)) goto err ; + /** ensure that we have an empty line at the end of the string*/ + if (!stralloc_cats(sasv,"\n")) retstralloc(0,"parse_service_before") ; + if (!stralloc_0(sasv)) retstralloc(0,"parse_service_before") ; + }else if (!read_svfile(sasv,svname,svsrc)) return 0 ; memcpy(svpath,svsrc,svsrclen) ; - memcpy(svpath + svsrclen,newsv.s,newsv.len) ; + memcpy(svpath + svsrclen,svname,svnamelen) ; if (sastr_cmp(parsed_list,svpath) >= 0) { @@ -199,20 +177,19 @@ int parse_service_before(ssexec_t *info,stralloc *parsed_list, char const *sv,un sv_alltype_free(&sv_before) ; goto freed ; } + /** keep the name by default, + * it will be overwritten if user set + * the @name key into the frontend file */ + sv_before.cname.name = keep.len ; + if (!stralloc_catb(&keep,svname,svnamelen + 1)) return 0 ; - if (!parser(&sv_before,sasv,newsv.s)) goto err ; + if (!parser(&sv_before,sasv,svname)) return 0 ; - if (!parse_add_service(parsed_list,&sv_before,svpath,nbsv,info->owner)) goto err ; + if (!parse_add_service(parsed_list,&sv_before,svpath,nbsv,info->owner)) return 0 ; - if ((sv_before.cname.itype > CLASSIC && force > 1) || !exist) - if (!parse_service_deps(info,parsed_list,&sv_before,sv,nbsv,sasv,force)) goto err ; + if ((sv_before.cname.itype > CLASSIC && force > 1) || !(*exist)) + if (!parse_service_deps(info,parsed_list,&sv_before,sv,nbsv,sasv,force)) return 0 ; freed: - stralloc_free(&newsv) ; - stralloc_free(&tmp) ; return 1 ; - err: - stralloc_free(&newsv) ; - stralloc_free(&tmp) ; - return 0 ; } diff --git a/src/lib66/parser_utils.c b/src/lib66/parser_utils.c index a7fbd0ccac4bce62c003666742d9687a2b5c904d..a90f7050ad3c879324c2892baa5b79cb0043df87 100644 --- a/src/lib66/parser_utils.c +++ b/src/lib66/parser_utils.c @@ -17,6 +17,8 @@ #include <string.h> #include <unistd.h>//getuid #include <stdlib.h> +#include <stdint.h> +#include <sys/types.h> //#include <stdio.h> #include <oblibs/bytes.h> @@ -24,8 +26,9 @@ #include <oblibs/files.h> #include <oblibs/error2.h> #include <oblibs/types.h> -#include <oblibs/directory.h> -#include <oblibs/strakeyval.h> +#include <oblibs/mill.h> +#include <oblibs/environ.h> +#include <oblibs/sastr.h> #include <skalibs/sig.h> #include <skalibs/genalloc.h> @@ -38,16 +41,33 @@ #include <66/constants.h> #include <66/enum.h> #include <66/utils.h>//MYUID -#include <66/environ.h>//MYUID stralloc keep = STRALLOC_ZERO ;//sv_alltype data stralloc deps = STRALLOC_ZERO ;//sv_name depends genalloc gadeps = GENALLOC_ZERO ;//unsigned int, pos in deps genalloc gasv = GENALLOC_ZERO ;//sv_alltype general +/********************************** + * function helper declaration + * *******************************/ + +void section_setsa(int id, stralloc_ref *p,section_t *sa) ; +int section_get_skip(char const *s,size_t pos,int nline) ; +int section_get_id(stralloc *secname, char const *string,size_t *pos,int *id) ; +int key_get_next_id(stralloc *sa, char const *string,size_t *pos) ; +int get_clean_val(keynocheck *ch) ; +int get_clean_val(keynocheck *ch) ; +int get_enum(char const *string, keynocheck *ch) ; +int get_timeout(keynocheck *ch,uint32_t *ui) ; +int get_uint(keynocheck *ch,uint32_t *ui) ; +void parse_err(int ierr,keynocheck *check) ; +int parse_line(stralloc *sa, size_t *pos) ; +int parse_bracket(stralloc *sa,size_t *pos) ; + /********************************** * freed function * *******************************/ + void sv_alltype_free(sv_alltype *sv) { stralloc_free(&sv->saenv) ; @@ -78,227 +98,75 @@ void freed_parser(void) sv_alltype_free(&genalloc_s(sv_alltype,&gasv)[i]) ; } /********************************** - * parser utilities + * Mill utilities * *******************************/ -int parse_line(stralloc *src, size_t *pos) -{ - size_t newpos = 0 ; - stralloc kp = STRALLOC_ZERO ; - char const *file = "parse_line" ; - parse_mill_t line = { .open = '@', .close = '\n', \ - .skip = " \t\r", .skiplen = 3, \ - .end = "\n", .endlen = 1, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - stralloc_inserts(src,0,"@") ; - if (!parse_config(&line,file,src,&kp,&newpos)) goto err ; - if (!stralloc_0(&kp)) goto err ; - if (!clean_value(&kp)) goto err ; - if (!stralloc_copy(src,&kp)) goto err ; - *pos += newpos - 1 ; - stralloc_free(&kp) ; - return 1 ; - err: - stralloc_free(&kp) ; - return 0 ; -} + +parse_mill_t MILL_FIRST_BRACKET = \ +{ \ + .search = "(", .searchlen = 1, \ + .inner.debug = "first_bracket" } ; -int parse_quote(stralloc *src,size_t *pos) -{ - int r, err = 0 ; - size_t newpos = 0 ; - char const *file = "parse_quote" ; - stralloc kp = STRALLOC_ZERO ; - parse_mill_t quote = { .open = '"', .close = '"', \ - .skip = 0, .skiplen = 0, \ - .end = "\n", .endlen = 1, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 0, \ - .inner = PARSE_MILL_INNER_ZERO } ; +parse_mill_t MILL_GET_AROBASE_KEY = \ +{ \ + .open = '@', .close = '=', .keepopen = 1, \ + .forceclose = 1, .skip = " \t\r", .skiplen = 3, \ + .forceskip = 1, .inner.debug = "get_arobase_key" } ; - r = parse_config("e,file,src,&kp,&newpos) ; - if (!r) goto err ; - else if (r == -1) { err = -1 ; goto err ; } - if (!stralloc_0(&kp)) goto err ; - if (!stralloc_copy(src,&kp)) goto err ; - *pos += newpos - 1 ; - stralloc_free(&kp) ; - return 1 ; - err: - stralloc_free(&kp) ; - return err ; -} - -int parse_bracket(stralloc *src,size_t *pos) -{ - int err = -1 ; - size_t newpos = 0 ; - ssize_t id = -1, start = -1, end = -1 ; - char const *file = "parse_bracket" ; - stralloc kp = STRALLOC_ZERO ; - stralloc tmp = STRALLOC_ZERO ; - - parse_mill_t key = { .open = '@', .close = '=', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 1, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - - while (id < 0 && newpos < src->len) - { - kp.len = 0 ; - key.inner.nclose = 0 ; - key.inner.nopen = 0 ; - if (!parse_config(&key,file,src,&kp,&newpos)) goto err ; - if (!kp.len) break ;//end of string - if (!stralloc_0(&kp)) goto err ; - if (!clean_value(&kp)) goto err ; - if (!stralloc_inserts(&kp,0,"@")) goto err ; - id = get_enumbyid(kp.s,key_enum_el) ; - } - /** id is negative and we are at the end of string - * field can contain instance name with @ character - * in this case we keep the src as it */ - if (id < 0) - { - if (!stralloc_cats(&tmp,src->s)) goto err ; - }else if (!stralloc_catb(&tmp,src->s,(newpos - (kp.len+1)))) goto err ;//+1 remove the @ of the next key - if (!stralloc_0(&tmp)) goto err ; - kp.len = 0 ; - start = get_len_until(tmp.s,'(') ; - if (start < 0) { err = -1 ; goto err ; } - start++ ; - end = get_rlen_until(tmp.s,')',tmp.len) ; - if (end < 0) { err = -1 ; goto err ; } - if (!stralloc_catb(&kp,tmp.s+start,end-start)) goto err ; - if (!stralloc_0(&kp)) goto err ; - if (!stralloc_copy(src,&kp)) goto err ; - *pos += end + 1 ; //+1 to remove the last ')' - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - return 1 ; - err: - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - return err ; -} +parse_mill_t MILL_GET_COMMENTED_KEY = \ +{ \ + .search = "#", .searchlen = 1, \ + .end = "@", .endlen = 1, + .inner.debug = "get_commented_key" } ; -int parse_env(stralloc *src,size_t *pos) -{ - int r ; - size_t newpos = 0 ; - size_t base ; - stralloc kp = STRALLOC_ZERO ; - stralloc tmp = STRALLOC_ZERO ; - char const *file = "parse_env" ; - parse_mill_t line = { .open = '@', .close = '\n', \ - .skip = " \t\r", .skiplen = 3, \ - .end = "\n", .endlen = 1, \ - .jump = "#", .jumplen = 1,\ - .check = 0, .flush = 0, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; +parse_mill_t MILL_GET_SECTION_NAME = \ +{ \ + .open = '[', .close = ']', \ + .forceclose = 1, .forceskip = 1, \ + .skip = " \t\r", .skiplen = 3, \ + .inner.debug = "get_section_name" } ; - size_t blen = src->len, n = 0 ; - if (!stralloc_inserts(src,0,"@")) goto err ; - while(newpos < (blen+n)) - { - base = kp.len ; - line.inner.nopen = line.inner.nclose = 0 ; - r = parse_config(&line,file,src,&kp,&newpos) ; - if (!r) goto err ; - else if (r < 0){ kp.len = base ; goto append ; } - if (!stralloc_cats(&kp,"\n")) goto err ; - append: - if (!stralloc_inserts(src,newpos,"@")) goto err ; - n++; - } - if (!stralloc_0(&kp)) goto err ; - if (!stralloc_copy(src,&kp)) goto err ; - *pos += newpos - 1 ; - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - return 1 ; - err: - stralloc_free(&kp) ; - stralloc_free(&tmp) ; - return 0 ; -} - /********************************** * parser split function * *******************************/ -int get_section_range(section_t *sasection,stralloc *src) +int section_get_range(section_t *sasection,stralloc *src) { + if (!src->len) return 0 ; size_t pos = 0, start = 0 ; - int n = 0, id = -1, /*idc = 0,*/ skip = 0, err = 0 ; + int r, n = 0, id = -1, skip = 0 ; stralloc secname = STRALLOC_ZERO ; stralloc_ref psasection ; - parse_mill_t section = { .open = '[', .close = ']', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 1, \ - .forceskip = 0, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - while (pos < src->len) + stralloc cp = STRALLOC_ZERO ; + /** be clean */ + wild_zero_all(&MILL_GET_LINE) ; + wild_zero_all(&MILL_GET_SECTION_NAME) ; + r = mill_string(&cp,src,&MILL_GET_LINE) ; + if (r == -1 || !r) goto err ; + if (!sastr_rebuild_in_nline(&cp)) goto err ; + while (pos < cp.len) { if(secname.len && n) { - skip = section_skip(src->s,pos,section.inner.nline) ; + skip = section_get_skip(cp.s,pos,MILL_GET_SECTION_NAME.inner.nline) ; id = get_enumbyid(secname.s,key_enum_section_el) ; section_setsa(id,&psasection,sasection) ; if (skip) sasection->idx[id] = 1 ; } - secname.len = section.inner.nclose = section.inner.nopen = 0 ; - id = -1 ; - while (id < 0 && pos < src->len) - { - secname.len = section.inner.nclose = section.inner.nopen = 0 ; - if(!parse_config(§ion,sasection->file,src,&secname,&pos)) goto err ; - if (!secname.len) break ; //end of string - if (!stralloc_0(&secname)) goto err ; - id = get_enumbyid(secname.s,key_enum_section_el) ; - /*if (id < 0) - { - idc = section_valid(id,section.inner.nline,pos,src,sasection->file) ; - if (!idc) goto err ; - else if (idc < 0) goto invalid ; - }*/ - } + if (!section_get_id(&secname,cp.s,&pos,&id)) goto err ; + if (!secname.len && !n) goto err ; if (!n) { - skip = section_skip(src->s,pos,section.inner.nline) ; + skip = section_get_skip(cp.s,pos,MILL_GET_SECTION_NAME.inner.nline) ; section_setsa(id,&psasection,sasection) ; if (skip) sasection->idx[id] = 1 ; start = pos ; - id = -1 ; - while (id < 0 && pos < src->len) - { - section.inner.nclose = section.inner.nopen = secname.len = 0 ; - if (!parse_config(§ion,sasection->file,src,&secname,&pos)) goto err ; - if (!secname.len) break ; //end of string - if (!stralloc_0(&secname)) goto err ; - id = get_enumbyid(secname.s,key_enum_section_el) ; - /*if (id < 0) - { - idc = section_valid(id,section.inner.nline,pos,src,sasection->file) ; - if (!idc) goto err ; - else if (idc < 0) goto invalid ; - }*/ - } + + if (!section_get_id(&secname,cp.s,&pos,&id)) goto err ; if(skip) { - if (!stralloc_catb(psasection,src->s+start,(pos - start) - (secname.len + 2))) goto err ;//+2 to remove '[]'character + r = get_rlen_until(cp.s,'\n',pos-1) ;//-1 to retrieve the end of previous line + if (r == -1) goto err ; + if (!stralloc_catb(psasection,cp.s+start,(r-start))) goto err ; if (!stralloc_0(psasection)) goto err ; } n++ ; @@ -308,37 +176,36 @@ int get_section_range(section_t *sasection,stralloc *src) { if (skip) { - if (!stralloc_catb(psasection,src->s+start,(pos - start) - (secname.len + 1))) goto err ;//only -1 to remove '\n'character + /** end of file do not contain section, avoid to remove the len of it if in the case*/ + if (secname.len) + { + r = get_rlen_until(cp.s,'\n',pos-1) ;//-1 to retrieve the end of previous line + if (r == -1) goto err ; + if (!stralloc_catb(psasection,cp.s+start,(r - start))) goto err ; + } + else if (!stralloc_cats(psasection,cp.s+start)) goto err ; if (!stralloc_0(psasection)) goto err ; } start = pos ; } } stralloc_free(&secname) ; + stralloc_free(&cp) ; return 1 ; - /*invalid: - err = -1 ; - VERBO1 strerr_warnw2x("invalid section: ",secname.s) ; - */err: + err: stralloc_free(&secname) ; - return err ; + stralloc_free(&cp) ; + return 0 ; } -int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtype) +int key_get_range(genalloc *ga, section_t *sasection,int *svtype) { int r ; - size_t pos = 0 ; + size_t pos = 0, fakepos = 0 ; uint8_t found = 0 ; stralloc sakey = STRALLOC_ZERO ; stralloc_ref psasection ; key_all_t const *list = total_list ; - parse_mill_t key = { .open = '@', .close = '=', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = "#", .jumplen = 1,\ - .check = 0, .flush = 1, \ - .forceskip = 1, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; for (int i = 0 ; i < key_enum_section_el ; i++) { @@ -354,7 +221,10 @@ int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtyp nocheck.mandatory = OPTS ; section_setsa(i,&psasection,sasection) ; if (!stralloc_cats(&nocheck.val,psasection->s+1)) goto err ; - if (!parse_env(&nocheck.val,&pos)) { strerr_warnwu2x("parse section: ",get_keybyid(i)) ; goto err ; } + if (!environ_get_clean_env(&nocheck.val)) { VERBO3 strerr_warnwu2x("parse section: ",get_keybyid(i)) ; goto err ; } + if (!stralloc_cats(&nocheck.val,"\n") || + !stralloc_0(&nocheck.val)) goto err ; + nocheck.val.len-- ; if (!genalloc_append(keynocheck,ga,&nocheck)) goto err ; } else @@ -365,14 +235,16 @@ int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtyp while (pos < blen) { keynocheck nocheck = KEYNOCHECK_ZERO ; - key.inner.nopen = key.inner.nclose = sakey.len = 0 ; - r = parse_config(&key,file,psasection,&sakey,&pos) ; - if (!r) goto err ; + sakey.len = 0 ; + r = mill_element(&sakey,psasection->s,&MILL_GET_AROBASE_KEY,&pos) ; + if (r == -1) goto err ; + if (!r) break ; //end of string + fakepos = get_rlen_until(psasection->s,'\n',pos) ; + r = mill_element(&sakey,psasection->s,&MILL_GET_COMMENTED_KEY,&fakepos) ; + if (r == -1) goto err ; + if (r) continue ; if (!stralloc_cats(&nocheck.val,psasection->s+pos)) goto err ; if (!stralloc_0(&nocheck.val)) goto err ; - if (!sakey.len) break ;// end of string - stralloc_inserts(&sakey,0,"@") ; - stralloc_0(&sakey) ; for (int j = 0 ; j < total_list_el[i]; j++) { found = 0 ; @@ -386,27 +258,39 @@ int get_key_range(genalloc *ga, section_t *sasection,char const *file,int *svtyp switch(list[i].list[j].expected) { case QUOTE: - r = parse_quote(&nocheck.val,&pos) ; - if (r < 0) + if (!sastr_get_double_quote(&nocheck.val)) { - VERBO3 parse_err(6,nocheck.idsec,nocheck.idkey) ; + VERBO3 parse_err(6,&nocheck) ; goto err ; } - else if (!r) goto err ; + if (!stralloc_0(&nocheck.val)) goto err ; break ; case BRACKET: r = parse_bracket(&nocheck.val,&pos) ; if (r < 0) { - VERBO3 parse_err(6,nocheck.idsec,nocheck.idkey) ; + VERBO3 parse_err(6,&nocheck) ; + goto err ; + } + if (nocheck.val.len == 1) + { + VERBO3 parse_err(9,&nocheck) ; goto err ; } - else if (!r) goto err ; break ; case LINE: case UINT: case SLASH: - if (!parse_line(&nocheck.val,&pos)) goto err ; + if (!parse_line(&nocheck.val,&pos)) + { + VERBO3 parse_err(7,&nocheck) ; + goto err ; + } + if (nocheck.val.len == 1) + { + VERBO3 parse_err(9,&nocheck) ; + goto err ; + } if (!i && !j) (*svtype) = get_enumbyid(nocheck.val.s,key_enum_el) ; break ; default: @@ -645,47 +529,32 @@ int nocheck_toservice(keynocheck *nocheck,int svtype, sv_alltype *service) /********************************** * store * *******************************/ - int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) { - int r, nbline ; - unsigned int i ; - genalloc gatmp = GENALLOC_ZERO ; - stralloc satmp = STRALLOC_ZERO ; - r = i = 0 ; - + int r = 0 ; + size_t pos = 0, *chlen = &nocheck->val.len ; + char *chval = nocheck->val.s ; + switch(nocheck->idkey){ case TYPE: - r = get_enumbyid(nocheck->val.s,key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,TYPE) ; - return 0 ; - } + r = get_enum(chval,nocheck) ; + if (!r) return 0 ; service->cname.itype = r ; break ; case NAME: service->cname.name = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) retstralloc(0,"parse_common") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_common") ; break ; case DESCRIPTION: service->cname.description = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) retstralloc(0,"parse_common") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_common") ; break ; case OPTIONS: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - for (i = 0;i<genalloc_len(stralist,&gatmp);i++) + if (!get_clean_val(nocheck)) return 0 ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) { - r = get_enumbyid(gaistr(&gatmp,i),key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,OPTIONS) ; - return 0 ; - } + r = get_enum(chval + pos,nocheck) ; + if (!r) return 0 ; if (svtype == CLASSIC || svtype == LONGRUN) { if (r == LOGGER) @@ -696,22 +565,13 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) if (r == ENVIR) service->opts[2] = 1 ; } - break ; case FLAGS: - if (!clean_val(&gatmp,nocheck->val.s)) + if (!get_clean_val(nocheck)) return 0 ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - for (unsigned int i = 0;i<genalloc_len(stralist,&gatmp);i++) - { - r = get_enumbyid(gaistr(&gatmp,i),key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,FLAGS) ; - return 0 ; - } + r = get_enum(chval + pos,nocheck) ; + if (!r) return 0 ; if (r == DOWN) service->flags[0] = 1 ;/**0 means not enabled*/ if (r == NOSETSID) @@ -719,230 +579,117 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) } break ; case USER: - if (!clean_val(&gatmp,nocheck->val.s)) + if (!get_clean_val(nocheck)) return 0 ; { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - /** special case, we don't know which user want to use - * the service, we need a general name to allow all user - * the term "user" is took here to allow the current user*/ - if (stra_cmp(&gatmp,"user")) - { - stra_remove(&gatmp,"user") ; - for (i=0;i<genalloc_len(stralist,&gatmp);i++) + uid_t owner = MYUID ; + if (!owner) { - r = scan_uidlist(gaistr(&gatmp,i),(uid_t *)service->user) ; - if (!r) + if (sastr_find(&nocheck->val,"root") == -1) { - VERBO3 parse_err(0,nocheck->idsec,USER) ; + VERBO3 strerr_warnwu3x("use service: ",keep.s+service->cname.name," -- permission denied") ; return 0 ; } } - uid_t nb = service->user[0] ; - nb++ ; - service->user[0] = nb ; - service->user[nb] = MYUID ; - //search for root permissions - int e = 1 ; - for (int i =1; i < nb; i++) - if (!service->user[i]) e = 0 ; - if ((!MYUID) && (e)) + /** special case, we don't know which user want to use + * the service, we need a general name to allow all user + * the term "user" is took here to allow the current user*/ + ssize_t p = sastr_cmp(&nocheck->val,"user") ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) { - VERBO3 strerr_warnwu3x("use ",keep.s+service->cname.name," service: permission denied") ; - return 0 ; + if (pos == (size_t)p) continue ; + if (!scan_uidlist(chval + pos,(uid_t *)service->user)) + { + VERBO3 parse_err(0,nocheck) ; + return 0 ; + } } - break ; - } - else - if (MYUID > 0) - { - VERBO3 strerr_warnwu3x("use ",keep.s+service->cname.name," service: permission denied") ; - return 0 ; - } - else if (genalloc_len(stralist,&gatmp) > 1) - { - r = scan_uidlist(nocheck->val.s,(uid_t *)service->user) ; - if (!r) + uid_t nb = service->user[0] ; + if (p == -1 && owner) { - VERBO3 parse_err(0,nocheck->idsec,USER) ; - return 0 ; + int e = 0 ; + for (int i = 1; i < nb+1; i++) + if (service->user[i] == owner) e = 1 ; + + if (!e) + { + VERBO3 strerr_warnwu3x("use service: ",keep.s+service->cname.name," -- permission denied") ; + return 0 ; + } } - break ; - } - else - r = scan_uidlist("root",(uid_t *)service->user) ; - if (!r) - { - VERBO3 parse_err(0,nocheck->idsec,USER) ; - return 0 ; } break ; case HIERCOPY: - if (!clean_val(&gatmp,nocheck->val.s)) + if (!get_clean_val(nocheck)) return 0 ; { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - for (i = 0 ; i < genalloc_len(stralist,&gatmp) ; i++) - { - char *name = gaistr(&gatmp,i) ; - size_t namelen = gaistrlen(&gatmp,i) ; - service->hiercopy[i+1] = keep.len ; - if (!stralloc_catb(&keep,name,namelen + 1)) retstralloc(0,"parse_common:hiercopy") ; - service->hiercopy[0] = i+1 ; + unsigned int idx = 0 ; + for (;pos < *chlen; pos += strlen(chval + pos)+1) + { + char *name = chval + pos ; + size_t namelen = strlen(chval + pos) ; + service->hiercopy[idx+1] = keep.len ; + if (!stralloc_catb(&keep,name,namelen + 1)) retstralloc(0,"parse_common:hiercopy") ; + service->hiercopy[0] = ++idx ; + } } break ; case DEPENDS: - if (service->cname.itype == CLASSIC) - { - VERBO3 strerr_warnw3x("key : ",get_keybyid(nocheck->idkey)," : is not valid for type classic") ; - return 0 ; - } - else - if (service->cname.itype == BUNDLE) - { - VERBO3 strerr_warnw3x("key : ",get_keybyid(nocheck->idkey)," : is not valid for type bundle") ; - return 0 ; - } - if (!clean_val(&gatmp,nocheck->val.s)) + if ((service->cname.itype == CLASSIC) || (service->cname.itype == BUNDLE)) { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; + VERBO3 strerr_warnw4x("key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; return 0 ; } + if (!get_clean_val(nocheck)) return 0 ; service->cname.idga = genalloc_len(unsigned int,&gadeps) ; - for (i = 0;i<genalloc_len(stralist,&gatmp);i++) + for (;pos < *chlen; pos += strlen(chval + pos)+1) { if (!genalloc_append(unsigned int,&gadeps,&deps.len)) retstralloc(0,"parse_common") ; - if (!stralloc_catb(&deps,gaistr(&gatmp,i),gaistrlen(&gatmp,i) + 1)) retstralloc(0,"parse_common") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_common") ; service->cname.nga++ ; } break ; case CONTENTS: if (service->cname.itype != BUNDLE) { - VERBO3 strerr_warnw4x("key : ",get_keybyid(nocheck->idkey)," : is not valid for type ",get_keybyid(service->cname.itype)) ; - return 0 ; - } - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; + VERBO3 strerr_warnw4x("key: ",get_keybyid(nocheck->idkey),": is not valid for type ",get_keybyid(service->cname.itype)) ; return 0 ; } + if (!get_clean_val(nocheck)) return 0 ; service->cname.idga = genalloc_len(unsigned int,&gadeps) ; - for (i = 0;i<genalloc_len(stralist,&gatmp);i++) + for (;pos < *chlen; pos += strlen(chval + pos) + 1) { if (!genalloc_append(unsigned int,&gadeps,&deps.len)) retstralloc(0,"parse_common") ; - if (!stralloc_catb(&deps,gaistr(&gatmp,i),gaistrlen(&gatmp,i) + 1)) retstralloc(0,"parse_common") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_common") ; service->cname.nga++ ; } break ; - case NOTIFY: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - if (!scan_uint32(gastr(&gatmp))) - { - VERBO3 parse_err(3,nocheck->idsec,NOTIFY) ; - return 0 ; - } - if (!uint32_scan(gastr(&gatmp),&service->notification)) - { - VERBO3 parse_err(3,nocheck->idsec,NOTIFY) ; - return 0 ; - } - break ; case T_KILL: - r = scan_timeout(nocheck->val.s,(uint32_t *)service->timeout,0) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_KILL) ; - return 0 ; - } - break ; case T_FINISH: - r = scan_timeout(nocheck->val.s,(uint32_t *)service->timeout,1) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_FINISH) ; - return 0 ; - } - break ; case T_UP: - r = scan_timeout(nocheck->val.s,(uint32_t *)service->timeout,2) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_UP) ; - return 0 ; - } - break ; case T_DOWN: - r = scan_timeout(nocheck->val.s,(uint32_t *)service->timeout,3) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_DOWN) ; - return 0 ; - } + if (!get_timeout(nocheck,(uint32_t *)service->timeout)) return 0 ; break ; case DEATH: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - if (!scan_uint32(gastr(&gatmp))) + if (!get_uint(nocheck,&service->death)) return 0 ; + break ; + case NOTIFY: + if (!get_uint(nocheck,&service->notification)) return 0 ; + break ; + case ENVAL: + if (!environ_clean_nline(&nocheck->val)) { - VERBO3 parse_err(3,nocheck->idsec,DEATH) ; + VERBO3 strerr_warnwu2x("clean environment value: ",chval) ; return 0 ; } - if (!uint32_scan(gastr(&gatmp),&service->death)) + if (!stralloc_copy(&service->saenv,&nocheck->val)) { - VERBO3 parse_err(3,nocheck->idsec,DEATH) ; + VERBO3 strerr_warnwu2x("store environment value: ",chval) ; return 0 ; } break ; - case ENVAL: - nbline = get_nbline_ga(nocheck->val.s,nocheck->val.len,&gatmp) ; - for (i = 0;i < nbline;i++) - { - satmp.len = 0 ; - if (!stralloc_cats(&satmp,gaistr(&gatmp,i)) || - !stralloc_0(&satmp)) - { - VERBO3 strerr_warnwu2x("append environment value: ",gaistr(&gatmp,i)) ; - stralloc_free(&satmp) ; - return 0 ; - } - r = env_clean(&satmp) ; - if (r > 0) - { - if (!stralloc_cats(&service->saenv,satmp.s) || - !stralloc_cats(&service->saenv,"\n")) - { - VERBO3 strerr_warnwu2x("store environment value: ",gaistr(&gatmp,i)) ; - stralloc_free(&satmp) ; - return 0 ; - } - } - else if (!r) - { - VERBO3 strerr_warnwu2x("clean environment value: ",gaistr(&gatmp,i)) ; - stralloc_free(&satmp) ; - return 0 ; - } - } - break ; case SIGNAL: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - if (!sig0_scan(gastr(&gatmp), &service->signal)) + if (!sig0_scan(chval,&service->signal)) { - VERBO3 parse_err(3,nocheck->idsec,SIGNAL) ; + VERBO3 parse_err(3,nocheck) ; return 0 ; } break ; @@ -951,65 +698,55 @@ int keep_common(sv_alltype *service,keynocheck *nocheck,int svtype) return 0 ; } - genalloc_deepfree(stralist,&gatmp,stra_free) ; - stralloc_free(&satmp) ; return 1 ; } int keep_runfinish(sv_exec *exec,keynocheck *nocheck) { - int r ; + int r = 0 ; + size_t *chlen = &nocheck->val.len ; + char *chval = nocheck->val.s ; - genalloc gatmp = GENALLOC_ZERO ; - - switch(nocheck->idkey){ + switch(nocheck->idkey) + { case BUILD: - r = get_enumbyid(nocheck->val.s,key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,BUILD) ; - return 0 ; - } + r = get_enum(chval,nocheck) ; + if (!r) return 0 ; exec->build = r ; break ; case RUNAS: - r = scan_uid(nocheck->val.s,&exec->runas) ; + r = scan_uid(chval,&exec->runas) ; if (!r) { - VERBO3 parse_err(0,nocheck->idsec,RUNAS) ; + VERBO3 parse_err(0,nocheck) ; return 0 ; } break ; case SHEBANG: - r = dir_scan_absopath(nocheck->val.s) ; - if (r < 0) + if (chval[0] != '/') { - VERBO3 parse_err(4,nocheck->idsec,SHEBANG) ; + VERBO3 parse_err(4,nocheck) ; return 0 ; } exec->shebang = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) exitstralloc("parse_runfinish:stralloc:SHEBANG") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) exitstralloc("parse_runfinish:stralloc:SHEBANG") ; break ; case EXEC: exec->exec = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) exitstralloc("parse_runfinish:stralloc:EXEC") ; - + if (!stralloc_catb(&keep,chval,*chlen + 1)) exitstralloc("parse_runfinish:stralloc:EXEC") ; break ; default: VERBO3 strerr_warnw2x("unknown key: ",get_keybyid(nocheck->idkey)) ; return 0 ; - } - - genalloc_deepfree(stralist,&gatmp,stra_free) ; - + } return 1 ; } int keep_logger(sv_execlog *log,keynocheck *nocheck) { - int r, i ; - - genalloc gatmp = GENALLOC_ZERO ; + int r ; + size_t pos = 0, *chlen = &nocheck->val.len ; + char *chval = nocheck->val.s ; switch(nocheck->idkey){ case BUILD: @@ -1019,16 +756,12 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck) if (!keep_runfinish(&log->run,nocheck)) return 0 ; break ; case DEPENDS: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } + if (!get_clean_val(nocheck)) return 0 ; log->idga = genalloc_len(unsigned int,&gadeps) ; - for (i = 0;i<genalloc_len(stralist,&gatmp);i++) + for (;pos < *chlen; pos += strlen(chval + pos) + 1) { if (!genalloc_append(unsigned int,&gadeps,&deps.len)) retstralloc(0,"parse_logger") ; - if (!stralloc_catb(&deps,gaistr(&gatmp,i),gaistrlen(&gatmp,i) + 1)) retstralloc(0,"parse_logger") ; + if (!stralloc_catb(&deps,chval + pos,strlen(chval + pos) + 1)) retstralloc(0,"parse_logger") ; log->nga++ ; } break ; @@ -1039,64 +772,33 @@ int keep_logger(sv_execlog *log,keynocheck *nocheck) if (!keep_runfinish(&log->run,nocheck)) return 0 ; break ; case T_KILL: - r = scan_timeout(nocheck->val.s,(uint32_t *)log->timeout,0) ; - if (r < 0) parse_err(3,nocheck->idsec,T_KILL) ; - break ; case T_FINISH: - r = scan_timeout(nocheck->val.s,(uint32_t *)log->timeout,1) ; - if (r < 0) - { - VERBO3 parse_err(3,nocheck->idsec,T_FINISH) ; - return 0 ; - } + if (!get_timeout(nocheck,(uint32_t *)log->timeout)) return 0 ; break ; case DESTINATION: - r = dir_scan_absopath(nocheck->val.s) ; - if (r < 0) + if (chval[0] != '/') { - VERBO3 parse_err(4,nocheck->idsec,DESTINATION) ; + VERBO3 parse_err(4,nocheck) ; return 0 ; } log->destination = keep.len ; - if (!stralloc_catb(&keep,nocheck->val.s,nocheck->val.len + 1)) retstralloc(0,"parse_logger") ; + if (!stralloc_catb(&keep,chval,*chlen + 1)) retstralloc(0,"parse_logger") ; break ; case BACKUP: - if (!clean_val(&gatmp,nocheck->val.s)) - { - VERBO3 strerr_warnwu2x("parse file ",nocheck->val.s) ; - return 0 ; - } - if (!scan_uint32(gastr(&gatmp))) - { - VERBO3 parse_err(3,nocheck->idsec,BACKUP) ; - return 0 ; - } - uint_scan(gastr(&gatmp),&log->backup) ; + if (!get_uint(nocheck,&log->backup)) return 0 ; break ; case MAXSIZE: - if (!scan_uint32(nocheck->val.s)) - { - VERBO3 parse_err(3,nocheck->idsec,MAXSIZE) ; - return 0 ; - } - uint_scan(nocheck->val.s,&log->maxsize) ; + if (!get_uint(nocheck,&log->maxsize)) return 0 ; break ; case TIMESTP: - r = get_enumbyid (nocheck->val.s,key_enum_el) ; - if (r < 0) - { - VERBO3 parse_err(0,nocheck->idsec,TIMESTP) ; - return 0 ; - } + r = get_enum(chval,nocheck) ; + if (!r) return 0 ; log->timestamp = r ; break ; default: VERBO3 strerr_warnw2x("unknown key: ",get_keybyid(nocheck->idkey)) ; return 0 ; } - - genalloc_deepfree (stralist,&gatmp,stra_free) ; - return 1 ; } @@ -1132,20 +834,63 @@ int read_svfile(stralloc *sasv,char const *name,char const *src) return 0 ; } /** ensure that we have an empty line at the end of the string*/ - if (!stralloc_cats(sasv,"\n")) retstralloc(0,"parse_service_before") ; - if (!stralloc_0(sasv)) retstralloc(0,"parse_service_before") ; + if (!stralloc_cats(sasv,"\n")) retstralloc(0,"read_svfile") ; + if (!stralloc_0(sasv)) retstralloc(0,"read_svfile") ; return 1 ; } -ssize_t get_sep_before (char const *line, char const sepstart, char const sepend) +int add_pipe(sv_alltype *sv, stralloc *sa) { - size_t linend, linesep ; - linesep=get_len_until(line,sepstart) ; - linend=get_len_until(line,sepend) ; - if (linesep > linend) return -1 ; - if (!linend) return 0 ; - return linesep ; + char *prodname = keep.s+sv->cname.name ; + + stralloc tmp = STRALLOC_ZERO ; + + sv->pipeline = sa->len ; + if (!stralloc_cats(&tmp,SS_PIPE_NAME)) retstralloc(0,"add_pipe") ; + if (!stralloc_cats(&tmp,prodname)) retstralloc(0,"add_pipe") ; + if (!stralloc_0(&tmp)) retstralloc(0,"add_pipe") ; + + if (!stralloc_catb(sa,tmp.s,tmp.len+1)) retstralloc(0,"add_pipe") ; + + stralloc_free(&tmp) ; + + return 1 ; +} + +int parse_line(stralloc *sa, size_t *pos) +{ + if (!sa->len) return 0 ; + int r = 0 ; + size_t newpos = 0 ; + stralloc kp = STRALLOC_ZERO ; + wild_zero_all(&MILL_CLEAN_LINE) ; + r = mill_element(&kp,sa->s,&MILL_CLEAN_LINE,&newpos) ; + if (r == -1 || !r) goto err ; + if (!stralloc_0(&kp)) goto err ; + if (!stralloc_copy(sa,&kp)) goto err ; + *pos += newpos - 1 ; + stralloc_free(&kp) ; + return 1 ; + err: + stralloc_free(&kp) ; + return 0 ; +} + +int parse_bracket(stralloc *sa,size_t *pos) +{ + if (!sa->len) return 0 ; + size_t newpos = 0 ; + stralloc kp = STRALLOC_ZERO ; + if (!key_get_next_id(&kp,sa->s,&newpos)) goto err ; + if (!stralloc_0(&kp)) goto err ; + if (!stralloc_copy(sa,&kp)) goto err ; + *pos += newpos ; + stralloc_free(&kp) ; + return 1 ; + err: + stralloc_free(&kp) ; + return 0 ; } void section_setsa(int id, stralloc_ref *p,section_t *sa) @@ -1161,147 +906,161 @@ void section_setsa(int id, stralloc_ref *p,section_t *sa) } } -int section_skip(char const *s,size_t pos,int nline) +int section_get_skip(char const *s,size_t pos,int nline) { ssize_t r = -1 ; if (nline == 1) { - r = get_sep_before(s,'#','\n') ; + r = get_sep_before(s,'#','[') ; if (r >= 0) return 0 ; } r = get_rlen_until(s,'\n',pos) ; if (r >= 0) { - r = get_sep_before(s+r+1,'#','\n') ; + r = get_sep_before(s+r+1,'#','[') ; if (r >= 0) return 0 ; } return 1 ; } -/*@Return 1 on success - * @Return 0 on fail - * @Return -1 on invalid section */ -int section_valid(int id, uint32_t nline, size_t pos,stralloc *src, char const *file) +int section_get_id(stralloc *secname, char const *string,size_t *pos,int *id) { - int r, rn, found = 0, err = 0 ; - size_t tpos = 0 ; - stralloc tmp = STRALLOC_ZERO ; - stralloc fake = STRALLOC_ZERO ; - key_all_t const *list = total_list ; - parse_mill_t key = { .open = '@', .close = '=', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 0, \ - .forceskip = 1, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - - - /* keys like execute can contain '[]' regex character, - * check it and ignore the regex if it's the case*/ - r = get_rlen_until(src->s,'\n',pos) ; - /*we are on first line?*/ - if (r < 0 && nline > 1) goto err ; - else if (nline == 1) goto freed ; - r++; - rn = get_sep_before(src->s+r,'@','\n') ; - if (rn < 0) goto invalid ; - if (!stralloc_cats(&tmp,src->s+r)) goto err ; - if (!stralloc_0(&tmp)) goto err ; - if (!parse_config(&key,file,&tmp,&fake,&tpos)) goto err ; - if (!fake.len) goto err ; - stralloc_inserts(&fake,0,"@") ; - stralloc_0(&fake) ; - for (int i = 0 ; i < key_enum_section_el; i++) + size_t len = strlen(string) ; + size_t newpos = 0 ; + (*id) = -1 ; + + while ((*id) < 0 && (*pos) < len) { - for (int j = 0 ; j < total_list_el[i]; j++) + secname->len = 0 ; + newpos = 0 ; + if (mill_element(secname,string+(*pos),&MILL_GET_SECTION_NAME,&newpos) == -1) return 0 ; + if (secname->len) { - if (list[i].list[j].name && obstr_equal(fake.s,list[i].list[j].name)) - { found = 1 ; break ; } + if (!stralloc_0(secname)) return 0 ; + (*id) = get_enumbyid(secname->s,key_enum_section_el) ; } + (*pos) += newpos ; } - if (!found) goto invalid ; - freed: - stralloc_free(&tmp) ; - stralloc_free(&fake) ; - return 1 ; - invalid: - err = -1 ; - err: - stralloc_free(&tmp) ; - stralloc_free(&fake) ; - return err ; + return 1 ; } -int clean_value(stralloc *sa) +int key_get_next_id(stralloc *sa, char const *string,size_t *pos) { - size_t pos = 0 ; - char const *file = "clean_value" ; - stralloc tmp = STRALLOC_ZERO ; - parse_mill_t empty = { .open = '@', .close = ' ', \ - .skip = " \n\t\r", .skiplen = 4, \ - .end = 0, .endlen = 0, \ - .jump = 0, .jumplen = 0,\ - .check = 0, .flush = 0, \ - .forceskip = 1, .force = 1, \ - .inner = PARSE_MILL_INNER_ZERO } ; - if (!stralloc_inserts(sa,0,"@")) goto err ; - if (!stralloc_cats(sa," ")) goto err ; - if (!parse_config(&empty,file,sa,&tmp,&pos)) goto err ; - if (!stralloc_0(&tmp)) goto err ; - if (!stralloc_copy(sa,&tmp)) goto err ; - stralloc_free(&tmp) ; + if (!string) return 0 ; + int r = 0 ; + size_t newpos = 0, len = strlen(string) ; + stralloc kp = STRALLOC_ZERO ; + wild_zero_all(&MILL_GET_AROBASE_KEY) ; + wild_zero_all(&MILL_FIRST_BRACKET) ; + int id = -1 ; + r = mill_element(&kp,string,&MILL_FIRST_BRACKET,&newpos) ; + if (r == -1 || !r) goto err ; + *pos = newpos ; + while (id == -1 && newpos < len) + { + kp.len = 0 ; + r = mill_element(&kp,string,&MILL_GET_AROBASE_KEY,&newpos) ; + if (r == -1) goto err ; + if (!stralloc_0(&kp)) goto err ; + id = get_enumbyid(kp.s,key_enum_el) ; + } + newpos = get_rlen_until(string,')',newpos) ; + if (newpos == -1) goto err ; + stralloc_catb(sa,string+*pos,newpos - *pos) ; + *pos = newpos + 1 ; //+1 remove the last ')' + stralloc_free(&kp) ; return 1 ; err: - stralloc_free(&tmp) ; + stralloc_free(&kp) ; return 0 ; } -void parse_err(int ierr,int idsec,int idkey) +int get_clean_val(keynocheck *ch) { + if (!sastr_clean_element(&ch->val) || + !stralloc_0(&ch->val) || + !sastr_split_element_in_nline(&ch->val)) + { + VERBO3 parse_err(8,ch) ; + return 0 ; + } + return 1 ; +} + +int get_enum(char const *string, keynocheck *ch) +{ + int r = get_enumbyid(string,key_enum_el) ; + if (r == -1) + { + VERBO3 parse_err(0,ch) ; + return 0 ; + } + return r ; +} + +int get_timeout(keynocheck *ch,uint32_t *ui) +{ + int time = 0 ; + if (ch->idkey == T_KILL) time = 0 ; + else if (ch->idkey == T_FINISH) time = 1 ; + else if (ch->idkey == T_UP) time = 2 ; + else if (ch->idkey == T_DOWN) time = 3 ; + if (scan_timeout(ch->val.s,ui,time) == -1) + { + VERBO3 parse_err(3,ch) ; + return 0 ; + } + return 1 ; +} + +int get_uint(keynocheck *ch,uint32_t *ui) +{ + if (!uint32_scan(ch->val.s,ui)) + { + VERBO3 parse_err(3,ch) ; + return 0 ; + } + return 1 ; +} + +void parse_err(int ierr,keynocheck *check) +{ + int idsec = check->idsec ; + int idkey = check->idkey ; switch(ierr) { case 0: - strerr_warnw4x("invalid value for key: ",get_keybyid(idkey)," in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("invalid value for key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 1: - strerr_warnw4x("multiple definition of key: ",get_keybyid(idkey)," in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("multiple definition of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 2: - strerr_warnw4x("same value for key: ",get_keybyid(idkey)," in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("same value for key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; case 3: - strerr_warnw4x("key: ",get_keybyid(idkey)," must be an integrer value in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("key: ",get_keybyid(idkey),": must be an integrer value in section: ",get_keybyid(idsec)) ; break ; case 4: - strerr_warnw4x("key: ",get_keybyid(idkey)," must be an absolute path in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("key: ",get_keybyid(idkey),": must be an absolute path in section: ",get_keybyid(idsec)) ; break ; case 5: - strerr_warnw4x("key: ",get_keybyid(idkey)," must be set in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("key: ",get_keybyid(idkey),": must be set in section: ",get_keybyid(idsec)) ; break ; case 6: - strerr_warnw4x("invalid format of key: ",get_keybyid(idkey)," in section: ",get_keybyid(idsec)) ; + strerr_warnw4x("invalid format of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + break ; + case 7: + strerr_warnwu4x("parse key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + break ; + case 8: + strerr_warnwu4x("clean value of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; + break ; + case 9: + strerr_warnw4x("empty value of key: ",get_keybyid(idkey),": in section: ",get_keybyid(idsec)) ; break ; default: strerr_warnw1x("unknown parse_err number") ; break ; } } - -int add_pipe(sv_alltype *sv, stralloc *sa) -{ - char *prodname = keep.s+sv->cname.name ; - - stralloc tmp = STRALLOC_ZERO ; - - sv->pipeline = sa->len ; - if (!stralloc_cats(&tmp,SS_PIPE_NAME)) retstralloc(0,"add_pipe") ; - if (!stralloc_cats(&tmp,prodname)) retstralloc(0,"add_pipe") ; - if (!stralloc_0(&tmp)) retstralloc(0,"add_pipe") ; - - if (!stralloc_catb(sa,tmp.s,tmp.len+1)) retstralloc(0,"add_pipe") ; - - stralloc_free(&tmp) ; - - return 1 ; -} diff --git a/src/lib66/parser_write.c b/src/lib66/parser_write.c index 25f1f033af8cdc2afcd34e9cd35cf9d6c6475aa5..2426b4555830f8d6e889ee404c8eb756805fc30c 100644 --- a/src/lib66/parser_write.c +++ b/src/lib66/parser_write.c @@ -17,6 +17,7 @@ #include <string.h> #include <errno.h> #include <sys/stat.h> +#include <stdint.h> //#include <stdio.h> #include <oblibs/string.h> @@ -46,7 +47,7 @@ /** @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, unsigned int conf) +int write_services(ssexec_t *info,sv_alltype *sv, char const *workdir, uint8_t force, uint8_t conf) { int r ; @@ -158,7 +159,7 @@ 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,unsigned int conf) +int write_classic(sv_alltype *sv, char const *dst, uint8_t force,uint8_t conf) { /**notification,timeout, ...*/ if (!write_common(sv, dst, conf)) @@ -195,7 +196,7 @@ int write_classic(sv_alltype *sv, char const *dst, unsigned int force,unsigned i return 1 ; } -int write_longrun(sv_alltype *sv,char const *dst, unsigned int force, unsigned int conf) +int write_longrun(sv_alltype *sv,char const *dst, uint8_t force, uint8_t conf) { size_t r ; char *name = keep.s+sv->cname.name ; @@ -262,7 +263,7 @@ int write_longrun(sv_alltype *sv,char const *dst, unsigned int force, unsigned i return 1 ; } -int write_oneshot(sv_alltype *sv,char const *dst,unsigned int conf) +int write_oneshot(sv_alltype *sv,char const *dst,uint8_t conf) { if (!write_common(sv, dst,conf)) @@ -313,7 +314,7 @@ int write_bundle(sv_alltype *sv, char const *dst) return 1 ; } -int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *dst, int mode, unsigned int force) +int write_logger(sv_alltype *sv, sv_execlog *log,char const *name, char const *dst, int mode, uint8_t force) { int r ; int logbuild = log->run.build ; @@ -567,7 +568,7 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char memcpy(prodfile,proddst,proddstlen) ; prodfile[proddstlen] = 0 ; - char pipefile[consdstlen + consnamelen + 1 + 1] ; + char pipefile[consdstlen + 1 + consnamelen + 1 + 1] ; /**producer-for*/ if (!file_write_unsafe(consfile,get_keybyid(CONSUMER),prodname,strlen(prodname))) @@ -587,9 +588,11 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char size_t len = strlen(deps.s+sv->pipeline) ; char pipename[len + 1] ; memcpy(pipefile,consdst,consdstlen) ; - memcpy(pipefile + consdstlen, consname,consnamelen) ; - memcpy(pipefile + consdstlen + consnamelen, "/", 1) ; - pipefile[consdstlen + consnamelen + 1] = 0 ; + pipefile[consdstlen] = '/' ; + memcpy(pipefile + consdstlen + 1, consname,consnamelen) ; + pipefile[consdstlen + 1 + consnamelen] = '/' ; + pipefile[consdstlen + 1 + consnamelen + 1] = 0 ; + memcpy(pipename,deps.s+sv->pipeline,len) ; pipename[len] = 0 ; if (!file_write_unsafe(pipefile,PIPELINE_NAME,pipename,len)) @@ -602,7 +605,7 @@ int write_consprod(sv_alltype *sv,char const *prodname,char const *consname,char return 1 ; } -int write_common(sv_alltype *sv, char const *dst,unsigned int conf) +int write_common(sv_alltype *sv, char const *dst,uint8_t conf) { int r ; char *time = NULL ; @@ -758,7 +761,6 @@ int write_common(sv_alltype *sv, char const *dst,unsigned int conf) return 1 ; } - int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,int mode) { @@ -877,28 +879,12 @@ int write_exec(sv_alltype *sv, sv_exec *exec,char const *file,char const *dst,in int write_dependencies(unsigned int nga,unsigned int idga,char const *dst,char const *filename, genalloc *ga) { - int r ; - stralloc contents = STRALLOC_ZERO ; stralloc namedeps = STRALLOC_ZERO ; for (unsigned int i = 0; i < nga; i++) { if (!stralloc_obreplace(&namedeps,deps.s+genalloc_s(unsigned int,ga)[idga+i])) return 0 ; - r = insta_check(namedeps.s) ; - if (!r) - { - VERBO3 strerr_warnw2x(" invalid instance name: ",namedeps.s) ; - return 0 ; - } - if (r > 0) - { - if (!insta_splitname(&namedeps,namedeps.s,r,1)) - { - VERBO3 strerr_warnwu2x("split copy name of instance: ",namedeps.s) ; - return 0 ; - } - } if (!stralloc_cats(&contents,namedeps.s)) retstralloc(0,"write_dependencies") ; if (!stralloc_cats(&contents,"\n")) retstralloc(0,"write_dependencies") ; } diff --git a/src/lib66/resolve.c b/src/lib66/resolve.c index cc943043528107e3124e8e3622a837b7305e5b01..ce7e274a170415f27dc6a6b0825ce7b5d9872015 100644 --- a/src/lib66/resolve.c +++ b/src/lib66/resolve.c @@ -14,7 +14,9 @@ #include <string.h> #include <sys/stat.h> +#include <stdint.h> #include <stdlib.h>//realpath +#include <sys/types.h> //#include <stdio.h> #include <oblibs/types.h> @@ -175,8 +177,6 @@ int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,int *found stralloc subdir = STRALLOC_ZERO ; stralloc satmp = STRALLOC_ZERO ; - obr = insta = 0 ; - DIR *dir = opendir(src) ; if (!dir) { @@ -214,11 +214,11 @@ int ss_resolve_src(stralloc *sasrc, char const *name, char const *src,int *found obr = 0 ; insta = 0 ; obr = obstr_equal(name,d->d_name) ; - insta = insta_check(name) ; + insta = instance_check(name) ; if (insta > 0) { - if (!insta_splitname(&sainsta,name,insta,0)) goto errdir ; + if (!instance_splitname(&sainsta,name,insta,0)) goto errdir ; obr = obstr_equal(sainsta.s,d->d_name) ; } @@ -570,8 +570,6 @@ int ss_resolve_setlognwrite(ss_resolve_t *sv, char const *dst,ssexec_t *info) int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) { - int r ; - char ownerstr[UID_FMT] ; size_t ownerlen = uid_fmt(ownerstr,info->owner) ; ownerstr[ownerlen] = 0 ; @@ -656,20 +654,6 @@ int ss_resolve_setnwrite(sv_alltype *services, ssexec_t *info, char const *dst) for (unsigned int i = 0; i < res.ndeps; i++) { if (!stralloc_obreplace(&namedeps,deps.s+genalloc_s(unsigned int,&gadeps)[services->cname.idga+i])) goto err ; - r = insta_check(namedeps.s) ; - if (!r) - { - VERBO1 strerr_warnw2x(" invalid instance name: ",namedeps.s) ; - goto err ; - } - if (r > 0) - { - if (!insta_splitname(&namedeps,namedeps.s,r,1)) - { - VERBO1 strerr_warnwu2x("split copy name of instance: ",namedeps.s) ; - goto err ; - } - } namedeps.len--; if (!stralloc_catb(&final,namedeps.s,namedeps.len)) { VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } if (!stralloc_catb(&final," ",1)) {VERBO1 warnstralloc("ss_resolve_setnwrite") ; goto err ; } diff --git a/src/lib66/ssexec_enable.c b/src/lib66/ssexec_enable.c index f69384ba8a46882b3fe6c75d85c0aa92c7491118..354a3ca87ebcdf0f3ee7c6ac1be548cfef3fdd7d 100644 --- a/src/lib66/ssexec_enable.c +++ b/src/lib66/ssexec_enable.c @@ -13,8 +13,9 @@ */ #include <string.h> +#include <stdint.h> #include <errno.h> -//#include <stdio.h> +#include <stdio.h> #include <oblibs/obgetopt.h> #include <oblibs/error2.h> @@ -37,9 +38,9 @@ /** force == 1, only rewrite the service * force == 2, rewrite the service and it dependencies*/ -static unsigned int FORCE = 0 ; +static uint8_t FORCE = 0 ; /** rewrite configuration file */ -static unsigned int CONF = 0 ; +static uint8_t CONF = 0 ; static void cleanup(char const *dst) { @@ -55,13 +56,12 @@ static void check_identifier(char const *name) static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv) { - unsigned int exist = 0 ; + uint8_t exist = 0 ; stralloc sares = STRALLOC_ZERO ; stralloc sasv = STRALLOC_ZERO ; stralloc tmp = STRALLOC_ZERO ; ss_resolve_t res = RESOLVE_ZERO ; -// if (!parse_service_get_list(&tmp,list)) strerr_diefu1x(111,"get services list") ; -// if (!stralloc_copy(list,&tmp)) strerr_diefu1sys(111,"copy stralloc") ; + tmp.len = 0 ; size_t i = 0, len = list->len ; if (!ss_resolve_pointo(&sares,info,SS_NOTYPE,SS_RESOLVE_SRC)) strerr_diefu1sys(111,"set revolve pointer to source") ; @@ -74,7 +74,7 @@ static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv) size_t namelen = strlen(name) ; char svname[namelen + 1] ; if (!basename(svname,name)) strerr_diefu2sys(111,"get basename of: ", name) ; - if (ss_resolve_check(sares.s,svname)) + if (ss_resolve_check(sares.s,svname)) { if (!ss_resolve_read(&res,sares.s,svname)) strerr_diefu2sys(111,"read resolve file of: ",svname) ; if (res.disen) @@ -88,7 +88,7 @@ static void start_parser(stralloc *list,ssexec_t *info, unsigned int *nbsv) } } - if (!parse_service_before(info,&tmp,name,nbsv,&sasv,FORCE,exist)) + if (!parse_service_before(info,&tmp,name,nbsv,&sasv,FORCE,&exist)) strerr_diefu3x(111,"parse service file: ",svname,": or its dependencies") ; } stralloc_free(&sares) ;