On 11/23/2010 04:49 PM, Eric Blake wrote:
From: Daniel P. Berrange <berrange(a)redhat.com>
This introduces a new set of APIs in src/util/command.h
to use for invoking commands. This is intended to replace
all current usage of virRun and virExec variants, with a
more flexible and less error prone API.
+/*
+ * Call after adding all arguments and environment settings, but before
+ * Run/RunAsync, to immediately output the environment and arguments of
+ * cmd to logfd. If virCommandRun cannot succeed (because of an
+ * out-of-memory condition while building cmd), nothing will be logged.
+ */
+void virCommandWriteArgLog(virCommandPtr cmd,
+ int logfd);
+
+/*
+ * Call after adding all arguments and environment settings, but before
+ * Run/RunAsync, to return a string representation of the environment and
+ * arguments of cmd. If virCommandRun cannot succeed (because of an
+ * out-of-memory condition while building cmd), NULL will be returned.
+ * Caller is responsible for freeing the resulting string.
+ */
+char *virCommandToString(virCommandPtr cmd) ATTRIBUTE_RETURN_CHECK;
Bummer. Just realized that these functions should probably be modified
to take another parameter that controls whether the output should be
quoted for shell use.
Basically, I just tested the recent addition of <smbios mode='host'/>,
and found out that it has a bug: it takes the host string (which may
have spaces), and passes it to the qemu command line as:
-smbios 'type=0,version="6FET82WW (3.12 )"'
which means that the guest gets literal "" in the SMBIOS string, whereas
the host did not have them, such that it is not a true host mirroring as
intended. But in the /var/log/libvirt/qemu/...log, the argument only
shows up as:
-smbios type=0,version="6FET82WW (3.12 )"
which, when pasted literally into a shell, does the right thing.
Therefore, adding the ability to shell-quote the log will make it easier
to log complex shell commands, where we really did intend to pass shell
metacharacters via a single argument.
I'll have to fold that in to my next revision.
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org