// #define _GNU_SOURCE /* See feature_test_macros(7) */ #include #include #include #include #include #include "modelbahn.h" #define DEBUG_FILE "/tmp/modelbahn-server.log" int _debuglevel = 0xff; pid_t gettid(); void debug (int type, char *fmt,...) { va_list args; char text1[DEBUG_TEXT1LEN]; char text2[DEBUG_TEXT2LEN]; pid_t pid = gettid(); va_start (args, fmt); vsnprintf (text1, (DEBUG_TEXT1LEN-1), fmt, args); va_end (args); text1[DEBUG_TEXT1LEN-1] = 0; text2[DEBUG_TEXT2LEN-1] = 0; if (type > 0) snprintf (text2, DEBUG_TEXT2LEN-1, "(%d)%d: %s", pid, type, text1); else snprintf (text2, DEBUG_TEXT2LEN-1, "(%d) %s", pid, text1); if (type == 0 || (type & _debuglevel) != 0) { FILE *f; printf ("%s\n", text2); f= fopen(DEBUG_FILE, "a"); if (f) { fprintf (f, "%s\n", text2); fclose (f); } } }; /******************************************************************************************* * helper stuff *******************************************************************************************/ // // return the current thread process id // pid_t gettid() { pid_t tid = 0; tid = syscall(SYS_gettid); return tid; };