summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch
blob: 76ad8d9d4dc1e78e9ea9b5dbe20c0bd974ec677a (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From 38b3d65f4a79d39ad9cdf841f2b3b29fd0c961ca Mon Sep 17 00:00:00 2001
From: Fabio Berton <fabio.berton@ossystems.com.br>
Date: Fri, 9 Sep 2016 16:00:42 -0300
Subject: [PATCH] handle read-only files

Patch from:
https://github.com/darealshinji/patchelf/commit/40e66392bc4b96e9b4eda496827d26348a503509

Upstream-Status: Denied [https://github.com/NixOS/patchelf/pull/89]

Signed-off-by: Fabio Berton <fabio.berton@ossystems.com.br>
---
 src/patchelf.cc | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/patchelf.cc b/src/patchelf.cc
index 49accae..fb6c7ed 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -378,8 +378,16 @@ void ElfFile<ElfFileParamNames>::sortShdrs()
 
 static void writeFile(const std::string & fileName, const FileContents & contents)
 {
+    struct stat st;
+
     debug("writing %s\n", fileName.c_str());
 
+    if (stat(fileName.c_str(), &st) != 0)
+        error("stat");
+
+    if (chmod(fileName.c_str(), 0600) != 0)
+        error("chmod");
+
     int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0777);
     if (fd == -1)
         error("open");
@@ -395,8 +403,6 @@ static void writeFile(const std::string & fileName, const FileContents & content
         bytesWritten += portion;
     }
 
-    if (close(fd) >= 0)
-        return;
     /*
      * Just ignore EINTR; a retry loop is the wrong thing to do.
      *
@@ -405,9 +411,11 @@ static void writeFile(const std::string & fileName, const FileContents & content
      * http://utcc.utoronto.ca/~cks/space/blog/unix/CloseEINTR
      * https://sites.google.com/site/michaelsafyan/software-engineering/checkforeintrwheninvokingclosethinkagain
      */
-    if (errno == EINTR)
-        return;
-    error("close");
+    if ((close(fd) < 0) && errno != EINTR)
+        error("close");
+
+    if (chmod(fileName.c_str(), st.st_mode) != 0)
+        error("chmod");
 }
 
 
-- 
2.30.2