Refactor amd_request.c 39/54639/3 accepted/tizen/mobile/20151217.093014 accepted/tizen/tv/20151217.093153 accepted/tizen/wearable/20151217.093130 submit/tizen/20151217.025256
authorJunghoon Park <jh9216.park@samsung.com>
Thu, 17 Dec 2015 00:57:42 +0000 (09:57 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Thu, 17 Dec 2015 01:46:34 +0000 (17:46 -0800)
- remove the feature for process limit
  (It will be made by using data structural of app-group later)

Change-Id: I481888066eb35c7efb5e72e84937ff2706a164bc
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
am_daemon/amd_main.c
am_daemon/amd_request.c
am_daemon/amd_status.h

index 319d3bb..abb1570 100644 (file)
 #define AUL_SP_DBUS_SIGNAL_INTERFACE "org.tizen.aul.syspopup"
 #define AUL_SP_DBUS_LAUNCH_REQUEST_SIGNAL "syspopup_launch_request"
 
-typedef struct _r_app_info_t {
-       char pkg_name[MAX_PACKAGE_STR_SIZE];
-       int pid;
-       uid_t user;
-} r_app_info_t;
-
 struct restart_info {
        char *appid;
        int count;
        guint timer;
 };
 
-static GSList *r_app_info_list;
 static GHashTable *restart_tbl;
 
 static void __vconf_cb(keynode_t *key, void *data);
 static int __init(void);
 
-static int __send_to_sigkill(int pid)
-{
-       int pgid;
-
-       pgid = getpgid(pid);
-       if (pgid <= 1)
-               return -1;
-
-       if (killpg(pgid, SIGKILL) < 0)
-               return -1;
-
-       return 0;
-}
-
-static int __kill_bg_apps(int limit)
-{
-       int len;
-       int i;
-       int n;
-       r_app_info_t *info_t;
-       GSList *iter;
-
-       len = g_slist_length(r_app_info_list);
-
-       n = len - limit;
-
-       if (n <= 0)
-               return 0;
-
-       for (i = 0, iter = r_app_info_list; i < n; i++) {
-               info_t = (r_app_info_t *)iter->data;
-               aul_send_app_terminate_request_signal(info_t->pid, NULL, NULL, NULL);
-               __send_to_sigkill(info_t->pid);
-               iter = g_slist_next(iter);
-               r_app_info_list = g_slist_remove(r_app_info_list, info_t);
-               free(info_t);
-       }
-
-       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);
-               }
-       }
-       return 0;
-}
-
-static int __remove_item_running_list(int pid, 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 ((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);
-                       free(info_t);
-                       break;
-               }
-       }
-       return 0;
-}
-
-gboolean __add_item_running_list(gpointer user_data)
-{
-       bool taskmanage;
-       pkgmgrinfo_appinfo_h handle;
-       int ret;
-       r_app_info_t *info_t;
-       GSList *iter;
-       int found = 0;
-       int limit;
-       char *pkgname;
-       int pid;
-       uid_t user;
-       item_pkt_t *item;
-
-       item = (item_pkt_t *)user_data;
-
-       pkgname = item->appid;
-       pid = item->pid;
-       user = item->uid;
-       if (vconf_get_int(VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, &limit) != 0) {
-               _E("Unable to get VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n");
-               limit = 0;
-       }
-
-       if (pkgname == NULL)
-               return false;
-       else if (strncmp(pkgname, "org.tizen.cluster-home", 24) == 0) {
-               if (limit > 0)
-                       __kill_bg_apps(limit - 1);
-               return false;
-       }
-
-       if (user != GLOBAL_USER)
-               ret = pkgmgrinfo_appinfo_get_usr_appinfo(pkgname, user, &handle);
-       else
-               ret = pkgmgrinfo_appinfo_get_appinfo(pkgname, &handle);
-       if (ret != PMINFO_R_OK) {
-               _E("pkgmgrinfo_pkginfo_get_pkginfo with %s failed", pkgname);
-               return false;
-       }
-
-       ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage);
-       if (ret != PMINFO_R_OK) {
-               _E("pkgmgrinfo_appinfo_is_taskmanage failed");
-               goto END;
-       }
-
-       if (taskmanage == false)
-               goto END;
-
-       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;
-                       r_app_info_list = g_slist_remove_link(r_app_info_list, iter);
-                       r_app_info_list = g_slist_concat(r_app_info_list, iter);
-                       break;
-               }
-       }
-       if (found == 0) {
-               info_t = malloc(sizeof(r_app_info_t));
-               if (info_t == NULL) {
-                       _E("out of memory");
-                       goto END;
-               }
-               strncpy(info_t->pkg_name, pkgname, sizeof(info_t->pkg_name));
-               info_t->pkg_name[sizeof(info_t->pkg_name) - 1] = '\0';
-               info_t->pid = pid;
-               info_t->user = user;
-               r_app_info_list = g_slist_append(r_app_info_list, info_t);
-       }
-
-       for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter))
-               info_t = (r_app_info_t *)iter->data;
-
-       if (limit > 0)
-               __kill_bg_apps(limit);
-
-       for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter))
-               info_t = (r_app_info_t *)iter->data;
-
-END:
-       ret = pkgmgrinfo_appinfo_destroy_appinfo(handle);
-       if (ret != PMINFO_R_OK)
-               _E("pkgmgrinfo_appinfo_destroy_appinfo failed");
-
-       free(item);
-       return false;
-}
-
 static void __vconf_cb(keynode_t *key, void *data)
 {
-       int limit;
        const char *name;
 
        name = vconf_keynode_get_name(key);
        if (name == NULL)
                return;
        else if (strcmp(name, VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS) == 0) {
-               limit = vconf_keynode_get_int(key);
-               if (limit > 0)
-                       __kill_bg_apps(limit);
+               //TODO : clear bgapp
+
        }
 }
 
