Add a mandatory command line flag for kernel options

Change-Id: I74045650d975bdf7b6a6b4ce7f09c77de0a1ac63
(cherry picked from commit 459f00aa40d8de6f06cb6649d767717d8ee7854c)
diff --git a/ivserver/vsoc_mem.json b/ivserver/vsoc_mem.json
index 25eb672..afeed4f 100644
--- a/ivserver/vsoc_mem.json
+++ b/ivserver/vsoc_mem.json
@@ -1,18 +1,4 @@
 {
-  "guest": {
-    "kernel_command_line" : [
-           "loop.max_part=7",
-           "console=ttyS0",
-           "androidboot.console=ttyS0",
-           "androidboot.hardware=vsoc",
-           "security=selinux",
-           "androidboot.selinux=permissive",
-           "androidboot.serialno=CUTTLEFISHAVD01",
-           "enforcing=0",
-           "audit=0",
-           "CUTTLEFISH"
-    ]
-  },
   "vsoc_device_regions" : [
    {
      "device_name" : "hwcomposer",
diff --git a/launcher/main.cc b/launcher/main.cc
index 60d0c08..738c51f 100644
--- a/launcher/main.cc
+++ b/launcher/main.cc
@@ -30,6 +30,7 @@
 DEFINE_string(qemusocket, "/tmp/ivshmem_socket_qemu", "QEmu socket path");
 DEFINE_string(clientsocket, "/tmp/ivshmem_socket_client", "Client socket path");
 DEFINE_string(cache_image, "", "Location of the cache partition image.");
+DEFINE_string(kernel_command_line, "", "Location of a text file with the kernel command line.");
 DEFINE_string(data_image, "", "Location of the data partition image.");
 DEFINE_string(system_image_dir, "", "Location of the system partition images.");
 DEFINE_string(initrd, "/usr/share/cuttlefish-common/gce_ramdisk.img",
@@ -145,10 +146,24 @@
   auto cache_partition =  config::FilePartition::ReuseExistingFile(
       FLAGS_cache_image);
 
-  std::stringstream cmdline;
-  for (const auto& value : json_root["guest"]["kernel_command_line"]) {
-    cmdline << value.asString() << ' ';
+  if (!FLAGS_kernel_command_line.size()) {
+    LOG(FATAL) << "--kernel_command_line is required";
   }
+  std::ifstream t(FLAGS_kernel_command_line);
+  if (!t) {
+    LOG(FATAL) << "Unable to open " << FLAGS_kernel_command_line;
+  }
+  t.seekg(0, std::ios::end);
+  size_t commandline_size = t.tellg();
+  if (commandline_size < 1) {
+    LOG(FATAL) << "no command line data found at " << FLAGS_kernel_command_line;
+  }
+  std::string cmdline;
+  cmdline.reserve(commandline_size);
+  t.seekg(0, std::ios::beg);
+  cmdline.assign((std::istreambuf_iterator<char>(t)),
+             std::istreambuf_iterator<char>());
+  t.close();
 
   unsigned long libvirt_version;
   CHECK(virGetVersion(&libvirt_version, nullptr, nullptr) == 0)
@@ -170,7 +185,7 @@
       .SetMemoryMB(FLAGS_memory_mb)
       .SetKernelName(FLAGS_kernel)
       .SetInitRDName(FLAGS_initrd)
-      .SetKernelArgs(cmdline.str())
+      .SetKernelArgs(cmdline)
       .SetIVShMemSocketPath(FLAGS_qemusocket)
       .SetIVShMemVectorCount(json_root["vsoc_device_regions"].size())
       .SetRamdiskPartitionPath(ramdisk_partition->GetName())