summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendra@redhat.com>2012-10-18 14:42:16 +0530
committerVijay Bellur <vbellur@redhat.com>2012-10-19 08:24:14 -0400
commitacd958ed5ea5e100ea141ff670e68022a3752d7f (patch)
treef230a0144e845ad2f0b6d8717d3a27e12d8167c0 /libglusterfs
parente5fc29c264397e3c76262b2cff9a4516fd4c6475 (diff)
core/statedump: dump the information in a temporary file and
then rename Change-Id: Id35fd5b3801f46db75660a26d1f3011883c293a7 BUG: 852041 Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-on: https://code.engineering.redhat.com/gerrit/120 Reviewed-by: Vijay Bellur <vbellur@redhat.com> Tested-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/statedump.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c
index 8e0b7aeca24..06c2e6391d0 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_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)
{
@@ -711,6 +704,8 @@ gf_proc_dump_info (int signum)
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 ();
@@ -727,10 +722,12 @@ gf_proc_dump_info (int signum)
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;
@@ -801,6 +798,7 @@ gf_proc_dump_info (int signum)
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 ();