From: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
linux-kernel@vger.kernel.org, yrl.pp-manager.tt@hitachi.com
Subject: [PATCH V2 1/5] [CLEANUP] trace-cmd: Split out binding a port and fork reader from open_udp()
Date: Fri, 13 Sep 2013 11:06:30 +0900 [thread overview]
Message-ID: <20130913020630.28927.94339.stgit@yunodevel> (raw)
In-Reply-To: <20130913020627.28927.69090.stgit@yunodevel>
Split out binding a port and fork reader from open_udp() for avoiding duplicate
codes between listen mode and virt-server mode.
Changes in V2: Add a comment in open_udp()
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
---
trace-listen.c | 38 ++++++++++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/trace-listen.c b/trace-listen.c
index 8b8f02c..bf187c9 100644
--- a/trace-listen.c
+++ b/trace-listen.c
@@ -228,13 +228,12 @@ static void process_udp_child(int sfd, const char *host, const char *port,
#define START_PORT_SEARCH 1500
#define MAX_PORT_SEARCH 6000
-static int open_udp(const char *node, const char *port, int *pid,
- int cpu, int pagesize, int start_port)
+static int udp_bind_a_port(int start_port, int *sfd)
{
struct addrinfo hints;
struct addrinfo *result, *rp;
- int sfd, s;
char buf[BUFSIZ];
+ int s;
int num_port = start_port;
again:
@@ -250,15 +249,15 @@ static int open_udp(const char *node, const char *port, int *pid,
pdie("getaddrinfo: error opening udp socket");
for (rp = result; rp != NULL; rp = rp->ai_next) {
- sfd = socket(rp->ai_family, rp->ai_socktype,
- rp->ai_protocol);
- if (sfd < 0)
+ *sfd = socket(rp->ai_family, rp->ai_socktype,
+ rp->ai_protocol);
+ if (*sfd < 0)
continue;
- if (bind(sfd, rp->ai_addr, rp->ai_addrlen) == 0)
+ if (bind(*sfd, rp->ai_addr, rp->ai_addrlen) == 0)
break;
- close(sfd);
+ close(*sfd);
}
if (rp == NULL) {
@@ -270,6 +269,12 @@ static int open_udp(const char *node, const char *port, int *pid,
freeaddrinfo(result);
+ return num_port;
+}
+
+static void fork_udp_reader(int sfd, const char *node, const char *port,
+ int *pid, int cpu, int pagesize)
+{
*pid = fork();
if (*pid < 0)
@@ -279,6 +284,23 @@ static int open_udp(const char *node, const char *port, int *pid,
process_udp_child(sfd, node, port, cpu, pagesize);
close(sfd);
+}
+
+static int open_udp(const char *node, const char *port, int *pid,
+ int cpu, int pagesize, int start_port)
+{
+ int sfd;
+ int num_port;
+
+ /*
+ * udp_bind_a_port() currently does not return an error, but if that
+ * changes in the future, we have a check for it now.
+ */
+ num_port = udp_bind_a_port(start_port, &sfd);
+ if (num_port < 0)
+ return num_port;
+
+ fork_udp_reader(sfd, node, port, pid, cpu, pagesize);
return num_port;
}
next prev parent reply other threads:[~2013-09-13 2:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-13 2:06 [PATCH V2 0/5] trace-cmd: Support the feature recording trace data of guests on the host Yoshihiro YUNOMAE
2013-09-13 2:06 ` Yoshihiro YUNOMAE [this message]
2013-09-13 2:06 ` [PATCH V2 2/5] trace-cmd: Apply the trace-msg protocol for communication between a server and clients Yoshihiro YUNOMAE
2013-10-15 2:21 ` Steven Rostedt
2013-10-17 6:34 ` Yoshihiro YUNOMAE
2013-10-17 21:21 ` Steven Rostedt
2013-10-18 2:19 ` Steven Rostedt
2013-10-22 8:53 ` Yoshihiro YUNOMAE
2013-09-13 2:06 ` [PATCH V2 3/5] trace-cmd: Use poll(2) to wait for a message Yoshihiro YUNOMAE
2013-09-13 2:06 ` [PATCH V2 4/5] trace-cmd: Add virt-server mode for a virtualization environment Yoshihiro YUNOMAE
2013-10-18 2:32 ` Steven Rostedt
2013-10-22 8:55 ` Yoshihiro YUNOMAE
2013-09-13 2:06 ` [PATCH V2 5/5] trace-cmd: Add --virt option for record mode Yoshihiro YUNOMAE
2013-10-11 1:39 ` [PATCH V2 0/5] trace-cmd: Support the feature recording trace data of guests on the host Yoshihiro YUNOMAE
2013-10-11 1:46 ` Steven Rostedt
2013-10-14 21:26 ` Steven Rostedt
2013-10-17 6:32 ` Yoshihiro YUNOMAE
2013-10-17 21:11 ` Steven Rostedt
2013-10-18 15:06 ` Steven Rostedt
2013-10-22 8:53 ` Yoshihiro YUNOMAE
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=20130913020630.28927.94339.stgit@yunodevel \
--to=yoshihiro.yunomae.ez@hitachi.com \
--cc=hidehiro.kawai.ez@hitachi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=rostedt@goodmis.org \
--cc=yrl.pp-manager.tt@hitachi.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox