summaryrefslogtreecommitdiffstats
path: root/adb/remount_service.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-05-07 23:37:40 -0700
committerElliott Hughes <enh@google.com>2015-05-08 10:49:31 -0700
commit207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6 (patch)
treed5e5a6e057e8d93a4b5c5d38dd3b71ec0917a984 /adb/remount_service.cpp
parentc33e62bdc63ddaf7a17c5f317e73349bf3df2b83 (diff)
downloadsystem_core-207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6.zip
system_core-207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6.tar.gz
system_core-207ddb20ac2f25de19d74fe88f2a526e0ee5cfa6.tar.bz2
Fix "adb remount" for devices without an oem partition.
On a device without an oem partition, we now have an /oem directory anyway. This causes find_mount to fail, and that was returning nullptr from a std::string-returning function. Boom! Also clean up the bits of code I had to trace through between "adb remount" on the host to the crash on the device as I debugged this. The only other meaningful change is the error checking in adb_connect_command --- adb_connect can also return -2. Bug: http://b/20916855 Change-Id: I4c3b7858e13f3a3a8bbc7d30b3c0ee470bead587 (cherry picked from commit 5677c23e8d0c085be8d8429a5d125147d11e9bb2)
Diffstat (limited to 'adb/remount_service.cpp')
-rw-r--r--adb/remount_service.cpp53
1 files changed, 22 insertions, 31 deletions
diff --git a/adb/remount_service.cpp b/adb/remount_service.cpp
index 87702b0..f645a78 100644
--- a/adb/remount_service.cpp
+++ b/adb/remount_service.cpp
@@ -38,23 +38,20 @@ static int system_ro = 1;
static int vendor_ro = 1;
static int oem_ro = 1;
-/* Returns the device used to mount a directory in /proc/mounts */
-static std::string find_mount(const char *dir) {
- FILE* fp;
- struct mntent* mentry;
- char* device = NULL;
-
- if ((fp = setmntent("/proc/mounts", "r")) == NULL) {
- return NULL;
+// Returns the device used to mount a directory in /proc/mounts.
+static std::string find_mount(const char* dir) {
+ std::unique_ptr<FILE, int(*)(FILE*)> fp(setmntent("/proc/mounts", "r"), endmntent);
+ if (!fp) {
+ return "";
}
- while ((mentry = getmntent(fp)) != NULL) {
- if (strcmp(dir, mentry->mnt_dir) == 0) {
- device = mentry->mnt_fsname;
- break;
+
+ mntent* e;
+ while ((e = getmntent(fp.get())) != nullptr) {
+ if (strcmp(dir, e->mnt_dir) == 0) {
+ return e->mnt_fsname;
}
}
- endmntent(fp);
- return device;
+ return "";
}
int make_block_device_writable(const std::string& dev) {
@@ -75,7 +72,7 @@ int make_block_device_writable(const std::string& dev) {
// Init mounts /system as read only, remount to enable writes.
static int remount(const char* dir, int* dir_ro) {
- std::string dev(find_mount(dir));
+ std::string dev = find_mount(dir);
if (dev.empty() || make_block_device_writable(dev)) {
return -1;
}
@@ -86,35 +83,29 @@ static int remount(const char* dir, int* dir_ro) {
}
static bool remount_partition(int fd, const char* partition, int* ro) {
- if (!directory_exists(partition)) {
+ if (!directory_exists(partition)) {
+ return true;
+ }
+ if (remount(partition, ro)) {
+ WriteFdFmt(fd, "remount of %s failed: %s\n", partition, strerror(errno));
+ return false;
+ }
return true;
- }
- if (remount(partition, ro)) {
- WriteFdFmt(fd, "remount of %s failed: %s\n", partition, strerror(errno));
- return false;
- }
- return true;
}
void remount_service(int fd, void* cookie) {
- char prop_buf[PROPERTY_VALUE_MAX];
-
if (getuid() != 0) {
WriteFdExactly(fd, "Not running as root. Try \"adb root\" first.\n");
adb_close(fd);
return;
}
- bool system_verified = false, vendor_verified = false;
+ char prop_buf[PROPERTY_VALUE_MAX];
property_get("partition.system.verified", prop_buf, "");
- if (strlen(prop_buf) > 0) {
- system_verified = true;
- }
+ bool system_verified = (strlen(prop_buf) > 0);
property_get("partition.vendor.verified", prop_buf, "");
- if (strlen(prop_buf) > 0) {
- vendor_verified = true;
- }
+ bool vendor_verified = (strlen(prop_buf) > 0);
if (system_verified || vendor_verified) {
// Allow remount but warn of likely bad effects