[IMPROVE] WSP: pass data via debugfs
authorAlexander Aksenov <a.aksenov@samsung.com>
Tue, 29 Sep 2015 14:39:11 +0000 (17:39 +0300)
committerAlexander Aksenov <a.aksenov@samsung.com>
Wed, 28 Oct 2015 12:06:12 +0000 (15:06 +0300)
Webapp path and ewebkit path were hardcoded, now
they are written in wsp debug by manager.

Change-Id: Ia16de26c1db89f791108a44639b9f79ae3dbdca1
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
wsp/wsp.c
wsp/wsp.h
wsp/wsp_debugfs.c

index 296b077..85b8bdf 100644 (file)
--- a/wsp/wsp.c
+++ b/wsp/wsp.c
@@ -20,6 +20,7 @@
  */
 
 
+#include <linux/string.h>
 #include <uprobe/swap_uaccess.h>
 #include <us_manager/sspt/sspt.h>
 #include <us_manager/probes/probe_info_new.h>
@@ -40,9 +41,8 @@ struct wsp_bin {
 };
 
 
-/* TODO: configure this from outside (using debugfs) */
-static const char webapp_path[] = "/usr/bin/wrt_launchpad_daemon";
-static const char ewebkit_path[] = "/usr/lib/libewebkit2.so";
+static char *webapp_path = NULL;
+static char *ewebkit_path = NULL;
 
 
 #define WSP_PROBE_MAKE(__name, __desc) \
@@ -296,7 +296,7 @@ enum {
 };
 
 static struct wsp_bin ewebkit = {
-       .name = ewebkit_path,
+       .name = NULL,
        .cnt = ewebkit_probes_cnt,
        .probe_array = ewebkit_probe_array
 };
@@ -369,6 +369,22 @@ static void wsp_bin_unregister(struct pf_group *pfg, struct wsp_bin *bin)
                wsp_probe_unregister(pfg, dentry, &bin->probe_array[i]);
 }
 
+static void do_set_path(char **dest, char *path, size_t len)
+{
+       *dest = kmalloc(len, GFP_KERNEL);
+       if (*dest == NULL) {
+               printk("Not enough memory to init path\n");
+               return;
+       }
+
+       strncpy(*dest, path, len);
+}
+
+static void do_free_path(char **dest)
+{
+       kfree(*dest);
+}
+
 
 static struct pf_group *g_pfg;
 
@@ -376,6 +392,13 @@ static int wsp_app_register(void)
 {
        struct dentry *dentry;
 
+       if (webapp_path == NULL || ewebkit_path == NULL) {
+               printk("WSP: some required paths are not set!\n");
+               return -EINVAL;
+       }
+
+       ewebkit.name = ewebkit_path;
+
        dentry = dentry_by_path(webapp_path);
        if (dentry == NULL) {
                pr_err("dentry not found (path='%s'\n", webapp_path);
@@ -393,6 +416,11 @@ static int wsp_app_register(void)
 
 static void wsp_app_unregister(void)
 {
+       if (ewebkit.name != NULL) {
+               printk("WSP: ewebkit path is not initialized\n");
+               return;
+       }
+
        wsp_bin_unregister(g_pfg, &ewebkit);
        put_pf_group(g_pfg);
 }
@@ -417,6 +445,8 @@ static void do_wsp_off(void)
 {
        wsp_app_unregister();
        wsp_res_exit();
+       do_free_path(&webapp_path);
+       do_free_path(&ewebkit_path);
 }
 
 
@@ -484,6 +514,18 @@ enum wsp_mode wsp_get_mode(void)
        return g_mode;
 }
 
+void wsp_set_webapp_path(char *path, size_t len)
+{
+       do_free_path(&webapp_path);
+       do_set_path(&webapp_path, path, len);
+}
+
+void wsp_set_ewebkit_path(char *path, size_t len)
+{
+       do_free_path(&ewebkit_path);
+       do_set_path(&ewebkit_path, path, len);
+}
+
 int wsp_init(void)
 {
        return 0;
index 9a1db28..c7f82f6 100644 (file)
--- a/wsp/wsp.h
+++ b/wsp/wsp.h
@@ -34,6 +34,9 @@ int wsp_set_addr(const char *name, unsigned long offset);
 int wsp_set_mode(enum wsp_mode mode);
 enum wsp_mode wsp_get_mode(void);
 
+void wsp_set_webapp_path(char *path, size_t len);
+void wsp_set_ewebkit_path(char *path, size_t len);
+
 int wsp_init(void);
 void wsp_exit(void);
 
index 09189f1..797ebcb 100644 (file)
@@ -51,7 +51,7 @@ free_name:
 }
 
 /* ============================================================================
- * ===                         DEBUGFS FOR ENABLE                           ===
+ * ===                          DEBUGFS FOR CMD                             ===
  * ============================================================================
  */
 static ssize_t write_cmd(struct file *file, const char __user *user_buf,
@@ -140,6 +140,88 @@ static const struct file_operations fops_enabled = {
 };
 
 
+
+
+/* ============================================================================
+ * ===                       DEBUGFS FOR WEBAPP_PATH                        ===
+ * ============================================================================
+ */
+static ssize_t write_webapp_path(struct file *file, const char __user *user_buf,
+                            size_t len, loff_t *ppos)
+{
+       ssize_t ret;
+       char *path;
+
+       path = kmalloc(len, GFP_KERNEL);
+       if (path == NULL) {
+               ret = -ENOMEM;
+               goto write_webapp_path_failed;
+       }
+
+       if (copy_from_user(path, user_buf, len)) {
+               ret = -EINVAL;
+               goto write_webapp_path_failed;
+       }
+
+       path[len - 1] = '\0';
+
+       wsp_set_webapp_path(path, len);
+
+       ret = len;
+
+write_webapp_path_failed:
+       kfree(path);
+
+       return ret;
+}
+
+static const struct file_operations fops_webapp_path = {
+       .write = write_webapp_path
+};
+
+
+
+
+/* ============================================================================
+ * ===                      DEBUGFS FOR EWEBKIT_PATH                        ===
+ * ============================================================================
+ */
+static ssize_t write_ewebkit_path(struct file *file, const char __user *user_buf,
+                            size_t len, loff_t *ppos)
+{
+       ssize_t ret;
+       char *path;
+
+       path = kmalloc(len, GFP_KERNEL);
+       if (path == NULL) {
+               ret = -ENOMEM;
+               goto write_ewebkit_path_failed;
+       }
+
+       if (copy_from_user(path, user_buf, len)) {
+               ret = -EINVAL;
+               goto write_ewebkit_path_failed;
+       }
+
+       path[len - 1] = '\0';
+
+       wsp_set_ewebkit_path(path, len);
+
+       ret = len;
+
+write_ewebkit_path_failed:
+       kfree(path);
+
+       return ret;
+}
+
+static const struct file_operations fops_ewebkit_path = {
+       .write = write_ewebkit_path
+};
+
+
+
+
 static struct dentry *wsp_dir;
 
 void wsp_debugfs_exit(void)
@@ -171,6 +253,16 @@ int wsp_debugfs_init(void)
        if (dentry == NULL)
                goto fail;
 
+       dentry = debugfs_create_file("webapp_path", 0600, wsp_dir, NULL,
+                                    &fops_webapp_path);
+       if (dentry == NULL)
+               goto fail;
+
+       dentry = debugfs_create_file("ewebkit_path", 0600, wsp_dir, NULL,
+                                    &fops_ewebkit_path);
+       if (dentry == NULL)
+               goto fail;
+
        return 0;
 
 fail: