Revert "Fix memory leak and add EINTR error handling." 56/23156/2
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Wed, 18 Jun 2014 12:44:24 +0000 (14:44 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Wed, 18 Jun 2014 12:53:14 +0000 (14:53 +0200)
This revert is due to moving security-manager to separate repository
This reverts commit 2c9421804005c397d53911199b1817204261ed33.

Change-Id: Ia99d6f501291c5ccf6707fa14281366cc8bd2df3

src/server/service/installer.cpp
src/server/service/smack-rules.cpp

index 90608d77f6819c81102f36c646507c857aacb991..92d98ad170ea49eb5c043e4e2b7c6769b0e31ee3 100644 (file)
@@ -100,25 +100,24 @@ FileDecision labelLinksToExecs(const FTSENT *ftsent)
     LogSecureDebug("Entering function: " << __func__);
 
     struct stat buf;
+    char *target;
 
     // check if it's a link
     if ( !S_ISLNK(ftsent->fts_statp->st_mode))
         return FileDecision::SKIP;
 
-    std::unique_ptr<char, std::function<void(void*)>> target(realpath(ftsent->fts_path, NULL), free);
-
-    if (!target.get()) {
+    target = realpath(ftsent->fts_path, NULL);
+    if (!target) {
         LogSecureError("Getting link target for " << ftsent->fts_path << " failed (Error = " << strerror(errno) << ")");
         return FileDecision::ERROR;
     }
-
-    if (-1 == stat(target.get(), &buf)) {
-        LogSecureError("stat failed for " << target.get() << " (Error = " << strerror(errno) << ")");
+    if (-1 == stat(target, &buf)) {
+        LogSecureError("stat failed for " << target << " (Error = " << strerror(errno) << ")");
         return FileDecision::ERROR;
     }
     // skip if link target is not a regular executable file
     if (buf.st_mode != (buf.st_mode | S_IXUSR | S_IFREG)) {
-        LogSecureDebug(target.get() << "is not a regular executable file. Skipping.");
+        LogSecureDebug(target << "is not a regular executable file. Skipping.");
         return FileDecision::SKIP;
     }
 
index 687795ef5b2e1b16f0a8cf1e63407c6a48e1eee4..4319ca99061ac24ffa3cc480bc5db5dfc9d612f4 100644 (file)
@@ -29,7 +29,6 @@
 #include <sys/smack.h>
 #include <fcntl.h>
 #include <fstream>
-#include <cstring>
 
 #include <dpl/log/log.h>
 
@@ -75,7 +74,7 @@ bool SmackRules::loadFromFile(const std::string &path)
     int fd;
     bool ret = true;
 
-    fd = TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY));
+    fd = open(path.c_str(), O_RDONLY);
     if (fd == -1) {
         LogError("Failed to open file: %s" << path);
         return false;
@@ -86,11 +85,7 @@ bool SmackRules::loadFromFile(const std::string &path)
         ret = false;
     }
 
-    if (close(fd) == -1) {
-        // don't change the return code, the descriptor should be closed despite the error.
-        LogWarning("Error while closing the file: " << path << ", error: " << strerror(errno));
-    }
-
+    close(fd);
     return ret;
 }
 
@@ -99,7 +94,7 @@ bool SmackRules::saveToFile(const std::string &path) const
     int fd;
     bool ret = true;
 
-    fd = TEMP_FAILURE_RETRY(open(path.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644));
+    fd = open(path.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644);
     if (fd == -1) {
         LogError("Failed to create file: %s" << path);
         return false;
@@ -111,18 +106,7 @@ bool SmackRules::saveToFile(const std::string &path) const
         ret = false;
     }
 
-    if (close(fd) == -1) {
-        if (errno == EIO) {
-            LogError("I/O Error occured while closing the file: " << path << ", error: " << strerror(errno));
-            unlink(path.c_str());
-            return false;
-        } else {
-            // non critical error
-            // don't change the return code, the descriptor should be closed despite the error.
-            LogWarning("Error while closing the file: " << path << ", error: " << strerror(errno));
-        }
-    }
-
+    close(fd);
     return ret;
 }