From 2ee82710c088461cf4d3769625723346345566f9 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Tue, 14 May 2013 14:00:08 +0530 Subject: libglusterfs/statedump: move options file and statedumps from /tmp Change-Id: I6b107b9a668b0521b955dba8895cbbeaf9e7cb02 BUG: 764890 Signed-off-by: Raghavendra Bhat Reviewed-on: http://review.gluster.org/5005 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- libglusterfs/src/Makefile.am | 3 ++- libglusterfs/src/glusterfs.h | 2 ++ libglusterfs/src/run.c | 2 +- libglusterfs/src/statedump.c | 25 +++++++++++++++++-------- 4 files changed, 22 insertions(+), 10 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index ac1a9f58e21..aadd97971c2 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -1,5 +1,6 @@ libglusterfs_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) \ - $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) + $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) \ + -DDATADIR=\"$(localstatedir)\" libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 \ -D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" \ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 035bb7c0e7d..4dfb4cfb095 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -129,6 +129,8 @@ #define ZR_FILE_CONTENT_REQUEST(key) (!strncmp(key, ZR_FILE_CONTENT_STR, \ ZR_FILE_CONTENT_STRLEN)) +#define DEFAULT_VAR_RUN_DIRECTORY DATADIR "/run/gluster" + /* GlusterFS's maximum supported Auxilary GIDs */ /* TODO: Keeping it to 200, so that we can fit in 2KB buffer for auth data * in RPC server code, if there is ever need for having more aux-gids, then diff --git a/libglusterfs/src/run.c b/libglusterfs/src/run.c index 34d75df69c2..adc61513a72 100644 --- a/libglusterfs/src/run.c +++ b/libglusterfs/src/run.c @@ -467,7 +467,7 @@ main (int argc, char **argv) printf ("%d %d [%s]\n", ret, errno, strerror (errno)); TBANNER ("output redirection"); - fd = open ("/tmp/foof", O_WRONLY|O_CREAT|O_TRUNC, 0600); + fd = mkstemp ("/tmp/foof"); assert (fd != -1); runinit (&runner); runner_add_args (&runner, "echo", "foo", NULL); 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; -- cgit