diff options
author | Suchang Woo <suchang.woo@samsung.com> | 2015-02-11 21:45:38 -0800 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.vlan103.tizen.org> | 2015-02-11 21:45:38 -0800 |
commit | bc8d2ef9191decf75a6061746e6e88db076b2a81 (patch) | |
tree | 3de7620ab73bb78377eb79ce36e9fda1fdbadf5a | |
parent | 07fefaa55a064d41c6028086fbf5a8b7bd0c89f6 (diff) | |
parent | a59f5024f1d3c86ae70015ce1fa4916875b3a21b (diff) | |
download | aul-1-bc8d2ef9191decf75a6061746e6e88db076b2a81.tar.gz aul-1-bc8d2ef9191decf75a6061746e6e88db076b2a81.tar.bz2 aul-1-bc8d2ef9191decf75a6061746e6e88db076b2a81.zip |
Merge "session agent changed to send dead signal to amd." into tizensubmit/tizen_tv/20150212.054854accepted/tizen/tv/20150213.052913
-rw-r--r-- | am_daemon/amd_main.c | 33 | ||||
-rw-r--r-- | am_daemon/amd_request.c | 44 | ||||
-rw-r--r-- | am_daemon/amd_status.c | 39 | ||||
-rw-r--r-- | am_session_agent/agent.c | 19 | ||||
-rw-r--r-- | am_session_agent/sigchild.h | 5 | ||||
-rw-r--r-- | include/app_sock.h | 3 | ||||
-rw-r--r-- | include/aul_util.h | 7 |
7 files changed, 116 insertions, 34 deletions
diff --git a/am_daemon/amd_main.c b/am_daemon/amd_main.c index 5b526418..6fb608d1 100644 --- a/am_daemon/amd_main.c +++ b/am_daemon/amd_main.c @@ -95,13 +95,29 @@ static int __kill_bg_apps(int limit) return 0; } +static int __remove_item_running_list_with_uid(uid_t user) +{ + r_app_info_t *info_t; + GSList *iter; + GSList *iter_next; + + GSLIST_FOREACH_SAFE(r_app_info_list, iter, iter_next) { + info_t = (r_app_info_t *)iter->data; + if (user == info_t->user) { + r_app_info_list = g_slist_remove(r_app_info_list, info_t); + free(info_t); + break; + } + } +} + static int __remove_item_running_list(int pid, uid_t user) { - r_app_info_t *info_t = NULL; - GSList *iter = NULL; + r_app_info_t *info_t; + GSList *iter; + GSList *iter_next; - for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter)) - { + GSLIST_FOREACH_SAFE(r_app_info_list, iter, iter_next) { info_t = (r_app_info_t *)iter->data; if( (pid == info_t->pid) && (user == info_t->user || 0 == info_t->user )) { r_app_info_list = g_slist_remove(r_app_info_list, info_t); @@ -160,8 +176,7 @@ gboolean __add_item_running_list(gpointer user_data) if (taskmanage == false) goto END; - for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter)) - { + for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter)) { info_t = (r_app_info_t *)iter->data; if((pid == info_t->pid) && (user == info_t->user)) { found = 1; @@ -221,6 +236,12 @@ int __app_dead_handler(int pid, uid_t user) return 0; } +int __agent_dead_handler(uid_t user) +{ + __remove_item_running_list_with_uid(user); + _status_remove_app_info_list_with_uid(user); +} + static void __start_cb(void *user_data, const char *filename, const struct appinfo *ai) { diff --git a/am_daemon/amd_request.c b/am_daemon/amd_request.c index 20502992..6dc90fff 100644 --- a/am_daemon/amd_request.c +++ b/am_daemon/amd_request.c @@ -50,6 +50,7 @@ static int __send_result_to_client(int fd, int res); static gboolean __request_handler(gpointer data); extern int __app_dead_handler(int pid, uid_t user); +extern int __agent_dead_handler(uid_t user); static int __send_result_to_client(int fd, int res) { @@ -192,21 +193,22 @@ static int __release_srv(uid_t caller_uid, const char *filename) return 0; } -static int __handle_dead_signal(bundle* kb,int clifd, struct ucred * pcr) { - int ret=-1; +static int __handle_dead_signal(bundle *kb, int clifd, struct ucred *pcr) +{ + int ret = -1; const char *pid_str; - int pid=0; + int pid = 0; /* check the credentials from the caller: must be the amd agent */ - // exe of calling process - char * caller=__proc_get_exe_bypid(pcr->pid); + char *caller = __proc_get_exe_bypid(pcr->pid); if (!caller) { _D("handle_dead_signal: unable to get caller exe"); return -1; } - if (strcmp(caller,"/usr/bin/amd_session_agent")) { - _D("handle_dead_signal: caller is not amd session agent, %d : '%s'", pcr->pid,caller); + if (strcmp(caller, "/usr/bin/amd_session_agent")) { + _D("handle_dead_signal: caller is not amd session agent, %d : '%s'", + pcr->pid, caller); free(caller); return -1; } @@ -214,20 +216,28 @@ static int __handle_dead_signal(bundle* kb,int clifd, struct ucred * pcr) { /* get app pid from bundle */ pid_str = bundle_get_val(kb, AUL_K_PID); - if(!pid_str) + if (!pid_str) return -1; - pid=atoi(pid_str); - if (pid<=1) + pid = atoi(pid_str); + if (pid <= 1) return -1; - _D("APP_DEAD_SIGNAL : %d",pid); + _D("APP_DEAD_SIGNAL : %d", pid); - ret=__app_dead_handler(pid,pcr->uid); + ret = __app_dead_handler(pid, pcr->uid); return ret; } +static void __handle_agent_dead_signal(struct ucred *pcr) +{ + /* TODO: check the credentials from the caller: must be the amd agent */ + + _D("AGENT_DEAD_SIGNAL : %d", pcr->uid); + __agent_dead_handler(pcr->uid); +} + static gboolean __request_handler(gpointer data) { GPollFD *gpollfd = (GPollFD *) data; @@ -346,10 +356,14 @@ static gboolean __request_handler(gpointer data) __send_result_to_client(clifd, ret); break; case APP_DEAD_SIGNAL: - _E("APP_DEAD_SIGNAL"); - + _D("APP_DEAD_SIGNAL"); kb = bundle_decode(pkt->data, pkt->len); - ret=__handle_dead_signal(kb,clifd,&cr); + ret = __handle_dead_signal(kb, clifd, &cr); + close(clifd); + break; + case AGENT_DEAD_SIGNAL: + _D("AMD_AGENT_DEAD_SIGNAL"); + __handle_agent_dead_signal(&cr); close(clifd); break; default: diff --git a/am_daemon/amd_status.c b/am_daemon/amd_status.c index 12f595ee..9fef48bd 100644 --- a/am_daemon/amd_status.c +++ b/am_daemon/amd_status.c @@ -39,11 +39,11 @@ struct appinfomgr *_saf = NULL; int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid, uid_t uid) { - GSList *iter = NULL; - app_status_info_t *info_t = NULL; + GSList *iter; + GSList *iter_next; + app_status_info_t *info_t; - for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) - { + GSLIST_FOREACH_SAFE(app_status_info_list, iter, iter_next) { info_t = (app_status_info_t *)iter->data; if(pid == info_t->pid) { if(uid == info_t->user) @@ -51,9 +51,9 @@ int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid, else { //PID is unique so if it is exist but user value is not correct remove it. app_status_info_list = g_slist_remove(app_status_info_list, info_t); - free(info_t); - break; - } + free(info_t); + break; + } } } @@ -100,13 +100,30 @@ int _status_update_app_info_list(int pid, int status, uid_t uid) return 0; } +int _status_remove_app_info_list_with_uid(uid_t uid) +{ + GSList *iter; + GSList *iter_next; + app_status_info_t *info_t; + + GSLIST_FOREACH_SAFE(app_status_info_list, iter, iter_next) { + info_t = (app_status_info_t *)iter->data; + if (info_t->user == uid) { + app_status_info_list = + g_slist_remove(app_status_info_list, info_t); + free(info_t); + break; + } + } +} + int _status_remove_app_info_list(int pid, uid_t uid) { - GSList *iter = NULL; - app_status_info_t *info_t = NULL; + GSList *iter; + GSList *iter_next; + app_status_info_t *info_t; - for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter)) - { + GSLIST_FOREACH_SAFE(app_status_info_list, iter, iter_next) { info_t = (app_status_info_t *)iter->data; if((pid == info_t->pid) && ((info_t->user == uid) || (info_t->user == 0))) { app_status_info_list = g_slist_remove(app_status_info_list, info_t); diff --git a/am_session_agent/agent.c b/am_session_agent/agent.c index 7b748dde..6193cf90 100644 --- a/am_session_agent/agent.c +++ b/am_session_agent/agent.c @@ -63,6 +63,7 @@ static char *agent_cmdline; static int initialized = 0; +static bool loop_flag = TRUE; _static_ void __set_oom(); @@ -88,6 +89,12 @@ _static_ int __agent_post_init(); +void __sigterm_handler(int signo) +{ + _D("received SIGTERM siganl %d", signo); + loop_flag = FALSE; +} + _static_ void __set_oom() { char buf[MAX_LOCAL_BUFSZ]; @@ -778,6 +785,15 @@ _static_ int __agent_post_init() return 0; } +static void __send_dead_siganl_to_amd(void) +{ + bundle *kb; + + kb = bundle_create(); + app_send_cmd_with_noreply(AUL_UTIL_PID, AGENT_DEAD_SIGNAL, kb); + bundle_free(kb); +} + int main(int argc, char **argv) { int main_fd; @@ -797,7 +813,7 @@ int main(int argc, char **argv) pfds[0].events = POLLIN; pfds[0].revents = 0; - while (1) { + while (loop_flag == TRUE) { if (poll(pfds, POLLFD_MAX, -1) < 0) continue; @@ -814,5 +830,6 @@ int main(int argc, char **argv) } } } + __send_dead_siganl_to_amd(); } diff --git a/am_session_agent/sigchild.h b/am_session_agent/sigchild.h index c75bde3a..b557e736 100644 --- a/am_session_agent/sigchild.h +++ b/am_session_agent/sigchild.h @@ -27,6 +27,8 @@ static struct sigaction old_sigchild; static DBusConnection *bus = NULL; sigset_t oldmask; +extern void __sigterm_handler(int signo); + static inline void __socket_garbage_collector() { DIR *dp; @@ -196,6 +198,9 @@ static inline int __signal_init(void) case SIGSEGV: case SIGPIPE: break; + case SIGTERM: + signal(SIGTERM, __sigterm_handler); + break; default: signal(i, SIG_DFL); break; diff --git a/include/app_sock.h b/include/app_sock.h index dde5b08d..f6129c6b 100644 --- a/include/app_sock.h +++ b/include/app_sock.h @@ -54,7 +54,8 @@ enum app_cmd { APP_TERM_REQ_BY_PID, /* reserved for AMD Agent */ - APP_DEAD_SIGNAL + APP_DEAD_SIGNAL, + AGENT_DEAD_SIGNAL }; #define AUL_SOCK_PREFIX "/tmp/alaunch" diff --git a/include/aul_util.h b/include/aul_util.h index c3a60aae..996fdaf2 100644 --- a/include/aul_util.h +++ b/include/aul_util.h @@ -34,6 +34,13 @@ #define MAX_PACKAGE_APP_PATH_SIZE 512 #define MAX_RUNNING_APP_INFO 512 +#define GSLIST_FOREACH_SAFE(list, l, l_next) \ + for (l = list, \ + l_next = g_slist_next(l); \ + l; \ + l = l_next, \ + l_next = g_slist_next(l)) + typedef struct _app_status_info_t{ char appid[MAX_PACKAGE_STR_SIZE]; char app_path[MAX_PACKAGE_APP_PATH_SIZE]; |