@@ -369,7 +195,6 @@ static int __app_dead_handler(int pid, void *data)
                app_group_remove(pid);
        }
 
-       __remove_item_running_list(pid, getuid());
        _status_remove_app_info_list(pid, getuid());
        _request_flush_pending_request(pid);
        aul_send_app_terminated_signal(pid);
@@ -384,7 +209,6 @@ static int __app_dead_handler(int pid, void *data)
 
 int __agent_dead_handler(uid_t user)
 {
-       __remove_item_running_list_with_uid(user);
        _status_remove_app_info_list_with_uid(user);
        return 0;
 }
index 62c66a9..f1a788e 100644 (file)
@@ -83,8 +83,17 @@ struct request {
        struct ucred cr;
 };
 
-typedef int (*app_cmd_dispatch_func)(int clifd, const app_pkt_t *pkt, struct ucred *cr);
+typedef struct _rua_stat_pkt_t {
+       int uid;
+       char *stat_tag;
+       char *stat_caller;
+       char appid[512];
+       gboolean is_group_app;
+       char *data;
+       int len;
+} rua_stat_pkt_t;
 
+typedef int (*app_cmd_dispatch_func)(int clifd, const app_pkt_t *pkt, struct ucred *cr);
 
 static int __send_result_to_client(int fd, int res);
 static gboolean __request_handler(gpointer data);
@@ -410,6 +419,66 @@ static gboolean __add_history_handler(gpointer user_data)
        return FALSE;
 }
 
