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

537ca1
From cb54210f7f02b07768cfbf49ae266d487f580e1b Mon Sep 17 00:00:00 2001
537ca1
From: rpm-build <rpm-build>
537ca1
Date: Thu, 29 Jun 2017 15:32:58 +0200
537ca1
Subject: [PATCH] Move /tmp to /var/tmp
537ca1
537ca1
Fedora is using tmpfs which is limited by the size of RAM, thus we need
537ca1
to use different directory on different filesystem.
537ca1
---
537ca1
 ui/qt/about_dialog.cpp         |  3 +-
537ca1
 ui/qt/iax2_analysis_dialog.cpp |  5 +--
537ca1
 ui/qt/rtp_analysis_dialog.cpp  |  5 +--
537ca1
 ui/qt/rtp_audio_stream.cpp     |  3 +-
537ca1
 wsutil/tempfile.c              |  9 +++---
537ca1
 wsutil/tempfile.h              |  4 +--
537ca1
 wsutil/wstmpdir.c              | 70 ++++++++++++++++++++++++++++++++++++++++++
537ca1
 wsutil/wstmpdir.h              | 39 +++++++++++++++++++++++
537ca1
 8 files changed, 132 insertions(+), 11 deletions(-)
537ca1
 create mode 100644 wsutil/wstmpdir.c
537ca1
 create mode 100644 wsutil/wstmpdir.h
537ca1
537ca1
diff --git a/ui/qt/about_dialog.cpp b/ui/qt/about_dialog.cpp
537ca1
index 31dc581..2f74285 100644
537ca1
--- a/ui/qt/about_dialog.cpp
537ca1
+++ b/ui/qt/about_dialog.cpp
537ca1
@@ -26,6 +26,7 @@
537ca1
 
537ca1
 #include "wireshark_application.h"
537ca1
 #include <wsutil/filesystem.h>
537ca1
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
537ca1
 
537ca1
 #include <QDesktopServices>
537ca1
 #include <QUrl>
537ca1
@@ -206,7 +206,7 @@ FolderListModel::FolderListModel(QObject * parent):
537ca1
     appendRow(QStringList() << tr("\"File\" dialogs") << get_last_open_dir() << tr("capture files"));
537ca1
 
537ca1
     /* temp */
537ca1
-    appendRow(QStringList() << tr("Temp") << g_get_tmp_dir() << tr("untitled capture files"));
537ca1
+    appendRow(QStringList() << tr("Temp") << get_tmp_dir() << tr("untitled capture files"));
537ca1
 
537ca1
     /* pers conf */
