From: Jason Andryuk <jandryuk@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>, Wei Liu <wl@xen.org>,
Jason Andryuk <jandryuk@gmail.com>
Subject: [PATCH v2 07/10] vchan-socket-proxy: Switch data_loop() to take state
Date: Wed, 10 Jun 2020 23:29:33 -0400 [thread overview]
Message-ID: <20200611032936.350657-8-jandryuk@gmail.com> (raw)
In-Reply-To: <20200611032936.350657-1-jandryuk@gmail.com>
Switch data_loop to take a pointer to vchan_proxy_state.
No functional change.
This removes a dead store to input_fd identified by Coverity.
Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
---
tools/libvchan/vchan-socket-proxy.c | 65 +++++++++++++++--------------
1 file changed, 33 insertions(+), 32 deletions(-)
diff --git a/tools/libvchan/vchan-socket-proxy.c b/tools/libvchan/vchan-socket-proxy.c
index a932c94c97..29a12260ed 100644
--- a/tools/libvchan/vchan-socket-proxy.c
+++ b/tools/libvchan/vchan-socket-proxy.c
@@ -286,13 +286,13 @@ static void discard_buffers(struct libxenvchan *ctrl) {
}
}
-int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd)
+int data_loop(struct vchan_proxy_state *state)
{
int ret;
int libxenvchan_fd;
int max_fd;
- libxenvchan_fd = libxenvchan_fd_for_select(ctrl);
+ libxenvchan_fd = libxenvchan_fd_for_select(state->ctrl);
for (;;) {
fd_set rfds;
fd_set wfds;
@@ -300,15 +300,15 @@ int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd)
FD_ZERO(&wfds);
max_fd = -1;
- if (input_fd != -1 && insiz != BUFSIZE) {
- FD_SET(input_fd, &rfds);
- if (input_fd > max_fd)
- max_fd = input_fd;
+ if (state->input_fd != -1 && insiz != BUFSIZE) {
+ FD_SET(state->input_fd, &rfds);
+ if (state->input_fd > max_fd)
+ max_fd = state->input_fd;
}
- if (output_fd != -1 && outsiz) {
- FD_SET(output_fd, &wfds);
- if (output_fd > max_fd)
- max_fd = output_fd;
+ if (state->output_fd != -1 && outsiz) {
+ FD_SET(state->output_fd, &wfds);
+ if (state->output_fd > max_fd)
+ max_fd = state->output_fd;
}
FD_SET(libxenvchan_fd, &rfds);
if (libxenvchan_fd > max_fd)
@@ -319,52 +319,53 @@ int data_loop(struct libxenvchan *ctrl, int input_fd, int output_fd)
exit(1);
}
if (FD_ISSET(libxenvchan_fd, &rfds)) {
- libxenvchan_wait(ctrl);
- if (!libxenvchan_is_open(ctrl)) {
+ libxenvchan_wait(state->ctrl);
+ if (!libxenvchan_is_open(state->ctrl)) {
if (verbose)
fprintf(stderr, "vchan client disconnected\n");
while (outsiz)
- socket_wr(output_fd);
- close(output_fd);
- close(input_fd);
- discard_buffers(ctrl);
+ socket_wr(state->output_fd);
+ close(state->output_fd);
+ close(state->input_fd);
+ discard_buffers(state->ctrl);
break;
}
- vchan_wr(ctrl);
+ vchan_wr(state->ctrl);
}
- if (FD_ISSET(input_fd, &rfds)) {
- ret = read(input_fd, inbuf + insiz, BUFSIZE - insiz);
+ if (FD_ISSET(state->input_fd, &rfds)) {
+ ret = read(state->input_fd, inbuf + insiz, BUFSIZE - insiz);
if (ret < 0 && errno != EAGAIN)
exit(1);
if (verbose)
fprintf(stderr, "from-unix: %.*s\n", ret, inbuf + insiz);
if (ret == 0) {
/* EOF on socket, write everything in the buffer and close the
- * input_fd socket */
+ * state->input_fd socket */
while (insiz) {
- vchan_wr(ctrl);
- libxenvchan_wait(ctrl);
+ vchan_wr(state->ctrl);
+ libxenvchan_wait(state->ctrl);
}
- close(input_fd);
- input_fd = -1;
+ close(state->input_fd);
+ state->input_fd = -1;
/* TODO: maybe signal the vchan client somehow? */
break;
}
if (ret)
insiz += ret;
- vchan_wr(ctrl);
+ vchan_wr(state->ctrl);
}
- if (FD_ISSET(output_fd, &wfds))
- socket_wr(output_fd);
- while (libxenvchan_data_ready(ctrl) && outsiz < BUFSIZE) {
- ret = libxenvchan_read(ctrl, outbuf + outsiz, BUFSIZE - outsiz);
+ if (FD_ISSET(state->output_fd, &wfds))
+ socket_wr(state->output_fd);
+ while (libxenvchan_data_ready(state->ctrl) && outsiz < BUFSIZE) {
+ ret = libxenvchan_read(state->ctrl, outbuf + outsiz,
+ BUFSIZE - outsiz);
if (ret < 0)
exit(1);
if (verbose)
fprintf(stderr, "from-vchan: %.*s\n", ret, outbuf + outsiz);
outsiz += ret;
- socket_wr(output_fd);
+ socket_wr(state->output_fd);
}
}
return 0;
@@ -481,7 +482,7 @@ int main(int argc, char **argv)
ret = 1;
break;
}
- if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0)
+ if (data_loop(&state) != 0)
break;
/* keep it running only when get UNIX socket path */
if (socket_path[0] != '/')
@@ -504,7 +505,7 @@ int main(int argc, char **argv)
ret = 1;
break;
}
- if (data_loop(state.ctrl, state.input_fd, state.output_fd) != 0)
+ if (data_loop(&state) != 0)
break;
/* don't reconnect if output was stdout */
if (strcmp(socket_path, "-") == 0)
--
2.25.1
next prev parent reply other threads:[~2020-06-11 3:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 3:29 [PATCH v2 00/10] Coverity fixes for vchan-socket-proxy Jason Andryuk
2020-06-11 3:29 ` [PATCH v2 01/10] vchan-socket-proxy: Ensure UNIX path NUL terminated Jason Andryuk
2020-06-11 3:29 ` [PATCH v2 02/10] vchan-socket-proxy: Move perror() into listen_socket Jason Andryuk
2020-06-11 3:29 ` [PATCH v2 03/10] vchan-socket-proxy: Move perror() into connect_socket Jason Andryuk
2020-06-11 3:29 ` [PATCH v2 04/10] vchan-socket-proxy: Check xs_watch return value Jason Andryuk
2020-06-11 3:29 ` [PATCH v2 05/10] vchan-socket-proxy: Unify main " Jason Andryuk
2020-06-11 3:29 ` [PATCH v2 06/10] vchan-socket-proxy: Use a struct to store state Jason Andryuk
2020-06-11 3:29 ` Jason Andryuk [this message]
2020-06-11 3:29 ` [PATCH v2 08/10] vchan-socket-proxy: Set closed FDs to -1 Jason Andryuk
2020-06-11 3:29 ` [PATCH v2 09/10] vchan-socket-proxy: Cleanup resources on exit Jason Andryuk
2020-06-11 3:29 ` [PATCH v2 10/10] vchan-socket-proxy: Handle closing shared input/output_fd Jason Andryuk
2020-06-26 10:18 ` [PATCH v2 00/10] Coverity fixes for vchan-socket-proxy Wei Liu
2020-06-26 10:41 ` Paul Durrant
2020-06-26 11:12 ` Marek Marczykowski-Górecki
2020-06-26 11:31 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200611032936.350657-8-jandryuk@gmail.com \
--to=jandryuk@gmail.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.