Earlydbg as new -v option for main prog

master
Alexey Khromov 7 months ago
parent d94ba35438
commit c2f9843291

@ -102,6 +102,7 @@ static void usage(void)
" -S <connect_str> connect string (for slave mode only)\n" " -S <connect_str> connect string (for slave mode only)\n"
" -p <port> override modem port (must be defined in config)\n" " -p <port> override modem port (must be defined in config)\n"
" -u binkp|ifcico|telnet protocol to use over TCP/IP\n" " -u binkp|ifcico|telnet protocol to use over TCP/IP\n"
" -v display early debug info on stderr\n"
" -h show this help message\n" " -h show this help message\n"
"\n", "\n",
conf_getconfname() conf_getconfname()
@ -257,7 +258,7 @@ int main(int argc, char *argv[], char *envp[])
// parsing // parsing
while( (ch=getopt(argc, argv, "hfI:p:n:l:a:u:oiC:S:dq")) != (int)-1 ) while( (ch=getopt(argc, argv, "hfI:p:n:l:a:u:oivC:S:dq")) != (int)-1 )
{ {
switch( ch ) { switch( ch ) {
case 'h': case 'h':
@ -308,6 +309,9 @@ int main(int argc, char *argv[], char *envp[])
//if( opts.runmode != MODE_ANSWER || opts.inetd ) { usage(); exit(BFERR_FATALERROR); } //if( opts.runmode != MODE_ANSWER || opts.inetd ) { usage(); exit(BFERR_FATALERROR); }
opts.inetd = 1; opts.inetd = 1;
break; break;
case 'v':
opts.earlydbg = TRUE;
break;
case 'C': case 'C':
if( opts.confname || !optarg ) { usage(); exit(BFERR_FATALERROR); } if( opts.confname || !optarg ) { usage(); exit(BFERR_FATALERROR); }
opts.confname = (char *)xstrcpy(optarg); opts.confname = (char *)xstrcpy(optarg);
@ -435,15 +439,16 @@ int main(int argc, char *argv[], char *envp[])
/* Process primary config file */ /* Process primary config file */
if( opts.confname && *opts.confname ) if( opts.confname && *opts.confname )
rc = conf_readconf(opts.confname, 0); rc = conf_readconf(opts.confname, 0, opts.earlydbg);
else else
rc = conf_readconf(conf_getconfname(), 0); rc = conf_readconf(conf_getconfname(), 0, opts.earlydbg);
if( rc ) gotoexit(BFERR_FATALERROR); if( rc ) gotoexit(BFERR_FATALERROR);
/* Process additional config file, ignore errors */ /* Process additional config file, ignore errors */
if( opts.incname && *opts.incname ) if( opts.incname && *opts.incname )
(void)conf_readconf(opts.incname, 1); if (conf_readconf(opts.incname, 1, opts.earlydbg))
gotoexit(BFERR_FATALERROR);
/* 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) )
@ -459,6 +464,7 @@ int main(int argc, char *argv[], char *envp[])
switch( opts.runmode ) switch( opts.runmode )
{ {
case MODE_DAEMON: case MODE_DAEMON:
DEB((D_STATEM, "Daemon mode"));
log("Daemon mode"); log("Daemon mode");
rc = bforce_daemon(&opts); rc = bforce_daemon(&opts);
break; break;
@ -466,14 +472,17 @@ case MODE_CALL_DEFAULT:
case MODE_CALL_IP: case MODE_CALL_IP:
case MODE_CALL_MODEM: case MODE_CALL_MODEM:
case MODE_CALL_STDIO: case MODE_CALL_STDIO:
DEB((D_STATEM, "Outgoing call"));
log("Outgoing call"); log("Outgoing call");
rc = bforce_master(&opts); rc = bforce_master(&opts);
break; break;
case MODE_ANSWER: case MODE_ANSWER:
DEB((D_STATEM, "Start answer"));
log("Start answer"); log("Start answer");
rc = bforce_slave(&opts); rc = bforce_slave(&opts);
break; break;
default: default:
DEB((D_STATEM, "Could not determine run mode"));
log("Could not determine run mode"); log("Could not determine run mode");
} }

@ -129,11 +129,11 @@ static void conf_parsestr(char *str, char **key, char **expr, char **value)
return; return;
} }
int conf_readconf(const char *confname, int inclevel) int conf_readconf(const char *confname, int inclevel, bool earlydbg)
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr,"BF-DEBUG: Parsing config file: %s %d\n", confname, inclevel); fprintf(stderr,"BF-DEBUG: Parsing config file: %s %d\n", confname, inclevel);
#endif
FILE *fp = NULL; FILE *fp = NULL;
char tmp[BF_MAXCFGLINE + 1]; char tmp[BF_MAXCFGLINE + 1];
int rc, maxrc = 0; int rc, maxrc = 0;
@ -158,10 +158,9 @@ int conf_readconf(const char *confname, int inclevel)
{ {
if( i != (int)bforce_config[i].real_key ) if( i != (int)bforce_config[i].real_key )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr,"BF-DEBUG: invalid config table: found %d instead of %d\n", fprintf(stderr,"BF-DEBUG: invalid config table: found %d instead of %d\n",
bforce_config[i].real_key, i); bforce_config[i].real_key, i);
#endif
return -1; return -1;
} }
} }
@ -169,14 +168,12 @@ int conf_readconf(const char *confname, int inclevel)
if( (fp = file_open(confname,"r")) == NULL ) if( (fp = file_open(confname,"r")) == NULL )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr,"BF-DEBUG: can't open config file \"%s\"\n", confname); fprintf(stderr,"BF-DEBUG: can't open config file \"%s\"\n", confname);
#endif
return(PROC_RC_IGNORE); return(PROC_RC_IGNORE);
} }
#ifdef DEBUG if (earlydbg)
fprintf(stderr,"BF-DEBUG: start reading config \"%s\"\n", confname); fprintf(stderr,"BF-DEBUG: start reading config \"%s\"\n", confname);
#endif
while( fgets(tmp, sizeof(tmp), fp) ) while( fgets(tmp, sizeof(tmp), fp) )
{ {
@ -187,9 +184,9 @@ int conf_readconf(const char *confname, int inclevel)
{ {
if( isifexpr ) if( isifexpr )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr,"BF-DEBUG: warning: automatically close expression at empty line %d\n", line); fprintf(stderr,"BF-DEBUG: warning: automatically close expression at empty line %d\n", line);
#endif
if( ifexpr ) { free(ifexpr); ifexpr = NULL; } if( ifexpr ) { free(ifexpr); ifexpr = NULL; }
isifexpr = FALSE; isifexpr = FALSE;
} }
@ -197,9 +194,9 @@ int conf_readconf(const char *confname, int inclevel)
if( !isappend ) if( !isappend )
continue; continue;
#ifdef DEBUG if (earlydbg)
fprintf(stderr,"BF-DEBUG: warning: appending empty or comment line %d\n", line); fprintf(stderr,"BF-DEBUG: warning: appending empty or comment line %d\n", line);
#endif
isappend = FALSE; isappend = FALSE;
} }
@ -242,10 +239,10 @@ int conf_readconf(const char *confname, int inclevel)
p_value = NULL; p_value = NULL;
conf_parsestr(fullstr ? fullstr : tmp, &p_key, &p_expr, &p_value); conf_parsestr(fullstr ? fullstr : tmp, &p_key, &p_expr, &p_value);
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: conf_readconf: [%d] key \"%s\" expr \"%s\" value \"%s\"\n", fprintf(stderr, "BF-DEBUG: conf_readconf: [%d] key \"%s\" expr \"%s\" value \"%s\"\n",
line, p_key, p_expr, p_value); line, p_key, p_expr, p_value);
#endif
if( p_value ) if( p_value )
{ {
@ -269,24 +266,24 @@ int conf_readconf(const char *confname, int inclevel)
{ {
if( value == NULL || expr ) if( value == NULL || expr )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key); fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key);
#endif
rc = PROC_RC_IGNORE; rc = PROC_RC_IGNORE;
} }
else if( inclevel < MAXINCLUDELEVEL ) else if( inclevel < MAXINCLUDELEVEL )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: conf_readconf: process inlude file \"%s\"\n", value); fprintf(stderr, "BF-DEBUG: conf_readconf: process inlude file \"%s\"\n", value);
#endif
rc = conf_readconf(value, inclevel + 1); rc = conf_readconf(value, inclevel + 1, earlydbg);
if( rc ) rc = PROC_RC_IGNORE; if( rc ) rc = PROC_RC_IGNORE;
} }
else else
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: conf_readconf: too deep include\n"); fprintf(stderr, "BF-DEBUG: conf_readconf: too deep include\n");
#endif
rc = PROC_RC_IGNORE; rc = PROC_RC_IGNORE;
} }
} }
@ -294,9 +291,9 @@ int conf_readconf(const char *confname, int inclevel)
{ {
if( value || isifexpr ) if( value || isifexpr )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key); fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key);
#endif
rc = PROC_RC_ABORT; rc = PROC_RC_ABORT;
} }
else else
@ -312,9 +309,9 @@ int conf_readconf(const char *confname, int inclevel)
{ {
if( value || expr || !isifexpr ) if( value || expr || !isifexpr )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key); fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key);
#endif
rc = PROC_RC_IGNORE; rc = PROC_RC_IGNORE;
} }
else else
@ -326,9 +323,9 @@ int conf_readconf(const char *confname, int inclevel)
else else
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: unknown directive `%s'\n", p_key); fprintf(stderr, "BF-DEBUG: unknown directive `%s'\n", p_key);
#endif
rc = PROC_RC_IGNORE; rc = PROC_RC_IGNORE;
} }
} }
@ -336,9 +333,9 @@ int conf_readconf(const char *confname, int inclevel)
{ {
if( isifexpr && expr ) if( isifexpr && expr )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: can't use expressions inside $ifexpr block\n"); fprintf(stderr, "BF-DEBUG: can't use expressions inside $ifexpr block\n");
#endif
rc = PROC_RC_IGNORE; rc = PROC_RC_IGNORE;
} }
else if( isifexpr ) else if( isifexpr )
@ -352,9 +349,9 @@ int conf_readconf(const char *confname, int inclevel)
} }
else else
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: incorrect config string %s\n", fullstr); fprintf(stderr, "BF-DEBUG: incorrect config string %s\n", fullstr);
#endif
rc = PROC_RC_IGNORE; rc = PROC_RC_IGNORE;
} }
@ -369,19 +366,19 @@ int conf_readconf(const char *confname, int inclevel)
case PROC_RC_OK: case PROC_RC_OK:
break; break;
case PROC_RC_WARN: case PROC_RC_WARN:
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: warning in config \"%s\" line %d\n", confname, line); fprintf(stderr, "BF-DEBUG: warning in config \"%s\" line %d\n", confname, line);
#endif
break; break;
case PROC_RC_IGNORE: case PROC_RC_IGNORE:
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: ignore line %d in config \"%s\"\n", line, confname); fprintf(stderr, "BF-DEBUG: ignore line %d in config \"%s\"\n", line, confname);
#endif
break; break;
case PROC_RC_ABORT: case PROC_RC_ABORT:
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: fatal error in config \"%s\" in line %d\n", confname, line); fprintf(stderr, "BF-DEBUG: fatal error in config \"%s\" in line %d\n", confname, line);
#endif
break; break;
default: default:
ASSERT_MSG(); ASSERT_MSG();
@ -395,9 +392,9 @@ int conf_readconf(const char *confname, int inclevel)
if( isifexpr ) if( isifexpr )
{ {
maxrc = 1; maxrc = 1;
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: unterminated directive `#ifexp'\n"); fprintf(stderr, "BF-DEBUG: unterminated directive `#ifexp'\n");
#endif
} }
if( fullstr ) if( fullstr )
@ -405,17 +402,17 @@ int conf_readconf(const char *confname, int inclevel)
if( ifexpr ) if( ifexpr )
free(ifexpr); free(ifexpr);
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: readconfig: exit with maxrc = %d\n", maxrc); fprintf(stderr, "BF-DEBUG: readconfig: exit with maxrc = %d\n", maxrc);
#endif
/* update subsystems */ /* update subsystems */
if (inclevel==0) { // end of main config if (inclevel==0) { // end of main config
if( log_reopen(log_getfilename(LOG_FILE_SESSION), NULL, NULL) ) if( log_reopen(log_getfilename(LOG_FILE_SESSION), NULL, NULL) )
{ {
#ifdef DEBUG if (earlydbg)
fprintf(stderr, "BF-DEBUG: can't continue without logging\n"); fprintf(stderr, "BF-DEBUG: can't continue without logging\n");
#endif
exit(-1); exit(-1);
} }
#ifdef DEBUG #ifdef DEBUG
@ -427,29 +424,3 @@ int conf_readconf(const char *confname, int inclevel)
return maxrc; return maxrc;
} }
#ifdef DEBUG
/*void debug_override(void)
{
s_cval_entry *ptrl;
char abuf[BF_MAXADDRSTR+1];
DEB((D_CONFIG, "debug_override: BEGIN"));
for( ptrl = bforce_config[cf_override].data; ptrl; ptrl = ptrl->next )
{
DEB((D_CONFIG, "log_overridelist: address %s",
ftn_addrstr(abuf, ptrl->d.override.addr)));
DEB((D_CONFIG, "log_overridelist: \tIpaddr = \"%s\"",
ptrl->d.override.sIpaddr));
DEB((D_CONFIG, "log_overridelist: \tPhone = \"%s\"",
ptrl->d.override.sPhone));
DEB((D_CONFIG, "log_overridelist: \tWorktime = \"%s\"",
timevec_string(abuf, &ptrl->d.override.worktime, sizeof(abuf))));
DEB((D_CONFIG, "log_overridelist: \tFlags = \"%s\"",
ptrl->d.override.sFlags));
}
DEB((D_CONFIG, "debug_override: END"));
}*/
#endif /* DEBUG */

@ -938,15 +938,15 @@ int daemon_run(const char *confname, const char *incname, bool quit)
/* Read primary config file */ /* Read primary config file */
if( confname && *confname ) if( confname && *confname )
rc = conf_readconf(confname, 0); rc = conf_readconf(confname, 0, false);
else else
rc = conf_readconf(conf_getconfname(), 0); rc = conf_readconf(conf_getconfname(), 0, false);
if( rc ) if( rc )
return(BFERR_FATALERROR); return(BFERR_FATALERROR);
/* Read additional config file (manual include) */ /* Read additional config file (manual include) */
if( incname && *incname && conf_readconf(incname, 1) ) if( incname && *incname && conf_readconf(incname, 1, false) )
log("cannot read additional config (ignore)"); log("cannot read additional config (ignore)");
dmstate = DM_Start; dmstate = DM_Start;

@ -209,7 +209,7 @@ int main(int argc, char *argv[])
} }
if( conf_readconf(conf_getconfname(), 0) ) if( conf_readconf(conf_getconfname(), 0, false) )
{ {
exit(1); exit(1);
} }

@ -301,7 +301,7 @@ int main(int argc, char *argv[])
/* Initialise current locale */ /* Initialise current locale */
(void)setlocale(LC_ALL, ""); (void)setlocale(LC_ALL, "");
if( conf_readconf(conf_getconfname(), 0) ) if( conf_readconf(conf_getconfname(), 0, false) )
exit(1); exit(1);
memset(&ocb, '\0', sizeof(s_outbound_callback_data)); memset(&ocb, '\0', sizeof(s_outbound_callback_data));

@ -159,7 +159,7 @@ int main(int argc, char *argv[])
exit(BFERR_FATALERROR); exit(BFERR_FATALERROR);
} }
if( conf_readconf(conf_getconfname(), 0) ) if( conf_readconf(conf_getconfname(), 0, false) )
exit(BFERR_FATALERROR); exit(BFERR_FATALERROR);
if( rawstring ) if( rawstring )

