Commit 923a89e2 authored by Stas Korobeynikov's avatar Stas Korobeynikov Committed by Pavel Vainerman

add read/write log

parent 7bc9be0f
......@@ -353,6 +353,12 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd,
c->istate = CHAN_INPUT_OPEN;
c->flags = 0;
channel_register_fds(c, rfd, wfd, efd, extusage, nonblock, 0);
#ifdef TEST
logit("NX> 280 Channel opened with in: %d out: %d err: %d",
rfd, wfd, efd);
#endif
c->notbefore = 0;
c->self = found;
c->type = type;
......@@ -1739,6 +1745,17 @@ channel_handle_rfd(Channel *c, fd_set *readset, fd_set *writeset)
if (c->rfd != -1 && (force || FD_ISSET(c->rfd, readset))) {
errno = 0;
len = read(c->rfd, buf, sizeof(buf));
#ifdef TEST
logit("NX> 280 Reading: %u bytes from fd: %d in context: 4",
sizeof(buf) - 1, c->rfd);
#endif
#ifdef TEST
logit("NX> 280 Read: %d bytes error: %d in context: 4",
len, (len < 0 ? errno : 0));
#endif
if (len < 0 && (errno == EINTR ||
((errno == EAGAIN || errno == EWOULDBLOCK) && !force)))
return 1;
......@@ -1829,6 +1846,17 @@ channel_handle_wfd(Channel *c, fd_set *readset, fd_set *writeset)
dlen = MIN(dlen, 8*1024);
#endif
#ifdef TEST
logit("NX> 280 Writing: %d bytes to fd: %d in context: 5",
dlen, c->wfd);
#endif
#ifdef TEST
logit("NX> 280 Written: %d bytes error: %d in context: 5",
len, (len < 0 ? errno : 0));
#endif
len = write(c->wfd, buf, dlen);
if (len < 0 &&
(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
......@@ -1881,8 +1909,19 @@ channel_handle_efd(Channel *c, fd_set *readset, fd_set *writeset)
if (c->extended_usage == CHAN_EXTENDED_WRITE &&
FD_ISSET(c->efd, writeset) &&
buffer_len(&c->extended) > 0) {
#ifdef TEST
logit("NX> 280 Writing: %d bytes to fd: %d in context 6",
buffer_len(&c->extended), c->efd);
#endif
len = write(c->efd, buffer_ptr(&c->extended),
buffer_len(&c->extended));
#ifdef TEST
logit("NX> 280 Written: %d bytes error: %d in context: 6",
len, (len < 0 ? errno : 0));
#endif
debug2("channel %d: written %d to efd %d",
c->self, len, c->efd);
if (len < 0 && (errno == EINTR || errno == EAGAIN ||
......@@ -1900,7 +1939,18 @@ channel_handle_efd(Channel *c, fd_set *readset, fd_set *writeset)
(c->extended_usage == CHAN_EXTENDED_READ ||
c->extended_usage == CHAN_EXTENDED_IGNORE) &&
(c->detach_close || FD_ISSET(c->efd, readset))) {
#ifdef TEST
logit("NX> 280 Reading: %u bytes from fd: %d in context: 5",
sizeof(buf), c->efd);
#endif
len = read(c->efd, buf, sizeof(buf));
#ifdef TEST
logit("NX> 280 Read: %d bytes error: %d in context: 5",
len, (len < 0 ? errno : 0));
#endif
debug2("channel %d: read %d from efd %d",
c->self, len, c->efd);
if (len < 0 && (errno == EINTR || ((errno == EAGAIN ||
......@@ -2087,8 +2137,19 @@ channel_post_output_drain_13(Channel *c, fd_set *readset, fd_set *writeset)
/* Send buffered output data to the socket. */
if (FD_ISSET(c->sock, writeset) && buffer_len(&c->output) > 0) {
#ifdef TEST
logit("NX> 280 Writing: %d bytes to fd: %d in context 7",
buffer_len(&c->output), c->sock);
#endif
len = write(c->sock, buffer_ptr(&c->output),
buffer_len(&c->output));
#ifdef TEST
logit("NX> 280 Written: %d bytes error: %d in context: 7",
len, (len < 0 ? errno : 0));
#endif
if (len <= 0)
buffer_clear(&c->output);
else
......
......@@ -494,7 +494,19 @@ client_check_initial_eof_on_stdin(void)
enter_non_blocking();
/* Check for immediate EOF on stdin. */
#ifdef TEST
logit("NX> 280 Reading: %d bytes from fd: %d in context: 1",
1, fileno(stdin));
#endif
len = read(fileno(stdin), buf, 1);
#ifdef TEST
logit("NX> 280 Read: %d bytes error: %d in context: 1",
len, (len < 0 ? errno : 0));
#endif
if (len == 0) {
/*
* EOF. Record that we have seen it and send
......@@ -774,7 +786,19 @@ client_process_net_input(fd_set *readset)
*/
if (FD_ISSET(connection_in, readset)) {
/* Read as much as possible. */
#ifdef TEST
logit("NX> 280 Reading: %u bytes from fd: %d in context: 2",
sizeof(buf), connection_in);
#endif
len = read(connection_in, buf, sizeof(buf));
#ifdef TEST
logit("NX> 280 Read: %d bytes error: %d in context: 2",
len, (len < 0 ? errno : 0));
#endif
if (len == 0) {
/*
* Received EOF. The remote host has closed the
......@@ -1344,7 +1368,18 @@ client_process_input(fd_set *readset)
/* Read input from stdin. */
if (FD_ISSET(fileno(stdin), readset)) {
/* Read as much as possible. */
#ifdef TEST
logit("NX> 280 Reading: %u bytes from fd: %d in context: 3",
sizeof(buf), fileno(stdin));
#endif
len = read(fileno(stdin), buf, sizeof(buf));
#ifdef TEST
logit("NX> 280 Read: %d bytes error: %d in context: 3",
len, (len < 0 ? errno : 0));
#endif
if (len < 0 &&
(errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK))
return; /* we'll try again later */
......@@ -1400,8 +1435,20 @@ client_process_output(fd_set *writeset)
/* Write buffered output to stdout. */
if (FD_ISSET(fileno(stdout), writeset)) {
/* Write as much data as possible. */
#ifdef TEST
logit("NX> 280 Writing: %d bytes to fd: %d in context: 1",
buffer_len(&stdout_buffer), fileno(stdout));
#endif
len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
buffer_len(&stdout_buffer));
#ifdef TEST
logit("NX> 280 Written: %d bytes error: %d in context: 1",
len, (len < 0 ? errno : 0));
#endif
if (len <= 0) {
if (errno == EINTR || errno == EAGAIN ||
errno == EWOULDBLOCK)
......@@ -1424,8 +1471,20 @@ client_process_output(fd_set *writeset)
/* Write buffered output to stderr. */
if (FD_ISSET(fileno(stderr), writeset)) {
/* Write as much data as possible. */
#ifdef TEST
logit("NX> 280 Writing: %d bytes to fd: %d in context: 2",
buffer_len(&stderr_buffer), fileno(stderr));
#endif
len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
buffer_len(&stderr_buffer));
#ifdef TEST
logit("NX> 280 Written: %d bytes error: %d in context: 2",
len, (len < 0 ? errno : 0));
#endif
if (len <= 0) {
if (errno == EINTR || errno == EAGAIN ||
errno == EWOULDBLOCK)
......@@ -1767,8 +1826,19 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
/* Output any buffered data for stdout. */
if (buffer_len(&stdout_buffer) > 0) {
#ifdef TEST
logit("NX> 280 Writing: %d bytes to fd: %d in context: 3",
buffer_len(&stdout_buffer), fileno(stdout));
#endif
len = atomicio(vwrite, fileno(stdout),
buffer_ptr(&stdout_buffer), buffer_len(&stdout_buffer));
#ifdef TEST
logit("NX> 280 Written: %d bytes error: %d in context: 3",
len, (len < 0 ? errno : 0));
#endif
if (len < 0 || (u_int)len != buffer_len(&stdout_buffer))
error("Write failed flushing stdout buffer.");
else
......@@ -1777,8 +1847,19 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id)
/* Output any buffered data for stderr. */
if (buffer_len(&stderr_buffer) > 0) {
#ifdef TEST
logit("NX> 280 Writing: %d bytes to fd: %d in context: 4",
buffer_len(&stderr_buffer), fileno(stderr));
#endif
len = atomicio(vwrite, fileno(stderr),
buffer_ptr(&stderr_buffer), buffer_len(&stderr_buffer));
#ifdef TEST
logit("NX> 280 Written: %d bytes error: %d in context: 4",
len, (len < 0 ? errno : 0));
#endif
if (len < 0 || (u_int)len != buffer_len(&stderr_buffer))
error("Write failed flushing stderr buffer.");
else
......
......@@ -1476,7 +1476,19 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
goto out;
}
/* Read data from the socket. */
#ifdef TEST
logit("NX> 280 Reading: %u bytes from fd: %d in context: 7",
sizeof(buf), connection_in);
#endif
len = read(state->connection_in, buf, sizeof(buf));
#ifdef TEST
logit("NX> 280 Read: %d bytes error: %d in context: 7",
len, (len < 0 ? errno : 0));
#endif
if (len == 0) {
r = SSH_ERR_CONN_CLOSED;
goto out;
......@@ -2207,8 +2219,19 @@ ssh_packet_write_poll(struct ssh *ssh)
int r;
if (len > 0) {
#ifdef TEST
logit("NX> 280 Writing: %d bytes to fd: %d in context: 8",
len, connection_out);
#endif
len = write(state->connection_out,
sshbuf_ptr(state->output), len);
#ifdef TEST
logit("NX> 280 Written: %d bytes error: %d in context: 8",
len, (len < 0 ? errno : 0));
#endif
if (len == -1) {
if (errno == EINTR || errno == EAGAIN ||
errno == EWOULDBLOCK)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment