[PATCH 2/2] virCommand: document behavior on no output

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

 



Option 2.  Which one should I go with?  By the way, my pending patch
for converting openvz to use virCommand instead of popen is impacted
(it has a potential null dereference if we go with option 1).

* docs/internals/command.html.in: Update documentation.
* src/util/command.c (virCommandSetOutputBuffer)
(virCommandSetErrorBuffer, virCommandProcessIO) Guarantee empty
string on no output.
---
 docs/internals/command.html.in |    8 +++++---
 src/util/command.c             |   14 ++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/docs/internals/command.html.in b/docs/internals/command.html.in
index ea9ec64..d2fb133 100644
--- a/docs/internals/command.html.in
+++ b/docs/internals/command.html.in
@@ -348,9 +348,11 @@
 </pre>

     <p>
-      Once the command has finished executing, these buffers
-      will contain the output, or be NULL if there was no output. It
-      is the callers responsibility to free these buffers.
+      Once the command has finished executing, these buffers will
+      contain the output.  If there was no output but virCommandRun
+      was successful, then they will be an empty string; if there was
+      an error, then they might still be NULL. It is the callers
+      responsibility to free these buffers.
     </p>

     <h3><a name="directory">Setting working directory</a></h3>
diff --git a/src/util/command.c b/src/util/command.c
index 1923799..4fb5048 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -860,6 +860,20 @@ virCommandProcessIO(virCommandPtr cmd)
         }
     }

+    /* If there was no output, the populate with the empty string.  */
+    if (cmd->outbuf && !*cmd->outbuf) {
+        if ((*cmd->outbuf = strdup("")) == NULL) {
+            virReportOOMError();
+            return -1;
+        }
+    }
+    if (cmd->errbuf && !*cmd->errbuf) {
+        if ((*cmd->errbuf = strdup("")) == NULL) {
+            virReportOOMError();
+            return -1;
+        }
+    }
+
     return 0;
 }

-- 
1.7.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]