summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/rpm/rpm/rpmdb-prevent-race-in-tmpdir-creation.patch
blob: f483f3ad90ef39eb8342ce5f8c7f9ddc20e148de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
rpmdb: prevent race in tmpdir creation

If two (or more) instances of rpm are running at the same time they may
be trying to create the same (base-)temporary directory at the same time
which causes the other mkdir to fail with EEXIST. This patch prevents a
failure caused by this race by ignoring EEXIST error on directory
creation.

Upstream-Status: Pending

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>

diff --git a/rpmdb/signature.c b/rpmdb/signature.c
index dce6c4e..100204b 100644
--- a/rpmdb/signature.c
+++ b/rpmdb/signature.c
@@ -37,6 +37,7 @@ int rpmTempFile(const char * prefix, const char ** fnptr, void * fdptr)
     int temput;
     FD_t fd = NULL;
     unsigned int ran;
+    int ret = 0;
 
     if (!prefix) prefix = "";
 
@@ -44,8 +45,11 @@ int rpmTempFile(const char * prefix, const char ** fnptr, void * fdptr)
     if (!_initialized) {
 	_initialized = 1;
 	tempfn = rpmGenPath(prefix, tpmacro, NULL);
-	if (rpmioMkpath(tempfn, 0755, (uid_t) -1, (gid_t) -1))
-	    goto errxit;
+        ret = rpmioMkpath(tempfn, 0755, (uid_t) -1, (gid_t) -1);
+        if (ret && ret != EEXIST) {
+            rpmlog(RPMLOG_ERR, _("error creating temporary directory %s: %d\n"), tempfn, ret);
+            goto errxit;
+        }
     }
 
     /* XXX should probably use mkstemp here */
-- 
2.6.6