Merge \\\"ueventd: only relabel devices if there\\\'s a delta\\\" am: 95428817d6 am: 807fa4bd5c
am: 787468260d
Change-Id: I6becb7e8ef42a069f5daed0e7c332d6c2cd3b8c6
diff --git a/init/devices.cpp b/init/devices.cpp
index 1410e3b..32fec52 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -257,11 +257,25 @@
/* If the node already exists update its SELinux label to handle cases when
* it was created with the wrong context during coldboot procedure. */
if (mknod(path, mode, dev) && (errno == EEXIST)) {
- if (lsetfilecon(path, secontext)) {
+
+ char* fcon = nullptr;
+ int rc = lgetfilecon(path, &fcon);
+ if (rc < 0) {
+ ERROR("Cannot get SELinux label on '%s' device (%s)\n",
+ path, strerror(errno));
+ goto out;
+ }
+
+ bool different = strcmp(fcon, secontext) != 0;
+ freecon(fcon);
+
+ if (different && lsetfilecon(path, secontext)) {
ERROR("Cannot set '%s' SELinux label on '%s' device (%s)\n",
secontext, path, strerror(errno));
}
}
+
+out:
chown(path, uid, -1);
setegid(AID_ROOT);