mirror of
https://github.com/bol-van/zapret.git
synced 2025-08-10 01:02:03 +03:00
nfqws,tpws: --debug=android for NDK builds
This commit is contained in:
@@ -2,6 +2,7 @@ CC ?= gcc
|
||||
CFLAGS += -std=gnu99 -Os -flto=auto
|
||||
CFLAGS_SYSTEMD = -DUSE_SYSTEMD
|
||||
CFLAGS_BSD = -Wno-address-of-packed-member
|
||||
LDFLAGS_ANDROID = -llog
|
||||
LIBS = -lz -lpthread
|
||||
LIBS_SYSTEMD = -lsystemd
|
||||
LIBS_ANDROID = -lz
|
||||
@@ -17,7 +18,7 @@ systemd: $(SRC_FILES)
|
||||
$(CC) -s $(CFLAGS) $(CFLAGS_SYSTEMD) -o tpws $(SRC_FILES) $(LIBS) $(LIBS_SYSTEMD) $(LDFLAGS)
|
||||
|
||||
android: $(SRC_FILES)
|
||||
$(CC) -s $(CFLAGS) -o tpws $(SRC_FILES_ANDROID) $(LIBS_ANDROID) $(LDFLAGS)
|
||||
$(CC) -s $(CFLAGS) -o tpws $(SRC_FILES_ANDROID) $(LIBS_ANDROID) $(LDFLAGS) $(LDFLAGS_ANDROID)
|
||||
|
||||
bsd: $(SRC_FILES)
|
||||
$(CC) -s $(CFLAGS) $(CFLAGS_BSD) -Iepoll-shim/include -o tpws $(SRC_FILES) epoll-shim/src/*.c $(LIBS) $(LDFLAGS)
|
||||
|
@@ -2,6 +2,11 @@
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
#include <errno.h>
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
const char *progname = "tpws";
|
||||
|
||||
int DLOG_FILE(FILE *F, const char *format, va_list args)
|
||||
{
|
||||
@@ -25,18 +30,47 @@ int DLOG_FILENAME(const char *filename, const char *format, va_list args)
|
||||
return r;
|
||||
}
|
||||
|
||||
static char syslog_buf[1024];
|
||||
static size_t syslog_buf_sz=0;
|
||||
static void syslog_buffered(int priority, const char *format, va_list args)
|
||||
typedef void (*f_log_function)(int priority, const char *line);
|
||||
|
||||
static char log_buf[1024];
|
||||
static size_t log_buf_sz=0;
|
||||
static void syslog_log_function(int priority, const char *line)
|
||||
{
|
||||
if (vsnprintf(syslog_buf+syslog_buf_sz,sizeof(syslog_buf)-syslog_buf_sz,format,args)>0)
|
||||
syslog(priority,"%s",log_buf);
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
enum android_LogPriority syslog_priority_to_android(int priority)
|
||||
{
|
||||
enum android_LogPriority ap;
|
||||
switch(priority)
|
||||
{
|
||||
syslog_buf_sz=strlen(syslog_buf);
|
||||
case LOG_INFO:
|
||||
case LOG_NOTICE: ap=ANDROID_LOG_INFO; break;
|
||||
case LOG_ERR: ap=ANDROID_LOG_ERROR; break;
|
||||
case LOG_WARNING: ap=ANDROID_LOG_WARN; break;
|
||||
case LOG_EMERG:
|
||||
case LOG_ALERT:
|
||||
case LOG_CRIT: ap=ANDROID_LOG_FATAL; break;
|
||||
case LOG_DEBUG: ap=ANDROID_LOG_DEBUG; break;
|
||||
default: ap=ANDROID_LOG_UNKNOWN;
|
||||
}
|
||||
return ap;
|
||||
}
|
||||
static void android_log_function(int priority, const char *line)
|
||||
{
|
||||
__android_log_print(syslog_priority_to_android(priority), progname, "%s", line);
|
||||
}
|
||||
#endif
|
||||
static void log_buffered(f_log_function log_function, int syslog_priority, const char *format, va_list args)
|
||||
{
|
||||
if (vsnprintf(log_buf+log_buf_sz,sizeof(log_buf)-log_buf_sz,format,args)>0)
|
||||
{
|
||||
log_buf_sz=strlen(log_buf);
|
||||
// log when buffer is full or buffer ends with \n
|
||||
if (syslog_buf_sz>=(sizeof(syslog_buf)-1) || (syslog_buf_sz && syslog_buf[syslog_buf_sz-1]=='\n'))
|
||||
if (log_buf_sz>=(sizeof(log_buf)-1) || (log_buf_sz && log_buf[log_buf_sz-1]=='\n'))
|
||||
{
|
||||
syslog(priority,"%s",syslog_buf);
|
||||
syslog_buf_sz = 0;
|
||||
log_function(syslog_priority,log_buf);
|
||||
log_buf_sz = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,9 +98,16 @@ static int DLOG_VA(const char *format, int syslog_priority, bool condup, int lev
|
||||
break;
|
||||
case LOG_TARGET_SYSLOG:
|
||||
// skip newlines
|
||||
syslog_buffered(syslog_priority,format,args);
|
||||
log_buffered(syslog_log_function,syslog_priority,format,args);
|
||||
r = 1;
|
||||
break;
|
||||
#ifdef __ANDROID__
|
||||
case LOG_TARGET_ANDROID:
|
||||
// skip newlines
|
||||
log_buffered(android_log_function,syslog_priority,format,args);
|
||||
r = 1;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include <wordexp.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "tpws.h"
|
||||
#include "pools.h"
|
||||
#include "helpers.h"
|
||||
@@ -38,7 +39,7 @@ struct bind_s
|
||||
|
||||
#define MAX_SPLITS 16
|
||||
|
||||
enum log_target { LOG_TARGET_CONSOLE=0, LOG_TARGET_FILE, LOG_TARGET_SYSLOG };
|
||||
enum log_target { LOG_TARGET_CONSOLE=0, LOG_TARGET_FILE, LOG_TARGET_SYSLOG, LOG_TARGET_ANDROID };
|
||||
|
||||
struct desync_profile
|
||||
{
|
||||
@@ -153,6 +154,7 @@ struct params_s
|
||||
};
|
||||
|
||||
extern struct params_s params;
|
||||
extern const char *progname;
|
||||
|
||||
int DLOG(const char *format, int level, ...);
|
||||
int DLOG_CONDUP(const char *format, ...);
|
||||
|
20
tpws/tpws.c
20
tpws/tpws.c
@@ -224,7 +224,11 @@ static void exithelp(void)
|
||||
#endif
|
||||
" --ipcache-lifetime=<int>\t\t; time in seconds to keep cached domain name (default %u). 0 = no expiration\n"
|
||||
" --ipcache-hostname=[0|1]\t\t; 1 or no argument enables ip->hostname caching\n"
|
||||
#ifdef __ANDROID__
|
||||
" --debug=0|1|2|syslog|android|@<filename> ; 1 and 2 means log to console and set debug level. for other targets use --debug-level.\n"
|
||||
#else
|
||||
" --debug=0|1|2|syslog|@<filename>\t; 1 and 2 means log to console and set debug level. for other targets use --debug-level.\n"
|
||||
#endif
|
||||
" --debug-level=0|1|2\t\t\t; specify debug level\n"
|
||||
" --dry-run\t\t\t\t; verify parameters and exit with code 0 if successful\n"
|
||||
" --version\t\t\t\t; print version and exit\n"
|
||||
@@ -1345,13 +1349,25 @@ void parse_params(int argc, char *argv[])
|
||||
{
|
||||
if (!params.debug) params.debug = 1;
|
||||
params.debug_target = LOG_TARGET_SYSLOG;
|
||||
openlog("tpws",LOG_PID,LOG_USER);
|
||||
openlog(progname,LOG_PID,LOG_USER);
|
||||
}
|
||||
else
|
||||
#ifdef __ANDROID__
|
||||
else if (!strcmp(optarg,"android"))
|
||||
{
|
||||
if (!params.debug) params.debug = 1;
|
||||
params.debug_target = LOG_TARGET_ANDROID;
|
||||
}
|
||||
#endif
|
||||
else if (optarg[0]>='0' && optarg[0]<='2')
|
||||
{
|
||||
params.debug = atoi(optarg);
|
||||
params.debug_target = LOG_TARGET_CONSOLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "invalid debug mode : %s\n", optarg);
|
||||
exit_clean(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user