wireshark/wireshark-0012-move-default-temporary-directory-to-var-tmp.patch

231 lines
6.4 KiB
Diff
Raw Normal View History

From: Peter Hatina <phatina@redhat.com>
Date: Tue, 24 Sep 2013 10:55:09 +0200
Subject: [PATCH] move default temporary directory to /var/tmp
diff --git a/epan/filesystem.c b/epan/filesystem.c
index 053711d..adf3b91 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -74,6 +74,8 @@
#include <wiretap/wtap.h> /* for WTAP_ERR_SHORT_WRITE */
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
+
#define PROFILES_DIR "profiles"
#define PLUGINS_DIR_NAME "plugins"
@@ -1574,7 +1576,7 @@ deletefile(const char *path)
*/
char *get_tempfile_path(const char *filename)
{
- return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), filename);
+ return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_tmp_dir(), filename);
}
/*
diff --git a/tempfile.c b/tempfile.c
index 2fab0df..10ab3e6 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -50,6 +50,7 @@
#include "tempfile.h"
#include <wsutil/file_util.h>
+#include <wsutil/wstmpdir.h> /* For get_tmp_dir() */
#ifndef __set_errno
#define __set_errno(x) errno=(x)
@@ -203,7 +204,7 @@ create_tempfile(char **namebuf, const char *pfx)
/*
* We can't use get_tempfile_path here because we're called from dumpcap.c.
*/
- tmp_dir = g_get_tmp_dir();
+ tmp_dir = get_tmp_dir();
#ifdef _WIN32
_tzset();
@@ -237,7 +238,7 @@ create_tempfile(char **namebuf, const char *pfx)
/**
* Create a directory with the given prefix (e.g. "wireshark"). The path
- * is created using g_get_tmp_dir and mkdtemp.
+ * is created using get_tmp_dir and mkdtemp.
*
* @param namebuf
* @param pfx A prefix for the temporary directory.
@@ -265,7 +266,7 @@ create_tempdir(char **namebuf, const char *pfx)
/*
* We can't use get_tempfile_path here because we're called from dumpcap.c.
*/
- tmp_dir = g_get_tmp_dir();
+ tmp_dir = get_tmp_dir();
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]) {
td_path_len[idx] *= 2;
diff --git a/ui/gtk/proto_help.c b/ui/gtk/proto_help.c
index bbf5fe0..9998a22 100644
--- a/ui/gtk/proto_help.c
+++ b/ui/gtk/proto_help.c
@@ -44,6 +44,8 @@
#include <epan/strutil.h>
#include <epan/proto.h>
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
+
#include "ui/gtk/proto_help.h"
/*
@@ -162,7 +164,7 @@ void proto_help_init(void)
/* Start loop */
#ifdef PH_DEBUG_LOG
- ph_log_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), PH_FILE_LOG);
+ ph_log_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_tmp_dir(), PH_FILE_LOG);
#endif
for (i = 0; i < PH_CONF_DIRS; i++) {
diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common
index 570dbe6..7a33f5b 100644
--- a/wsutil/Makefile.common
+++ b/wsutil/Makefile.common
@@ -43,7 +43,8 @@ LIBWSUTIL_SRC = \
mpeg-audio.c \
privileges.c \
str_util.c \
- type_util.c
+ type_util.c \
+ wstmpdir.c
# Header files that are not generated from other files
LIBWSUTIL_INCLUDES = \
@@ -60,4 +61,5 @@ LIBWSUTIL_INCLUDES = \
mpeg-audio.h \
privileges.h \
str_util.h \
- type_util.h
+ type_util.h \
+ wstmpdir.h
diff --git a/wsutil/wstmpdir.c b/wsutil/wstmpdir.c
new file mode 100644
index 0000000..d8b733b
--- /dev/null
+++ b/wsutil/wstmpdir.c
@@ -0,0 +1,70 @@
+/* wstmpdir.c
+ *
+ * Copyright (C) 2013 Red Hat, Inc. All right reserved.
+ *
+ * Temporary directory routine
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Author: Peter Hatina <phatina@redhat.com>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include "wstmpdir.h"
+
+/**
+ * Gets the directory to use for temporary files.
+ *
+ * Inspired by glib-2.0. If no TMP, TEMP or TMPDIR is set,
+ * /var/tmp is returned (Fedora specific).
+ *
+ * Returns: the directory to use for temporary files.
+ */
+const char *get_tmp_dir(void)
+{
+ static gchar *tmp_dir;
+
+ if (g_once_init_enter(&tmp_dir)) {
+ gchar *tmp;
+
+ tmp = g_strdup(g_getenv("TEMP"));
+ if (tmp == NULL || *tmp == '\0') {
+ g_free(tmp);
+ tmp = g_strdup(g_getenv("TMPDIR"));
+ }
+
+#ifdef P_tmpdir
+ if (tmp == NULL || *tmp == '\0') {
+ gsize k;
+ g_free(tmp);
+ tmp = g_strdup(P_tmpdir);
+ k = strlen(tmp);
+ if (k > 1 && G_IS_DIR_SEPARATOR(tmp[k - 1]))
+ tmp[k - 1] = '\0';
+ }
+#endif /* P_tmpdir */
+
+ if (tmp == NULL || *tmp == '\0') {
+ g_free(tmp);
+ tmp = g_strdup("/var/tmp");
+ }
+
+ g_once_init_leave(&tmp_dir, tmp);
+ }
+
+ return tmp_dir;
+}
diff --git a/wsutil/wstmpdir.h b/wsutil/wstmpdir.h
new file mode 100644
index 0000000..021b615
--- /dev/null
+++ b/wsutil/wstmpdir.h
@@ -0,0 +1,39 @@
+/* wstmpdir.c
+ *
+ * Copyright (C) 2013 Red Hat, Inc. All right reserved.
+ *
+ * Temporary directory routine
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Author: Peter Hatina <phatina@redhat.com>
+ */
+
+#ifndef __WS_TMP_DIR_H__
+#define __WS_TMP_DIR_H__
+
+#include "ws_symbol_export.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+WS_DLL_PUBLIC const char *get_tmp_dir(void);
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif // __WS_TMP_DIR_H__