diff options
author | Raghavendra Bhat <raghavendra@redhat.com> | 2013-05-14 14:00:08 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2013-05-14 10:47:09 -0700 |
commit | 2ee82710c088461cf4d3769625723346345566f9 (patch) | |
tree | c0d0ae7dec81921a9b2bac047de91219e64800bf /libglusterfs/src/statedump.c | |
parent | c59166c5a3306231864fe7d99e383259a9385233 (diff) |
libglusterfs/statedump: move options file and statedumps from /tmp
Change-Id: I6b107b9a668b0521b955dba8895cbbeaf9e7cb02
BUG: 764890
Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com>
Reviewed-on: http://review.gluster.org/5005
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs/src/statedump.c')
-rw-r--r-- | libglusterfs/src/statedump.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 899d8ef2b1b..90d345dadbe 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -55,15 +55,11 @@ gf_proc_dump_unlock (void) static int -gf_proc_dump_open (char *dump_dir, char *brickname) +gf_proc_dump_open (char path[]) { - char path[PATH_MAX] = {0,}; int dump_fd = -1; - snprintf (path, sizeof (path), "%s/%s.%d.dump", (dump_dir ? - dump_dir : "/tmp"), brickname, getpid()); - - dump_fd = open (path, O_CREAT|O_RDWR|O_TRUNC|O_APPEND, 0600); + dump_fd = mkostemp (path, O_CREAT|O_RDWR|O_TRUNC|O_APPEND); if (dump_fd < 0) return -1; @@ -572,7 +568,8 @@ gf_proc_dump_options_init () char dump_option_file[PATH_MAX]; snprintf (dump_option_file, sizeof (dump_option_file), - "/tmp/glusterdump.%d.options", getpid ()); + DEFAULT_VAR_RUN_DIRECTORY + "glusterdump.%d.options", getpid ()); fp = fopen (dump_option_file, "r"); @@ -619,6 +616,8 @@ gf_proc_dump_info (int signum) glusterfs_ctx_t *ctx = NULL; glusterfs_graph_t *trav = NULL; char brick_name[PATH_MAX] = {0,}; + char tmp_dump_name[PATH_MAX] = {0,}; + char path[PATH_MAX] = {0,}; gf_proc_dump_lock (); @@ -631,7 +630,16 @@ gf_proc_dump_info (int signum) } else strncpy (brick_name, "glusterdump", sizeof (brick_name)); - ret = gf_proc_dump_open (ctx->statedump_path, brick_name); + snprintf (path, sizeof (path), "%s/%s.%d.dump", + ((ctx->statedump_path != NULL)?ctx->statedump_path: + DEFAULT_VAR_RUN_DIRECTORY), + brick_name, getpid()); + + snprintf (tmp_dump_name, PATH_MAX, "%s/dumpXXXXXX", + ((ctx->statedump_path != NULL)?ctx->statedump_path: + DEFAULT_VAR_RUN_DIRECTORY)); + + ret = gf_proc_dump_open (tmp_dump_name); if (ret < 0) goto out; @@ -673,6 +681,7 @@ gf_proc_dump_info (int signum) out: if (gf_dump_fd != -1) gf_proc_dump_close (); + rename (tmp_dump_name, path); gf_proc_dump_unlock (); return; |