env init probe

master
Alexey Khromov 6 months ago
parent c2e418676b
commit 27b4c624b3

@ -20,6 +20,8 @@
#include "nodelist.h" #include "nodelist.h"
#include "session.h" #include "session.h"
char ** sessenv;
/* PID of our child process (if use fork) */ /* PID of our child process (if use fork) */
pid_t child_pid = 0; pid_t child_pid = 0;
@ -254,6 +256,10 @@ int main(int argc, char *argv[], char *envp[])
int ch = 0; int ch = 0;
opts.runmode = MODE_UNDEFINED; opts.runmode = MODE_UNDEFINED;
int i = 0;
int argsz = 0;
memset(&opts, '\0', sizeof(s_bforce_opts)); memset(&opts, '\0', sizeof(s_bforce_opts));
// parsing // parsing
@ -453,7 +459,7 @@ int main(int argc, char *argv[], char *envp[])
/* Reopen log file if it was defined in config */ /* Reopen log file if it was defined in config */
if( log_reopen(log_getfilename(LOG_FILE_SESSION), NULL, NULL) ) if( log_reopen(log_getfilename(LOG_FILE_SESSION), NULL, NULL) )
{ {
log("can't continue without logging"); DEB((D_CONFIG, "can't continue without logging"));
gotoexit(BFERR_FATALERROR); gotoexit(BFERR_FATALERROR);
} }
@ -461,6 +467,21 @@ int main(int argc, char *argv[], char *envp[])
//snprintf(runmode_str, 20, "Run mode: %d", opts.runmode); //snprintf(runmode_str, 20, "Run mode: %d", opts.runmode);
//log(runmode_str); //log(runmode_str);
/* Init environment table for childs */
argsz = 4096;
//argsz = sysconf(_SC_ARG_MAX);
DEB((D_CONFIG, "Limits: %d\n",argsz));
sessenv = malloc(sizeof(sessenv)*argsz);
sessenv[0] = NULL;
i=0;
while (envp[i]) {
sessenv[i] = malloc(strlen(envp[i])+2);
strcpy(sessenv[i], envp[i]);
sessenv[i++] = NULL;
DEB((D_FREE, "session ENV: %s\n", sessenv[(i-1)]));
}
switch( opts.runmode ) switch( opts.runmode )
{ {
case MODE_DAEMON: case MODE_DAEMON:
@ -488,6 +509,14 @@ default:
exit: exit:
/* de-init sessenv */
i=0;
while(sessenv[i]) {
DEB((D_FREE, "De-init session ENV: %s\n", sessenv[(i)]));
free(sessenv[i]);
}
free(sessenv);
deinit_conf(); deinit_conf();
deinit_opts(&opts); deinit_opts(&opts);

@ -82,10 +82,10 @@ void exec_options_init(s_exec_options *eopt)
eopt->umask = EXEC_DEFAULT_UMASK; eopt->umask = EXEC_DEFAULT_UMASK;
eopt->envp[0] = NULL; eopt->envp[0] = NULL;
while(environ[i]) { while(sessenv[i]) {
log("EXEC: Added ENV variable: %s\n", environ[i]); log("EXEC: Added ENV variable: %s\n", sessenv[i]);
eopt->envp[i] = xmalloc(strlen(environ[i]) + 2); eopt->envp[i] = xmalloc(strlen(sessenv[i]) + 2);
sprintf(eopt->envp[i], environ[i++]); sprintf(eopt->envp[i], sessenv[i++]);
eopt->envp[i] = NULL; eopt->envp[i] = NULL;
} }

@ -175,6 +175,9 @@ typedef struct {
#define MODE_ANSWER (5) #define MODE_ANSWER (5)
#define MODE_DAEMON (6) #define MODE_DAEMON (6)
/* Environment for use with external tools as default */
extern char ** sessenv;
/* /*
* Global variables * Global variables

Loading…
Cancel
Save