diff mbox

[v3,05/14] qga: Use return values instead of error_is_set(errp)

Message ID 1399030002-27222-6-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster May 2, 2014, 11:26 a.m. UTC
Using error_is_set(errp) to check whether a function call failed is
fragile: it breaks when errp is null.  ga_get_fd_handle() and
guest_file_handle_add() don't return a useful value when they fail,
but that's just stupid.  Fix that, and check them instead.  As far
as I can tell, errp can't be null there, but this is more robust and
more obviously correct.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/commands-posix.c | 6 +++---
 qga/main.c           | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index f6af7d1..6af974f 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -223,8 +223,8 @@  static int64_t guest_file_handle_add(FILE *fh, Error **errp)
     int64_t handle;
 
     handle = ga_get_fd_handle(ga_state, errp);
-    if (error_is_set(errp)) {
-        return 0;
+    if (handle < 0) {
+        return -1;
     }
 
     gfh = g_malloc0(sizeof(GuestFileHandle));
@@ -407,7 +407,7 @@  int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode,
     }
 
     handle = guest_file_handle_add(fh, errp);
-    if (error_is_set(errp)) {
+    if (handle < 0) {
         fclose(fh);
         return -1;
     }
diff --git a/qga/main.c b/qga/main.c
index d838c3e..eb792a3 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -910,6 +910,7 @@  int64_t ga_get_fd_handle(GAState *s, Error **errp)
 
     if (!write_persistent_state(&s->pstate, s->pstate_filepath)) {
         error_setg(errp, "failed to commit persistent state to disk");
+        return -1;
     }
 
     return handle;