Add IPMI 2.0 ColdReset command support

* Implement reset by reboot command issued in a shell
* Work with related changes in phosphor-host-ipmid repo

Resolves openbmc/openbmc#437

Change-Id: I8143b1ee9c0d547ee47e5bd3659a5126b6e5af98
Signed-off-by: Nan Li <william.bjlinan@hotmail.com>
diff --git a/bmcctl/control_bmc_obj.c b/bmcctl/control_bmc_obj.c
index c3ef723..c0135c4 100644
--- a/bmcctl/control_bmc_obj.c
+++ b/bmcctl/control_bmc_obj.c
@@ -40,6 +40,27 @@
     return TRUE;
 }
 
+static gboolean on_cold_reset(ControlBmc *bmc,
+                              GDBusMethodInvocation *invocation,
+                              gpointer user_data)
+{
+    GError *err = NULL;
+    /* Wait a while before reboot, so the caller can be responded.
+     * Note that g_spawn_command_line_async() cannot parse ';' as
+     * a command separator. Need to use 'sh -c' to let shell parse it.
+     */
+    gchar *reboot_command = "/bin/sh -c 'sleep 3;reboot'";
+
+    g_spawn_command_line_async(reboot_command, &err);
+    if(err != NULL) {
+       fprintf(stderr, "coldReset() error: %s\n", err->message);
+       g_error_free(err);
+    }
+
+    control_bmc_complete_cold_reset(bmc, invocation);
+    return TRUE;
+}
+
 static void on_bus_acquired(GDBusConnection *connection, const gchar *name,
                             gpointer user_data)
 {
@@ -66,6 +87,9 @@
     g_signal_connect(control_bmc, "handle-warm-reset",
                      G_CALLBACK(on_warm_reset), NULL); /* user_data */
 
+    g_signal_connect(control_bmc, "handle-cold-reset",
+                     G_CALLBACK(on_cold_reset), NULL); /* user_data */
+
     /* Export the object (@manager takes its own reference to @object) */
     g_dbus_object_manager_server_export(manager,
                                         G_DBUS_OBJECT_SKELETON(object));