+static int __add_rua_info(const app_pkt_t *pkt, bundle *kb, uid_t uid, const char *appid)
+{
+       const char *stat_caller = NULL;
+       const char *stat_tag = NULL;
+       rua_stat_pkt_t *rua_stat_item = NULL;
+
+       rua_stat_item = calloc(1, sizeof(rua_stat_pkt_t));
+       if (rua_stat_item == NULL) {
+               _E("out of memory");
+               goto error;
+       }
+
+       if (pkt->len > 0) {
+               rua_stat_item->data = (char *)calloc(pkt->len, sizeof(char));
+               if (rua_stat_item->data == NULL) {
+                       _E("out of memory");
+                       goto error;
+               }
+               memcpy(rua_stat_item->data, pkt->data, pkt->len);
+       }
+       stat_caller = bundle_get_val(kb, AUL_SVC_K_RUA_STAT_CALLER);
+       stat_tag = bundle_get_val(kb, AUL_SVC_K_RUA_STAT_TAG);
+
+       rua_stat_item->len = pkt->len;
+       if (stat_caller != NULL) {
+               rua_stat_item->stat_caller = strdup(stat_caller);
+               if (rua_stat_item->stat_caller == NULL) {
+                       _E("Out of memory");
+                       goto error;
+               }
+       }
+
+       if (stat_tag != NULL) {
+               rua_stat_item->stat_tag = strdup(stat_tag);
+               if (rua_stat_item->stat_tag == NULL) {
+                       _E("Out of memory");
+                       goto error;
+               }
+
+       }
+       rua_stat_item->uid = uid;
+       rua_stat_item->is_group_app = app_group_is_group_app(kb);
+       strncpy(rua_stat_item->appid, appid, 511);
+
+       g_timeout_add(1500, __add_history_handler, rua_stat_item);
+
+       return 0;
+error:
+       if (rua_stat_item) {
+               if (rua_stat_item->data)
+                       free(rua_stat_item->data);
+               if (rua_stat_item->stat_caller)
+                       free(rua_stat_item->stat_caller);
+               if (rua_stat_item->stat_tag)
+                       free(rua_stat_item->stat_tag);
+               free(rua_stat_item);
+       }
+       return -1;
+}
+
 static void __handle_agent_dead_signal(struct ucred *pcr)
 {
        /* TODO: check the credentials from the caller: must be the amd agent */
@@ -720,10 +789,6 @@ static int __dispatch_app_start(int clifd, const app_pkt_t *pkt, struct ucred *c
        int ret = -1;
        int t_uid;
        char *state;
-       item_pkt_t *item = NULL;
-       char *stat_caller = NULL;
-       char *stat_tag = NULL;
-       rua_stat_pkt_t *rua_stat_item = NULL;
        bool pending = false;
        struct pending_item *pending_item;
        const char *operation = NULL;
@@ -781,75 +846,14 @@ static int __dispatch_app_start(int clifd, const app_pkt_t *pkt, struct ucred *c
                                pending_item);
        }
 
-       if (ret > 0) {
-               item = calloc(1, sizeof(item_pkt_t));
-               if (item == NULL) {
-                       _E("out of memory");
-                       goto error;
-               }
-               item->pid = ret;
-               item->uid = cr->uid;
-               strncpy(item->appid, appid, 511);
-
-               g_timeout_add(1200, __add_item_running_list, item);
-
-               rua_stat_item = calloc(1, sizeof(rua_stat_pkt_t));
-               if (rua_stat_item == NULL) {
-                       _E("out of memory");
-                       goto error;
-               }
-
-               if (pkt->len > 0) {
-                       rua_stat_item->data = (char *)calloc(pkt->len, sizeof(char));
-                       if (rua_stat_item->data == NULL) {
-                               _E("out of memory");
-                               goto error;
-                       }
-                       memcpy(rua_stat_item->data, pkt->data, pkt->len);
-               }
-               stat_caller = (char *)bundle_get_val(kb, AUL_SVC_K_RUA_STAT_CALLER);
-               stat_tag = (char *)bundle_get_val(kb, AUL_SVC_K_RUA_STAT_TAG);
-
-               rua_stat_item->len = pkt->len;
-               if (stat_caller != NULL) {
-                       rua_stat_item->stat_caller = strdup(stat_caller);
-                       if (rua_stat_item->stat_caller == NULL) {
-                               _E("Out of memory");
-                               goto error;
-                       }
-               }
-
-               if (stat_tag != NULL) {
-                       rua_stat_item->stat_tag = strdup(stat_tag);
-                       if (rua_stat_item->stat_tag == NULL) {
-                               _E("Out of memory");
-                               goto error;
-                       }
-
-               }
-               rua_stat_item->uid = cr->uid;
-               rua_stat_item->is_group_app = app_group_is_group_app(kb);
-               strncpy(rua_stat_item->appid, appid, 511);
-
-               g_timeout_add(1500, __add_history_handler, rua_stat_item);
-       }
+       if (ret > 0 && __add_rua_info(pkt, kb, cr->uid, appid) < 0)
+               goto error;
        bundle_free(kb);
        return 0;
 
 error:
        if (kb)
                bundle_free(kb);
-       if (item)
-               free(item);
-       if (rua_stat_item) {
-               if (rua_stat_item->data)
-                       free(rua_stat_item->data);
-               if (rua_stat_item->stat_caller)
-                       free(rua_stat_item->stat_caller);
-               if (rua_stat_item->stat_tag)
-                       free(rua_stat_item->stat_tag);
-               free(rua_stat_item);
-       }
        return -1;
 }
 
index 0c50a00..d6a545a 100644 (file)
@@ -1,23 +1,20 @@
 /*
- *  aul
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
  *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an AS IS BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
+#ifndef __AUL_AMD_APP_STATUS_H_
+#define __AUL_AMD_APP_STATUS_H_
 
 #include <unistd.h>
 #include <sys/types.h>
@@ -40,25 +37,6 @@ int _status_get_appid_bypid(int fd, int pid);
 int _status_get_pkgid_bypid(int fd, int pid);
 int _status_init(void);
 
-//TODO : remove
-
-typedef struct _item_pkt_t {
-       int pid;
-       uid_t uid;
-       char appid[512];
-} item_pkt_t;
-
-typedef struct _rua_stat_pkt_t {
-       int uid;
-       char *stat_tag;
-       char *stat_caller;
-       char appid[512];
-       gboolean is_group_app;
-       char *data;
-       int len;
-} rua_stat_pkt_t;
-
-gboolean __add_item_running_list(gpointer user_data);
-
+#endif