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

use parser from oblibs

parent 20c30065
No related branches found
No related tags found
No related merge requests found
...@@ -19,21 +19,21 @@ ...@@ -19,21 +19,21 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/reboot.h>
#include <oblibs/error2.h> #include <oblibs/error2.h>
#include <oblibs/files.h> #include <oblibs/files.h>
#include <oblibs/string.h> #include <oblibs/string.h>
#include <oblibs/obgetopt.h> #include <oblibs/obgetopt.h>
#include <oblibs/environ.h>
#include <oblibs/sastr.h>
#include <skalibs/buffer.h> #include <skalibs/buffer.h>
#include <skalibs/djbunix.h> #include <skalibs/djbunix.h>
#include <skalibs/diuint32.h>
#include <skalibs/genalloc.h>
#include <skalibs/stralloc.h> #include <skalibs/stralloc.h>
#include <skalibs/types.h> #include <skalibs/types.h>
#include <66/config.h> #include <66/config.h>
#include <66/environ.h>
#include <66/constants.h> #include <66/constants.h>
unsigned int VERBOSITY = 1 ; unsigned int VERBOSITY = 1 ;
...@@ -68,7 +68,7 @@ static void sulogin(char const *msg,char const *arg) ...@@ -68,7 +68,7 @@ static void sulogin(char const *msg,char const *arg)
fd_close(0) ; fd_close(0) ;
if (dup2(fdin,0) == -1) strerr_diefu1x(111,"duplicate stdin -- you are on your own") ; if (dup2(fdin,0) == -1) strerr_diefu1x(111,"duplicate stdin -- you are on your own") ;
fd_close(fdin) ; fd_close(fdin) ;
if (*msg) strerr_warnwu2sys(msg,arg) ; if (*msg) strerr_warnwu2x(msg,arg) ;
pid = child_spawn0(newarg[0],newarg,genv) ; pid = child_spawn0(newarg[0],newarg,genv) ;
if (waitpid_nointr(pid,&wstat, 0) < 0) if (waitpid_nointr(pid,&wstat, 0) < 0)
strerr_diefu1sys(111,"wait for sulogin -- you are on your own") ; strerr_diefu1sys(111,"wait for sulogin -- you are on your own") ;
...@@ -101,10 +101,9 @@ static void parse_conf(void) ...@@ -101,10 +101,9 @@ static void parse_conf(void)
static char const *valid[] = static char const *valid[] =
{ "VERBOSITY", "PATH", "LIVE", "TREE", "RCINIT", "UMASK", "RESCAN", 0 } ; { "VERBOSITY", "PATH", "LIVE", "TREE", "RCINIT", "UMASK", "RESCAN", 0 } ;
int r ; int r ;
unsigned int i = 0, j = 0 ; unsigned int j = 0 ;
stralloc src = STRALLOC_ZERO ; stralloc src = STRALLOC_ZERO ;
stralloc saconf = STRALLOC_ZERO ; stralloc val = STRALLOC_ZERO ;
genalloc gaconf = GENALLOC_ZERO ;
if (skel[0] != '/') sulogin("skeleton directory must be an aboslute path: ",skel) ; if (skel[0] != '/') sulogin("skeleton directory must be an aboslute path: ",skel) ;
size_t skelen = strlen(skel) ; size_t skelen = strlen(skel) ;
memcpy(confile,skel,skelen) ; memcpy(confile,skel,skelen) ;
...@@ -114,51 +113,44 @@ static void parse_conf(void) ...@@ -114,51 +113,44 @@ static void parse_conf(void)
size_t filesize=file_get_size(confile) ; size_t filesize=file_get_size(confile) ;
r = openreadfileclose(confile,&src,filesize) ; r = openreadfileclose(confile,&src,filesize) ;
if(!r) sulogin("open configuration file: ",confile) ; 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) ; for (char const *const *p = valid;*p;p++,j++)
if (!r) sulogin("parse configuration file: ",confile) ;
for (;i < genalloc_len(diuint32,&gaconf) ; i++)
{ {
char *key = saconf.s + genalloc_s(diuint32,&gaconf)[i].left ; if (!stralloc_copy(&val,&src)) sulogin("copy stralloc of file: ",confile) ;
char *val = saconf.s + genalloc_s(diuint32,&gaconf)[i].right ; if (!environ_get_val_of_key(&val,*p)) continue ;
j = 0 ; sastr_clean_element(&val) ;
for (char const *const *p = valid;*p;p++,j++) if (!val.len) strerr_warnwu3x("get value of: ",*p," -- keeps the default") ;
switch (j)
{ {
if (!strcmp(*p,key)) case 0: if (!uint0_scan(val.s, &VERBOSITY)) sulogin("parse VERBOSITY value: ",val.s) ;
{ break ;
switch (j) case 1: memcpy(tpath,val.s,val.len) ;
{ tpath[val.len] = 0 ;
case 0: if (!uint0_scan(val, &VERBOSITY)) sulogin("invalid VERBOSITY value: ","") ; path = tpath ;
break ; break ;
case 1: memcpy(tpath,val,strlen(val)) ; case 2: memcpy(tlive,val.s,val.len) ;
tpath[strlen(val)] = 0 ; tlive[val.len] = 0 ;
path = tpath ; live = tlive ;
break ; if (live[0] != '/') sulogin ("LIVE must be an absolute path: ",val.s) ;
case 2: memcpy(tlive,val,strlen(val)) ; break ;
tlive[strlen(val)] = 0 ; case 3: memcpy(ttree,val.s,val.len) ;
live = tlive ; ttree[val.len] = 0 ;
if (live[0] != '/') sulogin ("LIVE must be an absolute path","") ; tree = ttree ;
break ; break ;
case 3: memcpy(ttree,val,strlen(val)) ; case 4: memcpy(trcinit,val.s,val.len) ;
ttree[strlen(val)] = 0 ; trcinit[val.len] = 0 ;
tree = ttree ; rcinit = trcinit ;
break ; if (rcinit[0] != '/') sulogin ("RCINIT must be an absolute path: ",val.s) ;
case 4: memcpy(trcinit,val,strlen(val)) ; break ;
trcinit[strlen(val)] = 0 ; case 5: if (!uint0_oscan(val.s, &mask)) sulogin("invalid MASK value: ",val.s) ; break ;
rcinit = trcinit ; case 6: if (!uint0_scan(val.s, &rescan)) sulogin("invalid RESCAN value: ",val.s) ; break ;
if (rcinit[0] != '/') sulogin ("RCINIT must be an absolute path","") ; default: break ;
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 ;
}
}
} }
} }
genalloc_free(diuint32,&gaconf) ; stralloc_free(&val) ;
stralloc_free(&saconf) ;
stralloc_free(&src) ; stralloc_free(&src) ;
} }
...@@ -330,8 +322,10 @@ int main(int argc, char const *const *argv,char const *const *envp) ...@@ -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) ; make_cmdline(SS_EXTBINPREFIX "66-init",t,3,"initiate earlier service of tree: ",tree,envp) ;
} }
if (envdir) if (envdir) {
if (!env_get_from_src(&envmodifs,envdir)) sulogin("get environment from: ",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") ; 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) ...@@ -360,6 +354,7 @@ int main(int argc, char const *const *argv,char const *const *envp)
pid = fork() ; pid = fork() ;
if (pid == -1) sulogin("fork: ",rcinit) ; if (pid == -1) sulogin("fork: ",rcinit) ;
if (!pid) run_stage2(newenvp, 2, envmodifs.s,envmodifs.len) ; 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","") ; if (fd_copy(2, 1) == -1) sulogin("copy stderr to stdout","") ;
fd_close(fdin) ; fd_close(fdin) ;
xpathexec_r(newargv, newenvp, 2, envmodifs.s, envmodifs.len) ; xpathexec_r(newargv, newenvp, 2, envmodifs.s, envmodifs.len) ;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <oblibs/types.h> #include <oblibs/types.h>
#include <oblibs/files.h> #include <oblibs/files.h>
#include <oblibs/string.h> #include <oblibs/string.h>
#include <oblibs/environ.h>
#include <skalibs/buffer.h> #include <skalibs/buffer.h>
#include <skalibs/stralloc.h> #include <skalibs/stralloc.h>
...@@ -549,7 +550,7 @@ int main(int argc, char const *const *argv, char const *const *envp) ...@@ -549,7 +550,7 @@ int main(int argc, char const *const *argv, char const *const *envp)
if (envdir.s[0] != '/') if (envdir.s[0] != '/')
strerr_dief3x(110,"environment: ",envdir.s," must be an absolute path") ; 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 ; genv = newenv ;
} }
else genv = envp ; else genv = envp ;
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include <stdio.h> #include <stdio.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <oblibs/environ.h>
#include <skalibs/posixplz.h> #include <skalibs/posixplz.h>
#include <skalibs/uint32.h> #include <skalibs/uint32.h>
#include <skalibs/types.h> #include <skalibs/types.h>
...@@ -40,7 +42,6 @@ ...@@ -40,7 +42,6 @@
#include <skalibs/djbunix.h> #include <skalibs/djbunix.h>
#include <skalibs/iopause.h> #include <skalibs/iopause.h>
#include <skalibs/skamisc.h> #include <skalibs/skamisc.h>
#include <skalibs/diuint32.h>
#include <execline/config.h> #include <execline/config.h>
...@@ -48,7 +49,6 @@ ...@@ -48,7 +49,6 @@
#include <66/config.h> #include <66/config.h>
#include <66/constants.h> #include <66/constants.h>
#include <66/environ.h>
#define STAGE4_FILE "stage4" #define STAGE4_FILE "stage4"
#define DOTPREFIX ".66-shutdownd:" #define DOTPREFIX ".66-shutdownd:"
...@@ -107,29 +107,16 @@ ssize_t file_get_size(const char* filename) ...@@ -107,29 +107,16 @@ ssize_t file_get_size(const char* filename)
static void parse_conf(char const *confile,char *rcshut,size_t filesize) static void parse_conf(char const *confile,char *rcshut,size_t filesize)
{ {
int r ; int r ;
unsigned int i = 0 ;
stralloc src = STRALLOC_ZERO ; stralloc src = STRALLOC_ZERO ;
stralloc saconf = STRALLOC_ZERO ;
genalloc gaconf = GENALLOC_ZERO ;
r = openreadfileclose(confile,&src,filesize) ; r = openreadfileclose(confile,&src,filesize) ;
if(!r) strerr_diefu2sys(111,"open configuration file: ",confile) ; if(!r) strerr_diefu2sys(111,"open configuration file: ",confile) ;
if (!stralloc_0(&src)) strerr_diefu1sys(111,"append stralloc configuration file") ; if (!stralloc_0(&src)) strerr_diefu1sys(111,"append stralloc configuration file") ;
r = env_split(&gaconf,&saconf,&src) ; if (environ_get_val_of_key(&src,"RCSHUTDOWN"))
if (!r) strerr_diefu2sys(111,"parse configuration file: ",confile) ;
for (;i < genalloc_len(diuint32,&gaconf) ; i++)
{ {
char *key = saconf.s + genalloc_s(diuint32,&gaconf)[i].left ; memcpy(rcshut,src.s,src.len) ;
char *val = saconf.s + genalloc_s(diuint32,&gaconf)[i].right ; rcshut[src.len] = 0 ;
if (!strcmp(key,"RCSHUTDOWN"))
{
memcpy(rcshut,val,strlen(val)) ;
rcshut[strlen(val)] = 0 ;
}
} }
genalloc_free(diuint32,&gaconf) ;
stralloc_free(&saconf) ;
stralloc_free(&src) ; stralloc_free(&src) ;
} }
......
${LIB66} ${LIB66}
-lexecline ${LIBEXECLINE}
-loblibs -loblibs
-lexecline
-lskarnet -lskarnet
${LIBEXECLINE}
${LIB66} ${LIB66}
-lexecline
-loblibs -loblibs
-lexecline
-lskarnet -lskarnet
${LIBEXECLINE} ${LIBEXECLINE}
...@@ -21,28 +21,20 @@ ...@@ -21,28 +21,20 @@
#include <oblibs/stralist.h> #include <oblibs/stralist.h>
#include <oblibs/error2.h> #include <oblibs/error2.h>
#include <oblibs/types.h> #include <oblibs/types.h>
#include <oblibs/obgetopt.h>
#include <oblibs/directory.h> #include <oblibs/directory.h>
#include <oblibs/files.h> #include <oblibs/files.h>
#include <oblibs/environ.h>
#include <oblibs/sastr.h>
#include <skalibs/bytestr.h> #include <skalibs/bytestr.h>
#include <skalibs/stralloc.h> #include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/env.h> #include <skalibs/env.h>
#include <skalibs/djbunix.h> #include <skalibs/djbunix.h>
#include <skalibs/diuint32.h>
#include <skalibs/env.h> #include <skalibs/env.h>
#include <skalibs/sgetopt.h> #include <skalibs/sgetopt.h>
#include <execline/execline.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" #define USAGE "execl-envfile [ -h help ] [ -l ] src prog"
static inline void info_help (void) static inline void info_help (void)
...@@ -60,43 +52,36 @@ static inline void info_help (void) ...@@ -60,43 +52,36 @@ static inline void info_help (void)
strerr_diefu1sys(111, "write to stdout") ; 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 ; if (!environ_clean_envfile(modifs,src)) strerr_diefu2sys(111,"prepare modified environment of: ",src->s) ;
for (;i < len; i += strlen(sa->s + i) + 1) if (!sastr_split_string_in_nline(modifs)) strerr_diefu2sys(111,"build environment line of: ",src->s) ; ;
if (!strcmp(sa->s+i,search)) return 1 ; if (!stralloc_cats(dst,src->s)) exitstralloc("clean_n_unexport") ;
return 0 ;
} }
int main (int argc, char const *const *argv, char const *const *envp) int main (int argc, char const *const *argv, char const *const *envp)
{ {
int r, i, unexport ; int r = 0, unexport = 0, insist = 1, nfile = 0, nvar = 0 ;
int insist = 1 ; size_t pos = 0, pathlen = 0 ;
size_t pathlen ; char const *path = 0, *file = 0 ;
char const *path = 0 ; char tpath[MAXENV + 1], tfile[MAXENV+1] ;
char const *file = 0 ;
char tpath[MAXENV + 1] ;
char tfile[MAXENV+1] ;
stralloc src = STRALLOC_ZERO ; stralloc src = STRALLOC_ZERO ;
stralloc modifs = STRALLOC_ZERO ; stralloc modifs = STRALLOC_ZERO ;
stralloc dst = 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 ; exlsn_t info = EXLSN_ZERO ;
r = i = unexport = 0 ;
insist = 1 ;
PROG = "execl-envfile" ; PROG = "execl-envfile" ;
{ {
subgetopt_t l = SUBGETOPT_ZERO ; subgetopt_t l = SUBGETOPT_ZERO ;
for (;;) for (;;)
{ {
int opt = subgetopt_r(argc,argv, ">hlf:", &l) ; int opt = subgetopt_r(argc,argv, "hlf:", &l) ;
if (opt == -1) break ; if (opt == -1) break ;
if (opt == -2) strerr_dief1x(110,"options must be set first") ;
switch (opt) switch (opt)
{ {
case 'h' : info_help(); return 0 ; case 'h' : info_help(); return 0 ;
...@@ -107,7 +92,6 @@ int main (int argc, char const *const *argv, char const *const *envp) ...@@ -107,7 +92,6 @@ int main (int argc, char const *const *argv, char const *const *envp)
} }
argc -= l.ind ; argv += l.ind ; argc -= l.ind ; argv += l.ind ;
} }
if (argc < 2) exitusage(USAGE) ; if (argc < 2) exitusage(USAGE) ;
path = *argv ; path = *argv ;
...@@ -123,11 +107,11 @@ int main (int argc, char const *const *argv, char const *const *envp) ...@@ -123,11 +107,11 @@ int main (int argc, char const *const *argv, char const *const *envp)
else else
{ {
r = scan_mode(path,S_IFREG) ; r = scan_mode(path,S_IFREG) ;
if (!r) strerr_diefu2sys(111,"find: ",path) ; if (!r && insist) strerr_diefu2sys(111,"find: ",path) ;
if (r < 0) if (r < 0)
{ {
r = scan_mode(path,S_IFDIR) ; 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 (r < 0) strerr_dief2x(111,"invalid format of: ", path) ;
if (path[0] == '.') if (path[0] == '.')
{ {
...@@ -152,16 +136,15 @@ int main (int argc, char const *const *argv, char const *const *envp) ...@@ -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) ; 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) ; xpathexec_run(argv[0],argv,envp) ;
} }
if (file) if (file)
{ {
r = stra_findidx(&toparse,file) ; ssize_t r = sastr_cmp(&toparse,file) ;
if (r < 0) if (r < 0)
{ {
if (insist) strerr_diefu2x(111,"find: ",file) ; if (insist) strerr_diefu2x(111,"find: ",file) ;
...@@ -170,27 +153,23 @@ int main (int argc, char const *const *argv, char const *const *envp) ...@@ -170,27 +153,23 @@ int main (int argc, char const *const *argv, char const *const *envp)
xpathexec_run(argv[0],argv,envp) ; xpathexec_run(argv[0],argv,envp) ;
} }
} }
if (!file_readputsa(&src,path,file)) strerr_diefu4sys(111,"read file: ",path,"/",file) ; 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) ; clean_n_unexport(&modifs,&dst,&src) ;
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) ;
} }
else else
{ {
for (i = 0 ; i < genalloc_len(stralist,&toparse) ; i++) for (;pos < toparse.len; pos += strlen(toparse.s + pos) + 1)
{ {
nfile++;
src.len = 0 ; src.len = 0 ;
size_t n = genalloc_len(diuint32,&GAENV) + MAXVAR ; if (nfile > MAXFILE) strerr_dief2x(111,"to many file to parse in: ",path) ;
if (i > 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) ;
if (!file_readputsa(&src,path,gaistr(&toparse,i))) strerr_diefu4sys(111,"read file: ",path,"/",gaistr(&toparse,i)) ; clean_n_unexport(&modifs,&dst,&src) ;
if (!env_parsenclean(&modifs,&src)) strerr_diefu4x(111,"parse and clean environment of: ",path,"/",gaistr(&toparse,i)) ; nvar = environ_get_num_of_line(&src) ;
if (!env_split(&GAENV,&SAENV,&src)) strerr_diefu4x(111,"split environment of: ",path,"/",gaistr(&toparse,i)) ; if (nvar == -1) strerr_diefu4sys(111,"get number of line of:",path,"/",toparse.s+pos) ;
if (genalloc_len(diuint32,&GAENV) > n) strerr_dief4x(111,"to many variables in file: ",path,"/",gaistr(&toparse,i)) ; if (nvar > MAXVAR) strerr_dief4x(111,"to many variables in file: ",path,"/",toparse.s+pos) ;
} }
} }
genalloc_deepfree(stralist,&toparse,stra_free) ;
stralloc_free(&src) ; stralloc_free(&src) ;
/** be able to freed the stralloc before existing */ /** be able to freed the stralloc before existing */
...@@ -203,35 +182,45 @@ int main (int argc, char const *const *argv, char const *const *envp) ...@@ -203,35 +182,45 @@ int main (int argc, char const *const *argv, char const *const *envp)
char const *newenv[n + 1] ; char const *newenv[n + 1] ;
if (!env_merge (newenv, n ,envp,env_len(envp),tmp, modifs.len)) strerr_diefu1sys(111,"build environment") ; 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++) if (!sastr_split_string_in_nline(&dst)) strerr_diefu1x(111,"split line") ;
{ pos = 0 ;
unexport = 0 ; while (pos < dst.len)
int key = genalloc_s(diuint32,&GAENV)[i].left ; {
int val = genalloc_s(diuint32,&GAENV)[i].right ; unexport = 0 ;
if ((SAENV.s+val)[0] == SS_VAR_UNEXPORT) key.len = val.len = 0 ;
{ if (!stralloc_copy(&key,&dst) ||
val++ ; !stralloc_copy(&val,&dst)) retstralloc(111,"main") ;
unexport = 1 ;
} if (!environ_get_key_nclean(&key,&pos)) strerr_diefu2x(111,"get key from line: ",key.s) ;
if(!loop_stra(&info.vars,SAENV.s + key)) pos-- ;// retrieve the '=' character
if (!env_substitute(SAENV.s + key,SAENV.s + val,&info,newenv,unexport)) if (!environ_get_val(&val,&pos)) strerr_diefu2x(111,"get value from line: ",val.s) ;
strerr_diefu4x(111,"substitute value of: ",SAENV.s + key," by: ",SAENV.s + val) ;
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(&key) ;
stralloc_free(&SAENV) ; 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") ; 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, 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)) ; genalloc_s (elsubst_t const, &info.data),genalloc_len (elsubst_t const, &info.data)) ;
if (r < 0) strerr_diefu1sys(111,"el_substitute") ; if (r < 0) strerr_diefu1sys(111,"el_substitute") ;
else if (!r) _exit(0) ; else if (!r) _exit(0) ;
stralloc_free(&modifs) ; stralloc_free(&modifs) ;
char const *v[r + 1] ; char const *v[r + 1] ;
if (!env_make (v, r ,dst.s, dst.len)) strerr_diefu1sys(111,"make environment") ; if (!env_make (v, r ,dst.s, dst.len)) strerr_diefu1sys(111,"make environment") ;
v[r] = 0 ; v[r] = 0 ;
pathexec_r (v, newenv, env_len(newenv),info.modifs.s,info.modifs.len) ; pathexec_r (v, newenv, env_len(newenv),info.modifs.s,info.modifs.len) ;
} }
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
#include <oblibs/error2.h> #include <oblibs/error2.h>
#include <oblibs/environ.h>
#include <skalibs/types.h> #include <skalibs/types.h>
#include <skalibs/buffer.h> #include <skalibs/buffer.h>
...@@ -83,8 +85,8 @@ int main (int argc, char const **argv, char const *const *envp) ...@@ -83,8 +85,8 @@ int main (int argc, char const **argv, char const *const *envp)
cuid[uid_fmt(cuid,uid)] = 0 ; cuid[uid_fmt(cuid,uid)] = 0 ;
cgid[gid_fmt(cgid,gid)] = 0 ; cgid[gid_fmt(cgid,gid)] = 0 ;
if (!env_addkv("UID",cuid,&info)) strerr_diefu1sys(111,"set UID") ; if (!environ_add_key_val("UID",cuid,&info)) strerr_diefu1sys(111,"set UID") ;
if (!env_addkv("GID",cgid,&info)) strerr_diefu1sys(111,"set GID") ; 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") ; if (!env_string(&sa,argv,(unsigned int) argc)) strerr_diefu1sys(111,"environment string") ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment