Environment patch

This commit is contained in:
Alexey Khromov 2024-05-15 18:35:10 +03:00
parent db29b72ede
commit d010e16b15
3 changed files with 37 additions and 0 deletions

View File

@ -54,6 +54,9 @@ const char *BFERR[] = {
/* 27 */ "Unused entry"
};
/* Main environment on startup (copied) for external processes */
char ** mainenv;
static void deinit_opts(s_bforce_opts *opts);
/*
@ -253,9 +256,25 @@ int main(int argc, char *argv[], char *envp[])
int rc = 0;
int ch = 0;
opts.runmode = MODE_UNDEFINED;
int i = 0;
int argsz = 0;
memset(&opts, '\0', sizeof(s_bforce_opts));
// Copying environment
argsz = 4096;
//argsz = sysconf(_SC_ARG_MAX);
DEB((D_CONFIG, "Limits: %d\n",argsz));
mainenv = malloc(sizeof(mainenv)*argsz);
mainenv[0] = NULL;
i=0;
while (envp[i]) {
mainenv[i] = malloc(strlen(envp[i])+2);
strcpy(mainenv[i], envp[i]);
mainenv[i++] = NULL;
DEB((D_FREE, "Program ENV: %s\n", mainenv[(i-1)]));
}
// parsing
while( (ch=getopt(argc, argv, "hfI:p:n:l:a:u:oivC:S:dq")) != (int)-1 )
@ -488,6 +507,15 @@ default:
exit:
/* de-init sessenv */
i=0;
while(mainenv[i]) {
DEB((D_FREE, "De-init session ENV: %s\n", mainenv[(i)]));
free(mainenv[i]);
}
free(mainenv);
deinit_conf();
deinit_opts(&opts);

View File

@ -73,9 +73,16 @@ int exec_options_parse(char *str)
void exec_options_init(s_exec_options *eopt)
{
int i = 0;
memset(eopt, '\0', sizeof(s_exec_options));
eopt->umask = EXEC_DEFAULT_UMASK;
eopt->envp[0] = NULL;
while(mainenv[i]) {
log("EXEC: Added ENV variable: %s\n", mainenv[i]);
eopt->envp[i] = xmalloc(strlen(mainenv[i]) + 2);
sprintf(eopt->envp[i], mainenv[i++]);
eopt->envp[i] = NULL;
}
}
void exec_options_deinit(s_exec_options *eopt)

View File

@ -183,4 +183,6 @@ extern const char *BFERR[];
int daemon_run(const char *confname, const char *incname, bool quit);
extern char ** mainenv;
#endif