Earlydbg as new -v option for main prog

master
Alexey Khromov 6 months ago
parent d94ba35438
commit c2f9843291

@ -102,6 +102,7 @@ static void usage(void)
" -S <connect_str> connect string (for slave mode only)\n"
" -p <port> override modem port (must be defined in config)\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"
"\n",
conf_getconfname()
@ -257,7 +258,7 @@ int main(int argc, char *argv[], char *envp[])
// 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 ) {
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); }
opts.inetd = 1;
break;
case 'v':
opts.earlydbg = TRUE;
break;
case 'C':
if( opts.confname || !optarg ) { usage(); exit(BFERR_FATALERROR); }
opts.confname = (char *)xstrcpy(optarg);
@ -435,15 +439,16 @@ int main(int argc, char *argv[], char *envp[])
/* Process primary config file */
if( opts.confname && *opts.confname )
rc = conf_readconf(opts.confname, 0);
rc = conf_readconf(opts.confname, 0, opts.earlydbg);
else
rc = conf_readconf(conf_getconfname(), 0);
rc = conf_readconf(conf_getconfname(), 0, opts.earlydbg);
if( rc ) gotoexit(BFERR_FATALERROR);
/* Process additional config file, ignore errors */
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 */
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 )
{
case MODE_DAEMON:
DEB((D_STATEM, "Daemon mode"));
log("Daemon mode");
rc = bforce_daemon(&opts);
break;
@ -466,14 +472,17 @@ case MODE_CALL_DEFAULT:
case MODE_CALL_IP:
case MODE_CALL_MODEM:
case MODE_CALL_STDIO:
DEB((D_STATEM, "Outgoing call"));
log("Outgoing call");
rc = bforce_master(&opts);
break;
case MODE_ANSWER:
DEB((D_STATEM, "Start answer"));
log("Start answer");
rc = bforce_slave(&opts);
break;
default:
DEB((D_STATEM, "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;
}
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);
#endif
FILE *fp = NULL;
char tmp[BF_MAXCFGLINE + 1];
int rc, maxrc = 0;
@ -158,10 +158,9 @@ int conf_readconf(const char *confname, int inclevel)
{
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",
bforce_config[i].real_key, i);
#endif
return -1;
}
}
@ -169,14 +168,12 @@ int conf_readconf(const char *confname, int inclevel)
if( (fp = file_open(confname,"r")) == NULL )
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr,"BF-DEBUG: can't open config file \"%s\"\n", confname);
#endif
return(PROC_RC_IGNORE);
}
#ifdef DEBUG
if (earlydbg)
fprintf(stderr,"BF-DEBUG: start reading config \"%s\"\n", confname);
#endif
while( fgets(tmp, sizeof(tmp), fp) )
{
@ -187,9 +184,9 @@ int conf_readconf(const char *confname, int inclevel)
{
if( isifexpr )
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr,"BF-DEBUG: warning: automatically close expression at empty line %d\n", line);
#endif
if( ifexpr ) { free(ifexpr); ifexpr = NULL; }
isifexpr = FALSE;
}
@ -197,9 +194,9 @@ int conf_readconf(const char *confname, int inclevel)
if( !isappend )
continue;
#ifdef DEBUG
if (earlydbg)
fprintf(stderr,"BF-DEBUG: warning: appending empty or comment line %d\n", line);
#endif
isappend = FALSE;
}
@ -242,10 +239,10 @@ int conf_readconf(const char *confname, int inclevel)
p_value = NULL;
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",
line, p_key, p_expr, p_value);
#endif
if( p_value )
{
@ -269,24 +266,24 @@ int conf_readconf(const char *confname, int inclevel)
{
if( value == NULL || expr )
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key);
#endif
rc = PROC_RC_IGNORE;
}
else if( inclevel < MAXINCLUDELEVEL )
{
#ifdef DEBUG
if (earlydbg)
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;
}
else
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: conf_readconf: too deep include\n");
#endif
rc = PROC_RC_IGNORE;
}
}
@ -294,9 +291,9 @@ int conf_readconf(const char *confname, int inclevel)
{
if( value || isifexpr )
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key);
#endif
rc = PROC_RC_ABORT;
}
else
@ -312,9 +309,9 @@ int conf_readconf(const char *confname, int inclevel)
{
if( value || expr || !isifexpr )
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: incorrect usage of `%s' directive\n", p_key);
#endif
rc = PROC_RC_IGNORE;
}
else
@ -326,9 +323,9 @@ int conf_readconf(const char *confname, int inclevel)
else
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: unknown directive `%s'\n", p_key);
#endif
rc = PROC_RC_IGNORE;
}
}
@ -336,9 +333,9 @@ int conf_readconf(const char *confname, int inclevel)
{
if( isifexpr && expr )
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: can't use expressions inside $ifexpr block\n");
#endif
rc = PROC_RC_IGNORE;
}
else if( isifexpr )
@ -352,9 +349,9 @@ int conf_readconf(const char *confname, int inclevel)
}
else
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: incorrect config string %s\n", fullstr);
#endif
rc = PROC_RC_IGNORE;
}
@ -369,19 +366,19 @@ int conf_readconf(const char *confname, int inclevel)
case PROC_RC_OK:
break;
case PROC_RC_WARN:
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: warning in config \"%s\" line %d\n", confname, line);
#endif
break;
case PROC_RC_IGNORE:
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: ignore line %d in config \"%s\"\n", line, confname);
#endif
break;
case PROC_RC_ABORT:
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: fatal error in config \"%s\" in line %d\n", confname, line);
#endif
break;
default:
ASSERT_MSG();
@ -395,9 +392,9 @@ int conf_readconf(const char *confname, int inclevel)
if( isifexpr )
{
maxrc = 1;
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: unterminated directive `#ifexp'\n");
#endif
}
if( fullstr )
@ -405,17 +402,17 @@ int conf_readconf(const char *confname, int inclevel)
if( ifexpr )
free(ifexpr);
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: readconfig: exit with maxrc = %d\n", maxrc);
#endif
/* update subsystems */
if (inclevel==0) { // end of main config
if( log_reopen(log_getfilename(LOG_FILE_SESSION), NULL, NULL) )
{
#ifdef DEBUG
if (earlydbg)
fprintf(stderr, "BF-DEBUG: can't continue without logging\n");
#endif
exit(-1);
}
#ifdef DEBUG
@ -427,29 +424,3 @@ int conf_readconf(const char *confname, int inclevel)
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 */
if( confname && *confname )
rc = conf_readconf(confname, 0);
rc = conf_readconf(confname, 0, false);
else
rc = conf_readconf(conf_getconfname(), 0);
rc = conf_readconf(conf_getconfname(), 0, false);
if( rc )
return(BFERR_FATALERROR);
/* 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)");
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);
}

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

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

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

@ -347,7 +347,7 @@ void deinit_translate(s_translate *dest);
const char *conf_getconfname(void);
int conf_postreadcheck(void);
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
void log_overridelist(s_override *subst);
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
# define D_CONFIG 0x0000001L
# define D_OVERRIDE 0x0000002L
# define D_EVENT 0x0000004L
# define D_NODELIST 0x0000008L
# define D_OUTBOUND 0x0000010L
# define D_INFO 0x0000020L
# define D_HSHAKE 0x0000040L
# define D_TTYIO 0x0000080L
# define D_MODEM 0x0000100L
# define D_PROT 0x0000200L
# define D_FREQ 0x0000400L
# define D_STATEM 0x0000800L
# define D_DAEMON 0x0001000L
# define D_24554 0x0002000L
# define D_FREE 0x0004000L
# define D_FULL 0xfffffffL
#define D_CONFIG 0x0000001L
#define D_OVERRIDE 0x0000002L
#define D_EVENT 0x0000004L
#define D_NODELIST 0x0000008L
#define D_OUTBOUND 0x0000010L
#define D_INFO 0x0000020L
#define D_HSHAKE 0x0000040L
#define D_TTYIO 0x0000080L
#define D_MODEM 0x0000100L
#define D_PROT 0x0000200L
#define D_FREQ 0x0000400L
#define D_STATEM 0x0000800L
#define D_DAEMON 0x0001000L
#define D_24554 0x0002000L
#define D_FREE 0x0004000L
#define D_FULL 0xfffffffL
#endif
#ifdef DEBUG

Loading…
Cancel
Save