diff options
author | Raghavendra Bhat <raghavendra@redhat.com> | 2012-10-08 11:02:55 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2012-10-15 22:43:02 -0700 |
commit | 3d10587d9d6400c9141b1f278bb5e2027fa784b8 (patch) | |
tree | 38e4872c1b1901d3775de6cb0d56b06f9f1add9f /libglusterfs/src | |
parent | 3c05477e69ad61eb744948a7e921ae53665f97e5 (diff) |
glusterfs: code cleanup
Change-Id: I99bbb720d8b42c8b3899bb1353c6b73f7fcd50f1
BUG: 764890
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-on: http://review.gluster.org/4042
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/statedump.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 8e7e905fb80..f74bd37cfba 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -53,18 +53,12 @@ gf_proc_dump_unlock (void) pthread_mutex_unlock (&gf_proc_dump_mutex); } - static int -gf_proc_dump_open (char *dump_dir, char *brickname) +gf_proc_dump_open (char *tmpname) { - char path[PATH_MAX] = {0,}; int dump_fd = -1; - snprintf (path, sizeof (path), "%s/%s.%d.dump.%"PRIu64, - (dump_dir ? dump_dir : "/tmp"), brickname, getpid(), - (uint64_t) time (NULL)); - - dump_fd = open (path, O_CREAT|O_RDWR|O_TRUNC|O_APPEND, 0600); + dump_fd = mkostemp (tmpname, O_CREAT|O_EXCL|O_RDWR|O_TRUNC|O_APPEND); if (dump_fd < 0) return -1; @@ -72,7 +66,6 @@ gf_proc_dump_open (char *dump_dir, char *brickname) return 0; } - static void gf_proc_dump_close (void) { @@ -710,6 +703,8 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) struct timeval tv = {0,}; char timestr[256] = {0,}; char sign_string[512] = {0,}; + char tmp_dump_name[] = "/tmp/dumpXXXXXX"; + char path[PATH_MAX] = {0,}; gf_proc_dump_lock (); @@ -725,10 +720,12 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) if (ret < 0) goto out; - if (dump_options.dump_path) - ret = gf_proc_dump_open (dump_options.dump_path, brick_name); - else - ret = gf_proc_dump_open (ctx->statedump_path, brick_name); + snprintf (path, sizeof (path), "%s/%s.%d.dump.%"PRIu64, + ((dump_options.dump_path != NULL)?dump_options.dump_path: + ((ctx->statedump_path != NULL)?ctx->statedump_path:"/tmp")), + brick_name, getpid(), (uint64_t) time (NULL)); + + ret = gf_proc_dump_open (tmp_dump_name); if (ret < 0) goto out; @@ -797,6 +794,7 @@ gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) out: if (gf_dump_fd != -1) gf_proc_dump_close (); + rename (tmp_dump_name, path); GF_FREE (dump_options.dump_path); dump_options.dump_path = NULL; gf_proc_dump_unlock (); |