xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: xen-devel@lists.xen.org
Cc: Keir Fraser <keir.fraser@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH 5/5] xc_save: simplify switch_qemu_logdirty() by use stack strings
Date: Tue, 11 Mar 2014 22:15:25 +0800	[thread overview]
Message-ID: <1394547325-18537-5-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1394547325-18537-1-git-send-email-laijs@cn.fujitsu.com>

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
 tools/xcutils/xc_save.c |   35 +++++++++++++----------------------
 1 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/tools/xcutils/xc_save.c b/tools/xcutils/xc_save.c
index 1304433..521bbae 100644
--- a/tools/xcutils/xc_save.c
+++ b/tools/xcutils/xc_save.c
@@ -101,40 +101,33 @@ static int suspend(void* data)
  * the new active buffer.  xc_save can then process and clear the old
  * active buffer. */
 
-
 static int switch_qemu_logdirty(int domid, unsigned int enable, void *data)
 {
     struct xs_handle *xs;
-    char *path, *p, *ret_str, *cmd_str, **watch;
+    char *ret_str, *cmd_str, **watch;
     unsigned int len;
     struct timeval tv;
     fd_set fdset;
 
+#define PATH_FMT	"/local/domain/0/device-model/%d/logdirty/%s"
+#define PATH_LEN	(sizeof(PATH_FMT) + 10 + sizeof("cmd"))
+    char path_cmd[PATH_LEN], path_ret[PATH_LEN];
+
+    snprintf(path_cmd, PATH_LEN, PATH_FMT, domid, "cmd");
+    snprintf(path_ret, PATH_LEN, PATH_FMT, domid, "ret");
+
     if ((xs = xs_daemon_open()) == NULL)
         errx(1, "Couldn't contact xenstore");
-    if (!(path = strdup("/local/domain/0/device-model/")))
-        errx(1, "can't get domain path in store");
-    if (!(path = realloc(path, strlen(path) 
-                         + 10 
-                         + strlen("/logdirty/cmd") + 1)))
-        errx(1, "no memory for constructing xenstore path");
-    snprintf(path + strlen(path), 11, "%i", domid);
-    strcat(path, "/logdirty/");
-    p = path + strlen(path);
-
 
     /* Watch for qemu's return value */
-    strcpy(p, "ret");
-    if (!xs_watch(xs, path, "qemu-logdirty-ret"))
-        errx(1, "can't set watch in store (%s)\n", path);
+    if (!xs_watch(xs, path_ret, "qemu-logdirty-ret"))
+        errx(1, "can't set watch in store (%s)\n", path_ret);
 
     cmd_str = enable == 0 ? "disable" : "enable";
 
     /* Tell qemu that we want it to start logging dirty page to Xen */
-    strcpy(p, "cmd");
-    if (!xs_write(xs, XBT_NULL, path, cmd_str, strlen(cmd_str)))
-        errx(1, "can't write  to store path (%s)\n",
-             path);
+    if (!xs_write(xs, XBT_NULL, path_cmd, cmd_str, strlen(cmd_str)))
+        errx(1, "can't write  to store path (%s)\n", path_cmd);
 
     /* Wait a while for qemu to signal that it has service logdirty command */
  read_again:
@@ -149,13 +142,11 @@ static int switch_qemu_logdirty(int domid, unsigned int enable, void *data)
     watch = xs_read_watch(xs, &len);
     free(watch);
 
-    strcpy(p, "ret");
-    ret_str = xs_read(xs, XBT_NULL, path, &len);
+    ret_str = xs_read(xs, XBT_NULL, path_ret, &len);
     if (ret_str == NULL || strcmp(ret_str, cmd_str))
         /* Watch fired but value is not yet right */
         goto read_again;
 
-    free(path);
     free(ret_str);
 
     return 0;
-- 
1.7.1

  parent reply	other threads:[~2014-03-11 14:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-11 14:15 [PATCH 1/5] libxl, gc: fix memory leak in libxl__strndup() Lai Jiangshan
2014-03-11 14:15 ` [PATCH 2/5] libxl: simplify libxl__dirname() Lai Jiangshan
2014-03-13 16:51   ` Ian Jackson
2014-03-11 14:15 ` [PATCH 3/5] libxl: add @count to libxl_gc Lai Jiangshan
2014-03-13 16:52   ` Ian Jackson
2014-03-11 14:15 ` [PATCH 4/5] xc_save: avoid to alloc local constant string Lai Jiangshan
2014-03-13 16:55   ` Ian Jackson
2014-03-11 14:15 ` Lai Jiangshan [this message]
2014-03-13 16:54   ` [PATCH 5/5] xc_save: simplify switch_qemu_logdirty() by use stack strings Ian Jackson
2014-03-14  9:21     ` Lai Jiangshan
2014-03-13 16:50 ` [PATCH 1/5] libxl, gc: fix memory leak in libxl__strndup() Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394547325-18537-5-git-send-email-laijs@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=keir.fraser@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).