Merge changes I459078c4,I36be1b49

* changes:
  storaged: clean up output format
  storaged: replace string functions that can throw exception
diff --git a/demangle/.clang-format b/demangle/.clang-format
new file mode 120000
index 0000000..fd0645f
--- /dev/null
+++ b/demangle/.clang-format
@@ -0,0 +1 @@
+../.clang-format-2
\ No newline at end of file
diff --git a/init/action.cpp b/init/action.cpp
index 09de81a..1bba0f2 100644
--- a/init/action.cpp
+++ b/init/action.cpp
@@ -246,20 +246,16 @@
 }
 
 std::string Action::BuildTriggersString() const {
-    std::string result;
+    std::vector<std::string> triggers;
 
     for (const auto& [trigger_name, trigger_value] : property_triggers_) {
-        result += trigger_name;
-        result += '=';
-        result += trigger_value;
-        result += ' ';
+        triggers.emplace_back(trigger_name + '=' + trigger_value);
     }
     if (!event_trigger_.empty()) {
-        result += event_trigger_;
-        result += ' ';
+        triggers.emplace_back(event_trigger_);
     }
-    result.pop_back();
-    return result;
+
+    return Join(triggers, " && ");
 }
 
 void Action::DumpState() const {
@@ -268,7 +264,7 @@
 
     for (const auto& c : commands_) {
         std::string cmd_str = c.BuildCommandString();
-        LOG(INFO) << "  %s" << cmd_str;
+        LOG(INFO) << "  " << cmd_str;
     }
 }
 
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 507c4a0..43eb378 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -494,6 +494,10 @@
             parser.ParseConfig(args[i]);
         }
     }
+
+    // Turning this on and letting the INFO logging be discarded adds 0.2s to
+    // Nexus 9 boot time, so it's disabled by default.
+    if (false) parser.DumpState();
 }
 
 /* mount_fstab
diff --git a/init/devices.cpp b/init/devices.cpp
index bd11f5f..405f92e 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -390,6 +390,34 @@
     return 0;
 }
 
+/* Given a path that may start with a virtual block device, populate
+ * the supplied buffer with the virtual block device ID and return 0.
+ * If it doesn't start with a virtual block device, or there is some
+ * error, return -1 */
+static int find_vbd_device_prefix(const char *path, char *buf, ssize_t buf_sz)
+{
+    const char *start, *end;
+
+    /* Beginning of the prefix is the initial "vbd-" after "/devices/" */
+    if (strncmp(path, "/devices/vbd-", 13))
+        return -1;
+
+    /* End of the prefix is one path '/' later, capturing the
+       virtual block device ID. Example: 768 */
+    start = path + 13;
+    end = strchr(start, '/');
+    if (!end)
+        return -1;
+
+    /* Make sure we have enough room for the string plus null terminator */
+    if (end - start + 1 > buf_sz)
+        return -1;
+
+    strncpy(buf, start, end - start);
+    buf[end - start] = '\0';
+    return 0;
+}
+
 static void parse_event(const char *msg, struct uevent *uevent)
 {
     uevent->action = "";
@@ -516,6 +544,9 @@
     } else if (!find_pci_device_prefix(uevent->path, buf, sizeof(buf))) {
         device = buf;
         type = "pci";
+    } else if (!find_vbd_device_prefix(uevent->path, buf, sizeof(buf))) {
+        device = buf;
+        type = "vbd";
     } else {
         return NULL;
     }
diff --git a/init/init.cpp b/init/init.cpp
index 5ab421b..4e31865 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -1254,6 +1254,10 @@
         parser.set_is_odm_etc_init_loaded(true);
     }
 
+    // Turning this on and letting the INFO logging be discarded adds 0.2s to
+    // Nexus 9 boot time, so it's disabled by default.
+    if (false) parser.DumpState();
+
     ActionManager& am = ActionManager::GetInstance();
 
     am.QueueEventTrigger("early-init");
diff --git a/init/init_parser.cpp b/init/init_parser.cpp
index 406b339..326ebf2 100644
--- a/init/init_parser.cpp
+++ b/init/init_parser.cpp
@@ -106,10 +106,6 @@
         sp.second->EndFile(path);
     }
 
-    // Turning this on and letting the INFO logging be discarded adds 0.2s to
-    // Nexus 9 boot time, so it's disabled by default.
-    if (false) DumpState();
-
     LOG(VERBOSE) << "(Parsing " << path << " took " << t << ".)";
     return true;
 }