mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu: use line breaks in command line args written to log
The QEMU command line arguments are very long and currently all written on a single line to /var/log/libvirt/qemu/$GUEST.log. This introduces logic to add line breaks after every env variable and "-" optional argument, and every positional argument. This will create a clearer log file, which will in turn present better in bug reports when people cut + paste from the log into a bug comment. An example log file entry now looks like this: 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 LC_ALL=C \ PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin \ HOME=/home/berrange \ USER=berrange \ LOGNAME=berrange \ QEMU_AUDIO_DRV=none \ /usr/bin/qemu-system-ppc64 \ -name guest=guest,debug-threads=on \ -S \ -object secret,id=masterKey0,format=raw,file=/home/berrange/.config/libvirt/qemu/lib/domain-33-guest/master-key.aes \ -machine pseries-2.10,accel=tcg,usb=off,dump-guest-core=off \ -m 1024 \ -realtime mlock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid c8a74977-ab18-41d0-ae3b-4041c7fffbcd \ -display none \ -no-user-config \ -nodefaults \ -chardev socket,id=charmonitor,fd=23,server,nowait \ -mon chardev=charmonitor,id=monitor,mode=control \ -rtc base=utc \ -no-shutdown \ -boot strict=on \ -device qemu-xhci,id=usb,bus=pci.0,addr=0x1 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on 2018-12-14 12:57:03.730+0000: shutting down, reason=failed Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
@@ -630,7 +630,7 @@ static int test16(const void *unused ATTRIBUTE_UNUSED)
|
||||
virCommandAddArg(cmd, "F");
|
||||
virCommandAddArg(cmd, "G H");
|
||||
|
||||
if ((outactual = virCommandToString(cmd)) == NULL) {
|
||||
if ((outactual = virCommandToString(cmd, false)) == NULL) {
|
||||
printf("Cannot convert to string: %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -1135,6 +1135,67 @@ static int test25(const void *unused ATTRIBUTE_UNUSED)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Don't run program; rather, log what would be run.
|
||||
*/
|
||||
static int test26(const void *unused ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virCommandPtr cmd = virCommandNew("true");
|
||||
char *outactual = NULL;
|
||||
const char *outexpect =
|
||||
"A=B \\\n"
|
||||
"C='D E' \\\n"
|
||||
"true \\\n"
|
||||
"--foo bar \\\n"
|
||||
"--oooh \\\n"
|
||||
"-f \\\n"
|
||||
"--wizz 'eek eek' \\\n"
|
||||
"-w \\\n"
|
||||
"-z \\\n"
|
||||
"-l \\\n"
|
||||
"--mmm flash \\\n"
|
||||
"bang \\\n"
|
||||
"wallop";
|
||||
|
||||
int ret = -1;
|
||||
int fd = -1;
|
||||
|
||||
virCommandAddEnvPair(cmd, "A", "B");
|
||||
virCommandAddEnvPair(cmd, "C", "D E");
|
||||
virCommandAddArgList(cmd, "--foo", "bar", "--oooh", "-f",
|
||||
"--wizz", "eek eek", "-w", "-z", "-l",
|
||||
"--mmm", "flash", "bang", "wallop",
|
||||
NULL);
|
||||
|
||||
if ((outactual = virCommandToString(cmd, true)) == NULL) {
|
||||
printf("Cannot convert to string: %s\n", virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
if ((fd = open(abs_builddir "/commandhelper.log",
|
||||
O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) {
|
||||
printf("Cannot open log file: %s\n", strerror(errno));
|
||||
goto cleanup;
|
||||
}
|
||||
virCommandWriteArgLog(cmd, fd);
|
||||
if (VIR_CLOSE(fd) < 0) {
|
||||
printf("Cannot close log file: %s\n", strerror(errno));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (STRNEQ(outactual, outexpect)) {
|
||||
virTestDifference(stderr, outexpect, outactual);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = checkoutput("test26", NULL);
|
||||
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
VIR_FREE(outactual);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void virCommandThreadWorker(void *opaque)
|
||||
{
|
||||
virCommandTestDataPtr test = opaque;
|
||||
@@ -1288,6 +1349,7 @@ mymain(void)
|
||||
DO_TEST(test23);
|
||||
DO_TEST(test24);
|
||||
DO_TEST(test25);
|
||||
DO_TEST(test26);
|
||||
|
||||
virMutexLock(&test->lock);
|
||||
if (test->running) {
|
||||
|
||||
Reference in New Issue
Block a user