[LIBREPORT PATCH] do not store potentially big data in /tmp

Jakub Filak jfilak at redhat.com
Thu Aug 1 16:42:04 UTC 2013


Closes rhbz#990208

Signed-off-by: Jakub Filak <jfilak at redhat.com>
---
 configure.ac                      |  6 ++++++
 src/cli/Makefile.am               |  1 +
 src/cli/cli-report.c              |  2 +-
 src/include/report.h              |  2 +-
 src/lib/Makefile.am               |  1 +
 src/lib/create_dump_dir.c         |  4 ++--
 src/lib/report.c                  |  2 +-
 src/plugins/Makefile.am           |  2 ++
 src/plugins/reporter-rhtsupport.c |  8 ++++----
 src/plugins/reporter-upload.c     | 15 ++++++++-------
 10 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5fa76cf..bfb9957 100644
--- a/configure.ac
+++ b/configure.ac
@@ -216,6 +216,12 @@ AC_ARG_WITH(debugdumpsdir,
                            [Directory where debugdumps are created])],
             [DEBUG_DUMPS_DIR="$withval"])
 
+AC_ARG_WITH(largedatatmpdir,
+            [AS_HELP_STRING([--with-largedatatmpdir=DIR],
+                           [Directory where potentially large data are created (default: /var/tmp)])],
+            [], [with_largedatatmpdir="/var/tmp"])
+AC_SUBST([LARGE_DATA_TMP_DIR], [$with_largedatatmpdir])
+
 AC_ARG_WITH([defaultdumpdirmode],
             AS_HELP_STRING([--with-defaultdumpdirmode=OCTAL-MODE],
                            [Default dump dir mode (default: 0660)]),
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index 5edc119..7eec572 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -10,6 +10,7 @@ report_cli_CPPFLAGS = \
     -I$(srcdir)/../lib \
     -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
     -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
+    -DLARGE_DATA_TMP_DIR=\"$(LARGE_DATA_TMP_DIR)\" \
     $(GLIB_CFLAGS) \
     -D_GNU_SOURCE \
     $(LIBREPORT_CFLAGS)
diff --git a/src/cli/cli-report.c b/src/cli/cli-report.c
index 8370185..426561a 100644
--- a/src/cli/cli-report.c
+++ b/src/cli/cli-report.c
@@ -341,7 +341,7 @@ static int launch_editor(const char *path)
 static int run_report_editor(problem_data_t *problem_data)
 {
     /* Open a temporary file and write the crash report to it. */
-    char filename[] = "/tmp/abrt-report.XXXXXX";
+    char filename[] = LARGE_DATA_TMP_DIR"/abrt-report.XXXXXX";
     int fd = mkstemp(filename);
     if (fd == -1) /* errno is set */
     {
diff --git a/src/include/report.h b/src/include/report.h
index 29b18d7..d31eb0a 100644
--- a/src/include/report.h
+++ b/src/include/report.h
@@ -40,7 +40,7 @@ enum {
 int report_problem_in_dir(const char *dirname, int flags);
 
 /* Reports a problem stored in problem_data_t.
- * It's first saved to /tmp and then processed as a dump dir.
+ * It's first saved to a temporary directory and then processed as a dump dir.
  */
 int report_problem_in_memory(problem_data_t *pd, int flags);
 
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 261aaf2..aceb892 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -67,6 +67,7 @@ libreport_la_CPPFLAGS = \
     -DBIN_DIR=\"$(bindir)\" \
     -DDEFAULT_DUMP_DIR_MODE=$(DEFAULT_DUMP_DIR_MODE) \
     -DDUMP_DIR_OWNED_BY_USER=$(DUMP_DIR_OWNED_BY_USER) \
+    -DLARGE_DATA_TMP_DIR=\"$(LARGE_DATA_TMP_DIR)\" \
     $(GLIB_CFLAGS) \
     $(GOBJECT_CFLAGS) \
     -D_GNU_SOURCE
diff --git a/src/lib/create_dump_dir.c b/src/lib/create_dump_dir.c
index 873139d..fdf5183 100644
--- a/src/lib/create_dump_dir.c
+++ b/src/lib/create_dump_dir.c
@@ -89,9 +89,9 @@ struct dump_dir *create_dump_dir_from_problem_data(problem_data_t *problem_data,
             }
         }
 //TODO: try user's home dir obtained by getpwuid(getuid())?
-        /* Try /tmp */
+        /* Try system temporary directory */
         if (!dd)
-            dd = try_dd_create("/tmp", problem_id, uid);
+            dd = try_dd_create(LARGE_DATA_TMP_DIR, problem_id, uid);
     }
 
     if (!dd) /* try_dd_create() already emitted the error message */
diff --git a/src/lib/report.c b/src/lib/report.c
index e4cff2c..e85f6ce 100644
--- a/src/lib/report.c
+++ b/src/lib/report.c
@@ -185,7 +185,7 @@ int report_problem_in_dir(const char *dirname, int flags)
 int report_problem_in_memory(problem_data_t *pd, int flags)
 {
     int result = 0;
-    struct dump_dir *dd = create_dump_dir_from_problem_data(pd, "/tmp"/* /var/tmp ?? */);
+    struct dump_dir *dd = create_dump_dir_from_problem_data(pd, LARGE_DATA_TMP_DIR);
     if (!dd)
         return -1;
     char *dir_name = xstrdup(dd->dd_dirname);
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 166604c..f8699be 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -140,6 +140,7 @@ reporter_rhtsupport_CPPFLAGS = \
     -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \
     -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \
     -DPLUGINS_CONF_DIR=\"$(REPORT_PLUGINS_CONF_DIR)\" \
+    -DLARGE_DATA_TMP_DIR=\"$(LARGE_DATA_TMP_DIR)\" \
     $(GLIB_CFLAGS) \
     $(LIBREPORT_CFLAGS) \
     $(LIBXML_CFLAGS) \
@@ -162,6 +163,7 @@ reporter_upload_CPPFLAGS = \
     -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \
     -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \
     -DPLUGINS_CONF_DIR=\"$(REPORT_PLUGINS_CONF_DIR)\" \
+    -DLARGE_DATA_TMP_DIR=\"$(LARGE_DATA_TMP_DIR)\" \
     $(GLIB_CFLAGS) \
     $(CURL_CFLAGS) \
     $(LIBREPORT_CFLAGS) \
diff --git a/src/plugins/reporter-rhtsupport.c b/src/plugins/reporter-rhtsupport.c
index b6e2a86..bbf0a1e 100644
--- a/src/plugins/reporter-rhtsupport.c
+++ b/src/plugins/reporter-rhtsupport.c
@@ -361,12 +361,12 @@ int main(int argc, char **argv)
         dsc = make_description_bz(problem_data, CD_TEXT_ATT_SIZE_BZ);
     }
 
-    char tmpdir_name[sizeof("/tmp/rhtsupport-"LIBREPORT_ISO_DATE_STRING_SAMPLE"-XXXXXX")];
-    snprintf(tmpdir_name, sizeof(tmpdir_name), "/tmp/rhtsupport-%s-XXXXXX", iso_date_string(NULL));
+    char tmpdir_name[sizeof(LARGE_DATA_TMP_DIR"/rhtsupport-"LIBREPORT_ISO_DATE_STRING_SAMPLE"-XXXXXX")];
+    snprintf(tmpdir_name, sizeof(tmpdir_name), LARGE_DATA_TMP_DIR"/rhtsupport-%s-XXXXXX", iso_date_string(NULL));
     /* mkdtemp does mkdir(xxx, 0700), should be safe (is it?) */
     if (mkdtemp(tmpdir_name) == NULL)
     {
-        error_msg_and_die(_("Can't create a temporary directory in /tmp"));
+        error_msg_and_die(_("Can't create a temporary directory in "LARGE_DATA_TMP_DIR));
     }
     /* Starting from here, we must perform cleanup on errors
      * (delete temp dir)
@@ -375,7 +375,7 @@ int main(int argc, char **argv)
     tempfile = append_to_malloced_string(tempfile, ".tar.gz");
     if (create_tarball(tempfile, problem_data) != 0)
     {
-        errmsg = _("Can't create temporary file in /tmp");
+        errmsg = _("Can't create temporary file in "LARGE_DATA_TMP_DIR);
         goto ret;
     }
 
diff --git a/src/plugins/reporter-upload.c b/src/plugins/reporter-upload.c
index bde573e..59dccd5 100644
--- a/src/plugins/reporter-upload.c
+++ b/src/plugins/reporter-upload.c
@@ -49,7 +49,8 @@ static int create_and_upload_archive(
     /* Create a child gzip which will compress the data */
     /* SELinux guys are not happy with /tmp, using /var/run/abrt */
     /* Reverted back to /tmp for ABRT2 */
-    tempfile = concat_path_basename("/tmp", dump_dir_name);
+    /* Changed again to /var/tmp because of Fedora feature tmp-on-tmpfs */
+    tempfile = concat_path_basename(LARGE_DATA_TMP_DIR, dump_dir_name);
     tempfile = append_to_malloced_string(tempfile, ".tar.gz");
 
     int pipe_from_parent_to_child[2];
@@ -75,7 +76,7 @@ static int create_and_upload_archive(
     if (tar_fdopen(&tar, pipe_from_parent_to_child[1], tempfile,
                 /*fileops:(standard)*/ NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0)
     {
-        errmsg = "Can't create temporary file in /tmp";
+        errmsg = "Can't create temporary file in "LARGE_DATA_TMP_DIR;
         goto ret;
     }
 
@@ -98,7 +99,7 @@ static int create_and_upload_archive(
             //}
             if (tar_append_file(tar, full_name, short_name) != 0)
             {
-                errmsg = "Can't create temporary file in /tmp";
+                errmsg = "Can't create temporary file in "LARGE_DATA_TMP_DIR;
                 free(short_name);
                 free(full_name);
                 goto ret;
@@ -114,7 +115,7 @@ static int create_and_upload_archive(
     /* Close tar writer... */
     if (tar_append_eof(tar) != 0 || tar_close(tar) != 0)
     {
-        errmsg = "Can't create temporary file in /tmp";
+        errmsg = "Can't create temporary file in "LARGE_DATA_TMP_DIR;
         goto ret;
     }
     tar = NULL;
@@ -125,13 +126,13 @@ static int create_and_upload_archive(
     if (status != 0)
     {
         /* We assume the error was out-of-disk-space or out-of-quota */
-        errmsg = "Can't create temporary file in /tmp";
+        errmsg = "Can't create temporary file in "LARGE_DATA_TMP_DIR;
         goto ret;
     }
 
     /* Upload the tarball */
     /* Upload from /tmp to /tmp + deletion -> BAD, exclude this possibility */
-    if (url && url[0] && strcmp(url, "file:///tmp/") != 0)
+    if (url && url[0] && strcmp(url, "file://"LARGE_DATA_TMP_DIR"/") != 0)
     {
         char *remote_name = upload_file(url, tempfile);
         result = (remote_name == NULL); /* error if NULL */
@@ -184,7 +185,7 @@ int main(int argc, char **argv)
         "& [-v] -d DIR [-c CONFFILE] [-u URL]\n"
         "\n"
         "Uploads compressed tarball of problem directory DIR to URL.\n"
-        "If URL is not specified, creates tarball in /tmp and exits.\n"
+        "If URL is not specified, creates tarball in "LARGE_DATA_TMP_DIR" and exits.\n"
         "\n"
         "URL should have form 'protocol://[user[:pass]@]host/dir/[file.tar.gz]'\n"
         "where protocol can be http(s), ftp, scp, or file.\n"
-- 
1.8.3.1



More information about the Crash-catcher mailing list