Blame wireshark-0012-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
c06811
Peter Hatina 1fba24
diff --git a/epan/filesystem.c b/epan/filesystem.c
c06811
index 053711d..adf3b91 100644
Peter Hatina 1fba24
--- a/epan/filesystem.c
Peter Hatina 1fba24
+++ b/epan/filesystem.c
Peter Hatina 1fba24
@@ -74,6 +74,8 @@
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 #include <wiretap/wtap.h>   /* for WTAP_ERR_SHORT_WRITE */
Peter Hatina 1fba24
 
Peter Hatina 1fba24
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
Peter Hatina 1fba24
+
Peter Hatina 1fba24
 #define PROFILES_DIR    "profiles"
Peter Hatina 1fba24
 #define PLUGINS_DIR_NAME    "plugins"
Peter Hatina 1fba24
 
Peter Hatina 1fba24
@@ -1574,7 +1576,7 @@ deletefile(const char *path)
Peter Hatina 1fba24
  */
Peter Hatina 1fba24
 char *get_tempfile_path(const char *filename)
Peter Hatina 1fba24
 {
Peter Hatina 1fba24
-    return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), filename);
Peter Hatina 1fba24
+    return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_tmp_dir(), filename);
Peter Hatina 1fba24
 }
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 /*
Peter Hatina 1fba24
diff --git a/tempfile.c b/tempfile.c
c06811
index 2fab0df..10ab3e6 100644
Peter Hatina 1fba24
--- a/tempfile.c
Peter Hatina 1fba24
+++ b/tempfile.c
Peter Hatina 1fba24
@@ -50,6 +50,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)
Peter Hatina 1fba24
@@ -203,7 +204,7 @@ create_tempfile(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
 #ifdef _WIN32
Peter Hatina 1fba24
 	_tzset();
Peter Hatina 1fba24
@@ -237,7 +238,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.
Peter Hatina 1fba24
@@ -265,7 +266,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/ui/gtk/proto_help.c b/ui/gtk/proto_help.c
c06811
index bbf5fe0..9998a22 100644
Peter Hatina 1fba24
--- a/ui/gtk/proto_help.c
Peter Hatina 1fba24
+++ b/ui/gtk/proto_help.c
Peter Hatina 1fba24
@@ -44,6 +44,8 @@
Peter Hatina 1fba24
 #include <epan/strutil.h>
Peter Hatina 1fba24
 #include <epan/proto.h>
Peter Hatina 1fba24
 
Peter Hatina 1fba24
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
Peter Hatina 1fba24
+
Peter Hatina 1fba24
 #include "ui/gtk/proto_help.h"
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 /*
Peter Hatina 1fba24
@@ -162,7 +164,7 @@ void proto_help_init(void)
Peter Hatina 1fba24
 	/* Start loop */
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 #ifdef PH_DEBUG_LOG
Peter Hatina 1fba24
-	ph_log_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), PH_FILE_LOG);
Peter Hatina 1fba24
+	ph_log_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_tmp_dir(), PH_FILE_LOG);
Peter Hatina 1fba24
 #endif
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 	for (i = 0; i < PH_CONF_DIRS; i++) {
Peter Hatina 1fba24
diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common
c06811
index 570dbe6..7a33f5b 100644
Peter Hatina 1fba24
--- a/wsutil/Makefile.common
Peter Hatina 1fba24
+++ b/wsutil/Makefile.common
Peter Hatina 1fba24
@@ -43,7 +43,8 @@ LIBWSUTIL_SRC = 	\
Peter Hatina 1fba24
 	mpeg-audio.c	\
Peter Hatina 1fba24
 	privileges.c	\
Peter Hatina 1fba24
 	str_util.c	\
Peter Hatina 1fba24
-	type_util.c
Peter Hatina 1fba24
+	type_util.c     \
Peter Hatina 1fba24
+	wstmpdir.c
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 # Header files that are not generated from other files
Peter Hatina 1fba24
 LIBWSUTIL_INCLUDES = 	\
Peter Hatina 1fba24
@@ -60,4 +61,5 @@ LIBWSUTIL_INCLUDES = 	\
Peter Hatina 1fba24
 	mpeg-audio.h	\
Peter Hatina 1fba24
 	privileges.h	\
Peter Hatina 1fba24
 	str_util.h	\
Peter Hatina 1fba24
-	type_util.h
Peter Hatina 1fba24
+	type_util.h     \
Peter Hatina 1fba24
+	wstmpdir.h
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__