add trace option '-t' to sj3proxy.
it makes debugging easy.
This commit is contained in:
parent
c90c1d0078
commit
509c85f69f
6 changed files with 27 additions and 7 deletions
|
|
@ -361,7 +361,7 @@ AC_CHECK_FUNCS([ \
|
|||
strerror \
|
||||
strlcat \
|
||||
strlcpy \
|
||||
strnvis \
|
||||
strvisx \
|
||||
strrchr \
|
||||
strstr \
|
||||
strtol \
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
EXTRA_DIST = sj3compat.h sys-queue.h
|
||||
EXTRA_DIST = sj3compat.h sj3vis.h sys-queue.h
|
||||
|
||||
|
|
|
|||
|
|
@ -126,9 +126,9 @@ size_t sj3_strlcpy(char *, const char *, size_t);
|
|||
#endif
|
||||
|
||||
/* vis.c */
|
||||
#ifndef HAVE_STRNVIS
|
||||
#define strnvis sj3strnvis
|
||||
int strnvis(char *, const char *, size_t, int);
|
||||
#ifndef HAVE_STRVISX
|
||||
#define strvisx sj3strvisx
|
||||
int strvisx(char *, const char *, size_t, int);
|
||||
#endif
|
||||
|
||||
#endif /* SJ3COMPAT_H */
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vis.h"
|
||||
#include "sj3vis.h"
|
||||
|
||||
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
|
||||
#define isvisible(c) \
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@
|
|||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/param.h>
|
||||
#if defined(HAVE_STRVISX) && defined(HAVE_VIS_H)
|
||||
# include <vis.h>
|
||||
#endif
|
||||
#include "sys-queue.h"
|
||||
|
||||
#include <lua.h>
|
||||
|
|
@ -50,6 +53,8 @@ char socket_file[MAXPATHLEN];
|
|||
char host_name[NI_MAXHOST];
|
||||
char service_name[NI_MAXSERV];
|
||||
|
||||
static int trace_enable = 0;
|
||||
|
||||
struct listen_addr {
|
||||
TAILQ_ENTRY(listen_addr) entry;
|
||||
struct sockaddr_storage sa;
|
||||
|
|
@ -143,6 +148,12 @@ readwrite(int inet_fd)
|
|||
shutdown(inet_fd, SHUT_RD);
|
||||
return;
|
||||
} else {
|
||||
if (trace_enable) {
|
||||
char fmtbuf[BUFSIZ * 4 + 1];
|
||||
strvisx(fmtbuf, buf, readlen, VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL);
|
||||
fmtbuf[BUFSIZ * 4] = 0;
|
||||
printf("i< %s\n", fmtbuf);
|
||||
}
|
||||
if (atomicio(vwrite, sj3_fd, buf, readlen) != readlen)
|
||||
return;
|
||||
}
|
||||
|
|
@ -156,6 +167,12 @@ readwrite(int inet_fd)
|
|||
shutdown(inet_fd, SHUT_WR);
|
||||
return;
|
||||
} else {
|
||||
if (trace_enable) {
|
||||
char fmtbuf[BUFSIZ * 4 + 1];
|
||||
strvisx(fmtbuf, buf, readlen, VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL);
|
||||
fmtbuf[BUFSIZ * 4] = 0;
|
||||
printf("o> %s\n", fmtbuf);
|
||||
}
|
||||
if (atomicio(vwrite, inet_fd, buf, readlen) != readlen)
|
||||
return;
|
||||
}
|
||||
|
|
@ -217,7 +234,7 @@ main(int argc, char *argv[])
|
|||
int opt_inet4 = 0, opt_inet6 = 0;
|
||||
char *config_file = SJ3PROXYCFG;
|
||||
|
||||
while ((c = getopt(argc, argv, "46c:d")) != EOF) {
|
||||
while ((c = getopt(argc, argv, "46c:dt")) != EOF) {
|
||||
switch (c) {
|
||||
case '4':
|
||||
opt_inet4 = 1;
|
||||
|
|
@ -231,6 +248,9 @@ main(int argc, char *argv[])
|
|||
case 'd':
|
||||
daemon_disable = 1;
|
||||
break;
|
||||
case 't':
|
||||
trace_enable = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
errflg++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue