Blame wireshark-0008-move-default-temporary-directory-to-var-tmp.patch

c06811
From: Peter Hatina <phatina@redhat.com>
c06811
Date: Tue, 24 Sep 2013 10:55:09 +0200
173888
Subject: [PATCH] move default temporary directory to /var/tmp
c06811
d3e571
Conflicts:
d3e571
	wsutil/Makefile.common
d3e571
	wsutil/filesystem.c
d3e571
	wsutil/tempfile.c
c06811
d3e571
Change-Id: I881c17e1fa3cb292dabe7612bc06748cccfcfcda
d3e571
d3e571
diff --git a/ui/gtk/proto_help.c b/ui/gtk/proto_help.c
d3e571
index 6de7daa..a644615 100644
d3e571
--- a/ui/gtk/proto_help.c
d3e571
+++ b/ui/gtk/proto_help.c
d3e571
@@ -42,6 +42,8 @@
d3e571
 #include <epan/strutil.h>
d3e571
 #include <epan/proto.h>
Peter Hatina 1fba24
 
Peter Hatina 1fba24
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
Peter Hatina 1fba24
+
d3e571
 #include "ui/gtk/proto_help.h"
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 /*
d3e571
@@ -160,7 +162,7 @@ void proto_help_init(void)
d3e571
 	/* Start loop */
d3e571
 
d3e571
 #ifdef PH_DEBUG_LOG
d3e571
-	ph_log_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), PH_FILE_LOG);
d3e571
+	ph_log_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_tmp_dir(), PH_FILE_LOG);
d3e571
 #endif
d3e571
 
d3e571
 	for (i = 0; i < PH_CONF_DIRS; i++) {
d3e571
diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common
d3e571
index 75c31bd..81648a7 100644
d3e571
--- a/wsutil/Makefile.common
d3e571
+++ b/wsutil/Makefile.common
d3e571
@@ -62,7 +62,8 @@ LIBWSUTIL_SRC = 	\
d3e571
 	time_util.c	\
d3e571
 	type_util.c	\
d3e571
 	u3.c		\
d3e571
-	unicode-utils.c
d3e571
+	unicode-utils.c \
d3e571
+	wstmpdir.c
d3e571
 
d3e571
 # Header files that are not generated from other files
d3e571
 LIBWSUTIL_INCLUDES = 	\
Peter Hatina 05ceca
@@ -104,7 +105,8 @@ LIBWSUTIL_INCLUDES = 	\
d3e571
 	time_util.h	\
d3e571
 	type_util.h	\
d3e571
 	u3.h		\
d3e571
-	unicode-utils.h
d3e571
+	unicode-utils.h \
d3e571
+	wstmpdir.h
Peter Hatina 05ceca
 
Peter Hatina 05ceca
 #
Peter Hatina 05ceca
 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
d3e571
diff --git a/wsutil/tempfile.c b/wsutil/tempfile.c
d3e571
index ccefe30..ac40319 100644
d3e571
--- a/wsutil/tempfile.c
d3e571
+++ b/wsutil/tempfile.c
d3e571
@@ -48,6 +48,7 @@
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 #include "tempfile.h"
Peter Hatina 1fba24
 #include <wsutil/file_util.h>
Peter Hatina 1fba24
+#include <wsutil/wstmpdir.h>    /* For get_tmp_dir() */
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 #ifndef __set_errno
Peter Hatina 1fba24
 #define __set_errno(x) errno=(x)
d3e571
@@ -150,7 +151,7 @@ mkdtemp (char *template)
d3e571
  */
d3e571
 char *get_tempfile_path(const char *filename)
d3e571
 {
d3e571
-    return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), filename);
d3e571
+    return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_tmp_dir(), filename);
d3e571
 }
d3e571
 
d3e571
 #define MAX_TEMPFILES   3
d3e571
@@ -207,7 +208,7 @@ create_tempfile(char **namebuf, const char *pfx)
d3e571
 		tf[idx].path = (char *)g_malloc(tf[idx].len);
d3e571
 	}
d3e571
 
Peter Hatina 1fba24
-	tmp_dir = g_get_tmp_dir();
Peter Hatina 1fba24
+	tmp_dir = get_tmp_dir();
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 #ifdef _WIN32
Peter Hatina 1fba24
 	_tzset();
d3e571
@@ -241,7 +242,7 @@ create_tempfile(char **namebuf, const char *pfx)
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 /**
Peter Hatina 1fba24
  * Create a directory with the given prefix (e.g. "wireshark"). The path
Peter Hatina 1fba24
- * is created using g_get_tmp_dir and mkdtemp.
Peter Hatina 1fba24
+ * is created using get_tmp_dir and mkdtemp.
Peter Hatina 1fba24
  *
Peter Hatina 1fba24
  * @param namebuf
Peter Hatina 1fba24
  * @param pfx A prefix for the temporary directory.
d3e571
@@ -269,7 +270,7 @@ create_tempdir(char **namebuf, const char *pfx)
Peter Hatina 1fba24
 	/*
Peter Hatina 1fba24
 	 * We can't use get_tempfile_path here because we're called from dumpcap.c.
Peter Hatina 1fba24
 	 */
