Patchwork [BUG:1506] crash fixed in 'gluster volume log locate'

login
register
Submitter Amar Tumballi
Date 2010-09-02 06:52:15
Message ID <20100902065215.GA16359@gluster.com>
Download mbox | patch
Permalink /patch/4466/
State Accepted
Delegated to: Anand Avati
Headers show

Comments

Amar Tumballi - 2010-09-02 06:52:15
Signed-off-by: Amar Tumballi <amar@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-handler.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 7ecebd0..5c93a8e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -1639,12 +1639,15 @@  glusterd_handle_log_locate (rpcsvc_request_t *req)
         gf1_cli_log_locate_req  cli_req = {0,};
         gf1_cli_log_locate_rsp  rsp     = {0,};
         dict_t                 *dict    = NULL;
+        glusterd_conf_t        *priv = NULL;
         glusterd_volinfo_t     *volinfo = NULL;
         glusterd_brickinfo_t   *brickinfo = NULL;
-        char                   *tmp_str = NULL;
+        char                    tmp_str[PATH_MAX] = {0,};
 
         GF_ASSERT (req);
 
+        priv    = THIS->private;
+
         if (!gf_xdr_to_cli_log_locate_req (req->msg[0], &cli_req)) {
                 //failed to decode msg;
                 req->rpc_err = GARBAGE_ARGS;
@@ -1671,8 +1674,13 @@  glusterd_handle_log_locate (rpcsvc_request_t *req)
         }
 
         list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
-                tmp_str = gf_strdup (brickinfo->logfile);
-                rsp.path = dirname (tmp_str);
+                if (brickinfo->logfile) {
+                        strcpy (tmp_str, brickinfo->logfile);
+                        rsp.path = dirname (tmp_str);
+                } else {
+                        snprintf (tmp_str, PATH_MAX, "%s/logs/", priv->workdir);
+                        rsp.path = tmp_str;
+                }
                 break;
         }
 
@@ -1685,9 +1693,6 @@  out:
         ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
                                      gf_xdr_serialize_cli_log_locate_rsp);
 
-        if (tmp_str)
-                GF_FREE (tmp_str);
-
         return ret;
 }