Blame wireshark-0006-Move-tmp-to-var-tmp.patch

Martin Sehnoutka 4cab85
From cb54210f7f02b07768cfbf49ae266d487f580e1b Mon Sep 17 00:00:00 2001
Martin Sehnoutka 4cab85
From: rpm-build <rpm-build>
Martin Sehnoutka 4cab85
Date: Thu, 29 Jun 2017 15:32:58 +0200
Martin Sehnoutka 4cab85
Subject: [PATCH] Move /tmp to /var/tmp
c06811
Martin Sehnoutka 4cab85
Fedora is using tmpfs which is limited by the size of RAM, thus we need
Martin Sehnoutka 4cab85
to use different directory on different filesystem.
Martin Sehnoutka 4cab85
---
Martin Sehnoutka 4cab85
 ui/gtk/about_dlg.c             |  3 +-
Martin Sehnoutka 4cab85
 ui/qt/about_dialog.cpp         |  3 +-
Martin Sehnoutka 4cab85
 ui/qt/iax2_analysis_dialog.cpp |  5 +--
Martin Sehnoutka 4cab85
 ui/qt/rtp_analysis_dialog.cpp  |  5 +--
Martin Sehnoutka 4cab85
 ui/qt/rtp_audio_stream.cpp     |  3 +-
Martin Sehnoutka 4cab85
 wsutil/Makefile.am             |  6 ++--
Martin Sehnoutka 4cab85
 wsutil/tempfile.c              |  9 +++---
Martin Sehnoutka 4cab85
 wsutil/tempfile.h              |  4 +--
Martin Sehnoutka 4cab85
 wsutil/wstmpdir.c              | 70 ++++++++++++++++++++++++++++++++++++++++++
Martin Sehnoutka 4cab85
 wsutil/wstmpdir.h              | 39 +++++++++++++++++++++++
Martin Sehnoutka 4cab85
 10 files changed, 132 insertions(+), 15 deletions(-)
Martin Sehnoutka 4cab85
 create mode 100644 wsutil/wstmpdir.c
Martin Sehnoutka 4cab85
 create mode 100644 wsutil/wstmpdir.h
d3e571
Peter Hatina fe8eca
diff --git a/ui/gtk/about_dlg.c b/ui/gtk/about_dlg.c
Martin Sehnoutka 4cab85
index 22ca841..6bcb527 100644
Peter Hatina fe8eca
--- a/ui/gtk/about_dlg.c
Peter Hatina fe8eca
+++ b/ui/gtk/about_dlg.c
Martin Sehnoutka 4cab85
@@ -28,6 +28,7 @@
Martin Sehnoutka 4cab85
 #include <gtk/gtk.h>
Peter Hatina c9a65b
 
Peter Hatina fe8eca
 #include <wsutil/filesystem.h>
Martin Sehnoutka 4cab85
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
Peter Hatina fe8eca
 #include <wsutil/copyright_info.h>
Michal Ruprich 97ece0
 #include <version_info.h>
Peter Hatina fe8eca
 #ifdef HAVE_LIBSMI
Martin Sehnoutka 4cab85
@@ -427,7 +428,7 @@ about_folders_page_new(void)
Peter Hatina fe8eca
       "capture files");
Peter Hatina fe8eca
 
Peter Hatina fe8eca
   /* temp */
