Enable debug logging data too

This commit is contained in:
Kim Woelders
2018-10-15 07:55:00 +02:00
parent 08e7fb1d7e
commit 6dc40e44e2
+36
View File
@@ -97,10 +97,38 @@ _PRF2_ static void _log(int prio, const char *fmt, ...)
va_end(arg); va_end(arg);
} }
#define BPL 16 /* Bytes per line */
void _log_buf(int prio, const char *txt, const void *ptr_, unsigned int len)
{
unsigned int ix, i, imax;
int l, n;
char buf[128];
const unsigned char *ptr = ptr_;
for (ix = 0; ix < len || (len == 0 && ix == 0); ix += BPL)
{
n = snprintf(buf, sizeof(buf), "%s: %04x:", txt, ix);
if (n <= 0)
return; /* Just playing it safe */
imax = (len - ix < BPL) ? len - ix : BPL;
for (i = 0; i < imax; i++)
{
l = snprintf(buf + n, sizeof(buf) - n, " %02x", *ptr++);
if (l <= 0)
return; /* Just playing it safe */
n += l;
}
_log(prio, "%s\n", buf);
}
}
#define DBG(...) \ #define DBG(...) \
if (ttynvt_param.debug > 0) _log(LOG_DEBUG, __VA_ARGS__) if (ttynvt_param.debug > 0) _log(LOG_DEBUG, __VA_ARGS__)
#define DBG2(...) \ #define DBG2(...) \
if (ttynvt_param.debug > 1) _log(LOG_DEBUG, __VA_ARGS__) if (ttynvt_param.debug > 1) _log(LOG_DEBUG, __VA_ARGS__)
#define DBG2_BUF(txt, ptr, len) \
if (ttynvt_param.debug > 1) _log_buf(LOG_DEBUG, txt, ptr, len)
static volatile char _is_interrupted = 0; static volatile char _is_interrupted = 0;
@@ -226,9 +254,12 @@ static void *_read_net(void *arg)
break; break;
} }
tty->net_cnt += res; tty->net_cnt += res;
DBG2_BUF("Serv in A", tty->net_buf, tty->net_cnt);
res = telnet_rx(tty->tn, tty->net_buf, &tty->net_cnt); res = telnet_rx(tty->tn, tty->net_buf, &tty->net_cnt);
DBG2_BUF("Serv in B", tty->net_buf, tty->net_cnt);
if (tty->net_cnt > 0 && res == 0) if (tty->net_cnt > 0 && res == 0)
{ {
DBG2_BUF("TtyM out ", tty->net_buf, tty->net_cnt);
res = res =
write(tty->fds[FD_MASTER].fd, tty->net_buf, tty->net_cnt); write(tty->fds[FD_MASTER].fd, tty->net_buf, tty->net_cnt);
if (res < 0) if (res < 0)
@@ -248,6 +279,7 @@ static void *_read_net(void *arg)
_log(LOG_ERR, "master read error: %m\n"); _log(LOG_ERR, "master read error: %m\n");
break; break;
} }
DBG2_BUF("TtyM in ", tty->tmp_buf, res);
telnet_tx(tty->tn, tty->tmp_buf, res); telnet_tx(tty->tn, tty->tmp_buf, res);
} }
@@ -309,6 +341,8 @@ static int _srv_write(void *cctx, const void *buf, int len)
ttynvt_t *tty = cctx; ttynvt_t *tty = cctx;
int res; int res;
DBG2_BUF("Serv out ", buf, len);
res = write(tty->fds[FD_NET].fd, buf, len); res = write(tty->fds[FD_NET].fd, buf, len);
DBG2("%s: fd=%d: len=%u: res=%d\n", __func__, DBG2("%s: fd=%d: len=%u: res=%d\n", __func__,
@@ -340,7 +374,9 @@ static int _srv_read(void *cctx, int timeout)
if (res <= 0) if (res <= 0)
return res; return res;
tty->net_cnt += res; tty->net_cnt += res;
DBG2_BUF("Serv in a", tty->net_buf, tty->net_cnt);
res = telnet_rx(tty->tn, tty->net_buf, &tty->net_cnt); res = telnet_rx(tty->tn, tty->net_buf, &tty->net_cnt);
DBG2_BUF("Serv in b", tty->net_buf, tty->net_cnt);
DBG2("%s: res=%d net_cnt=%d\n", __func__, res, tty->net_cnt); DBG2("%s: res=%d net_cnt=%d\n", __func__, res, tty->net_cnt);
if (res == 0) if (res == 0)
break; break;