Revert "Strictly check for SELinux labelling errors"

This reverts commit 2ef4e85448df5767b98e0d1dc793b7805249393f.

Reason for revert: b/271157681

Change-Id: I7224fd68027e2e9824694171547b8b2c808f9923
diff --git a/Utils.cpp b/Utils.cpp
index 7f64d33..33dbaf6 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -23,7 +23,6 @@
 #include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/properties.h>
-#include <android-base/scopeguard.h>
 #include <android-base/stringprintf.h>
 #include <android-base/strings.h>
 #include <android-base/unique_fd.h>
@@ -101,18 +100,13 @@
 status_t CreateDeviceNode(const std::string& path, dev_t dev) {
     std::lock_guard<std::mutex> lock(kSecurityLock);
     const char* cpath = path.c_str();
-    auto clearfscreatecon = android::base::make_scope_guard([] { setfscreatecon(nullptr); });
-    auto secontext = std::unique_ptr<char, void (*)(char*)>(nullptr, freecon);
-    char* tmp_secontext;
+    status_t res = 0;
 
-    if (selabel_lookup(sehandle, &tmp_secontext, cpath, S_IFBLK) != 0) {
-        PLOG(ERROR) << "Failed to look up selabel for device node " << path;
-        return -errno;
-    }
-    secontext.reset(tmp_secontext);
-    if (setfscreatecon(secontext.get()) != 0) {
-        LOG(ERROR) << "Failed to setfscreatecon for device node " << path;
-        return -EINVAL;
+    char* secontext = nullptr;
+    if (sehandle) {
+        if (!selabel_lookup(sehandle, &secontext, cpath, S_IFBLK)) {
+            setfscreatecon(secontext);
+        }
     }
 
     mode_t mode = 0660 | S_IFBLK;
@@ -120,10 +114,16 @@
         if (errno != EEXIST) {
             PLOG(ERROR) << "Failed to create device node for " << major(dev) << ":" << minor(dev)
                         << " at " << path;
-            return -errno;
+            res = -errno;
         }
     }
-    return OK;
+
+    if (secontext) {
+        setfscreatecon(nullptr);
+        freecon(secontext);
+    }
+
+    return res;
 }
 
 status_t DestroyDeviceNode(const std::string& path) {
@@ -449,23 +449,29 @@
                     unsigned int attrs) {
     std::lock_guard<std::mutex> lock(kSecurityLock);
     const char* cpath = path.c_str();
-    auto clearfscreatecon = android::base::make_scope_guard([] { setfscreatecon(nullptr); });
-    auto secontext = std::unique_ptr<char, void (*)(char*)>(nullptr, freecon);
-    char* tmp_secontext;
 
-    if (selabel_lookup(sehandle, &tmp_secontext, cpath, S_IFDIR) != 0) {
-        PLOG(ERROR) << "Failed to look up selabel for directory " << path;
+    char* secontext = nullptr;
+    if (sehandle) {
+        if (!selabel_lookup(sehandle, &secontext, cpath, S_IFDIR)) {
+            setfscreatecon(secontext);
+        }
+    }
+
+    int res = fs_prepare_dir(cpath, mode, uid, gid);
+
+    if (secontext) {
+        setfscreatecon(nullptr);
+        freecon(secontext);
+    }
+
+    if (res) return -errno;
+    if (attrs) res = SetAttrs(path, attrs);
+
+    if (res == 0) {
+        return OK;
+    } else {
         return -errno;
     }
-    secontext.reset(tmp_secontext);
-    if (setfscreatecon(secontext.get()) != 0) {
-        LOG(ERROR) << "Failed to setfscreatecon for directory " << path;
-        return -EINVAL;
-    }
-
-    if (fs_prepare_dir(cpath, mode, uid, gid) != 0) return -errno;
-    if (attrs && SetAttrs(path, attrs) != 0) return -errno;
-    return OK;
 }
 
 status_t ForceUnmount(const std::string& path) {