From db29b72ede1cfca757905de90c65be35c3a2b2ec Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Wed, 15 May 2024 18:34:40 +0300 Subject: [PATCH 1/7] Critical error on config file or include missing --- source/bforce/conf_read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/bforce/conf_read.c b/source/bforce/conf_read.c index 0543abb..68a6075 100644 --- a/source/bforce/conf_read.c +++ b/source/bforce/conf_read.c @@ -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); From d010e16b1592b82a86b0716af166c97cceb37d36 Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Wed, 15 May 2024 18:35:10 +0300 Subject: [PATCH 2/7] Environment patch --- source/bforce/bforce.c | 28 ++++++++++++++++++++++++++++ source/bforce/os_unix.c | 7 +++++++ source/include/bforce.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/source/bforce/bforce.c b/source/bforce/bforce.c index cc7a822..38c4d1c 100644 --- a/source/bforce/bforce.c +++ b/source/bforce/bforce.c @@ -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); diff --git a/source/bforce/os_unix.c b/source/bforce/os_unix.c index 1651756..b014d83 100644 --- a/source/bforce/os_unix.c +++ b/source/bforce/os_unix.c @@ -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) diff --git a/source/include/bforce.h b/source/include/bforce.h index 283be5b..8fcfdcc 100644 --- a/source/include/bforce.h +++ b/source/include/bforce.h @@ -183,4 +183,6 @@ extern const char *BFERR[]; int daemon_run(const char *confname, const char *incname, bool quit); +extern char ** mainenv; + #endif From 0c138843eb68839ba7c9e56385879f9292cb6248 Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Wed, 15 May 2024 19:10:16 +0300 Subject: [PATCH 3/7] Environment patch /2 --- source/bforce/bforce.c | 2 +- source/bforce/os_unix.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/bforce/bforce.c b/source/bforce/bforce.c index 38c4d1c..0f6512e 100644 --- a/source/bforce/bforce.c +++ b/source/bforce/bforce.c @@ -272,7 +272,7 @@ int main(int argc, char *argv[], char *envp[]) 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)])); + fprintf(stderr,"BF-DEBUG: ENV: %s\n", mainenv[(i-1)]); } // parsing diff --git a/source/bforce/os_unix.c b/source/bforce/os_unix.c index b014d83..7556e7d 100644 --- a/source/bforce/os_unix.c +++ b/source/bforce/os_unix.c @@ -77,6 +77,7 @@ void exec_options_init(s_exec_options *eopt) memset(eopt, '\0', sizeof(s_exec_options)); eopt->umask = EXEC_DEFAULT_UMASK; eopt->envp[0] = NULL; + i = 0; while(mainenv[i]) { log("EXEC: Added ENV variable: %s\n", mainenv[i]); eopt->envp[i] = xmalloc(strlen(mainenv[i]) + 2); From 74c05f4a0ca77c8cba1edf23e45e51d4402e782e Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Wed, 15 May 2024 20:57:10 +0300 Subject: [PATCH 4/7] Environment patch /3 --- source/bforce/bforce.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/bforce/bforce.c b/source/bforce/bforce.c index 0f6512e..34df4fa 100644 --- a/source/bforce/bforce.c +++ b/source/bforce/bforce.c @@ -271,8 +271,8 @@ int main(int argc, char *argv[], char *envp[]) 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)]); + mainenv[++i] = NULL; + //fprintf(stderr,"BF-DEBUG: ENV: %s\n", mainenv[(i-1)]); } // parsing @@ -511,9 +511,8 @@ exit: i=0; while(mainenv[i]) { DEB((D_FREE, "De-init session ENV: %s\n", mainenv[(i)])); - free(mainenv[i]); + free(mainenv[i++]); } - free(mainenv); deinit_conf(); From fbe1f1ea9dc74b266583af59b571218d13799593 Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Wed, 15 May 2024 21:19:09 +0300 Subject: [PATCH 5/7] Environment patch /4 --- source/bforce/os_unix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/bforce/os_unix.c b/source/bforce/os_unix.c index 7556e7d..c3ddb19 100644 --- a/source/bforce/os_unix.c +++ b/source/bforce/os_unix.c @@ -80,9 +80,9 @@ void exec_options_init(s_exec_options *eopt) i = 0; 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; + eopt->envp[i] = malloc(strlen(mainenv[i]) + 2); + sprintf(eopt->envp[i], mainenv[i]); + eopt->envp[++i] = NULL; } } From a315b13075f0249218a10c24713a37bc02f07f5f Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Wed, 15 May 2024 21:22:09 +0300 Subject: [PATCH 6/7] Environment patch /5 --- source/include/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/include/os.h b/source/include/os.h index dd86b33..ce2a4ad 100644 --- a/source/include/os.h +++ b/source/include/os.h @@ -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); From 8f2670091c94069584b03b56c9be0709f49dbdb6 Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Wed, 15 May 2024 21:53:57 +0300 Subject: [PATCH 7/7] Logger fixes for syslog, version up, merge --- source/.version | 2 +- source/bforce/logger.c | 10 +++++++--- source/bforce/os_unix.c | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/source/.version b/source/.version index 48b91fd..8b95abd 100644 --- a/source/.version +++ b/source/.version @@ -1 +1 @@ -0.24.1 +0.24.2 diff --git a/source/bforce/logger.c b/source/bforce/logger.c index c8e9a3e..c2f3541 100644 --- a/source/bforce/logger.c +++ b/source/bforce/logger.c @@ -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) diff --git a/source/bforce/os_unix.c b/source/bforce/os_unix.c index c3ddb19..ce08e07 100644 --- a/source/bforce/os_unix.c +++ b/source/bforce/os_unix.c @@ -79,8 +79,8 @@ void exec_options_init(s_exec_options *eopt) eopt->envp[0] = NULL; i = 0; while(mainenv[i]) { - log("EXEC: Added ENV variable: %s\n", mainenv[i]); - eopt->envp[i] = malloc(strlen(mainenv[i]) + 2); + 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; } @@ -109,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; } }