From 97185033e530e5d12029a039f496f38280653eec Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Sat, 27 Oct 2007 01:19:51 +0000 Subject: [PATCH] Refactor shell escaping code --- ChangeLog | 5 +++++ src/qemu_driver.c | 25 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6f9cf65e6..93f9262841 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Oct 26 21:17:44 EST 2007 Daniel P. Berrange + + * src/qemu_driver.c: Refactor shell ecscaping function to reuse + for monitor escaping + Fri Oct 26 21:14:44 EST 2007 Daniel P. Berrange * src/qemu_conf.h, src/qemu_conf.c: Refactor device parsing code diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 5f4db58996..aa9745ab11 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -1912,7 +1912,7 @@ static int qemudDomainGetInfo(virDomainPtr dom, } -static char *qemudEscapeShellArg(const char *in) +static char *qemudEscape(const char *in, int shell) { int len = 0; int i, j; @@ -1934,7 +1934,10 @@ static char *qemudEscapeShellArg(const char *in) len += 2; break; case '\'': - len += 5; + if (shell) + len += 5; + else + len += 1; break; default: len += 1; @@ -1961,11 +1964,15 @@ static char *qemudEscapeShellArg(const char *in) out[j++] = in[i]; break; case '\'': - out[j++] = '\''; - out[j++] = '\\'; - out[j++] = '\\'; - out[j++] = '\''; - out[j++] = '\''; + if (shell) { + out[j++] = '\''; + out[j++] = '\\'; + out[j++] = '\\'; + out[j++] = '\''; + out[j++] = '\''; + } else { + out[j++] = in[i]; + } break; default: out[j++] = in[i]; @@ -1977,6 +1984,10 @@ static char *qemudEscapeShellArg(const char *in) return out; } +static char *qemudEscapeShellArg(const char *in) +{ + return qemudEscape(in, 1); +} #define QEMUD_SAVE_MAGIC "LibvirtQemudSave" #define QEMUD_SAVE_VERSION 1