Altmost compilable, weak symbol definitions still missing.
[vblib.git] / vblib.c
diff --git a/vblib.c b/vblib.c
index 61017c7..9bf8ea1 100644 (file)
--- a/vblib.c
+++ b/vblib.c
 #include <setjmp.h>
 #include <sys/socket.h>
 #include <stddef.h>
+#ifdef HAVE_PTHREAD
 #include <pthread.h>
+#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))<len) len=size;
        was=len;
        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;
                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;
@@ -792,8 +803,10 @@ static void chatfn_help(void);
 
 static const struct chat_cmdtab  chat_cmdint[]={
        {"help"    ,0,chatfn_help    ,"This help"},
+#if 0
        {"quit"    ,0,chatfn_quit    ,"Close connection"},
        {"exit"    ,0,chatfn_quit    ,"Close connection"},
+#endif
 };
 
 static void chatfn_help(void)
@@ -856,7 +869,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)();
                        }
                }