Handle headless action 09/151709/4
authorPaweł Szewczyk <p.szewczyk@samsung.com>
Fri, 15 Sep 2017 10:44:43 +0000 (12:44 +0200)
committerPaweł Szewczyk <p.szewczyk@samsung.com>
Thu, 28 Sep 2017 16:21:25 +0000 (18:21 +0200)
Change-Id: Iae7568963986d017b4b75efd4a4bce197fb8a119
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
src/system-recovery/recovery-main.c

index 347ca98..4d10551 100644 (file)
@@ -18,6 +18,7 @@
 
 #define _POSIX_SOURCE
 
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <signal.h>
@@ -86,6 +87,28 @@ void run_factory_reset(void)
        reboot(RB_AUTOBOOT);
 }
 
+#ifndef RECOVERY_GUI
+static int run_default(config_t *cfg)
+{
+       config_setting_t *node;
+       const char *action, *handler;
+
+       node = config_lookup(cfg, "headless_action");
+       if (!node)
+               return -ENOENT;
+
+       action = config_setting_get_string(node);
+       node = config_lookup(cfg, "action_handlers");
+       if (!node)
+               return -ENOENT;
+
+       if (config_setting_lookup_string(node, action, &handler) == CONFIG_FALSE)
+               return -ENOENT;
+
+       return system(handler);
+}
+#endif
+
 int main(void)
 {
        config_t cfg;
@@ -133,8 +156,9 @@ int main(void)
        ev_exit();
        recovery_rui_exit();
 #else
-       // XXX: run default action
+       ret = run_default(&cfg);
 #endif
        LOGD("[main] recovery finished.\n");
+       config_destroy(&cfg);
        return 0;
 }