From: Nikita Kalyazin Date: Thu, 23 Jan 2014 11:49:20 +0000 (+0400) Subject: [PROTO] add handling of emtpy PID string X-Git-Tag: Tizen_SDK_2.3~82 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F15572%2F3;p=platform%2Fcore%2Fsystem%2Fswap-manager.git [PROTO] add handling of emtpy PID string Empty PID string means no filtering by PID is needed. Change-Id: Id593504d59db4a3fe53c4d3d8aa62be235027219 Signed-off-by: Nikita Kalyazin --- diff --git a/daemon/da_protocol_check.c b/daemon/da_protocol_check.c index d4076c4..c8fa651 100644 --- a/daemon/da_protocol_check.c +++ b/daemon/da_protocol_check.c @@ -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); diff --git a/daemon/daemon.c b/daemon/daemon.c index 52990b4..d4e6574 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -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); diff --git a/daemon/utils.c b/daemon/utils.c index 9e71b3b..6bf8bf4 100644 --- a/daemon/utils.c +++ b/daemon/utils.c @@ -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 */ diff --git a/daemon/utils.h b/daemon/utils.h index bc12874..de4dea1 100644 --- a/daemon/utils.h +++ b/daemon/utils.h @@ -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