[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 1/2] command: improve allocation failure reporting



* src/util/command.c (virCommandAddEnvString): Remove duplicate
code.
(virCommandToString, virCommandRun, virCommandRunAsync)
(virCommandWait): Report NULL command as ENOMEM, not invalid
usage.
Reported by Jiri Denemark.
---

New patch.  Fixes the root cause, so that patch 2 can
be smaller...

 src/util/command.c |   43 ++++++++++++++++++++-----------------------
 1 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/util/command.c b/src/util/command.c
index 38d462b..c0520ec 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -292,9 +292,6 @@ virCommandAddEnvPair(virCommandPtr cmd, const char *name, const char *value)
 void
 virCommandAddEnvString(virCommandPtr cmd, const char *str)
 {
-    if (!cmd || cmd->has_error)
-        return;
-
     char *env;

     if (!cmd || cmd->has_error)
@@ -710,13 +707,13 @@ virCommandToString(virCommandPtr cmd)

     /* Cannot assume virCommandRun will be called; so report the error
      * now.  If virCommandRun is called, it will report the same error. */
-    if (!cmd || cmd->has_error == -1) {
-        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("invalid use of command API"));
+    if (!cmd ||cmd->has_error == ENOMEM) {
+        virReportOOMError();
         return NULL;
     }
-    if (cmd->has_error == ENOMEM) {
-        virReportOOMError();
+    if (cmd->has_error) {
+        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
+                        _("invalid use of command API"));
         return NULL;
     }

@@ -876,13 +873,13 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
     char *errbuf = NULL;
     int infd[2];

-    if (!cmd || cmd->has_error == -1) {
-        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("invalid use of command API"));
+    if (!cmd ||cmd->has_error == ENOMEM) {
+        virReportOOMError();
         return -1;
     }
-    if (cmd->has_error == ENOMEM) {
-        virReportOOMError();
+    if (cmd->has_error) {
+        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
+                        _("invalid use of command API"));
         return -1;
     }

@@ -994,13 +991,13 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
     char *str;
     int i;

-    if (!cmd || cmd->has_error == -1) {
-        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("invalid use of command API"));
+    if (!cmd || cmd->has_error == ENOMEM) {
+        virReportOOMError();
         return -1;
     }
-    if (cmd->has_error == ENOMEM) {
-        virReportOOMError();
+    if (cmd->has_error) {
+        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
+                        _("invalid use of command API"));
         return -1;
     }

@@ -1065,13 +1062,13 @@ virCommandWait(virCommandPtr cmd, int *exitstatus)
     int ret;
     int status;

-    if (!cmd || cmd->has_error == -1) {
-        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
-                        _("invalid use of command API"));
+    if (!cmd ||cmd->has_error == ENOMEM) {
+        virReportOOMError();
         return -1;
     }
-    if (cmd->has_error == ENOMEM) {
-        virReportOOMError();
+    if (cmd->has_error) {
+        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
+                        _("invalid use of command API"));
         return -1;
     }

-- 
1.7.3.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]