537ca1
     appendRow(QStringList() << tr("Personal configuration")
537ca1
diff --git a/ui/qt/iax2_analysis_dialog.cpp b/ui/qt/iax2_analysis_dialog.cpp
537ca1
index ee4e5fd..fe17a95 100644
537ca1
--- a/ui/qt/iax2_analysis_dialog.cpp
537ca1
+++ b/ui/qt/iax2_analysis_dialog.cpp
537ca1
@@ -37,6 +37,7 @@
537ca1
 #include "ui/rtp_stream.h"
537ca1
 #endif
537ca1
 #include <wsutil/utf8_entities.h>
537ca1
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
537ca1
 
537ca1
 #include <wsutil/g711.h>
537ca1
 #include <wsutil/pint.h>
537ca1
@@ -271,10 +272,10 @@ Iax2AnalysisDialog::Iax2AnalysisDialog(QWidget &parent, CaptureFile &cf) :
537ca1
 
537ca1
     // We keep our temp files open for the lifetime of the dialog. The GTK+
537ca1
     // UI opens and closes at various points.
537ca1
-    QString tempname = QString("%1/wireshark_iax2_f").arg(QDir::tempPath());
537ca1
+    QString tempname = QString("%1/wireshark_iax2_f").arg(get_tmp_dir());
537ca1
     fwd_tempfile_ = new QTemporaryFile(tempname, this);
537ca1
     fwd_tempfile_->open();
537ca1
-    tempname = QString("%1/wireshark_iax2_r").arg(QDir::tempPath());
537ca1
+    tempname = QString("%1/wireshark_iax2_r").arg(get_tmp_dir());
537ca1
     rev_tempfile_ = new QTemporaryFile(tempname, this);
537ca1
     rev_tempfile_->open();
537ca1
 
537ca1
diff --git a/ui/qt/rtp_analysis_dialog.cpp b/ui/qt/rtp_analysis_dialog.cpp
537ca1
index 5d82e46..8008984 100644
537ca1
--- a/ui/qt/rtp_analysis_dialog.cpp
537ca1
+++ b/ui/qt/rtp_analysis_dialog.cpp
537ca1
@@ -37,6 +37,7 @@
537ca1
 
537ca1
 #include <wsutil/g711.h>
537ca1
 #include <wsutil/pint.h>
537ca1
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
537ca1
 
537ca1
 #include <QMessageBox>
537ca1
 #include <QPushButton>
537ca1
@@ -331,10 +332,10 @@ RtpAnalysisDialog::RtpAnalysisDialog(QWidget &parent, CaptureFile &cf, struct _r
537ca1
 
537ca1
     // We keep our temp files open for the lifetime of the dialog. The GTK+
537ca1
     // UI opens and closes at various points.
537ca1
-    QString tempname = QString("%1/wireshark_rtp_f").arg(QDir::tempPath());
537ca1
+    QString tempname = QString("%1/wireshark_rtp_f").arg(get_tmp_dir());
537ca1
     fwd_tempfile_ = new QTemporaryFile(tempname, this);
537ca1
     fwd_tempfile_->open();
537ca1
-    tempname = QString("%1/wireshark_rtp_r").arg(QDir::tempPath());
537ca1
+    tempname = QString("%1/wireshark_rtp_r").arg(get_tmp_dir());
537ca1
     rev_tempfile_ = new QTemporaryFile(tempname, this);
537ca1
     rev_tempfile_->open();
537ca1
 
537ca1
diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp
537ca1
index fde66c8..b9531d2 100644
537ca1
--- a/ui/qt/rtp_audio_stream.cpp
537ca1
+++ b/ui/qt/rtp_audio_stream.cpp
537ca1
@@ -37,6 +37,7 @@
537ca1
 #include <ui/rtp_stream.h>
537ca1
 
537ca1
 #include <wsutil/nstime.h>
537ca1
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
537ca1
 
537ca1
 #include <QAudioFormat>
537ca1
 #include <QAudioOutput>
537ca1
@@ -76,7 +77,7 @@ RtpAudioStream::RtpAudioStream(QObject *parent, _rtp_stream_info *rtp_stream) :
537ca1
                                                 visual_sample_rate_, SPEEX_RESAMPLER_QUALITY_MIN, NULL);
537ca1
     speex_resampler_skip_zeros(visual_resampler_);
537ca1
 
537ca1
-    QString tempname = QString("%1/wireshark_rtp_stream").arg(QDir::tempPath());
537ca1
+    QString tempname = QString("%1/wireshark_rtp_stream").arg(get_tmp_dir());
537ca1
     tempfile_ = new QTemporaryFile(tempname, this);
537ca1
     tempfile_->open();
537ca1
 
537ca1
diff --git a/wsutil/tempfile.c b/wsutil/tempfile.c
537ca1
index 5082452..f751a7c 100644
537ca1
--- a/wsutil/tempfile.c
537ca1
+++ b/wsutil/tempfile.c
537ca1
@@ -12,10 +12,12 @@
537ca1
537ca1
 #include <glib.h>
537ca1
 #include "tempfile.h"
537ca1
+#include <wsutil/file_util.h>
537ca1
+#include <wsutil/wstmpdir.h> /* for get_tmp_dir() */
537ca1
537ca1
  /**
537ca1
  * Create a tempfile with the given prefix (e.g. "wireshark"). The path
537ca1
- * is created using g_file_open_tmp.
537ca1
+ * is created using get_tmp_dir.
537ca1
  *
537ca1
  * @param namebuf [in,out] If not NULL, receives the full path of the temp file.
537ca1
  *                Must be freed.
537ca1
@@ -30,6 +31,9 @@ create_tempfile(gchar **namebuf, const char *pfx, const char *sfx, GError **err)
537ca1
 {
537ca1
   int fd;
537ca1
   gchar *safe_pfx = NULL;
537ca1
+  gchar *tmp_file;
537ca1
+  const char *tmp_dir;
537ca1
+  int old_mask;
537ca1
537ca1
   if (pfx) {
537ca1
     /* The characters in "delimiters" come from:
537ca1
@@ -49,7 +53,15 @@ create_tempfile(gchar **namebuf, const char *pfx, const char *sfx, GError **err)
537ca1
   gchar* filetmpl = g_strdup_printf("%sXXXXXX%s", safe_pfx ? safe_pfx : "", sfx ? sfx : "");
537ca1
   g_free(safe_pfx);
537ca1
537ca1
-  fd = g_file_open_tmp(filetmpl, namebuf, err);
537ca1
+  tmp_dir = get_tmp_dir();
537ca1
+  tmp_file = g_strconcat(tmp_dir, "/", filetmpl, NULL);
537ca1
+
537ca1
+  if (namebuf)
537ca1
+    *namebuf = tmp_file;
537ca1
+
537ca1
+  old_mask = ws_umask(0077);
537ca1
+  fd = mkstemps(tmp_file, sfx ? (int) strlen(sfx) : 0);
537ca1
+  ws_umask(old_mask);
537ca1
537ca1
   g_free(filetmpl);
537ca1
   return fd;
537ca1
diff --git a/wsutil/tempfile.h b/wsutil/tempfile.h
537ca1
index 1dca2df..bb3160c 100644
537ca1
--- a/wsutil/tempfile.h
537ca1
+++ b/wsutil/tempfile.h
537ca1
@@ -45,7 +45,7 @@ WS_DLL_PUBLIC char *get_tempfile_path(const char *filename);
537ca1
 
537ca1
 /**
537ca1
  * Create a tempfile with the given prefix (e.g. "wireshark"). The path
537ca1
- * is created using g_file_open_tmp.
537ca1
+ * is created using get_tmp_dir and mkstemp.
537ca1
  *
537ca1
  * @param namebuf [in,out] If not NULL, receives the full path of the temp file.
537ca1
  *                Must be freed.
537ca1
diff --git a/wsutil/wstmpdir.c b/wsutil/wstmpdir.c
537ca1
new file mode 100644
537ca1
index 0000000..d8b733b
537ca1
--- /dev/null
537ca1
+++ b/wsutil/wstmpdir.c
537ca1
@@ -0,0 +1,71 @@
537ca1
+/* wstmpdir.c
537ca1
+ *
537ca1
+ * Copyright (C) 2013 Red Hat, Inc. All right reserved.
537ca1
+ *
537ca1
+ * Temporary directory routine
537ca1
+ *
537ca1
+ * This program is free software; you can redistribute it and/or
537ca1
+ * modify it under the terms of the GNU General Public License
537ca1
+ * as published by the Free Software Foundation; either version 2
537ca1
+ * of the License, or (at your option) any later version.
537ca1
+ *
537ca1
+ * This program is distributed in the hope that it will be useful,
537ca1
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
537ca1
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
537ca1
+ * GNU General Public License for more details.
537ca1
+ *
537ca1
+ * You should have received a copy of the GNU General Public License
537ca1
+ * along with this program; if not, write to the Free Software
537ca1
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
537ca1
+ *
537ca1
+ * Author: Peter Hatina <phatina@redhat.com>
537ca1
+ */
537ca1
+
537ca1
+#include "config.h"
537ca1
+
537ca1
+#include <glib.h>
537ca1
+#include "wstmpdir.h"
537ca1
+
537ca1
+/**
537ca1
+ * Gets the directory to use for temporary files.
537ca1
+ *
537ca1
+ * Inspired by glib-2.0. If no TMP, TEMP or TMPDIR is set,
537ca1
+ * /var/tmp is returned (Fedora specific).
537ca1
+ *
537ca1
+ * Returns: the directory to use for temporary files.
537ca1
+ */
537ca1
+const char *get_tmp_dir(void)
537ca1
+{
537ca1
+    static gchar *tmp_dir;
537ca1
+
537ca1
+    if (g_once_init_enter(&tmp_dir)) {
537ca1
+        gchar *tmp;
537ca1
+
537ca1
+        tmp = g_strdup(g_getenv("TEMP"));
537ca1
+        if (tmp == NULL || *tmp == '\0') {
537ca1
+            g_free(tmp);
537ca1
+            tmp = g_strdup(g_getenv("TMPDIR"));
537ca1
+        }
537ca1
+
537ca1
+#ifdef P_tmpdir
537ca1
+        if (tmp == NULL || *tmp == '\0') {
537ca1
+            gsize k;
537ca1
+            g_free(tmp);
537ca1
+            tmp = g_strdup(P_tmpdir);
537ca1
+            k = strlen(tmp);
537ca1
+            if (k > 1 && G_IS_DIR_SEPARATOR(tmp[k - 1]))
537ca1
+                tmp[k - 1] = '\0';
537ca1
+            fprintf(stderr, "Using P_tmpdir: %s\n", P_tmpdir);
537ca1
+        }
537ca1
+#endif /* P_tmpdir */
537ca1
+
537ca1
+        if (tmp == NULL || *tmp == '\0') {
537ca1
+            g_free(tmp);
537ca1
+            tmp = g_strdup("/var/tmp");
537ca1
+        }
537ca1
+
537ca1
+        g_once_init_leave(&tmp_dir, tmp);
537ca1
+    }
537ca1
+
537ca1
+    return tmp_dir;
537ca1
+}
537ca1
diff --git a/wsutil/wstmpdir.h b/wsutil/wstmpdir.h
537ca1
new file mode 100644
537ca1
index 0000000..07ac583
537ca1
--- /dev/null
537ca1
+++ b/wsutil/wstmpdir.h
537ca1
@@ -0,0 +1,39 @@
537ca1
+/* wstmpdir.c
537ca1
+ *
537ca1
+ * Copyright (C) 2013 Red Hat, Inc. All right reserved.
537ca1
+ *
537ca1
+ * Temporary directory routine
537ca1
+ *
537ca1
+ * This program is free software; you can redistribute it and/or
537ca1
+ * modify it under the terms of the GNU General Public License
537ca1
+ * as published by the Free Software Foundation; either version 2
537ca1
+ * of the License, or (at your option) any later version.
537ca1
+ *
537ca1
+ * This program is distributed in the hope that it will be useful,
537ca1
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
537ca1
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
537ca1
+ * GNU General Public License for more details.
537ca1
+ *
537ca1
+ * You should have received a copy of the GNU General Public License
537ca1
+ * along with this program; if not, write to the Free Software
537ca1
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
537ca1
+ *
537ca1
+ * Author: Peter Hatina <phatina@redhat.com>
537ca1
+ */
537ca1
+
537ca1
+#ifndef __WS_TMP_DIR_H__
537ca1
+#define __WS_TMP_DIR_H__
537ca1
+
537ca1
+#include "ws_symbol_export.h"
537ca1
+
537ca1
+#ifdef __cplusplus
537ca1
+extern "C" {
537ca1
+#endif // __cplusplus
537ca1
+
537ca1
+WS_DLL_PUBLIC const char *get_tmp_dir(void);
537ca1
+
537ca1
+#ifdef __cplusplus
537ca1
+}
537ca1
+#endif // __cplusplus
537ca1
+
537ca1
+#endif
537ca1
-- 
537ca1
2.13.0
537ca1