X-Git-Url: http://git.jankratochvil.net/?p=vblib.git;a=blobdiff_plain;f=vblib.c;h=8850dc1c8a818b70f536122d811a8e2861057023;hp=61017c74813d7c558d3e12a717f7491c29bf5237;hb=2855398ad0fd631f11c2395da59bc3941fa75e5f;hpb=568dfce1d3c4b7b3bc4fc1503469a35b5e21734f diff --git a/vblib.c b/vblib.c index 61017c7..8850dc1 100644 --- a/vblib.c +++ b/vblib.c @@ -22,21 +22,20 @@ #include #include #include +#ifdef HAVE_PTHREAD #include +#endif -#include "common.h" -#include "dataserv.h" +#include "vblib.h" const int safesigs[]={SIGQUIT,SIGINT,SIGTERM,SIGIOT,SIGALRM,-1}; //SIGCHLD->childsignal anyway char vbnexact; -const char *upsc_sshpath="/usr/bin/ssh"; /* upsetupconn()... */ -const char *upsc_dstport=DS_PORT; void chk(const void *p) { vbsanity(); if (p) return; - FATAL(CRIT,"NULL-check failure, memory exhausted? FATAL: %m"); + VB_FATAL(CRIT,"NULL-check failure, memory exhausted? FATAL: %m"); } #ifndef NDEBUG @@ -48,12 +47,17 @@ static char vbcheckno; #else #define vbcheckno (0) #endif -pthread_mutex_t vbcheckmx=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +#ifdef HAVE_PTHREAD +static pthread_mutex_t vbcheckmx=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; static void vbchecklock (void) -{ if (pthread_mutex_lock (&vbcheckmx)) FATAL(CRIT,"Mutex ""lock on vbcheck mx"); } +{ if (pthread_mutex_lock (&vbcheckmx)) VB_FATAL(CRIT,"Mutex ""lock on vbcheck mx"); } static void vbcheckunlock(void) -{ if (pthread_mutex_unlock(&vbcheckmx)) FATAL(CRIT,"Mutex unlock on vbcheck mx"); } +{ if (pthread_mutex_unlock(&vbcheckmx)) VB_FATAL(CRIT,"Mutex unlock on vbcheck mx"); } +#else +#define vbchecklock() +#define vbcheckunlock() +#endif static char vbchecklist(struct varbuf *vb) { @@ -415,8 +419,15 @@ unsigned tot=0; char *d; for (d=s;(d=memchr(d,'\0',s+len-d));) { *d++=' '; tot++; } - if (tot) logmsg((quiet_null?MYLOG_DEBUG:MYLOG_ERR), - "%s() replaced %u '\\0's by ' ' in: %.*s",fname,tot,(int)len,s); + if (!tot) return; +#define ARG "%s() replaced %u '\\0's by ' ' in: %.*s",fname,tot,(int)len,s +#define VB_LOG1(a,b) VB_LOG(a,b) + if (quiet_null) + VB_LOG1(DEBUG,ARG); + else + VB_LOG1(ERR,ARG); +#undef VB_LOG1 +#undef ARG } char *vbgetline(struct varbuf *vb,char term) @@ -507,7 +518,7 @@ void vbpstrputstring(struct varbuf *vb,const char *s) { size_t len=strlen(s); if (len>PSTR_MAX) { - LOG(CRIT,"String longer (%u) than PSTRing max (%u)",len,PSTR_MAX); + VB_LOG(CRIT,"String longer (%u) than PSTRing max (%u)",len,PSTR_MAX); len=PSTR_MAX; dbg("vbpstrputstring-longer than MAX: \"%s\"\n",s); } @@ -522,7 +533,7 @@ size_t size,was; else if ((size=vbsize(vbs,len))PSTR_MAX) { - LOG(CRIT,"String longer (%u) than PSTRing max (%u)",len,PSTR_MAX); + VB_LOG(CRIT,"String longer (%u) than PSTRing max (%u)",len,PSTR_MAX); len=PSTR_MAX; vbdebug(vbs,"vbpstrputstring-longer than MAX"); } @@ -542,7 +553,7 @@ int i; i=vsnprintf(buf,sizeof(buf),fmt,ap); va_end(ap); if (i==-1) { - LOG(CRIT,"Buffer overflow (max=%u) during PSTR printf",PSTR_MAX); + VB_LOG(CRIT,"Buffer overflow (max=%u) during PSTR printf",PSTR_MAX); i=PSTR_MAX; } assert(i>=0 && i<=PSTR_MAX && !buf[i]); @@ -567,7 +578,7 @@ size_t r; chgd++; } if (chgd) - LOG(CRIT,"'\\0's found (%u total) in read PSTR \"%s\", changed to '?'",chgd,buf); + VB_LOG(CRIT,"'\\0's found (%u total) in read PSTR \"%s\", changed to '?'",chgd,buf); return(buf); } @@ -723,7 +734,7 @@ char buf[LOGF_FGETS_BUF],*s; if (!fgets(buf,sizeof(buf),f)) { dbg("vbgetlinef: fgets=NULL\n"); if (feof(f)) return; - FATAL(ERR,"linereading fail: %m"); + VB_FATAL(ERR,"linereading fail: %m"); } dbg("vbgetlinef: fgets: %s\n",buf); if ((s=strchr(buf,'\n'))) break; @@ -790,12 +801,21 @@ char *chat_cmdpars[CHAT_CMD_MAXPARS]; static void chatfn_help(void); +void chatfn_quit(void) __WEAK; +void chatfn_quit(void) +{ + VB_LOG(CRIT,"chatfn_quit() not initialized"); +} + static const struct chat_cmdtab chat_cmdint[]={ {"help" ,0,chatfn_help ,"This help"}, {"quit" ,0,chatfn_quit ,"Close connection"}, {"exit" ,0,chatfn_quit ,"Close connection"}, }; +const struct chat_cmdtab chat_cmdtable[] __WEAK = + {{NULL,0,NULL,NULL}}; + static void chatfn_help(void) { int i; @@ -845,6 +865,10 @@ const struct chat_cmdtab *cmd,*cmdt; } chat_parsepars(s); cmdt=chat_cmdtable; + if (!cmdt || !cmdt->name) { + VB_LOG(CRIT,"chat_cmdtable not initialized, \"%s\" tried to execute \"%s\"",who,cmds); + return; + } for (i=0;iname) cmd=cmdt++; else cmd=&chat_cmdint[i++]; @@ -856,7 +880,7 @@ const struct chat_cmdtab *cmd,*cmdt; vbprintf(chat_vbout,"205 %d parameter%s found, %d expected!\n",chat_cmdpar,(chat_cmdpar==1?"":"s"),cmd->npars); else { vbprintf(chat_vbout,"001 Running command: %s\n",cmds); - LOG(DEBUG,"%s is executing user command \"%s\"",who,cmds); + VB_LOG(DEBUG,"%s is executing user command \"%s\"",who,cmds); (*cmd->fnc)(); } }