Richard W.M. Jones
2009-Oct-21 15:33 UTC
[Libguestfs] [PATCH] Set LC_ALL=C before running qemu.
This patch by no means covers all the cases where we run external programs and expect to parse their output without setting LC_ALL=C. But it's a good start. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora -------------- next part -------------->From 48d1aac55e4d44c37512937d64d0d76b3910f8e2 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Wed, 21 Oct 2009 16:31:26 +0100 Subject: [PATCH] Set LC_ALL=C before running qemu. --- src/guestfs.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/guestfs.c b/src/guestfs.c index e49f57a..a25e9e7 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -1195,6 +1195,8 @@ guestfs__launch (guestfs_h *g) setpgid (0, 0); #endif + setenv ("LC_ALL", "C", 1); + execv (g->qemu, g->cmdline); /* Run qemu. */ perror (g->qemu); _exit (1); @@ -1486,7 +1488,7 @@ test_qemu (guestfs_h *g) g->qemu_help = NULL; g->qemu_version = NULL; - snprintf (cmd, sizeof cmd, "'%s' -help", g->qemu); + snprintf (cmd, sizeof cmd, "LC_ALL=C '%s' -help", g->qemu); fp = popen (cmd, "r"); /* qemu -help should always work (qemu -version OTOH wasn't @@ -1508,7 +1510,7 @@ test_qemu (guestfs_h *g) if (pclose (fp) == -1) goto error; - snprintf (cmd, sizeof cmd, "'%s' -version 2>/dev/null", g->qemu); + snprintf (cmd, sizeof cmd, "LC_ALL=C '%s' -version 2>/dev/null", g->qemu); fp = popen (cmd, "r"); if (fp) { -- 1.6.5.rc2
Richard W.M. Jones wrote:> This patch by no means covers all the cases where we run external > programs and expect to parse their output without setting LC_ALL=C. > But it's a good start....> Subject: [PATCH] Set LC_ALL=C before running qemu.This looks fine. One possible improvement.> diff --git a/src/guestfs.c b/src/guestfs.c > index e49f57a..a25e9e7 100644 > --- a/src/guestfs.c > +++ b/src/guestfs.c > @@ -1195,6 +1195,8 @@ guestfs__launch (guestfs_h *g) > setpgid (0, 0); > #endif > > + setenv ("LC_ALL", "C", 1);Failure is unlikely, but you might want to diagnose it, just in case.> execv (g->qemu, g->cmdline); /* Run qemu. */ > perror (g->qemu); > _exit (1); > @@ -1486,7 +1488,7 @@ test_qemu (guestfs_h *g) > g->qemu_help = NULL; > g->qemu_version = NULL; > > - snprintf (cmd, sizeof cmd, "'%s' -help", g->qemu); > + snprintf (cmd, sizeof cmd, "LC_ALL=C '%s' -help", g->qemu); > > fp = popen (cmd, "r"); > /* qemu -help should always work (qemu -version OTOH wasn't > @@ -1508,7 +1510,7 @@ test_qemu (guestfs_h *g) > if (pclose (fp) == -1) > goto error; > > - snprintf (cmd, sizeof cmd, "'%s' -version 2>/dev/null", g->qemu); > + snprintf (cmd, sizeof cmd, "LC_ALL=C '%s' -version 2>/dev/null", g->qemu); > > fp = popen (cmd, "r"); > if (fp) {
Reasonably Related Threads
- [PATCH 0/4] lib: qemu: Add test for mandatory locking.
- [PATCH v3 0/6] launch: direct: Disable qemu locking when opening drives readonly.
- [PATCH v2 0/5] launch: direct: Disable qemu locking when opening drives readonly (RHBZ#1417306)
- [PATCH 0/4] qemu: Use sqlite to store qemu detection data.
- [PATCH v2 0/2] lib: qemu: Memoize qemu feature detection.