[PROTO] add handling of emtpy PID string 72/15572/3
authorNikita Kalyazin <n.kalyazin@samsung.com>
Thu, 23 Jan 2014 11:49:20 +0000 (15:49 +0400)
committerNikita Kalyazin <n.kalyazin@samsung.com>
Thu, 23 Jan 2014 14:16:49 +0000 (18:16 +0400)
Empty PID string means no filtering by PID is needed.

Change-Id: Id593504d59db4a3fe53c4d3d8aa62be235027219
Signed-off-by: Nikita Kalyazin <n.kalyazin@samsung.com>
daemon/da_protocol_check.c
daemon/daemon.c
daemon/utils.c
daemon/utils.h

index d4076c4..c8fa651 100644 (file)
@@ -42,6 +42,21 @@ int check_app_type(uint32_t app_type)
        }
 }
 
+static int is_pid_string_valid(const char *pid_str)
+{
+       char *tmp;
+       long pid;
+
+       if (pid_str[0] == '\0') /* no pid filtering */
+               return 1;
+
+       /* otherwise this should be a valid number */
+       pid = strtol(pid_str, &tmp, 10);
+
+       /* TODO: get max pid value from /proc/sys/kernel/pid_max */
+       return *tmp == '\0' && pid > 0 && pid <= 32768;
+}
+
 int check_app_id(uint32_t app_type, char *app_id)
 {
        int res = 0;
@@ -51,11 +66,10 @@ int check_app_id(uint32_t app_type, char *app_id)
                        res = 1;
                        break;
                case APP_TYPE_RUNNING:
-                       strtol(app_id, &p, 10);
-                       if ((*app_id != 0) && (*p == 0))
-                               res = 1;
-                       else
+                       if (!is_pid_string_valid(app_id))
                                LOGE("wrong app id for APP_RUNNING\n");
+                       else
+                               res = 1;
                        break;
                case APP_TYPE_COMMON:
                        res = (strlen(app_id) == 0);
index 52990b4..d4e6574 100644 (file)
@@ -215,7 +215,7 @@ static int kill_app_by_info(const struct app_info_t *app_info)
                res = kill_app(app_info->exe_path);
                break;
        case APP_TYPE_WEB:
-               /* do nothing (it is restarted by itself */
+               /* do nothing (it is restarted by itself) */
                break;
        default:
                LOGE("Unknown app type %d\n", app_info->app_type);
index 9e71b3b..6bf8bf4 100644 (file)
@@ -211,7 +211,7 @@ int exec_app_web(const char *app_id)
        } else { /* child */
                execl(WRT_LAUNCHER_PATH,
                      WRT_LAUNCHER_NAME,
-                     WRT_LAUNCHER_LAUNCH,
+                     WRT_LAUNCHER_START,
                      app_id,
                      NULL);
                /* FIXME: If code flows here, it deserves greater attention */
index bc12874..de4dea1 100644 (file)
@@ -42,10 +42,10 @@ extern "C" {
 #define LAUNCH_APP_PATH                        "/usr/bin/launch_app"
 #define KILL_APP_PATH                  "/usr/bin/pkill"
 #define LAUNCH_APP_NAME                        "launch_app"
-#define        WRT_LAUNCHER_PATH               "/usr/bin/wrt-launcher"
-#define        WRT_LAUNCHER_NAME               "wrt-launcher"
-#define        WRT_LAUNCHER_LAUNCH             "-s"
-#define        WRT_LAUNCHER_KILL               "-k"
+#define WRT_LAUNCHER_PATH              "/usr/bin/wrt-launcher"
+#define WRT_LAUNCHER_NAME              "wrt-launcher"
+#define WRT_LAUNCHER_START             "-s"
+#define WRT_LAUNCHER_KILL              "-k"
 #define LAUNCH_APP_SDK                 "__AUL_SDK__"
 #define DA_PRELOAD_EXEC                        "DYNAMIC_ANALYSIS"
 #define DA_PRELOAD(AppType)            AppType ? DA_PRELOAD_OSP : DA_PRELOAD_TIZEN