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