Add option to run post boot commands on emulator 74/264674/1 submit/tizen/20210928.063523
authorKarthik <kv.bhat@samsung.com>
Tue, 28 Sep 2021 05:58:06 +0000 (11:28 +0530)
committerKarthik <kv.bhat@samsung.com>
Tue, 28 Sep 2021 05:58:06 +0000 (11:28 +0530)
Change-Id: I7aefde421fabe13aef5e8795621cf5892f62e64f
Signed-off-by: Karthik <kv.bhat@samsung.com>
packaging/emuld.spec
src/emuld.cpp

index 584fdcb24c83a5ae3e35fe080a1d006328f09c17..fa6f7674b1938d4ba42d5ea9fdf465ac26d2c008 100644 (file)
@@ -4,7 +4,7 @@
 
 %define emuld_major_version 0
 %define emuld_minor_version 11
-%define emuld_release_number 2
+%define emuld_release_number 3
 
 Name: emuld
 Version: %{emuld_major_version}.%{emuld_minor_version}.%{emuld_release_number}
index 638bbdc4b45bbc3480bd266a9bb0cce58009460f..1e1df8bb25ef877c6c796f2613bb8ff299b8c314 100644 (file)
@@ -38,6 +38,8 @@
 
 #include "emuld.h"
 
+#define MAX_PKGS_BUF            1024
+
 int g_epoll_fd;
 struct epoll_event g_events[MAX_EVENTS];
 void* dl_handles[MAX_PLUGINS];
@@ -141,11 +143,55 @@ static void send_to_kernel(void)
     LOGINFO("[DBUS] sent booting done to kernel");
 }
 
+
+static void run_postboot_script(char* fileName) {
+    int ret = -1;
+    char file_name[MAX_PKGS_BUF];
+    char launch_buf[MAX_PKGS_BUF + 2];
+    snprintf(file_name, sizeof(file_name), "/home/owner/share/tmp/.emul-scripts/%s", fileName); 
+    LOGINFO("[run_postboot_script] called %s\n",file_name);
+    ret = access(file_name, F_OK);
+    if (ret != 0)
+    {
+        LOGWARN("[RunScript] file does not exist: %s", file_name);
+        return;
+    }
+
+    ret = chmod(file_name, 0755);
+    if (ret != 0)
+    {
+        LOGWARN("[RunScript] file permission setting is failed : [%d] %s", ret, file_name);
+        return;
+    }
+
+    snprintf(launch_buf, sizeof(launch_buf), ". %s", file_name);
+
+    systemcall(launch_buf);
+}
+
+
+static void run_postboot_scripts()
+{
+    DIR *d;
+    struct dirent *dir;
+    d = opendir("/home/owner/share/tmp/.emul-scripts/");
+    if (d)
+    {
+        while ((dir = readdir(d)) != NULL)
+        {
+            run_postboot_script(dir->d_name);
+        }
+        closedir(d);
+    }
+}
+
 static void boot_done(void *data, DBusMessage *msg)
 {
     if (dbus_message_is_signal(msg,
                 DBUS_IFACE_BOOT_DONE,
                 BOOT_DONE_SIGNAL) != 0) {
+        LOGINFO("[DBUS] Running post boot scripts.");
+        run_postboot_scripts();
         LOGINFO("[DBUS] sending booting done to ecs.");
         send_to_ecs(IJTYPE_BOOT, 0, 0, NULL);
         LOGINFO("[DBUS] sending booting done to kernel for log.");
@@ -153,6 +199,7 @@ static void boot_done(void *data, DBusMessage *msg)
     }
 }
 
+
 static bool epoll_init(void)
 {
     g_epoll_fd = epoll_create(MAX_EVENTS); // create event pool