diff --git a/source/bforce/bforce.c b/source/bforce/bforce.c index cc7a822..0da76e2 100644 --- a/source/bforce/bforce.c +++ b/source/bforce/bforce.c @@ -23,6 +23,8 @@ /* PID of our child process (if use fork) */ pid_t child_pid = 0; +char * mainenv[EXEC_MAX_NUM_ENVS+1]; + const char *BFERR[] = { /* 00 */ "Successfull", /* 01 */ "Fatal error occured", @@ -253,6 +255,16 @@ int main(int argc, char *argv[], char *envp[]) int rc = 0; int ch = 0; opts.runmode = MODE_UNDEFINED; + int i = 0; + + 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)])); + } memset(&opts, '\0', sizeof(s_bforce_opts)); @@ -491,6 +503,13 @@ exit: deinit_conf(); deinit_opts(&opts); + /* de-init sessenv */ + i=0; + while(mainenv[i]) { + DEB((D_FREE, "De-init session ENV: %s\n", mainenv[(i)])); + free(mainenv[i++]); + } + /* Shutdown logging services */ if( log_isopened() ) log_close(); DEB((D_FREE, "good exit")); 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); diff --git a/source/bforce/logger.c b/source/bforce/logger.c index c8e9a3e..f3599cf 100644 --- a/source/bforce/logger.c +++ b/source/bforce/logger.c @@ -283,6 +283,8 @@ int logerr(const char *s, ...) #ifdef USE_SYSLOG +bool slog_active = FALSE; + const char *log_getfilename(int whatfor) { const char *p = "/dev/null"; @@ -291,22 +293,27 @@ const char *log_getfilename(int whatfor) bool log_isopened(void) { - return TRUE; + return slog_active; } int log_open(const char *logname, const char *ext, const char *tty) { - char *p = "bforce"; + char *p = "bforce "; + p = xstrcat(p, BF_VERSION); int fac = conf_number(cf_syslog_facility); if( tty && *tty ) strncpy(p, tty, sizeof(p)); openlog(p, LOG_PID, fac); + slog_active = TRUE; return 0; } int log_reopen(const char *logname, const char *ext, const char *tty) { - return 0; + if ( !slog_active ) { + return (log_reopen(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 1651756..442198a 100644 --- a/source/bforce/os_unix.c +++ b/source/bforce/os_unix.c @@ -73,9 +73,18 @@ 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]) { + DEB((D_FREE,"EXEC: Added ENV variable: %s\n", mainenv[i])); + eopt->envp[i] = xmalloc(strlen(mainenv[i]) + 2); + strcpy(eopt->envp[i],mainenv[i]); + eopt->envp[++i] = NULL; + } } void exec_options_deinit(s_exec_options *eopt) diff --git a/source/bforce/prot_binkp.c b/source/bforce/prot_binkp.c index a02bbec..694b0c3 100644 --- a/source/bforce/prot_binkp.c +++ b/source/bforce/prot_binkp.c @@ -106,7 +106,7 @@ int binkp_loop(s_binkp_state *bstate) { bool no_more_to_send = false; bool no_more_read = false; bool canread, canwrite; - + int timeout = conf_number(cf_binkp_timeout); if( timeout==0 ) timeout = 60; @@ -117,12 +117,13 @@ int binkp_loop(s_binkp_state *bstate) { // session criterium handshake criterium while (!bstate->complete || bstate->waiting_got) { - DEB((D_24554, "loop s: %d r: %d p: %d sp: %d", bstate->batchsendcomplete, bstate->batchreceivecomplete, + DEB((D_24554, ">>> BinkP loop sendcpl: %d recvcpl: %d phase: %d subphase: %d", bstate->batchsendcomplete, bstate->batchreceivecomplete, bstate->phase, bstate->subphase)); if (bstate->continuesend) { no_more_to_send = false; bstate->continuesend = false; } + if (have_to_write==0 && (!no_more_to_send || bstate->extracmd[0]!=-1)) { m = binkp_getforsend(bstate, writebuf+BINKP_HEADER, &block_type, &block_length); if(m==1 || m==3) { @@ -267,6 +268,7 @@ int binkp_loop(s_binkp_state *bstate) { have_to_write -= n; } } + DEB((D_24554,"+++ BinkP Loop ended with rc=%d", bstate->rc)); return bstate->rc; } @@ -339,7 +341,7 @@ int binkp_getforsend(s_binkp_state *bstate, char *buf, int *block_type, unsigned int my_sf, wr_pos; int n; // read file if (bstate->extracmd[0]!=-1) { - DEB((D_24554, "send command from receiver %d %s", bstate->extracmd[0], bstate->extracmd+1)); + DEB((D_24554, "Send cmd to remote %d %s", bstate->extracmd[0], bstate->extracmd+1)); buf[0] = bstate->extracmd[0]; strcpy(buf+1, bstate->extracmd+1); *block_type = BINKP_BLK_CMD; @@ -625,7 +627,7 @@ case 4: return 1; case 5: - DEB((D_24554, "nothing to send")); + DEB((D_24554, "BinkP_GetForSend: nothing to send")); return 2; @@ -804,7 +806,7 @@ case 0: bstate->frs = frs_data; return 1; } - DEB((D_24554, "making M_GET to skip downloaded part")); + DEB((D_24554, "making M_GET to skip downloaded part, file: %s, size %ld, time %ld, mode 0",recvfi.fn,recvfi.sz, recvfi.tm )); bstate->extracmd[0] = BPMSG_GET; sprintf(bstate->extracmd+1, "%s %ld %ld %ld", bstate->pi->recv->net_name, (long)bstate->pi->recv->bytes_total, diff --git a/source/bforce/prot_binkp_misc.c b/source/bforce/prot_binkp_misc.c index aa71ea2..fd6a832 100644 --- a/source/bforce/prot_binkp_misc.c +++ b/source/bforce/prot_binkp_misc.c @@ -45,7 +45,7 @@ int binkp_parsfinfo(const char *str, s_bpfinfo *fi, bool with_offset) return -1; } DEB((D_24554, "info to parse: %s", str)); - r = sscanf(str, with_offset? "%s %d %d %d": "%s %d %d", &fi->fn, &fi->sz, &fi->tm, &fi->offs); + r = sscanf(str, with_offset? "%s %ld %ld %ld": "%s %ld %ld", &fi->fn, &fi->sz, &fi->tm, &fi->offs); chkslash = fi->fn; while (1) { chkslash = strchr(chkslash, '/'); diff --git a/source/bforce/prot_common.c b/source/bforce/prot_common.c index 7e75140..4fd536f 100644 --- a/source/bforce/prot_common.c +++ b/source/bforce/prot_common.c @@ -860,6 +860,8 @@ int p_rx_fopen(s_protinfo *pi, char *fn, size_t sz, time_t tm, mode_t mode) size_t minfree = 0; size_t needed_bytes_total = 0; + DEB((D_FREE, "P_RX_FOPEN: File: %s, Size: %ld", fn, sz)); + /* * Check. May be we are receiving this file allready */ diff --git a/source/bforce/u_file.c b/source/bforce/u_file.c index 4c94b45..99ec3ec 100644 --- a/source/bforce/u_file.c +++ b/source/bforce/u_file.c @@ -145,6 +145,7 @@ char *file_name_makesafe(char *filename) char *file_getname(char *filename) { char *p = strrchr(filename, '/'); + DEB((D_FREE, "File_getname: %s", (p ? p + 1 : filename) )); return p ? p + 1 : filename; } diff --git a/source/include/bforce.h b/source/include/bforce.h index 283be5b..a6a7679 100644 --- a/source/include/bforce.h +++ b/source/include/bforce.h @@ -181,6 +181,8 @@ typedef struct { */ extern const char *BFERR[]; +extern char * mainenv[]; + int daemon_run(const char *confname, const char *incname, bool quit); #endif diff --git a/source/include/os.h b/source/include/os.h index dd86b33..0b46958 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 4095 #define EXEC_MAX_NUM_ARGS 20 #define EXEC_DEFAULT_UMASK ~(S_IRUSR|S_IWUSR);