[evince/wip/chpe/issue-988] libdocument: Fix temp file creation
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/chpe/issue-988] libdocument: Fix temp file creation
- Date: Tue, 25 Sep 2018 18:09:18 +0000 (UTC)
commit 988debc7f18dd57373b20c91362f27a7aa106a1f
Author: Christian Persch <chpe src gnome org>
Date: Tue Sep 25 20:06:33 2018 +0200
libdocument: Fix temp file creation
Add missing flags, and make the decompressor create non-CLOEXEC
temp files since the FD will be passed to the spawned decompressor
binary.
https://gitlab.gnome.org/GNOME/evince/issues/988
libdocument/ev-file-helpers.c | 45 +++++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 17 deletions(-)
---
diff --git a/libdocument/ev-file-helpers.c b/libdocument/ev-file-helpers.c
index c9de2f83..a16a1663 100644
--- a/libdocument/ev-file-helpers.c
+++ b/libdocument/ev-file-helpers.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
@@ -115,21 +116,12 @@ _ev_file_helpers_shutdown (void)
tmp_dir = NULL;
}
-/**
- * ev_mkstemp:
- * @tmpl: a template string; must contain 'XXXXXX', but not necessarily as a suffix
- * @file_name: a location to store the filename of the temp file
- * @error: a location to store a #GError
- *
- * Creates a temp file in the evince temp directory.
- *
- * Returns: a file descriptor to the newly created temp file name, or %-1
- * on error with @error filled in
- */
-int
-ev_mkstemp (const char *tmpl,
- char **file_name,
- GError **error)
+static int
+ev_mkstemp_full (const char *tmpl,
+ int flags,
+ int mode,
+ char **file_name,
+ GError **error)
{
const char *tmp;
char *name;
@@ -139,7 +131,7 @@ ev_mkstemp (const char *tmpl,
return -1;
name = g_build_filename (tmp, tmpl, NULL);
- fd = g_mkstemp_full (name, O_CLOEXEC, 0600);
+ fd = g_mkstemp_full (name, flags, mode);
if (fd == -1) {
int errsv = errno;
@@ -158,6 +150,25 @@ ev_mkstemp (const char *tmpl,
return fd;
}
+/**
+ * ev_mkstemp:
+ * @tmpl: a template string; must contain 'XXXXXX', but not necessarily as a suffix
+ * @file_name: a location to store the filename of the temp file
+ * @error: a location to store a #GError
+ *
+ * Creates a temp file in the evince temp directory.
+ *
+ * Returns: a file descriptor to the newly created temp file name, or %-1
+ * on error with @error filled in
+ */
+int
+ev_mkstemp (const char *tmpl,
+ char **file_name,
+ GError **error)
+{
+ return ev_mkstemp_full (tmpl, O_RDWR | O_CLOEXEC, 0600, file_name, error);
+}
+
static void
close_fd_cb (gpointer fdptr)
{
@@ -622,7 +633,7 @@ compression_run (const gchar *uri,
return NULL;
}
- fd = ev_mkstemp ("comp.XXXXXX", &filename_dst, error);
+ fd = ev_mkstemp_full ("comp.XXXXXX", O_RDWR /* not CLOEXEC */, 0600, &filename_dst, error);
if (fd == -1) {
g_free (cmd);
g_free (filename);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]