-From 682fb48c137b687477008b68863c2a0b73ed47d1 Mon Sep 17 00:00:00 2001
+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
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(-)
+ src/patchelf.cc | 18 +++++++++++++-----
+ 1 file changed, 13 insertions(+), 5 deletions(-)
-Index: git/src/patchelf.cc
-===================================================================
---- git.orig/src/patchelf.cc
-+++ git/src/patchelf.cc
-@@ -534,9 +534,19 @@ void ElfFile<ElfFileParamNames>::sortShd
+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;
-+ 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);
-+
+ int fd = open(fileName.c_str(), O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0777);
if (fd == -1)
error("open");
-
-@@ -551,8 +561,6 @@ static void writeFile(const std::string
+@@ -395,8 +403,6 @@ static void writeFile(const std::string & fileName, const FileContents & content
bytesWritten += portion;
}
/*
* Just ignore EINTR; a retry loop is the wrong thing to do.
*
-@@ -561,9 +569,11 @@ static void writeFile(const std::string
+@@ -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
*/
}
+--
+2.30.2
+