diff --git a/integrations/README.md b/integrations/README.md index bff41d8..1c6de50 100644 --- a/integrations/README.md +++ b/integrations/README.md @@ -11,6 +11,22 @@ Below are the specific instructions for each integration requiring *little to no For more support on these integrations, or if you'd like help creating a new integration, stop by our [community section](https://www.zerotier.com/community/)! +*** +## Build flags + +`SDK_DEBUG` - Turns on SDK activity/warning/error output. Levels of verbosity can be adjusted in `src/SDK_Debug.h` +`SDK_DEBUG_LOGFILE` - Used in conjunction with `SDK_DEBUG`, this will write all SDK debug chatter to a log file. +`SDK_LWIP_DEBUG` +`SDK_BUNDLED` +`SDK_SERVICE` +`SDK_SOCKS_PROXY` +`SDK_UNITY_3D` +`` +`` +`` + + + *** ## Current Integrations diff --git a/make-linux.mk b/make-linux.mk index 35ac462..d22ffb1 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -61,7 +61,10 @@ endif ifeq ($(SDK_DEBUG),1) DEFS+=-DSDK_DEBUG -g endif - +# Log debug chatter to file, path is determined by environment variable ZT_SDK_LOGFILE +ifeq ($(SDK_DEBUG_LOG_TO_FILE),1) + DEFS+=-DSDK_DEBUG_LOG_TO_FILE +endif all: shared_lib check @@ -110,7 +113,7 @@ tests: $(TEST_OBJDIR) $(TEST_TARGETS) clean: rm -rf zerotier-cli zerotier-idtool rm -rf build/* - find . -type f \( -name '*.o' -o -name '*.so' -o -name '*.o.d' -o -name '*.out' \) -delete + find . -type f \( -name '*.o' -o -name '*.so' -o -name '*.o.d' -o -name '*.out' -o -name '*.log' \) -delete # Remove junk generated by Android builds cd integrations/Android/proj; ./gradlew clean rm -rf integrations/Android/proj/.gradle diff --git a/make-mac.mk b/make-mac.mk index 118b6d2..9ed1a83 100644 --- a/make-mac.mk +++ b/make-mac.mk @@ -135,7 +135,7 @@ tests: $(TEST_OBJDIR) $(TEST_TARGETS) clean: rm -rf zerotier-cli zerotier-idtool rm -rf build/* - find . -type f \( -name '*.o' -o -name '*.so' -o -name '*.o.d' -o -name '*.out' \) -delete + find . -type f \( -name '*.o' -o -name '*.so' -o -name '*.o.d' -o -name '*.out' -o -name '*.log' \) -delete # android JNI lib project cd integrations/android/android_jni_lib/proj; ./gradlew clean rm -rf integrations/android/android_jni_lib/proj/.gradle diff --git a/src/SDK_Debug.c b/src/SDK_Debug.c index f38ebff..d9edcf2 100644 --- a/src/SDK_Debug.c +++ b/src/SDK_Debug.c @@ -42,15 +42,14 @@ #include #include -#define DEBUG_LEVEL 5 // Set this to adjust what you'd like to see in the debug traces - +#define DEBUG_LEVEL 4 // Set this to adjust what you'd like to see in the debug traces #define MSG_TRANSFER 1 // RX/TX specific statements #define MSG_ERROR 2 // Errors #define MSG_INFO 3 // Information which is generally useful to any user #define MSG_DEBUG 4 // Information which is only useful to someone debugging #define MSG_DEBUG_EXTRA 5 // If nothing in your world makes sense -#define DEBUG_LOGFILE_PATH "/Users/Joseph/code/ztnc_logfile.txt" +char *debug_logfile = (char*)0; void dwr(int level, const char *fmt, ... ); @@ -74,10 +73,18 @@ void dwr(int level, const char *fmt, ... ) #elif defined(__APPLE__) pid_t tid = pthread_mach_thread_np(pthread_self()); #endif - #if defined(SDK_DEBUG_WRITE_LOGFILE) - FILE *file = fopen(DEBUG_LOGFILE_PATH,"a"); - vfprintf(file, fmt, ap); + #if defined(SDK_DEBUG_LOG_TO_FILE) + if(!debug_logfile) { // Try to get logfile from env + debug_logfile = getenv("ZT_SDK_LOGFILE"); + } + if(debug_logfile) { + FILE *file = fopen(debug_logfile,"a"); + vfprintf(file, fmt, ap); + fclose(file); + va_end(ap); + } #endif + va_start(ap, fmt); fprintf(stderr, "%s [tid=%7d] ", timestring, tid); vfprintf(stderr, fmt, ap); fflush(stderr); diff --git a/src/SDK_Debug.h b/src/SDK_Debug.h index 860cb0b..00a4c98 100644 --- a/src/SDK_Debug.h +++ b/src/SDK_Debug.h @@ -34,6 +34,8 @@ #define MSG_DEBUG 4 // Information which is only useful to someone debugging #define MSG_DEBUG_EXTRA 5 // If nothing in your world makes sense +extern char *debug_logfile; + #ifdef __cplusplus extern "C" { #endif diff --git a/src/SDK_Intercept.c b/src/SDK_Intercept.c index ab9583d..59f667e 100644 --- a/src/SDK_Intercept.c +++ b/src/SDK_Intercept.c @@ -93,8 +93,7 @@ char *api_netpath; void load_symbols() { - dwr(MSG_DEBUG,"load_symbols\n"); - + dwr(MSG_DEBUG_EXTRA,"load_symbols\n"); #if defined(__linux__) realaccept4 = dlsym(RTLD_NEXT, "accept4"); #if !defined(__ANDROID__) @@ -115,7 +114,6 @@ char *api_netpath; realrecvfrom = (int(*)(RECVFROM_SIG))dlsym(RTLD_NEXT, "recvfrom"); realrecvmsg = (int(*)(RECVMSG_SIG))dlsym(RTLD_NEXT, "recvmsg"); #endif - dwr(MSG_DEBUG,"complete\n"); } // ------------------------------------------------------------------------------