Peter Hatina 1fba24
-	tmp_dir = g_get_tmp_dir();
Peter Hatina 1fba24
+	tmp_dir = get_tmp_dir();
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 	while (g_snprintf(td_path[idx], td_path_len[idx], "%s%c%s" TMP_FILE_SUFFIX, tmp_dir, G_DIR_SEPARATOR, pfx) > td_path_len[idx]) {
Peter Hatina 1fba24
 		td_path_len[idx] *= 2;
Peter Hatina 1fba24
diff --git a/wsutil/wstmpdir.c b/wsutil/wstmpdir.c
Peter Hatina 1fba24
new file mode 100644
Peter Hatina 1fba24
index 0000000..d8b733b
Peter Hatina 1fba24
--- /dev/null
Peter Hatina 1fba24
+++ b/wsutil/wstmpdir.c
Peter Hatina 1fba24
@@ -0,0 +1,70 @@
Peter Hatina 1fba24
+/* wstmpdir.c
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * Copyright (C) 2013 Red Hat, Inc. All right reserved.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * Temporary directory routine
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * This program is free software; you can redistribute it and/or
Peter Hatina 1fba24
+ * modify it under the terms of the GNU General Public License
Peter Hatina 1fba24
+ * as published by the Free Software Foundation; either version 2
Peter Hatina 1fba24
+ * of the License, or (at your option) any later version.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * This program is distributed in the hope that it will be useful,
Peter Hatina 1fba24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Peter Hatina 1fba24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Peter Hatina 1fba24
+ * GNU General Public License for more details.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * You should have received a copy of the GNU General Public License
Peter Hatina 1fba24
+ * along with this program; if not, write to the Free Software
Peter Hatina 1fba24
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * Author: Peter Hatina <phatina@redhat.com>
Peter Hatina 1fba24
+ */
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+#include "config.h"
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+#include <glib.h>
Peter Hatina 1fba24
+#include "wstmpdir.h"
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+/**
Peter Hatina 1fba24
+ * Gets the directory to use for temporary files.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * Inspired by glib-2.0. If no TMP, TEMP or TMPDIR is set,
Peter Hatina 1fba24
+ * /var/tmp is returned (Fedora specific).
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * Returns: the directory to use for temporary files.
Peter Hatina 1fba24
+ */
Peter Hatina 1fba24
+const char *get_tmp_dir(void)
Peter Hatina 1fba24
+{
Peter Hatina 1fba24
+    static gchar *tmp_dir;
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+    if (g_once_init_enter(&tmp_dir)) {
Peter Hatina 1fba24
+        gchar *tmp;
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+        tmp = g_strdup(g_getenv("TEMP"));
Peter Hatina 1fba24
+        if (tmp == NULL || *tmp == '\0') {
Peter Hatina 1fba24
+            g_free(tmp);
Peter Hatina 1fba24
+            tmp = g_strdup(g_getenv("TMPDIR"));
Peter Hatina 1fba24
+        }
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+#ifdef P_tmpdir
Peter Hatina 1fba24
+        if (tmp == NULL || *tmp == '\0') {
Peter Hatina 1fba24
+            gsize k;
Peter Hatina 1fba24
+            g_free(tmp);
Peter Hatina 1fba24
+            tmp = g_strdup(P_tmpdir);
Peter Hatina 1fba24
+            k = strlen(tmp);
Peter Hatina 1fba24
+            if (k > 1 && G_IS_DIR_SEPARATOR(tmp[k - 1]))
Peter Hatina 1fba24
+                tmp[k - 1] = '\0';
Peter Hatina 1fba24
+        }
Peter Hatina 1fba24
+#endif /* P_tmpdir */
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+        if (tmp == NULL || *tmp == '\0') {
Peter Hatina 1fba24
+            g_free(tmp);
Peter Hatina 1fba24
+            tmp = g_strdup("/var/tmp");
Peter Hatina 1fba24
+        }
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+        g_once_init_leave(&tmp_dir, tmp);
Peter Hatina 1fba24
+    }
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+    return tmp_dir;
Peter Hatina 1fba24
+}
Peter Hatina 1fba24
diff --git a/wsutil/wstmpdir.h b/wsutil/wstmpdir.h
Peter Hatina 1fba24
new file mode 100644
Peter Hatina 1fba24
index 0000000..021b615
Peter Hatina 1fba24
--- /dev/null
Peter Hatina 1fba24
+++ b/wsutil/wstmpdir.h
Peter Hatina 1fba24
@@ -0,0 +1,39 @@
Peter Hatina 1fba24
+/* wstmpdir.c
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * Copyright (C) 2013 Red Hat, Inc. All right reserved.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * Temporary directory routine
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * This program is free software; you can redistribute it and/or
Peter Hatina 1fba24
+ * modify it under the terms of the GNU General Public License
Peter Hatina 1fba24
+ * as published by the Free Software Foundation; either version 2
Peter Hatina 1fba24
+ * of the License, or (at your option) any later version.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * This program is distributed in the hope that it will be useful,
Peter Hatina 1fba24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Peter Hatina 1fba24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Peter Hatina 1fba24
+ * GNU General Public License for more details.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * You should have received a copy of the GNU General Public License
Peter Hatina 1fba24
+ * along with this program; if not, write to the Free Software
Peter Hatina 1fba24
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Peter Hatina 1fba24
+ *
Peter Hatina 1fba24
+ * Author: Peter Hatina <phatina@redhat.com>
Peter Hatina 1fba24
+ */
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+#ifndef __WS_TMP_DIR_H__
Peter Hatina 1fba24
+#define __WS_TMP_DIR_H__
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+#include "ws_symbol_export.h"
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+#ifdef __cplusplus
Peter Hatina 1fba24
+extern "C" {
Peter Hatina 1fba24
+#endif // __cplusplus
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+WS_DLL_PUBLIC const char *get_tmp_dir(void);
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+#ifdef __cplusplus
Peter Hatina 1fba24
+}
Peter Hatina 1fba24
+#endif // __cplusplus
Peter Hatina 1fba24
+
Peter Hatina 1fba24
+#endif // __WS_TMP_DIR_H__