From: Changgyu Choi Date: Tue, 19 Dec 2023 01:24:42 +0000 (+0900) Subject: Add startup timer X-Git-Tag: accepted/tizen/6.5/unified/20231221.112322~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99a8bc1c9b83c68277a870786103ac5ea6bd86fe;p=platform%2Fcore%2Fappfw%2Famd.git Add startup timer Rarely, launchpad child process continues to be created and OOM occurs. This patch adds a timer to recognize this case and monitor continuously. Change-Id: Ib57d1c20ca46f7e32d959b81f0e2744aad289bc4 Signed-off-by: Changgyu Choi --- diff --git a/src/lib/amd_app_status.c b/src/lib/amd_app_status.c index 10934253..b0eeb78c 100644 --- a/src/lib/amd_app_status.c +++ b/src/lib/amd_app_status.c @@ -83,6 +83,8 @@ struct app_status_s { bool debug_mode; guint timer; int real_pid; + guint startup_timer; + int delay_count; guint disconn_timer; }; @@ -540,6 +542,8 @@ static void __destroy_app_status(struct app_status_s *app_status) g_source_remove(app_status->timer); if (app_status->disconn_timer) g_source_remove(app_status->disconn_timer); + if (app_status->startup_timer) + g_source_remove(app_status->startup_timer); free(app_status); } @@ -710,7 +714,7 @@ void *_app_status_get_extra(app_status_h app_status, const char *key) int _app_status_add_app_info(const struct appinfo *ai, int pid, bool is_subapp, uid_t uid, int caller_pid, bool bg_launch, const char *instance_id, - bool debug_mode) + bool debug_mode, bool pending) { GSList *iter; GSList *iter_next; @@ -751,6 +755,8 @@ int _app_status_add_app_info(const struct appinfo *ai, int pid, _noti_send(AMD_NOTI_MSG_APP_STATUS_ADD, 0, 0, app_status, NULL); app_status_list = g_slist_append(app_status_list, app_status); __add_pkg_status(app_status); + if (pending) + _app_status_set_startup_timer(app_status); return 0; } @@ -1821,6 +1827,27 @@ static bool __dir_monitor_cb(const char *event_name, void *data) return true; } +static gboolean __startup_timeout_cb(gpointer data) +{ + const char *appid; + pid_t pid; + int delay_count; + + app_status_h app_status = (app_status_h)data; + if (app_status == NULL) + return G_SOURCE_REMOVE; + + appid = _app_status_get_appid(app_status); + pid = _app_status_get_pid(app_status); + delay_count = _app_status_get_delay_count(app_status); + + _E("App(%s[%d]) hasn't run main loop yet. delay_count(%d)", + appid, pid, delay_count); + + _app_status_increase_delay_count(app_status); + return G_SOURCE_CONTINUE; +} + int _app_status_usr_init(uid_t uid) { inotify_watch_info_h handle; @@ -2210,7 +2237,7 @@ int _app_status_register_pid(int pid, const char *appid, uid_t uid) component_type = _appinfo_get_value(ai, AIT_COMPTYPE); _app_status_add_app_info(ai, pid, false, uid, getpid(), - false, NULL, false); + false, NULL, false, false); _noti_send(AMD_NOTI_MSG_APP_STATUS_APP_REGISTER_PID, pid, 0, ai, NULL); if (component_type && strcmp(component_type, APP_TYPE_SERVICE) != 0) { ret = _signal_get_proc_status_async(pid, @@ -2924,3 +2951,50 @@ bool _app_status_is_subapp(app_status_h app_status) return app_status->is_subapp; } + +int _app_status_set_startup_timer(app_status_h app_status) +{ + if (!app_status) + return -1; + + + if (app_status->startup_timer > 0) { + _W("Already set"); + return 0; + } + + app_status->startup_timer = g_timeout_add(10 * 1000, + __startup_timeout_cb, app_status); + if (app_status->startup_timer == 0) { + _E("Failed to set timer"); + return -1; + } + + return 0; +} + +void _app_status_unset_startup_timer(app_status_h app_status) +{ + if (!app_status || app_status->startup_timer == 0) + return; + + g_source_remove(app_status->startup_timer); + app_status->startup_timer = 0; +} + +int _app_status_get_delay_count(app_status_h app_status) +{ + if (!app_status) + return -1; + + return app_status->delay_count; +} + +int _app_status_increase_delay_count(app_status_h app_status) +{ + if (!app_status) + return -1; + + app_status->delay_count++; + return 0; +} diff --git a/src/lib/amd_app_status.h b/src/lib/amd_app_status.h index 38746edf..681d29ce 100644 --- a/src/lib/amd_app_status.h +++ b/src/lib/amd_app_status.h @@ -51,7 +51,7 @@ void *_app_status_get_extra(app_status_h app_status, const char *key); int _app_status_add_app_info(const struct appinfo *ai, int pid, bool is_subapp, uid_t uid, int caller_pid, bool bg_launch, const char *instance_id, - bool debug_mode); + bool debug_mode, bool pending); int _app_status_remove_all_app_info_with_uid(uid_t uid); @@ -171,6 +171,14 @@ int _app_status_get_real_pid(app_status_h app_status); bool _app_status_is_subapp(app_status_h app_status); +int _app_status_set_startup_timer(app_status_h app_status); + +void _app_status_unset_startup_timer(app_status_h app_status); + +int _app_status_get_delay_count(app_status_h app_status); + +int _app_status_increase_delay_count(app_status_h app_status); + #ifdef __cplusplus } #endif diff --git a/src/lib/amd_launch.c b/src/lib/amd_launch.c index 7b415870..ca682015 100644 --- a/src/lib/amd_launch.c +++ b/src/lib/amd_launch.c @@ -1771,6 +1771,7 @@ static int __dispatch_app_startup_signal(request_h req) return -1; _app_status_update_is_starting(app_status, true); + _app_status_unset_startup_timer(app_status); if (_app_status_get_app_type(app_status) == AT_UI_APP && _app_status_get_status(app_status) != STATUS_VISIBLE) __launch_add_fgmgr(pid); @@ -3222,7 +3223,8 @@ static int __complete_starting_app(struct launch_s *handle, request_h req) _app_status_add_app_info(handle->ai, handle->pid, handle->is_subapp, target_uid, caller_pid, handle->bg_launch, - handle->instance_id, handle->debug_mode); + handle->instance_id, handle->debug_mode, + handle->new_process); _comp_status_add_comp_info(handle->ci, handle->pid, handle->instance_id, handle->is_subapp);