|
|
99cbc7 |
From 58a67e037eefae16bf2f831de482e9070d590151 Mon Sep 17 00:00:00 2001
|
|
|
99cbc7 |
Message-Id: <58a67e037eefae16bf2f831de482e9070d590151@dist-git>
|
|
|
99cbc7 |
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
|
|
|
99cbc7 |
Date: Tue, 21 May 2019 11:02:13 +0100
|
|
|
99cbc7 |
Subject: [PATCH] qemu: use line breaks in command line args written to log
|
|
|
99cbc7 |
MIME-Version: 1.0
|
|
|
99cbc7 |
Content-Type: text/plain; charset=UTF-8
|
|
|
99cbc7 |
Content-Transfer-Encoding: 8bit
|
|
|
99cbc7 |
|
|
|
99cbc7 |
The QEMU command line arguments are very long and currently all written
|
|
|
99cbc7 |
on a single line to /var/log/libvirt/qemu/$GUEST.log. This introduces
|
|
|
99cbc7 |
logic to add line breaks after every env variable and "-" optional
|
|
|
99cbc7 |
argument, and every positional argument. This will create a clearer log
|
|
|
99cbc7 |
file, which will in turn present better in bug reports when people cut +
|
|
|
99cbc7 |
paste from the log into a bug comment.
|
|
|
99cbc7 |
|
|
|
99cbc7 |
An example log file entry now looks like this:
|
|
|
99cbc7 |
|
|
|
99cbc7 |
2018-12-14 12:57:03.677+0000: starting up libvirt version: 5.0.0, qemu version: 3.0.0qemu-3.0.0-1.fc29, kernel: 4.19.5-300.fc29.x86_64, hostname: localhost.localdomain
|
|
|
99cbc7 |
LC_ALL=C \
|
|
|
99cbc7 |
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin \
|
|
|
99cbc7 |
HOME=/home/berrange \
|
|
|
99cbc7 |
USER=berrange \
|
|
|
99cbc7 |
LOGNAME=berrange \
|
|
|
99cbc7 |
QEMU_AUDIO_DRV=none \
|
|
|
99cbc7 |
/usr/bin/qemu-system-ppc64 \
|
|
|
99cbc7 |
-name guest=guest,debug-threads=on \
|
|
|
99cbc7 |
-S \
|
|
|
99cbc7 |
-object secret,id=masterKey0,format=raw,file=/home/berrange/.config/libvirt/qemu/lib/domain-33-guest/master-key.aes \
|
|
|
99cbc7 |
-machine pseries-2.10,accel=tcg,usb=off,dump-guest-core=off \
|
|
|
99cbc7 |
-m 1024 \
|
|
|
99cbc7 |
-realtime mlock=off \
|
|
|
99cbc7 |
-smp 1,sockets=1,cores=1,threads=1 \
|
|
|
99cbc7 |
-uuid c8a74977-ab18-41d0-ae3b-4041c7fffbcd \
|
|
|
99cbc7 |
-display none \
|
|
|
99cbc7 |
-no-user-config \
|
|
|
99cbc7 |
-nodefaults \
|
|
|
99cbc7 |
-chardev socket,id=charmonitor,fd=23,server,nowait \
|
|
|
99cbc7 |
-mon chardev=charmonitor,id=monitor,mode=control \
|
|
|
99cbc7 |
-rtc base=utc \
|
|
|
99cbc7 |
-no-shutdown \
|
|
|
99cbc7 |
-boot strict=on \
|
|
|
99cbc7 |
-device qemu-xhci,id=usb,bus=pci.0,addr=0x1 \
|
|
|
99cbc7 |
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
|
|
|
99cbc7 |
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
|
|
|
99cbc7 |
-msg timestamp=on
|
|
|
99cbc7 |
2018-12-14 12:57:03.730+0000: shutting down, reason=failed
|
|
|
99cbc7 |
|
|
|
99cbc7 |
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
99cbc7 |
(cherry picked from commit 07c9d6601d0b440acd13794b258bdcb570ae93f4)
|
|
|
99cbc7 |
|
|
|
99cbc7 |
https://bugzilla.redhat.com/show_bug.cgi?id=1672957
|
|
|
99cbc7 |
|
|
|
99cbc7 |
Conflicts:
|
|
|
99cbc7 |
src/util/vircommand.c
|
|
|
99cbc7 |
src/util/virfirewall.c
|
|
|
99cbc7 |
- Not using auto cleanup macros in old branch
|
|
|
99cbc7 |
|
|
|
99cbc7 |
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
99cbc7 |
Message-Id: <20190521100213.16875-3-berrange@redhat.com>
|
|
|
99cbc7 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
99cbc7 |
---
|
|
|
99cbc7 |
docs/internals/command.html.in | 2 +-
|
|
|
99cbc7 |
src/bhyve/bhyve_driver.c | 4 +-
|
|
|
99cbc7 |
src/qemu/qemu_driver.c | 2 +-
|
|
|
99cbc7 |
src/qemu/qemu_interface.c | 2 +-
|
|
|
99cbc7 |
src/qemu/qemu_process.c | 2 +-
|
|
|
99cbc7 |
src/security/security_apparmor.c | 2 +-
|
|
|
99cbc7 |
src/util/vircommand.c | 19 ++++++++--
|
|
|
99cbc7 |
src/util/vircommand.h | 2 +-
|
|
|
99cbc7 |
src/util/virfirewall.c | 2 +-
|
|
|
99cbc7 |
tests/bhyvexml2argvtest.c | 4 +-
|
|
|
99cbc7 |
tests/commanddata/test26.log | 1 +
|
|
|
99cbc7 |
tests/commandtest.c | 64 +++++++++++++++++++++++++++++++-
|
|
|
99cbc7 |
tests/qemuxml2argvtest.c | 2 +-
|
|
|
99cbc7 |
tests/storagepoolxml2argvtest.c | 2 +-
|
|
|
99cbc7 |
tests/storagevolxml2argvtest.c | 4 +-
|
|
|
99cbc7 |
15 files changed, 95 insertions(+), 19 deletions(-)
|
|
|
99cbc7 |
create mode 100644 tests/commanddata/test26.log
|
|
|
99cbc7 |
|
|
|
99cbc7 |
diff --git a/docs/internals/command.html.in b/docs/internals/command.html.in
|
|
|
99cbc7 |
index 43f51a49bb..8a9061e70f 100644
|
|
|
99cbc7 |
--- a/docs/internals/command.html.in
|
|
|
99cbc7 |
+++ b/docs/internals/command.html.in
|
|
|
99cbc7 |
@@ -426,7 +426,7 @@ dprintf(logfd, "%s: ", timestamp);
|
|
|
99cbc7 |
VIR_FREE(timestamp);
|
|
|
99cbc7 |
virCommandWriteArgLog(cmd, logfd);
|
|
|
99cbc7 |
|
|
|
99cbc7 |
-string = virCommandToString(cmd);
|
|
|
99cbc7 |
+string = virCommandToString(cmd, false);
|
|
|
99cbc7 |
if (string)
|
|
|
99cbc7 |
VIR_DEBUG("about to run %s", string);
|
|
|
99cbc7 |
VIR_FREE(string);
|
|
|
99cbc7 |
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
|
|
|
99cbc7 |
index 9284b51783..ae611fdb60 100644
|
|
|
99cbc7 |
--- a/src/bhyve/bhyve_driver.c
|
|
|
99cbc7 |
+++ b/src/bhyve/bhyve_driver.c
|
|
|
99cbc7 |
@@ -736,14 +736,14 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
|
|
|
99cbc7 |
NULL)))
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- virBufferAdd(&buf, virCommandToString(loadcmd), -1);
|
|
|
99cbc7 |
+ virBufferAdd(&buf, virCommandToString(loadcmd, false), -1);
|
|
|
99cbc7 |
virBufferAddChar(&buf, '\n');
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, def, true)))
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- virBufferAdd(&buf, virCommandToString(cmd), -1);
|
|
|
99cbc7 |
+ virBufferAdd(&buf, virCommandToString(cmd, false), -1);
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (virBufferCheckError(&buf) < 0)
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
99cbc7 |
index 3b3281c13f..704ba24215 100644
|
|
|
99cbc7 |
--- a/src/qemu/qemu_driver.c
|
|
|
99cbc7 |
+++ b/src/qemu/qemu_driver.c
|
|
|
99cbc7 |
@@ -7171,7 +7171,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
|
|
99cbc7 |
VIR_QEMU_PROCESS_START_COLD)))
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- ret = virCommandToString(cmd);
|
|
|
99cbc7 |
+ ret = virCommandToString(cmd, false);
|
|
|
99cbc7 |
|
|
|
99cbc7 |
cleanup:
|
|
|
99cbc7 |
virCommandFree(cmd);
|
|
|
99cbc7 |
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
|
|
|
99cbc7 |
index a3f13093f5..afef30d7cf 100644
|
|
|
99cbc7 |
--- a/src/qemu/qemu_interface.c
|
|
|
99cbc7 |
+++ b/src/qemu/qemu_interface.c
|
|
|
99cbc7 |
@@ -363,7 +363,7 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
|
|
|
99cbc7 |
char ebuf[1024];
|
|
|
99cbc7 |
char *errstr = NULL;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- if (!(cmdstr = virCommandToString(cmd)))
|
|
|
99cbc7 |
+ if (!(cmdstr = virCommandToString(cmd, false)))
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
virCommandAbort(cmd);
|
|
|
99cbc7 |
|
|
|
99cbc7 |
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
|
|
99cbc7 |
index 8811aefb95..2795796166 100644
|
|
|
99cbc7 |
--- a/src/qemu/qemu_process.c
|
|
|
99cbc7 |
+++ b/src/qemu/qemu_process.c
|
|
|
99cbc7 |
@@ -4327,7 +4327,7 @@ qemuLogOperation(virDomainObjPtr vm,
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (cmd) {
|
|
|
99cbc7 |
- char *args = virCommandToString(cmd);
|
|
|
99cbc7 |
+ char *args = virCommandToString(cmd, true);
|
|
|
99cbc7 |
qemuDomainLogContextWrite(logCtxt, "%s\n", args);
|
|
|
99cbc7 |
VIR_FREE(args);
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
|
|
|
99cbc7 |
index cb41df71a9..bb1742a686 100644
|
|
|
99cbc7 |
--- a/src/security/security_apparmor.c
|
|
|
99cbc7 |
+++ b/src/security/security_apparmor.c
|
|
|
99cbc7 |
@@ -661,7 +661,7 @@ AppArmorSetSecurityChildProcessLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
|
|
|
99cbc7 |
if ((profile_name = get_profile_name(def)) == NULL)
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- cmd_str = virCommandToString(cmd);
|
|
|
99cbc7 |
+ cmd_str = virCommandToString(cmd, false);
|
|
|
99cbc7 |
VIR_DEBUG("Changing AppArmor profile to %s on %s", profile_name, cmd_str);
|
|
|
99cbc7 |
virCommandSetAppArmorProfile(cmd, profile_name);
|
|
|
99cbc7 |
rc = 0;
|
|
|
99cbc7 |
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
|
|
|
99cbc7 |
index 68cf63c28a..f539bafab6 100644
|
|
|
99cbc7 |
--- a/src/util/vircommand.c
|
|
|
99cbc7 |
+++ b/src/util/vircommand.c
|
|
|
99cbc7 |
@@ -1971,6 +1971,7 @@ virCommandWriteArgLog(virCommandPtr cmd, int logfd)
|
|
|
99cbc7 |
/**
|
|
|
99cbc7 |
* virCommandToString:
|
|
|
99cbc7 |
* @cmd: the command to convert
|
|
|
99cbc7 |
+ * @linebreaks: true to break line after each env var or option
|
|
|
99cbc7 |
*
|
|
|
99cbc7 |
* Call after adding all arguments and environment settings, but
|
|
|
99cbc7 |
* before Run/RunAsync, to return a string representation of the
|
|
|
99cbc7 |
@@ -1980,10 +1981,11 @@ virCommandWriteArgLog(virCommandPtr cmd, int logfd)
|
|
|
99cbc7 |
* Caller is responsible for freeing the resulting string.
|
|
|
99cbc7 |
*/
|
|
|
99cbc7 |
char *
|
|
|
99cbc7 |
-virCommandToString(virCommandPtr cmd)
|
|
|
99cbc7 |
+virCommandToString(virCommandPtr cmd, bool linebreaks)
|
|
|
99cbc7 |
{
|
|
|
99cbc7 |
size_t i;
|
|
|
99cbc7 |
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
99cbc7 |
+ bool prevopt = false;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
/* Cannot assume virCommandRun will be called; so report the error
|
|
|
99cbc7 |
* now. If virCommandRun is called, it will report the same error. */
|
|
|
99cbc7 |
@@ -2012,11 +2014,22 @@ virCommandToString(virCommandPtr cmd)
|
|
|
99cbc7 |
virBufferAdd(&buf, cmd->env[i], eq - cmd->env[i]);
|
|
|
99cbc7 |
virBufferEscapeShell(&buf, eq);
|
|
|
99cbc7 |
virBufferAddChar(&buf, ' ');
|
|
|
99cbc7 |
+ if (linebreaks)
|
|
|
99cbc7 |
+ virBufferAddLit(&buf, "\\\n");
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
virBufferEscapeShell(&buf, cmd->args[0]);
|
|
|
99cbc7 |
for (i = 1; i < cmd->nargs; i++) {
|
|
|
99cbc7 |
virBufferAddChar(&buf, ' ');
|
|
|
99cbc7 |
+ if (linebreaks) {
|
|
|
99cbc7 |
+ /* Line break if this is a --arg or if
|
|
|
99cbc7 |
+ * the previous arg was a positional option
|
|
|
99cbc7 |
+ */
|
|
|
99cbc7 |
+ if (cmd->args[i][0] == '-' ||
|
|
|
99cbc7 |
+ !prevopt)
|
|
|
99cbc7 |
+ virBufferAddLit(&buf, "\\\n");
|
|
|
99cbc7 |
+ }
|
|
|
99cbc7 |
virBufferEscapeShell(&buf, cmd->args[i]);
|
|
|
99cbc7 |
+ prevopt = (cmd->args[i][0] == '-');
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (virBufferCheckError(&buf) < 0)
|
|
|
99cbc7 |
@@ -2459,7 +2472,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- str = virCommandToString(cmd);
|
|
|
99cbc7 |
+ str = virCommandToString(cmd, false);
|
|
|
99cbc7 |
if (dryRunBuffer || dryRunCallback) {
|
|
|
99cbc7 |
dryRunStatus = 0;
|
|
|
99cbc7 |
if (!str) {
|
|
|
99cbc7 |
@@ -2599,7 +2612,7 @@ virCommandWait(virCommandPtr cmd, int *exitstatus)
|
|
|
99cbc7 |
if (exitstatus && (cmd->rawStatus || WIFEXITED(status))) {
|
|
|
99cbc7 |
*exitstatus = cmd->rawStatus ? status : WEXITSTATUS(status);
|
|
|
99cbc7 |
} else if (status) {
|
|
|
99cbc7 |
- char *str = virCommandToString(cmd);
|
|
|
99cbc7 |
+ char *str = virCommandToString(cmd, false);
|
|
|
99cbc7 |
char *st = virProcessTranslateStatus(status);
|
|
|
99cbc7 |
bool haveErrMsg = cmd->errbuf && *cmd->errbuf && (*cmd->errbuf)[0];
|
|
|
99cbc7 |
|
|
|
99cbc7 |
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
|
|
|
99cbc7 |
index 883e212959..5ea2998f77 100644
|
|
|
99cbc7 |
--- a/src/util/vircommand.h
|
|
|
99cbc7 |
+++ b/src/util/vircommand.h
|
|
|
99cbc7 |
@@ -171,7 +171,7 @@ void virCommandSetPreExecHook(virCommandPtr cmd,
|
|
|
99cbc7 |
void virCommandWriteArgLog(virCommandPtr cmd,
|
|
|
99cbc7 |
int logfd);
|
|
|
99cbc7 |
|
|
|
99cbc7 |
-char *virCommandToString(virCommandPtr cmd) ATTRIBUTE_RETURN_CHECK;
|
|
|
99cbc7 |
+char *virCommandToString(virCommandPtr cmd, bool linebreaks) ATTRIBUTE_RETURN_CHECK;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
int virCommandExec(virCommandPtr cmd, gid_t *groups, int ngroups) ATTRIBUTE_RETURN_CHECK;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
|
|
|
99cbc7 |
index 10c370a2ae..79c2ef87e2 100644
|
|
|
99cbc7 |
--- a/src/util/virfirewall.c
|
|
|
99cbc7 |
+++ b/src/util/virfirewall.c
|
|
|
99cbc7 |
@@ -703,7 +703,7 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule,
|
|
|
99cbc7 |
if (ignoreErrors) {
|
|
|
99cbc7 |
VIR_DEBUG("Ignoring error running command");
|
|
|
99cbc7 |
} else {
|
|
|
99cbc7 |
- char *args = virCommandToString(cmd);
|
|
|
99cbc7 |
+ char *args = virCommandToString(cmd, false);
|
|
|
99cbc7 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
99cbc7 |
_("Failed to apply firewall rules %s: %s"),
|
|
|
99cbc7 |
NULLSTR(args), NULLSTR(error));
|
|
|
99cbc7 |
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
|
|
|
99cbc7 |
index 6d5f19e2c6..d1b486fa64 100644
|
|
|
99cbc7 |
--- a/tests/bhyvexml2argvtest.c
|
|
|
99cbc7 |
+++ b/tests/bhyvexml2argvtest.c
|
|
|
99cbc7 |
@@ -68,13 +68,13 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
|
|
99cbc7 |
goto out;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- if (!(actualargv = virCommandToString(cmd)))
|
|
|
99cbc7 |
+ if (!(actualargv = virCommandToString(cmd, false)))
|
|
|
99cbc7 |
goto out;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (actualdm != NULL)
|
|
|
99cbc7 |
virTrimSpaces(actualdm, NULL);
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- if (!(actualld = virCommandToString(ldcmd)))
|
|
|
99cbc7 |
+ if (!(actualld = virCommandToString(ldcmd, false)))
|
|
|
99cbc7 |
goto out;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (virTestCompareToFile(actualargv, cmdline) < 0)
|
|
|
99cbc7 |
diff --git a/tests/commanddata/test26.log b/tests/commanddata/test26.log
|
|
|
99cbc7 |
new file mode 100644
|
|
|
99cbc7 |
index 0000000000..db0d424875
|
|
|
99cbc7 |
--- /dev/null
|
|
|
99cbc7 |
+++ b/tests/commanddata/test26.log
|
|
|
99cbc7 |
@@ -0,0 +1 @@
|
|
|
99cbc7 |
+A=B C=D E true --foo bar --oooh -f --wizz eek eek -w -z -l --mmm flash bang wallop
|
|
|
99cbc7 |
diff --git a/tests/commandtest.c b/tests/commandtest.c
|
|
|
99cbc7 |
index 744a387aa0..4edef6157a 100644
|
|
|
99cbc7 |
--- a/tests/commandtest.c
|
|
|
99cbc7 |
+++ b/tests/commandtest.c
|
|
|
99cbc7 |
@@ -633,7 +633,7 @@ static int test16(const void *unused ATTRIBUTE_UNUSED)
|
|
|
99cbc7 |
virCommandAddArg(cmd, "F");
|
|
|
99cbc7 |
virCommandAddArg(cmd, "G H");
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- if ((outactual = virCommandToString(cmd)) == NULL) {
|
|
|
99cbc7 |
+ if ((outactual = virCommandToString(cmd, false)) == NULL) {
|
|
|
99cbc7 |
printf("Cannot convert to string: %s\n", virGetLastErrorMessage());
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
@@ -1138,6 +1138,67 @@ static int test25(const void *unused ATTRIBUTE_UNUSED)
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
|
|
|
99cbc7 |
+/*
|
|
|
99cbc7 |
+ * Don't run program; rather, log what would be run.
|
|
|
99cbc7 |
+ */
|
|
|
99cbc7 |
+static int test26(const void *unused ATTRIBUTE_UNUSED)
|
|
|
99cbc7 |
+{
|
|
|
99cbc7 |
+ virCommandPtr cmd = virCommandNew("true");
|
|
|
99cbc7 |
+ char *outactual = NULL;
|
|
|
99cbc7 |
+ const char *outexpect =
|
|
|
99cbc7 |
+ "A=B \\\n"
|
|
|
99cbc7 |
+ "C='D E' \\\n"
|
|
|
99cbc7 |
+ "true \\\n"
|
|
|
99cbc7 |
+ "--foo bar \\\n"
|
|
|
99cbc7 |
+ "--oooh \\\n"
|
|
|
99cbc7 |
+ "-f \\\n"
|
|
|
99cbc7 |
+ "--wizz 'eek eek' \\\n"
|
|
|
99cbc7 |
+ "-w \\\n"
|
|
|
99cbc7 |
+ "-z \\\n"
|
|
|
99cbc7 |
+ "-l \\\n"
|
|
|
99cbc7 |
+ "--mmm flash \\\n"
|
|
|
99cbc7 |
+ "bang \\\n"
|
|
|
99cbc7 |
+ "wallop";
|
|
|
99cbc7 |
+
|
|
|
99cbc7 |
+ int ret = -1;
|
|
|
99cbc7 |
+ int fd = -1;
|
|
|
99cbc7 |
+
|
|
|
99cbc7 |
+ virCommandAddEnvPair(cmd, "A", "B");
|
|
|
99cbc7 |
+ virCommandAddEnvPair(cmd, "C", "D E");
|
|
|
99cbc7 |
+ virCommandAddArgList(cmd, "--foo", "bar", "--oooh", "-f",
|
|
|
99cbc7 |
+ "--wizz", "eek eek", "-w", "-z", "-l",
|
|
|
99cbc7 |
+ "--mmm", "flash", "bang", "wallop",
|
|
|
99cbc7 |
+ NULL);
|
|
|
99cbc7 |
+
|
|
|
99cbc7 |
+ if ((outactual = virCommandToString(cmd, true)) == NULL) {
|
|
|
99cbc7 |
+ printf("Cannot convert to string: %s\n", virGetLastErrorMessage());
|
|
|
99cbc7 |
+ goto cleanup;
|
|
|
99cbc7 |
+ }
|
|
|
99cbc7 |
+ if ((fd = open(abs_builddir "/commandhelper.log",
|
|
|
99cbc7 |
+ O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) {
|
|
|
99cbc7 |
+ printf("Cannot open log file: %s\n", strerror(errno));
|
|
|
99cbc7 |
+ goto cleanup;
|
|
|
99cbc7 |
+ }
|
|
|
99cbc7 |
+ virCommandWriteArgLog(cmd, fd);
|
|
|
99cbc7 |
+ if (VIR_CLOSE(fd) < 0) {
|
|
|
99cbc7 |
+ printf("Cannot close log file: %s\n", strerror(errno));
|
|
|
99cbc7 |
+ goto cleanup;
|
|
|
99cbc7 |
+ }
|
|
|
99cbc7 |
+
|
|
|
99cbc7 |
+ if (STRNEQ(outactual, outexpect)) {
|
|
|
99cbc7 |
+ virTestDifference(stderr, outexpect, outactual);
|
|
|
99cbc7 |
+ goto cleanup;
|
|
|
99cbc7 |
+ }
|
|
|
99cbc7 |
+
|
|
|
99cbc7 |
+ ret = checkoutput("test26", NULL);
|
|
|
99cbc7 |
+
|
|
|
99cbc7 |
+ cleanup:
|
|
|
99cbc7 |
+ virCommandFree(cmd);
|
|
|
99cbc7 |
+ VIR_FORCE_CLOSE(fd);
|
|
|
99cbc7 |
+ VIR_FREE(outactual);
|
|
|
99cbc7 |
+ return ret;
|
|
|
99cbc7 |
+}
|
|
|
99cbc7 |
+
|
|
|
99cbc7 |
static void virCommandThreadWorker(void *opaque)
|
|
|
99cbc7 |
{
|
|
|
99cbc7 |
virCommandTestDataPtr test = opaque;
|
|
|
99cbc7 |
@@ -1291,6 +1352,7 @@ mymain(void)
|
|
|
99cbc7 |
DO_TEST(test23);
|
|
|
99cbc7 |
DO_TEST(test24);
|
|
|
99cbc7 |
DO_TEST(test25);
|
|
|
99cbc7 |
+ DO_TEST(test26);
|
|
|
99cbc7 |
|
|
|
99cbc7 |
virMutexLock(&test->lock);
|
|
|
99cbc7 |
if (test->running) {
|
|
|
99cbc7 |
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
|
|
|
99cbc7 |
index a29e63d950..9933e4bde1 100644
|
|
|
99cbc7 |
--- a/tests/qemuxml2argvtest.c
|
|
|
99cbc7 |
+++ b/tests/qemuxml2argvtest.c
|
|
|
99cbc7 |
@@ -575,7 +575,7 @@ testCompareXMLToArgv(const void *data)
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- if (!(actualargv = virCommandToString(cmd)))
|
|
|
99cbc7 |
+ if (!(actualargv = virCommandToString(cmd, false)))
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (virTestCompareToFile(actualargv, args) < 0)
|
|
|
99cbc7 |
diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c
|
|
|
99cbc7 |
index 1e48910566..19a64303a7 100644
|
|
|
99cbc7 |
--- a/tests/storagepoolxml2argvtest.c
|
|
|
99cbc7 |
+++ b/tests/storagepoolxml2argvtest.c
|
|
|
99cbc7 |
@@ -60,7 +60,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
};
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- if (!(actualCmdline = virCommandToString(cmd))) {
|
|
|
99cbc7 |
+ if (!(actualCmdline = virCommandToString(cmd, false))) {
|
|
|
99cbc7 |
VIR_TEST_DEBUG("pool type %d failed to get commandline\n", def->type);
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
|
|
|
99cbc7 |
index 105705f348..bc2da37410 100644
|
|
|
99cbc7 |
--- a/tests/storagevolxml2argvtest.c
|
|
|
99cbc7 |
+++ b/tests/storagevolxml2argvtest.c
|
|
|
99cbc7 |
@@ -104,14 +104,14 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
|
|
99cbc7 |
}
|
|
|
99cbc7 |
|
|
|
99cbc7 |
if (convertStep != VIR_STORAGE_VOL_ENCRYPT_CONVERT) {
|
|
|
99cbc7 |
- if (!(actualCmdline = virCommandToString(cmd)))
|
|
|
99cbc7 |
+ if (!(actualCmdline = virCommandToString(cmd, false)))
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
} else {
|
|
|
99cbc7 |
char *createCmdline = actualCmdline;
|
|
|
99cbc7 |
char *cvtCmdline;
|
|
|
99cbc7 |
int rc;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
- if (!(cvtCmdline = virCommandToString(cmd)))
|
|
|
99cbc7 |
+ if (!(cvtCmdline = virCommandToString(cmd, false)))
|
|
|
99cbc7 |
goto cleanup;
|
|
|
99cbc7 |
|
|
|
99cbc7 |
rc = virAsprintf(&actualCmdline, "%s\n%s",
|
|
|
99cbc7 |
--
|
|
|
99cbc7 |
2.21.0
|
|
|
99cbc7 |
|