Patchwork [BRANCH:release-3.2,BUG:3154,1/1] mgmt/glusterd: write complete string contained in value in to the volinfo file.

login
register
Submitter Mohammed Junaid Ahmed
Date 2011-07-12 18:01:37
Message ID <20110712180137.GA1131@shell.gluster.com>
Download mbox | patch
Permalink /patch/7854/
State Accepted
Delegated to: Vijay Bellur
Headers show

Comments

Mohammed Junaid Ahmed - 2011-07-12 18:01:37
Currently, we are writing 4096 bytes of value variable to the volinfo file
irrespective of its lenght, thus tampering with the volinfo file structure.

Signed-off-by: Junaid <junaid@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-store.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index ba59d79..f3fa2c0 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -908,16 +908,20 @@  int32_t
 glusterd_store_save_value (int fd, char *key, char *value)
 {
         int32_t         ret = -1;
-        char            buf[4096] = {0,};
 
         GF_ASSERT (fd > 0);
         GF_ASSERT (key);
         GF_ASSERT (value);
 
-        snprintf (buf, sizeof (buf), "%s=%s\n", key, value);
-        ret = write (fd, buf, strlen (buf));
+        ret = write (fd, key, strlen (key));
+        if (ret > 0)
+                ret = write (fd, "=", strlen ("="));
+        if (ret > 0)
+                ret = write (fd, value, strlen (value));
+        if (ret > 0)
+                ret = write (fd, "\n", strlen ("\n"));
 
-        if (ret < 0) {
+        if (ret <= 0) {
                 gf_log ("", GF_LOG_CRITICAL, "Unable to store key: %s,"
                         "value: %s, error: %s", key, value,
                         strerror (errno));