More debug

This commit is contained in:
Kim Woelders
2018-10-11 15:18:20 +02:00
parent d85251400f
commit 08e7fb1d7e
+31 -7
View File
@@ -196,10 +196,14 @@ static void *_read_net(void *arg)
int res;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
DBG2("%s: net_cnt=%d\n", __func__, tty->net_cnt);
while (1)
{
res = poll(tty->fds, 3, -1);
DBG2("%s: res=%d events-N/M/S=%#x/%#x/%#x\n", __func__, res,
tty->fds[FD_NET].revents, tty->fds[FD_MASTER].revents,
tty->fds[FD_SLAVE].revents);
if (res < 0)
{
if (errno == EINTR)
@@ -254,6 +258,8 @@ static void *_read_net(void *arg)
}
}
DBG2("%s: done\n", __func__);
tty->error = 1;
_notify(tty);
@@ -305,6 +311,9 @@ static int _srv_write(void *cctx, const void *buf, int len)
res = write(tty->fds[FD_NET].fd, buf, len);
DBG2("%s: fd=%d: len=%u: res=%d\n", __func__,
tty->fds[FD_NET].fd, len, res);
return res;
}
@@ -313,9 +322,12 @@ static int _srv_read(void *cctx, int timeout)
ttynvt_t *tty = cctx;
int res;
DBG2("%s: net_cnt=%d\n", __func__, tty->net_cnt);
while (1)
{
res = poll(&tty->fds[FD_NET], 1, timeout);
DBG("%s: res=%d events-N=%#x\n",
__func__, res, tty->fds[FD_NET].revents);
if (res <= 0)
return res;
@@ -323,10 +335,13 @@ static int _srv_read(void *cctx, int timeout)
{
res = read(tty->fds[FD_NET].fd, tty->net_buf + tty->net_cnt,
NET_BUF_SIZE - tty->net_cnt);
DBG2("%s: fd=%d: res=%d net_cnt=%d\n", __func__,
tty->fds[FD_NET].fd, res, tty->net_cnt);
if (res <= 0)
return res;
tty->net_cnt += res;
res = telnet_rx(tty->tn, tty->net_buf, &tty->net_cnt);
DBG2("%s: res=%d net_cnt=%d\n", __func__, res, tty->net_cnt);
if (res == 0)
break;
}
@@ -373,7 +388,7 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
int res;
int n;
DBG2("open: thread:%lu\n", pthread_self());
DBG("%s\n", __func__);
tty = calloc(1, sizeof(*tty));
if (!tty)
@@ -477,9 +492,11 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off,
ttynvt_t *tty = (ttynvt_t *) (uintptr_t) info->fh;
int res;
DBG2("%s\n", __func__);
if (tty->error)
{
DBG2("read (slave) in error state, thread:%lu\n", pthread_self());
DBG2("%s: tty->error=%d\n", __func__, tty->error);
if (tty->epipe == 0)
{
_log(LOG_WARNING, "Rx EPIPE\n");
@@ -502,12 +519,13 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off,
fuse_req_interrupt_func(req, NULL, NULL);
if (res < 0)
{
DBG2("read (slave) error: %m\n");
DBG2("%s: error: %m\n", __func__);
fuse_reply_err(req, errno);
return;
}
DBG2("read (slave): size:%d, thread:%lu\n", res, pthread_self());
DBG2("%s: fd=%d: sz=%u/%u: '%.*s'\n", __func__,
tty->fds[FD_SLAVE].fd, res, (int)size, res, tty->tmp_buf);
fuse_reply_buf(req, tty->tmp_buf, res);
}
@@ -519,6 +537,8 @@ ttynvt_write(fuse_req_t req, const char *data, size_t size, off_t off,
ttynvt_t *tty = (ttynvt_t *) (uintptr_t) info->fh;
int res;
DBG2("%s: fd=%d: sz=%u: '%.*s'\n", __func__,
tty->fds[FD_SLAVE].fd, (int)size, (int)size, data);
if (size == 0)
{
@@ -528,6 +548,7 @@ ttynvt_write(fuse_req_t req, const char *data, size_t size, off_t off,
if (tty->error)
{
DBG2("%s: tty->error=%d\n", __func__, tty->error);
fuse_reply_err(req, EPIPE);
return;
}
@@ -535,14 +556,12 @@ ttynvt_write(fuse_req_t req, const char *data, size_t size, off_t off,
res = write(tty->fds[FD_SLAVE].fd, data, size);
if (res < 0)
{
DBG2("write (slave) error: %m\n");
DBG2("%s: error: %m\n", __func__);
tty->error = 1;
fuse_reply_err(req, errno);
return;
}
DBG2("write (slave): size:%d, thread:%lu\n", (int)size, pthread_self());
fuse_reply_write(req, res);
}
@@ -891,6 +910,9 @@ ttynvt_poll(fuse_req_t req, struct fuse_file_info *info,
ttynvt_t *tty = (ttynvt_t *) (uintptr_t) info->fh;
int revents = 0;
DBG2("%s: tty->pollin=%d tty->error/epipe=%d/%d\n",
__func__, tty->pollin, tty->error, tty->epipe);
_update_notify(tty, ph);
if (tty->pollin)
@@ -906,6 +928,8 @@ ttynvt_poll(fuse_req_t req, struct fuse_file_info *info,
revents = 0;
}
DBG2("%s: revents=%#x\n", __func__, revents);
fuse_reply_poll(req, revents);
}