qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 09/15] tap: Convert launch_script() to Error
Date: Tue, 12 May 2015 14:03:01 +0200	[thread overview]
Message-ID: <1431432187-10993-10-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1431432187-10993-1-git-send-email-armbru@redhat.com>

Fixes inappropriate use of stderr in monitor command handler.

While there, improve the messages some.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 net/tap.c | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index d1f5644..08bfc51 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -59,7 +59,8 @@ typedef struct TAPState {
     unsigned host_vnet_hdr_len;
 } TAPState;
 
-static int launch_script(const char *setup_script, const char *ifname, int fd);
+static void launch_script(const char *setup_script, const char *ifname,
+                          int fd, Error **errp);
 
 static int tap_can_send(void *opaque);
 static void tap_send(void *opaque);
@@ -288,6 +289,7 @@ static void tap_set_offload(NetClientState *nc, int csum, int tso4,
 static void tap_cleanup(NetClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    Error **err = NULL;
 
     if (s->vhost_net) {
         vhost_net_cleanup(s->vhost_net);
@@ -296,8 +298,12 @@ static void tap_cleanup(NetClientState *nc)
 
     qemu_purge_queued_packets(nc);
 
-    if (s->down_script[0])
-        launch_script(s->down_script, s->down_script_arg, s->fd);
+    if (s->down_script[0]) {
+        launch_script(s->down_script, s->down_script_arg, s->fd, &err);
+        if (err) {
+            error_report_err(err);
+        }
+    }
 
     tap_read_poll(s, false);
     tap_write_poll(s, false);
@@ -368,7 +374,8 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
     return s;
 }
 
-static int launch_script(const char *setup_script, const char *ifname, int fd)
+static void launch_script(const char *setup_script, const char *ifname,
+                          int fd, Error **errp)
 {
     int pid, status;
     char *args[3];
@@ -376,6 +383,11 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
 
     /* try to launch network script */
     pid = fork();
+    if (pid < 0) {
+        error_setg_errno(errp, errno, "could not launch network script %s",
+                         setup_script);
+        return;
+    }
     if (pid == 0) {
         int open_max = sysconf(_SC_OPEN_MAX), i;
 
@@ -390,17 +402,17 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
         *parg = NULL;
         execv(setup_script, args);
         _exit(1);
-    } else if (pid > 0) {
+    } else {
         while (waitpid(pid, &status, 0) != pid) {
             /* loop */
         }
 
         if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
-            return 0;
+            return;
         }
+        error_setg(errp, "network script %s failed with status %d",
+                   setup_script, status);
     }
-    fprintf(stderr, "%s: could not launch network script\n", setup_script);
-    return -1;
 }
 
 static int recv_fd(int c)
@@ -571,6 +583,7 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,
                         const char *setup_script, char *ifname,
                         size_t ifname_sz, int mq_required)
 {
+    Error **err = NULL;
     int fd, vnet_hdr_required;
 
     if (tap->has_vnet_hdr) {
@@ -589,10 +602,13 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,
 
     if (setup_script &&
         setup_script[0] != '\0' &&
-        strcmp(setup_script, "no") != 0 &&
-        launch_script(setup_script, ifname, fd)) {
-        close(fd);
-        return -1;
+        strcmp(setup_script, "no") != 0) {
+        launch_script(setup_script, ifname, fd, &err);
+        if (err) {
+            error_report_err(err);
+            close(fd);
+            return -1;
+        }
     }
 
     return fd;
-- 
1.9.3

  parent reply	other threads:[~2015-05-12 12:03 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-12 12:02 [Qemu-devel] [PATCH 00/15] net: Improve error reporting Markus Armbruster
2015-05-12 12:02 ` [Qemu-devel] [PATCH 01/15] net: Improve error message for -net hubport a bit Markus Armbruster
2015-05-14 15:13   ` Eric Blake
2015-05-12 12:02 ` [Qemu-devel] [PATCH 02/15] net: Permit incremental conversion of init functions to Error Markus Armbruster
2015-05-14 15:45   ` Eric Blake
2015-05-12 12:02 ` [Qemu-devel] [PATCH 03/15] net: Improve -net nic error reporting Markus Armbruster
2015-05-14 16:07   ` Eric Blake
2015-05-15  8:38     ` Markus Armbruster
2015-05-12 12:02 ` [Qemu-devel] [PATCH 04/15] net/dump: Improve -net/host_net_add dump " Markus Armbruster
2015-05-14 16:37   ` Eric Blake
2015-05-12 12:02 ` [Qemu-devel] [PATCH 05/15] tap: net_tap_fd_init() can't fail, drop dead error handling Markus Armbruster
2015-05-14 16:48   ` Eric Blake
2015-05-15  8:42     ` Markus Armbruster
2015-05-12 12:02 ` [Qemu-devel] [PATCH 06/15] tap: Improve -netdev/netdev_add/-net/... bridge error reporting Markus Armbruster
2015-05-14 16:56   ` Eric Blake
2015-05-12 12:02 ` [Qemu-devel] [PATCH 07/15] tap: Convert tap_set_sndbuf() to Error Markus Armbruster
2015-05-14 17:02   ` Eric Blake
2015-05-12 12:03 ` [Qemu-devel] [PATCH 08/15] tap: Convert net_init_tap_one() " Markus Armbruster
2015-05-14 17:04   ` Eric Blake
2015-05-12 12:03 ` Markus Armbruster [this message]
2015-05-14 20:21   ` [Qemu-devel] [PATCH 09/15] tap: Convert launch_script() " Eric Blake
2015-05-12 12:03 ` [Qemu-devel] [PATCH 10/15] tap: Permit incremental conversion of tap_open() " Markus Armbruster
2015-05-14 21:49   ` Eric Blake
2015-05-12 12:03 ` [Qemu-devel] [PATCH 11/15] tap-linux: Convert " Markus Armbruster
2015-05-14 21:52   ` Eric Blake
2015-05-12 12:03 ` [Qemu-devel] [PATCH 12/15] tap-bsd: " Markus Armbruster
2015-05-14 21:55   ` Eric Blake
2015-05-15  8:44     ` Markus Armbruster
2015-05-12 12:03 ` [Qemu-devel] [PATCH 13/15] tap-solaris: " Markus Armbruster
2015-05-14 22:00   ` Eric Blake
2015-05-15  8:48     ` Markus Armbruster
2015-05-12 12:03 ` [Qemu-devel] [PATCH 14/15] tap: Finish conversion of " Markus Armbruster
2015-05-14 22:01   ` Eric Blake
2015-05-12 12:03 ` [Qemu-devel] [PATCH 15/15] tap: Improve -netdev/netdev_add/-net/... tap error reporting Markus Armbruster
2015-05-14 22:24   ` Eric Blake
2015-05-15  8:49     ` Markus Armbruster

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=1431432187-10993-10-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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;
as well as URLs for NNTP newsgroup(s).