Compare commits

...

8 Commits

7 changed files with 48 additions and 6 deletions

View File

@ -1 +1 @@
0.24.1
0.24.2

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;
//fprintf(stderr,"BF-DEBUG: 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,14 @@ default:
exit:
/* de-init sessenv */
i=0;
while(mainenv[i]) {
DEB((D_FREE, "De-init session ENV: %s\n", mainenv[(i)]));
free(mainenv[i++]);
}
deinit_conf();
deinit_opts(&opts);

View File

@ -170,7 +170,7 @@ int conf_readconf(const char *confname, int inclevel, bool earlydbg)
{
if (earlydbg)
fprintf(stderr,"BF-DEBUG: can't open config file \"%s\"\n", confname);
return(PROC_RC_IGNORE);
return(PROC_RC_ABORT);
}
if (earlydbg)
fprintf(stderr,"BF-DEBUG: start reading config \"%s\"\n", confname);

View File

@ -26,6 +26,7 @@ static char log_name[BF_MAXPATH+1] = BFORCE_LOGFILE;
static char log_extension[32] = "";
static char log_ident[32] = "";
static char log_ttyname[32] = "";
static int log_sl_opened = FALSE;
#ifdef DEBUG
/*
@ -291,7 +292,7 @@ const char *log_getfilename(int whatfor)
bool log_isopened(void)
{
return TRUE;
return log_sl_opened;
}
int log_open(const char *logname, const char *ext, const char *tty)
@ -299,14 +300,17 @@ int log_open(const char *logname, const char *ext, const char *tty)
char *p = "bforce";
int fac = conf_number(cf_syslog_facility);
if( tty && *tty )
strncpy(p, tty, sizeof(p));
strncpy(tty, p, sizeof(p));
openlog(p, LOG_PID, fac);
log_sl_opened = TRUE;
return 0;
}
int log_reopen(const char *logname, const char *ext, const char *tty)
{
return 0;
if (!log_sl_opened) {
return log_open(logname, ext, tty);
} else return 0;
}
int log_close(void)

View File

@ -73,9 +73,17 @@ 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;
i = 0;
while(mainenv[i]) {
DEB((D_FREE, "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)
@ -101,6 +109,7 @@ void exec_env_add(s_exec_options *eopt, const char *name, const char *value)
{
eopt->envp[i] = xmalloc(strlen(name) + strlen(value) + 2);
sprintf(eopt->envp[i], "%s=%s", name, value);
DEB((D_FREE, "EXEC: Added ENV variable: %s=%s\n", name, value));
eopt->envp[i+1] = NULL;
}
}

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

View File

@ -19,7 +19,7 @@
#define EXEC_OPT_LOGOUT 0x04
#define EXEC_OPT_USESHELL 0x08
#define EXEC_MAX_NUM_ENVS 40
#define EXEC_MAX_NUM_ENVS 4096
#define EXEC_MAX_NUM_ARGS 20
#define EXEC_DEFAULT_UMASK ~(S_IRUSR|S_IWUSR);