Peter Hatina fe8eca
-  about_folders_row(table, "Temp", g_get_tmp_dir(),
Peter Hatina fe8eca
+  about_folders_row(table, "Temp", get_tmp_dir(),
Peter Hatina fe8eca
       "untitled capture files");
Peter Hatina fe8eca
 
Peter Hatina fe8eca
   /* pers conf */
Peter Hatina fe8eca
diff --git a/ui/qt/about_dialog.cpp b/ui/qt/about_dialog.cpp
Martin Sehnoutka 4cab85
index 31dc581..2f74285 100644
Peter Hatina fe8eca
--- a/ui/qt/about_dialog.cpp
Peter Hatina fe8eca
+++ b/ui/qt/about_dialog.cpp
Martin Sehnoutka 4cab85
@@ -26,6 +26,7 @@
Martin Sehnoutka 4cab85
 
Martin Sehnoutka 4cab85
 #include "wireshark_application.h"
Martin Sehnoutka 4cab85
 #include <wsutil/filesystem.h>
Martin Sehnoutka 4cab85
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
Martin Sehnoutka 4cab85
 
Michal Ruprich 97ece0
 #include <QDesktopServices>
Michal Ruprich 97ece0
 #include <QUrl>
Michal Ruprich 97ece0
@@ -206,7 +206,7 @@ FolderListModel::FolderListModel(QObject * parent):
Michal Ruprich 97ece0
     appendRow( QStringList() << tr("\"File\" dialogs") << get_last_open_dir() << tr("capture files"));
Peter Hatina fe8eca
 
Peter Hatina fe8eca
     /* temp */
Michal Ruprich 97ece0
-    appendRow( QStringList() << tr("Temp") << g_get_tmp_dir() << tr("untitled capture files"));
Michal Ruprich 97ece0
+    appendRow( QStringList() << tr("Temp") << get_tmp_dir() << tr("untitled capture files"));
Peter Hatina fe8eca
 
Peter Hatina fe8eca
     /* pers conf */
Michal Ruprich 97ece0
     appendRow( QStringList() << tr("Personal configuration")
Peter Hatina fe8eca
diff --git a/ui/qt/iax2_analysis_dialog.cpp b/ui/qt/iax2_analysis_dialog.cpp
Martin Sehnoutka 4cab85
index ee4e5fd..fe17a95 100644
Peter Hatina fe8eca
--- a/ui/qt/iax2_analysis_dialog.cpp
Peter Hatina fe8eca
+++ b/ui/qt/iax2_analysis_dialog.cpp
Martin Sehnoutka 4cab85
@@ -37,6 +37,7 @@
Martin Sehnoutka 4cab85
 #include "ui/rtp_stream.h"
Martin Sehnoutka 4cab85
 #endif
Martin Sehnoutka 4cab85
 #include <wsutil/utf8_entities.h>
Martin Sehnoutka 4cab85
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
Martin Sehnoutka 4cab85
 
Peter Hatina fe8eca
 #include <wsutil/g711.h>
Peter Hatina fe8eca
 #include <wsutil/pint.h>
Martin Sehnoutka 4cab85
@@ -271,10 +272,10 @@ Iax2AnalysisDialog::Iax2AnalysisDialog(QWidget &parent, CaptureFile &cf) :
Peter Hatina fe8eca
 
Peter Hatina fe8eca
     // We keep our temp files open for the lifetime of the dialog. The GTK+
Peter Hatina fe8eca
     // UI opens and closes at various points.
Peter Hatina fe8eca
-    QString tempname = QString("%1/wireshark_iax2_f").arg(QDir::tempPath());
Peter Hatina fe8eca
+    QString tempname = QString("%1/wireshark_iax2_f").arg(get_tmp_dir());
Peter Hatina fe8eca
     fwd_tempfile_ = new QTemporaryFile(tempname, this);
Peter Hatina fe8eca
     fwd_tempfile_->open();
Peter Hatina fe8eca
-    tempname = QString("%1/wireshark_iax2_r").arg(QDir::tempPath());
Peter Hatina fe8eca
+    tempname = QString("%1/wireshark_iax2_r").arg(get_tmp_dir());
Peter Hatina fe8eca
     rev_tempfile_ = new QTemporaryFile(tempname, this);
Peter Hatina fe8eca
     rev_tempfile_->open();
Peter Hatina fe8eca
 
Peter Hatina fe8eca
diff --git a/ui/qt/rtp_analysis_dialog.cpp b/ui/qt/rtp_analysis_dialog.cpp
Martin Sehnoutka 4cab85
index 5d82e46..8008984 100644
Peter Hatina fe8eca
--- a/ui/qt/rtp_analysis_dialog.cpp
Peter Hatina fe8eca
+++ b/ui/qt/rtp_analysis_dialog.cpp
Martin Sehnoutka 4cab85
@@ -37,6 +37,7 @@
Martin Sehnoutka 4cab85
 
Peter Hatina fe8eca
 #include <wsutil/g711.h>
Peter Hatina fe8eca
 #include <wsutil/pint.h>
Peter Hatina fe8eca
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
Martin Sehnoutka 4cab85
 
Peter Hatina fe8eca
 #include <QMessageBox>
Michal Ruprich 276c25
 #include <QPushButton>
Martin Sehnoutka 4cab85
@@ -331,10 +332,10 @@ RtpAnalysisDialog::RtpAnalysisDialog(QWidget &parent, CaptureFile &cf, struct _r
Peter Hatina fe8eca
 
Peter Hatina fe8eca
     // We keep our temp files open for the lifetime of the dialog. The GTK+
Peter Hatina fe8eca
     // UI opens and closes at various points.
Peter Hatina fe8eca
-    QString tempname = QString("%1/wireshark_rtp_f").arg(QDir::tempPath());
Peter Hatina fe8eca
+    QString tempname = QString("%1/wireshark_rtp_f").arg(get_tmp_dir());
Peter Hatina fe8eca
     fwd_tempfile_ = new QTemporaryFile(tempname, this);
Peter Hatina fe8eca
     fwd_tempfile_->open();
Peter Hatina fe8eca
-    tempname = QString("%1/wireshark_rtp_r").arg(QDir::tempPath());
Peter Hatina fe8eca
+    tempname = QString("%1/wireshark_rtp_r").arg(get_tmp_dir());
Peter Hatina fe8eca
     rev_tempfile_ = new QTemporaryFile(tempname, this);
Peter Hatina fe8eca
     rev_tempfile_->open();
Peter Hatina fe8eca
 
Peter Hatina fe8eca
diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp
Martin Sehnoutka 4cab85
index fde66c8..b9531d2 100644
Peter Hatina fe8eca
--- a/ui/qt/rtp_audio_stream.cpp
Peter Hatina fe8eca
+++ b/ui/qt/rtp_audio_stream.cpp
Peter Hatina c9a65b
@@ -37,6 +37,7 @@
Peter Hatina fe8eca
 #include <ui/rtp_stream.h>
Peter Hatina fe8eca
 
Peter Hatina fe8eca
 #include <wsutil/nstime.h>
Peter Hatina fe8eca
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
Peter Hatina fe8eca
 
Peter Hatina fe8eca
 #include <QAudioFormat>
Peter Hatina fe8eca
 #include <QAudioOutput>
Martin Sehnoutka 4cab85
@@ -76,7 +77,7 @@ RtpAudioStream::RtpAudioStream(QObject *parent, _rtp_stream_info *rtp_stream) :
Peter Hatina fe8eca
                                                 visual_sample_rate_, SPEEX_RESAMPLER_QUALITY_MIN, NULL);
Peter Hatina c9a65b
     speex_resampler_skip_zeros(visual_resampler_);
Peter Hatina fe8eca
 
Peter Hatina fe8eca
-    QString tempname = QString("%1/wireshark_rtp_stream").arg(QDir::tempPath());
Peter Hatina fe8eca
+    QString tempname = QString("%1/wireshark_rtp_stream").arg(get_tmp_dir());
Peter Hatina fe8eca
     tempfile_ = new QTemporaryFile(tempname, this);
Peter Hatina fe8eca
     tempfile_->open();
Peter Hatina fe8eca
 
Peter Hatina f0e481
diff --git a/wsutil/Makefile.am b/wsutil/Makefile.am
Martin Sehnoutka 4cab85
index 2af1b6c..aa149a2 100644
Peter Hatina f0e481
--- a/wsutil/Makefile.am
Peter Hatina f0e481
+++ b/wsutil/Makefile.am
Michal Ruprich 97ece0
@@ -90,6 +90,7 @@ WSUTIL_PUBLIC_INCLUDES = \
Michal Ruprich 97ece0
 	ws_pipe.h		\
Martin Sehnoutka 4cab85
 	ws_printf.h		\
Michal Ruprich 97ece0
 	wsjsmn.h		\
Michal Ruprich 97ece0
+	wstmpdir.h		\
Michal Ruprich 97ece0
 	wsgcrypt.h		\
Michal Ruprich 97ece0
 	wsgetopt.h		\
Michal Ruprich 97ece0
 	wspcap.h		\
Michal Ruprich 97ece0
@@ -168,6 +169,7 @@ libwsutil_la_SOURCES = \
Michal Ruprich 97ece0
 	ws_pipe.c		\
Martin Sehnoutka 4cab85
 	wsgcrypt.c		\
Michal Ruprich 97ece0
 	wsjsmn.c		\
Michal Ruprich 97ece0
+	wstmpdir.c		\
Michal Ruprich 97ece0
 	xtea.c
Peter Hatina f0e481
 
Michal Ruprich 97ece0
 if HAVE_PLUGINS
d3e571
diff --git a/wsutil/tempfile.c b/wsutil/tempfile.c
Martin Sehnoutka 4cab85
index 8e1f8dc..dcf2f78 100644
d3e571
--- a/wsutil/tempfile.c
d3e571
+++ b/wsutil/tempfile.c
Peter Hatina c9a65b
@@ -36,6 +36,7 @@
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 #include "tempfile.h"
Peter Hatina 1fba24
 #include <wsutil/file_util.h>
Peter Hatina fe8eca
+#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)
Michal Ruprich 97ece0
@@ -83,13 +83,14 @@ mkstemps(char *path_template, int suffixlen)
d3e571
  */
d3e571
 char *get_tempfile_path(const char *filename)
d3e571
 {
Peter Hatina fe8eca
-  return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", g_get_tmp_dir(), filename);
Peter Hatina fe8eca
+  return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", get_tmp_dir(), filename);
d3e571
 }
d3e571
 
d3e571
 #define MAX_TEMPFILES   3
Michal Ruprich 97ece0
 
Michal Ruprich 97ece0
 /**
Michal Ruprich 97ece0
- * Create a tempfile with the given prefix (e.g. "wireshark").
Michal Ruprich 97ece0
+ * Create a tempfile with the given prefix (e.g. "wireshark"). The path
Michal Ruprich 97ece0
+ * is created using get_tmp_dir and mkdtemp
Michal Ruprich 97ece0
  *
Michal Ruprich 97ece0
  * @param namebuf If not NULL, receives the full path of the temp file.
Michal Ruprich 97ece0
  *                Should NOT be freed.
Martin Sehnoutka 4cab85
@@ -199,7 +200,7 @@ create_tempfile(char **namebuf, const char *pfx, const char *sfx)
Peter Hatina fe8eca
     tf[idx].path = (char *)g_malloc(tf[idx].len);
Peter Hatina fe8eca
   }
d3e571
 
Peter Hatina fe8eca
-  tmp_dir = g_get_tmp_dir();
Peter Hatina fe8eca
+  tmp_dir = get_tmp_dir();
Peter Hatina 1fba24
 
Peter Hatina 1fba24
 #ifdef _WIN32
Peter Hatina fe8eca
   _tzset();
Peter Hatina fe8eca
diff --git a/wsutil/tempfile.h b/wsutil/tempfile.h
Peter Hatina c9a65b
index 1dca2df..bb3160c 100644
Peter Hatina fe8eca
--- a/wsutil/tempfile.h
Peter Hatina fe8eca
+++ b/wsutil/tempfile.h
Peter Hatina fe8eca
@@ -45,7 +45,7 @@ WS_DLL_PUBLIC char *get_tempfile_path(const char *filename);
Peter Hatina fe8eca
 
Peter Hatina fe8eca
 /**
Peter Hatina fe8eca
  * Create a tempfile with the given prefix (e.g. "wireshark"). The path
Peter Hatina fe8eca
- * is created using g_get_tmp_dir and mkstemp.
Peter Hatina fe8eca
+ * is created using get_tmp_dir and mkstemp.
Peter Hatina fe8eca
  *
Peter Hatina fe8eca
  * @param namebuf [in,out] If not NULL, receives the full path of the temp file.
Peter Hatina fe8eca
  *                Must NOT be freed.
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
Martin Sehnoutka 4cab85
index 0000000..07ac583
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
+
Martin Sehnoutka 4cab85
+#endif
Martin Sehnoutka 4cab85
-- 
Martin Sehnoutka 4cab85
2.13.0
Martin Sehnoutka 4cab85