Enable multiple consoles

This CL allows enabling of multiple consoles. The expected format
of "androidboot.console" kernel parameter is a list of available
consoles, as follows:

  androidboot.console=tty0:ttyS0

A service can be mapped to a specific console by providing the
optional argument, IE "tty0", to "console" service attribute as follows:

service fbconsole /system/bin/sh
    class core
    console tty0
    disabled
    user shell
    group shell log readproc
    seclabel u:r:shell:s0

Bug: None
Change-Id: I3f8556425c8651bd121995869700f18b23365d55
Tracked-On: https://jira01.devtools.intel.com/browse/BP-289
diff --git a/init/init.cpp b/init/init.cpp
index bac27df..704597d 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -74,8 +74,7 @@
 
 static char qemu[32];
 
-int have_console;
-std::string console_name = "/dev/console";
+std::vector<std::string> console_names;
 static time_t process_needs_restart;
 
 const char *ENV[32];
@@ -298,38 +297,23 @@
 
 static int console_init_action(const std::vector<std::string>& args)
 {
-    std::string console = property_get("ro.boot.console");
-    if (!console.empty()) {
-        console_name = "/dev/" + console;
+    std::vector<std::string> consoles;
+    std::string c_prop = property_get("ro.boot.console");
+    if (c_prop.empty()) {
+        // Property is missing, so check the system console by default.
+        consoles.emplace_back(DEFAULT_CONSOLE);
+    } else {
+        consoles = android::base::Split(c_prop, ":");
     }
 
-    int fd = open(console_name.c_str(), O_RDWR | O_CLOEXEC);
-    if (fd >= 0)
-        have_console = 1;
-    close(fd);
-
-    fd = open("/dev/tty0", O_WRONLY | O_CLOEXEC);
-    if (fd >= 0) {
-        const char *msg;
-            msg = "\n"
-        "\n"
-        "\n"
-        "\n"
-        "\n"
-        "\n"
-        "\n"  // console is 40 cols x 30 lines
-        "\n"
-        "\n"
-        "\n"
-        "\n"
-        "\n"
-        "\n"
-        "\n"
-        "             A N D R O I D ";
-        write(fd, msg, strlen(msg));
-        close(fd);
+    for (const auto& c : consoles) {
+        std::string console = "/dev/" + c;
+        int fd = open(console.c_str(), O_RDWR | O_CLOEXEC);
+        if (fd != -1) {
+            console_names.emplace_back(c);
+            close(fd);
+        }
     }
-
     return 0;
 }