summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-04-01 12:21:10 +0200
committerMichael Vogt <mvo@ubuntu.com>2014-04-01 12:21:10 +0200
commita78578a9bfabf9c1b5a84e8f26fa5f193a56cb76 (patch)
tree3221acebaec1a3bc69c4ca82a61863c9a23bc8af /cmdline
parent26b3ade25dc90ab9288fcdd19af747eb62743013 (diff)
parent62f1ee1cc7a5e16ca0cbfbee3c00cefab1892f87 (diff)
Merge remote-tracking branch 'mvo/debian/sid' into debian/sid
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-extracttemplates.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc
index a82623444..e4428e051 100644
--- a/cmdline/apt-extracttemplates.cc
+++ b/cmdline/apt-extracttemplates.cc
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
#include "apt-extracttemplates.h"
@@ -239,23 +240,25 @@ static int ShowHelp(void)
static string WriteFile(const char *package, const char *prefix, const char *data)
{
char fn[512];
- static int i;
std::string tempdir = GetTempDir();
- snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d",
+ snprintf(fn, sizeof(fn), "%s/%s.%s.XXXXXX",
_config->Find("APT::ExtractTemplates::TempDir",
tempdir.c_str()).c_str(),
- package, prefix, getpid(), i++);
+ package, prefix);
FileFd f;
if (data == NULL)
data = "";
-
- if (!f.Open(fn, FileFd::WriteTemp, 0600))
+ int fd = mkstemp(fn);
+ if (fd < 0) {
+ _error->Errno("ofstream::ofstream",_("Unable to mkstemp %s"),fn);
+ return string();
+ }
+ if (!f.OpenDescriptor(fd, FileFd::WriteOnly, FileFd::None, true))
{
_error->Errno("ofstream::ofstream",_("Unable to write to %s"),fn);
return string();
}
-
f.Write(data, strlen(data));
f.Close();
return fn;