Merge "Use getmntent when accessing /proc/mounts."
diff --git a/adb/adb.h b/adb/adb.h
index 35d8a4d..a37fd5b 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -329,7 +329,7 @@
 #if !ADB_HOST
 void framebuffer_service(int fd, void *cookie);
 // Allow enable-verity to write to system and vendor block devices
-int make_system_and_vendor_block_devices_writable();
+int make_block_device_writable(const char* dev);
 void remount_service(int fd, void *cookie);
 void set_verity_enabled_state_service(int fd, void* cookie);
 #endif
diff --git a/adb/remount_service.c b/adb/remount_service.c
index 5b3fa9f..d7b0dd1 100644
--- a/adb/remount_service.c
+++ b/adb/remount_service.c
@@ -63,14 +63,12 @@
     return false;
 }
 
-static int make_block_device_writable(const char* dir)
+int make_block_device_writable(const char* dev)
 {
-    char *dev = 0;
     int fd = -1;
     int OFF = 0;
     int rc = -1;
 
-    dev = find_mount(dir);
     if (!dev)
         goto errout;
 
@@ -88,36 +86,27 @@
     if (fd >= 0) {
         adb_close(fd);
     }
-
-    if (dev) {
-        free(dev);
-    }
     return rc;
 }
 
 /* Init mounts /system as read only, remount to enable writes. */
 static int remount(const char* dir, int* dir_ro)
 {
-    char *dev;
-
-    if (dir_ro == 0) {
-        return 0;
-    }
-
-    if (make_block_device_writable(dir)) {
-        return -1;
-    }
+    char *dev = 0;
+    int rc = -1;
 
     dev = find_mount(dir);
 
-    if (!dev)
-        return -1;
+    if (!dev || make_block_device_writable(dev)) {
+        goto errout;
+    }
 
-    *dir_ro = mount(dev, dir, "none", MS_REMOUNT, NULL);
+    rc = mount(dev, dir, "none", MS_REMOUNT, NULL);
+    *dir_ro = rc;
 
+errout:
     free(dev);
-
-    return *dir_ro;
+    return rc;
 }
 
 static void write_string(int fd, const char* str)
@@ -125,28 +114,6 @@
     writex(fd, str, strlen(str));
 }
 
-int make_system_and_vendor_block_devices_writable(int fd)
-{
-    char buffer[200];
-    if (make_block_device_writable("/system")) {
-        snprintf(buffer, sizeof(buffer),
-                 "Failed to make system block device writable %s\n",
-                 strerror(errno));
-        write_string(fd, buffer);
-        return -1;
-    }
-
-    if (hasVendorPartition() && make_block_device_writable("/vendor")) {
-        snprintf(buffer, sizeof(buffer),
-                 "Failed to make vendor block device writable: %s\n",
-                 strerror(errno));
-        write_string(fd, buffer);
-        return -1;
-    }
-
-    return 0;
-}
-
 void remount_service(int fd, void *cookie)
 {
     char buffer[200];
diff --git a/adb/set_verity_enable_state_service.c b/adb/set_verity_enable_state_service.c
index 09e2eb9..2660ddd 100644
--- a/adb/set_verity_enable_state_service.c
+++ b/adb/set_verity_enable_state_service.c
@@ -87,9 +87,15 @@
     const uint32_t new_magic = enable ? VERITY_METADATA_MAGIC_NUMBER
                                       : VERITY_METADATA_MAGIC_DISABLE;
     uint64_t device_length;
-    int device;
+    int device = -1;
     int retval = -1;
 
+    if (make_block_device_writable(block_device)) {
+        write_console(fd, "Could not make block device %s writable (%s).\n",
+                      block_device, strerror(errno));
+        goto errout;
+    }
+
     device = adb_open(block_device, O_RDWR | O_CLOEXEC);
     if (device == -1) {
         write_console(fd, "Could not open block device %s (%s).\n",
@@ -191,10 +197,6 @@
         goto errout;
     }
 
-    if (enable && make_system_and_vendor_block_devices_writable(fd)) {
-        goto errout;
-    }
-
     /* Loop through entries looking for ones that vold manages */
     for (i = 0; i < fstab->num_entries; i++) {
         if(fs_mgr_is_verified(&fstab->recs[i])) {
diff --git a/include/log/log_read.h b/include/log/log_read.h
index 946711a..1b70aff 100644
--- a/include/log/log_read.h
+++ b/include/log/log_read.h
@@ -100,6 +100,12 @@
         log_time local(*this);
         return local -= T;
     }
+    log_time operator+= (const timespec &T);
+    log_time operator+ (const timespec &T) const
+    {
+        log_time local(*this);
+        return local += T;
+    }
 
     // log_time
     bool operator== (const log_time &T) const
@@ -134,6 +140,12 @@
         log_time local(*this);
         return local -= T;
     }
+    log_time operator+= (const log_time &T);
+    log_time operator+ (const log_time &T) const
+    {
+        log_time local(*this);
+        return local += T;
+    }
 
     uint64_t nsec() const
     {
diff --git a/liblog/log_time.cpp b/liblog/log_time.cpp
index 209a9da..50742df 100644
--- a/liblog/log_time.cpp
+++ b/liblog/log_time.cpp
@@ -150,6 +150,17 @@
     return *this;
 }
 
+log_time log_time::operator+= (const timespec &T) {
+    this->tv_nsec += (unsigned long int)T.tv_nsec;
+    if (this->tv_nsec >= NS_PER_SEC) {
+        this->tv_nsec -= NS_PER_SEC;
+        ++this->tv_sec;
+    }
+    this->tv_sec += T.tv_sec;
+
+    return *this;
+}
+
 log_time log_time::operator-= (const log_time &T) {
     // No concept of negative time, clamp to EPOCH
     if (*this <= T) {
@@ -166,3 +177,14 @@
 
     return *this;
 }
+
+log_time log_time::operator+= (const log_time &T) {
+    this->tv_nsec += T.tv_nsec;
+    if (this->tv_nsec >= NS_PER_SEC) {
+        this->tv_nsec -= NS_PER_SEC;
+        ++this->tv_sec;
+    }
+    this->tv_sec += T.tv_sec;
+
+    return *this;
+}