[incfs] return error if restorecon fails
Addressing comments in ag/10310771.
Test: atest libincfs-test
BUG: 133435829
Change-Id: I4ef4257dee3e7014f4522150a8e8040850fda5c9
Merged-In: I4ef4257dee3e7014f4522150a8e8040850fda5c9
diff --git a/incfs/incfs.cpp b/incfs/incfs.cpp
index 4c3b33b..6a48cfa 100644
--- a/incfs/incfs.cpp
+++ b/incfs/incfs.cpp
@@ -427,9 +427,10 @@
return {-error, -error, -error};
}
- int res = selinux_android_restorecon(targetDir, SELINUX_ANDROID_RESTORECON_RECURSE);
- if (res != 0) {
- PLOG(ERROR) << "[incfs] Failed to restorecon: " << res;
+ if (const auto err = selinux_android_restorecon(targetDir, SELINUX_ANDROID_RESTORECON_RECURSE);
+ err != 0) {
+ PLOG(ERROR) << "[incfs] Failed to restorecon: " << err;
+ return {err, err, err};
}
registry().addRoot(targetDir);
diff --git a/incfs/tests/incfs_test.cpp b/incfs/tests/incfs_test.cpp
index 0e299e5..eea8ddd 100644
--- a/incfs/tests/incfs_test.cpp
+++ b/incfs/tests/incfs_test.cpp
@@ -64,15 +64,15 @@
ASSERT_TRUE(control_.cmd >= 0) << "Expected >= 0 got " << control_.cmd;
ASSERT_TRUE(control_.pendingReads >= 0);
ASSERT_TRUE(control_.logs >= 0);
- checkRestoreconResult(mountPath(".pending_reads"));
- checkRestoreconResult(mountPath(".log"));
+ checkRestoreconResult(mountPath(INCFS_PENDING_READS_FILENAME));
+ checkRestoreconResult(mountPath(INCFS_LOG_FILENAME));
}
}
static void checkRestoreconResult(std::string_view path) {
char* ctx = nullptr;
ASSERT_NE(-1, getfilecon(path.data(), &ctx));
- ASSERT_NE("u:object_r:unlabeled:s0", std::string(ctx));
+ ASSERT_EQ("u:object_r:shell_data_file:s0", std::string(ctx));
freecon(ctx);
}