@ -151,6 +151,7 @@ typedef struct {
bool daemon; /* Run as daemon? */ bool daemon; /* Run as daemon? */
bool quit; /* Quit from daemon */ bool quit; /* Quit from daemon */
bool usestdio; /* Session on stdin and stdout */ bool usestdio; /* Session on stdin and stdout */
bool earlydbg; /* Early debug on stderr */
int inetd; /* Called from inetd? */ int inetd; /* Called from inetd? */
int force; /* Force call? */ int force; /* Force call? */
int hiddline; /* Hidden line number (0,1..) */ int hiddline; /* Hidden line number (0,1..) */

@ -347,7 +347,7 @@ void deinit_translate(s_translate *dest);
const char *conf_getconfname(void); const char *conf_getconfname(void);
int conf_postreadcheck(void); int conf_postreadcheck(void);
int conf_readpasswdlist(s_falist **pwdlist, char *fname); int conf_readpasswdlist(s_falist **pwdlist, char *fname);
int conf_readconf(const char *confname, int inclevel); int conf_readconf(const char *confname, int inclevel, bool earlydbg);
#ifdef DEBUG #ifdef DEBUG
void log_overridelist(s_override *subst); void log_overridelist(s_override *subst);
void log_options(s_options *opt); void log_options(s_options *opt);

@ -33,22 +33,22 @@ enum { LOG_FILE_DAEMON, LOG_FILE_SESSION, LOG_FILE_DEBUG, LOG_FILE_HISTORY };
#ifdef DEBUG #ifdef DEBUG
# define D_CONFIG 0x0000001L #define D_CONFIG 0x0000001L
# define D_OVERRIDE 0x0000002L #define D_OVERRIDE 0x0000002L
# define D_EVENT 0x0000004L #define D_EVENT 0x0000004L
# define D_NODELIST 0x0000008L #define D_NODELIST 0x0000008L
# define D_OUTBOUND 0x0000010L #define D_OUTBOUND 0x0000010L
# define D_INFO 0x0000020L #define D_INFO 0x0000020L
# define D_HSHAKE 0x0000040L #define D_HSHAKE 0x0000040L
# define D_TTYIO 0x0000080L #define D_TTYIO 0x0000080L
# define D_MODEM 0x0000100L #define D_MODEM 0x0000100L
# define D_PROT 0x0000200L #define D_PROT 0x0000200L
# define D_FREQ 0x0000400L #define D_FREQ 0x0000400L
# define D_STATEM 0x0000800L #define D_STATEM 0x0000800L
# define D_DAEMON 0x0001000L #define D_DAEMON 0x0001000L
# define D_24554 0x0002000L #define D_24554 0x0002000L
# define D_FREE 0x0004000L #define D_FREE 0x0004000L
# define D_FULL 0xfffffffL #define D_FULL 0xfffffffL
#endif #endif
#ifdef DEBUG #ifdef DEBUG

Loading…
Cancel
Save