summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand Simonnet <bsimonnet@google.com>2015-09-22 18:22:35 +0000
committerBertrand Simonnet <bsimonnet@google.com>2015-09-22 18:22:35 +0000
commit134aa097b9106e63e1622389fbb0d5543bd3d558 (patch)
tree867565ee7f5d305761408f7effcfe49fd3ac4681
parent4a2bdd8006a5ddf166bcc8973c135799da453e09 (diff)
downloadrootdev-134aa097b9106e63e1622389fbb0d5543bd3d558.tar.gz
Revert "rootdev: Don't try to access /dev/block."
This breaks when built with clang This reverts commit 4a2bdd8006a5ddf166bcc8973c135799da453e09. Change-Id: I2f89a9c19de91d4c46dce110e36a32551134e5d5
-rw-r--r--rootdev.c9
-rw-r--r--rootdev.h10
2 files changed, 11 insertions, 8 deletions
diff --git a/rootdev.c b/rootdev.c
index 82e423f..f0de1ff 100644
--- a/rootdev.c
+++ b/rootdev.c
@@ -357,10 +357,11 @@ int rootdev_get_path(char *path, size_t size, const char *device,
if (path_len != strlen(dev_path) + 1 + strlen(device))
return -1;
- // TODO(bsimonnet): We should check that |path| exists and is the right
- // device. We don't do this currently as OEMs can add custom SELinux rules
- // which may prevent us from accessing this.
- // See b/24267261.
+ if (stat(path, &dev_statbuf) != 0)
+ return 1;
+
+ if (dev && dev != dev_statbuf.st_rdev)
+ return 2;
return 0;
}
diff --git a/rootdev.h b/rootdev.h
index 05c3da1..74a48da 100644
--- a/rootdev.h
+++ b/rootdev.h
@@ -79,12 +79,14 @@ void rootdev_get_device_slave(char *slave, size_t size, dev_t *dev,
* @path is populated for all return codes.
* Returns 0 on success and non-zero on error:
* -1 on unexpected errors (@path may be invalid)
+ * 1 on no existing @path
+ * 2 @path exists but the dev_t value is mismatched.
*
* Nb, this function does NOT search /dev for a match. It performs a normal
- * string concatenation.
- * We can't check if the device actually exists as vendors may create an
- * SELinux context we don't know about for it (in which case, this function
- * would always fail).
+ * string concatenation and probes for the existence. If udev has moved,
+ * or otherwise renamed, the device, a positive value is returned.
+ * The caller may then use the dev_t and @path to create the node with
+ * mknod(2).
*/
int rootdev_get_path(char *path, size_t size, const char *device, dev_t dev,
const char *dev_path);