From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MHLJC-0006fl-FU for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MHLJ7-0006Zb-28 for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:54 -0400 Received: from [199.232.76.173] (port=43814 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MHLJ6-0006ZP-UN for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:48 -0400 Received: from mail26.svc.cra.dublin.eircom.net ([159.134.118.55]:45809) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MHLJ6-0008Ua-DW for qemu-devel@nongnu.org; Thu, 18 Jun 2009 13:21:48 -0400 From: Mark McLoughlin Date: Thu, 18 Jun 2009 18:21:33 +0100 Message-Id: <1245345696-20915-6-git-send-email-markmc@redhat.com> In-Reply-To: <1245345696-20915-5-git-send-email-markmc@redhat.com> References: <1245345696-20915-1-git-send-email-markmc@redhat.com> <1245345696-20915-2-git-send-email-markmc@redhat.com> <1245345696-20915-3-git-send-email-markmc@redhat.com> <1245345696-20915-4-git-send-email-markmc@redhat.com> <1245345696-20915-5-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH 5/8] net: return TAPState from net_tap_init() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Mark McLoughlin net_tap_fd_init() already returns TAPState, so this is a sensible cleanup in its own right. Signed-off-by: Mark McLoughlin --- net.c | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-) diff --git a/net.c b/net.c index e2e73ef..58f3d51 100644 --- a/net.c +++ b/net.c @@ -1429,9 +1429,9 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) return -1; } -static int net_tap_init(VLANState *vlan, const char *model, - const char *name, const char *ifname1, - const char *setup_script, const char *down_script) +static TAPState *net_tap_init(VLANState *vlan, const char *model, + const char *name, const char *ifname1, + const char *setup_script, const char *down_script) { TAPState *s; int fd; @@ -1443,13 +1443,13 @@ static int net_tap_init(VLANState *vlan, const char *model, ifname[0] = '\0'; TFR(fd = tap_open(ifname, sizeof(ifname))); if (fd < 0) - return -1; + return NULL; if (!setup_script || !strcmp(setup_script, "no")) setup_script = ""; - if (setup_script[0] != '\0') { - if (launch_script(setup_script, ifname, fd)) - return -1; + if (setup_script[0] != '\0' && + launch_script(setup_script, ifname, fd)) { + return NULL; } s = net_tap_fd_init(vlan, model, name, fd); snprintf(s->vc->info_str, sizeof(s->vc->info_str), @@ -1459,7 +1459,7 @@ static int net_tap_init(VLANState *vlan, const char *model, snprintf(s->down_script, sizeof(s->down_script), "%s", down_script); snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname); } - return 0; + return s; } #endif /* !_WIN32 */ @@ -2291,6 +2291,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) if (!strcmp(device, "tap")) { char ifname[64], chkbuf[64]; char setup_script[1024], down_script[1024]; + TAPState *s; int fd; vlan->nb_host_devs++; if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { @@ -2301,8 +2302,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) } fd = strtol(buf, NULL, 0); fcntl(fd, F_SETFL, O_NONBLOCK); - net_tap_fd_init(vlan, device, name, fd); - ret = 0; + s = net_tap_fd_init(vlan, device, name, fd); } else { static const char * const tap_params[] = { "vlan", "name", "ifname", "script", "downscript", NULL @@ -2321,7 +2321,12 @@ int net_client_init(Monitor *mon, const char *device, const char *p) if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) { pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT); } - ret = net_tap_init(vlan, device, name, ifname, setup_script, down_script); + s = net_tap_init(vlan, device, name, ifname, setup_script, down_script); + } + if (s != NULL) { + ret = 0; + } else { + ret = -1; } } else #endif -- 1.6.0.6