summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorShyamsundarR <srangana@redhat.com>2018-07-30 20:16:21 -0400
committerAmar Tumballi <amarts@redhat.com>2018-08-16 06:10:44 +0000
commit9297e1950f76270e99c76970f57810e01e305a3b (patch)
tree9b1cf851e6d44341b0c391fa67a717ad0cb17235 /libglusterfs
parent82e5acd6b30aabccb0a1e157dc633591c4919a3e (diff)
contrib: Remove gf_mkostemp copied from GLibC
gf_mkostemp is borrowed from GLibC a long time back, we now have mkostemp or mkstemp alternatives with all distributions and versions that we care for. As a result removing this from the contrib directory and modifying the one instance that is still using the same. This is part of code cleanup as we cleaned up coverity SECUR_TEMP errors. Updates: bz#1193929 Change-Id: I1ad7863043cdb0845c53748f5a0522e767079130 Signed-off-by: ShyamsundarR <srangana@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/Makefile.am2
-rw-r--r--libglusterfs/src/common-utils.c16
-rw-r--r--libglusterfs/src/compat.h2
3 files changed, 13 insertions, 7 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
index 92521cc44d1..a910d8e8a53 100644
--- a/libglusterfs/src/Makefile.am
+++ b/libglusterfs/src/Makefile.am
@@ -31,7 +31,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \
circ-buff.c event-history.c gidcache.c ctx.c client_t.c event-poll.c \
event-epoll.c syncop-utils.c cluster-syncop.c refcount.c \
$(CONTRIBDIR)/libgen/basename_r.c \
- $(CONTRIBDIR)/libgen/dirname_r.c $(CONTRIBDIR)/stdlib/gf_mkostemp.c \
+ $(CONTRIBDIR)/libgen/dirname_r.c \
strfd.c parse-utils.c $(CONTRIBDIR)/mount/mntent.c \
$(CONTRIBDIR)/libexecinfo/execinfo.c quota-common-utils.c rot-buffs.c \
$(CONTRIBDIR)/timer-wheel/timer-wheel.c \
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 543f8601ebe..374b76b0410 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -4238,16 +4238,26 @@ gf_backtrace_fillframes (char *buf)
size_t idx = 0;
size_t pos = 0;
size_t inc = 0;
- char tmpl[32] = "/tmp/btXXXXXX";
+ char tmpl[] = "/tmp/glfs-bt-XXXXXX";
frames = backtrace (array, GF_BACKTRACE_FRAME_COUNT);
if (!frames)
return -1;
- fd = gf_mkostemp (tmpl, 0, O_RDWR);
+ /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
+ fd = mkstemp (tmpl);
if (fd == -1)
return -1;
+ /* Calling unlink so that when the file is closed or program
+ * terminates the temporary file is deleted.
+ */
+ ret = sys_unlink (tmpl);
+ if (ret < 0) {
+ gf_msg (THIS->name, GF_LOG_INFO, 0, LG_MSG_FILE_OP_FAILED,
+ "Unable to delete temporary file: %s", tmpl);
+ }
+
/*The most recent two frames are the calling function and
* gf_backtrace_save, which we can infer.*/
@@ -4280,8 +4290,6 @@ out:
if (fp)
fclose (fp);
- sys_unlink (tmpl);
-
return (idx > 0)? 0: -1;
}
diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h
index 0c56fcc5cb9..e0ffe73926a 100644
--- a/libglusterfs/src/compat.h
+++ b/libglusterfs/src/compat.h
@@ -451,8 +451,6 @@ char *dirname_r(char *path);
#define dirname(path) dirname_r(path)
#endif /* THREAD_UNSAFE_DIRNAME */
-int gf_mkostemp (char *tmpl, int suffixlen, int flags);
-
#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
/* Linux, Solaris, Cygwin */
#define ST_ATIM_SEC(stbuf) ((stbuf)->st_atim.tv_sec)