summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/patchelf/patchelf/handle-read-only-files.patch
blob: bf721c1af86a75937a0a891e5226d7fd54521899 (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
From 7f1fd10cfebd5ea2f3e1938abe1bd1c4828164a7 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 | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Index: git/src/patchelf.cc
===================================================================
--- git.orig/src/patchelf.cc
+++ git/src/patchelf.cc
@@ -499,9 +499,19 @@ void ElfFile<ElfFileParamNames>::sortShd
 
 static void writeFile(std::string fileName, FileContents contents)
 {
+    struct stat st;
+    int fd;
+
     debug("writing %s\n", fileName.c_str());
 
-    int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0777);
+    if (stat(fileName.c_str(), &st) != 0)
+        error("stat");
+
+    if (chmod(fileName.c_str(), 0600) != 0)
+        error("chmod");
+
+    fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0777);
+
     if (fd == -1)
         error("open");
 
@@ -515,6 +525,10 @@ static void writeFile(std::string fileNa
 
     if (close(fd) != 0)
         error("close");
+
+    if (chmod(fileName.c_str(), st.st_mode) != 0)
+        error("chmod");
+
 }