Multi-user implementation feature 94/21994/1 submit/tizen_common/20140528.173953 submit/tizen_common/20140528.183233 submit/tizen_common/20140529.194900 submit/tizen_common/20140530.020532 submit/tizen_common/20140530.021300 submit/tizen_common/20140602.071652 submit/tizen_ivi/20140618.000000 submit/tizen_ivi/20140618.000001 submit/tizen_ivi/20140619.000000 submit/tizen_ivi/20140622.000000 submit/tizen_ivi/20140623.000000 submit/tizen_ivi/20140623.000001 submit/tizen_ivi/20140624.064036
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Fri, 28 Feb 2014 17:01:18 +0000 (18:01 +0100)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Wed, 28 May 2014 12:39:19 +0000 (14:39 +0200)
- Desactivate preload features
- Create am_agent process
- Remove old launchpad daemon
- Make am_agent discuss with amd process to launch an app
- Add Crosswalk Launchpad capabilities
- renamed am_agent to am_session_agent; fix segfault in amd_session_agent after first app launch
- cleanup agent code, added uid in amd request to agent
- Fix build with Cosswalk and add Dbus call
- fix build; added specific dlog tag for agent
- fix caller_uid check in agent
- Use DBUS SESSION bus instead of DBUS SYSTEM bus
- amd_session_agent now sends an APP_DEAD_SIGNAL request to amd daemon to signal the end of an app
- Fix Error Management
- amd: check that sender of APP_DEAD_SIGNAL is /usr/bin/amd_session_agent
- Add systemd service
- Add User Management for get applications ,Remove DBUS launch mechanism
- get uid for multiuser support

more info : https://wiki.tizen.org/wiki/Multi-user_Architecture

Change-Id: Iee37e603cb366d94bcc945df7edf3c3817fdee82
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
Signed-off-by: Stephane Desneux <stephane.desneux@open.eurogiciel.org>
Signed-off-by: Sabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Signed-off-by: Jean-Benoit MARTIN <jean-benoit.martin@open.eurogiciel.org>
31 files changed:
CMakeLists.txt
am_daemon/ac_status.c
am_daemon/amd_appinfo.c
am_daemon/amd_appinfo.h
am_daemon/amd_launch.c
am_daemon/amd_main.c
am_daemon/amd_request.c
am_daemon/amd_status.c
am_daemon/amd_status.h
am_session_agent/agent.c [moved from launchpad_src/launchpad.c with 86% similarity]
am_session_agent/agent_config.h [new file with mode: 0644]
am_session_agent/sigchild.h [moved from launchpad_src/sigchild.h with 79% similarity]
include/app_sock.h
include/aul.h
include/aul_util.h
include/simple_util.h
launchpad_src/config.h [deleted file]
launchpad_src/gl.h [deleted file]
launchpad_src/heap_dbg.h [deleted file]
launchpad_src/util_x.c [deleted file]
launchpad_src/util_x.h [deleted file]
packaging/amd_session_agent.service [new file with mode: 0644]
packaging/aul.spec
src/app_signal.c
src/app_sock.c
src/launch.c
src/simple_util.c
test/aul_dbus.c
test/dbusapp_test.c
test/launch_app.c
test/open_app.c

index af23cb0..22e73a7 100644 (file)
@@ -99,21 +99,15 @@ SET_TARGET_PROPERTIES(aul PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(aul PROPERTIES VERSION ${VERSION})
 
 # launchpad(old avatar) daemon
-SET(AVATAR_NAME "launchpad_preloading_preinitializing_daemon")
-IF (WITH_WAYLAND)
-add_executable(${AVATAR_NAME}
-        launchpad_src/launchpad.c
+SET(AM_SESSION_AGENT_NAME "amd_session_agent")
+add_executable(${AM_SESSION_AGENT_NAME}
+        am_session_agent/agent.c
         )
-ELSE(WITH_WAYLAND)
-add_executable(${AVATAR_NAME}
-       launchpad_src/launchpad.c
-       launchpad_src/util_x.c
-       )
-ENDIF(WITH_WAYLAND)
-
 MESSAGE("       "${pkgs_LDFLAGS})
-target_link_libraries(${AVATAR_NAME} aul_mods aul ${pkgs_LDFLAGS} ${LIB_DL})
-set_target_properties(${AVATAR_NAME}
+TARGET_LINK_LIBRARIES(${AM_SESSION_AGENT_NAME} ${PKGS_LDFLAGS} aul aul_mods)
+SET_TARGET_PROPERTIES(${AM_SESSION_AGENT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
+
+set_target_properties(${AM_SESSION_AGENT_NAME}
                PROPERTIES SKIP_BUILD_RPATH true
                ) # remove rpath option that is automatically generated by cmake.
 
@@ -156,7 +150,7 @@ CONFIGURE_FILE(feature/preexec_list.txt.in feature/preexec_list.txt @ONLY)
 
 ### Install ###
 INSTALL(TARGETS aul DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
-INSTALL(TARGETS ${AVATAR_NAME} DESTINATION bin)
+INSTALL(TARGETS ${AM_SESSION_AGENT_NAME} DESTINATION bin)
 INSTALL(TARGETS amd DESTINATION bin)
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul.h DESTINATION include/aul)
index 6507b24..ec8203b 100755 (executable)
@@ -27,7 +27,7 @@
 
 GSList *app_status_info_list = NULL;
 
-int _add_app_status_info_list(char *appid, int pid)
+int _add_app_status_info_list(char *appid, int pid, uid_t uid)
 {
        GSList *iter = NULL;
        app_status_info_t *info_t = NULL;
@@ -44,6 +44,7 @@ int _add_app_status_info_list(char *appid, int pid)
        strncpy(info_t->appid, appid, MAX_PACKAGE_STR_SIZE-1);
        info_t->status = STATUS_LAUNCHING;
        info_t->pid = pid;
+       info_t->user = uid;
        app_status_info_list = g_slist_append(app_status_info_list, info_t);
 
        for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
@@ -56,7 +57,7 @@ int _add_app_status_info_list(char *appid, int pid)
        return 0;
 }
 
-int _update_app_status_info_list(int pid, int status)
+int _update_app_status_info_list(int pid, int status, uid_t uid)
 {
        GSList *iter = NULL;
        app_status_info_t *info_t = NULL;
@@ -64,7 +65,7 @@ int _update_app_status_info_list(int pid, int status)
        for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
        {
                info_t = (app_status_info_t *)iter->data;
-               if(pid == info_t->pid) {
+               if((pid == info_t->pid) && ((info_t->user == uid) || (info_t->user == 0))) {
                        info_t->status = status;
                        break;
                }
@@ -80,7 +81,7 @@ int _update_app_status_info_list(int pid, int status)
        return 0;
 }
 
-int _remove_app_status_info_list(int pid)
+int _remove_app_status_info_list(int pid, uid_t uid)
 {
        GSList *iter = NULL;
        app_status_info_t *info_t = NULL;
@@ -88,7 +89,7 @@ int _remove_app_status_info_list(int pid)
        for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
        {
                info_t = (app_status_info_t *)iter->data;
-               if(pid == info_t->pid) {
+               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);
                        free(info_t);
                        break;
index 5349bd2..7b25565 100755 (executable)
@@ -247,6 +247,8 @@ static void __vconf_cb(keynode_t *key, void *data)
        char *noti_string;
        char *type_string;
        char *appid;
+       char *uid_string;
+       uid_t uid;
        char *saveptr;
        pkgmgrinfo_appinfo_h handle;
        struct appinfomgr *cf = (struct appinfomgr *)data;
@@ -258,12 +260,16 @@ static void __vconf_cb(keynode_t *key, void *data)
        }
 
        SECURE_LOGD("noti_string : %s",noti_string);
-
        type_string = strtok_r(noti_string, ":", &saveptr);
        appid = strtok_r(NULL, ":", &saveptr);
+       uid_string = strtok_r(NULL, ":", &saveptr);
+       uid = atoi(uid_string);
 
+       _D("type_string: [%s]\n", type_string);
+       _D("appid: [%s]\n", appid);
+       _D("uid: %d\n", uid);
        if ( strncmp(type_string, "create", 6) == 0) {
-               ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+               ret = pkgmgrinfo_appinfo_get_appinfo_user(appid, uid, &handle);
                if(ret < 0) {
                        _E("pkgmgrinfo_appinfo_get_appinfo fail");
                }
@@ -278,7 +284,7 @@ static void __vconf_cb(keynode_t *key, void *data)
        } else if (strncmp(type_string, "update", 6) == 0){
                /*REMOVE EXISTING ENTRY & CREATE AGAIN*/
                if (g_hash_table_remove(cf->tbl, appid)){
-                       if (pkgmgrinfo_appinfo_get_appinfo(appid, &handle) == PMINFO_R_OK){
+                       if (pkgmgrinfo_appinfo_get_appinfo_user(appid, uid, &handle) == PMINFO_R_OK){
                                __app_info_insert_handler(handle, data);
                                pkgmgrinfo_appinfo_destroy_appinfo(handle);
                        }
@@ -413,15 +419,115 @@ void appinfo_delete(struct appinfomgr *cf, const char *pkg_name)
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
 }
 
-const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename)
+const struct appinfo *appinfo_find(uid_t caller_uid, const char *appid)
 {
-       if (!cf || !filename || !*filename) {
-               errno = EINVAL;
-               _E("appinfo find: %s", strerror(errno));
-               return NULL;
+       struct appinfo *res;
+       gboolean r;
+       bool multiple;
+       bool preload;
+       bool onboot;
+       char *exec;
+       bool restart;
+       char *pkgid;
+       char *type;
+       pkgmgrinfo_app_hwacceleration hwacc;
+       pkgmgrinfo_appinfo_h handle;
+       pkgmgrinfo_app_component component;
+       pkgmgrinfo_permission_type permission;
+       int ret;
+
+       ret = pkgmgrinfo_appinfo_get_appinfo( appid, &handle);
+       if (ret != PMINFO_R_OK){
+               ret = pkgmgrinfo_appinfo_get_appinfo_user(appid , caller_uid , &handle);
        }
 
-       return g_hash_table_lookup(cf->tbl, FILENAME(filename));
+       res = calloc(1, sizeof(*res));
+       if (!res) {
+               _E("create appinfo: %s", strerror(errno));
+               return -1;
+       }
+
+       memset(res, 0, sizeof(struct appinfo));
+
+       res->val[_AI_FILE] = strdup(appid);
+       if (!res->val[_AI_FILE]) {
+               _E("create appinfo: %s", strerror(errno));
+               _free_appinfo(res);
+               return -1;
+       }
+
+       res->val[_AI_NAME] = strdup(appid); //TODO :
+
+       pkgmgrinfo_appinfo_get_component(handle, &component);
+       if(component == PMINFO_UI_APP) {
+               res->val[_AI_COMP] = strdup("ui"); //TODO :
+
+               r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
+               if(multiple == true)
+                       res->val[_AI_MULTI] = strdup("true");
+               else res->val[_AI_MULTI] = strdup("false");
+
+               r = pkgmgrinfo_appinfo_is_preload(handle, &preload);
+               if (preload == false) {
+                       res->val[_AI_PRELOAD] = strdup("false");
+               } else {
+                       res->val[_AI_PRELOAD] = strdup("true");
+               }
+
+               if(gles == 0) {
+                       res->val[_AI_HWACC] = strdup("NOT_USE");
+               } else {
+
+                       r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
+                       if (hwacc == PMINFO_HWACCELERATION_USE_GL) {
+                               res->val[_AI_HWACC] = strdup("USE");
+                       } else if (hwacc == PMINFO_HWACCELERATION_USE_SYSTEM_SETTING) {
+                               res->val[_AI_HWACC] = strdup("SYS");
+                       } else {
+                               res->val[_AI_HWACC] = strdup("NOT_USE");
+                       }
+               }
+       } else {
+               res->val[_AI_COMP] = strdup("svc");
+
+               r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
+               if(onboot == true)
+                       res->val[_AI_ONBOOT] = strdup("true");
+               else res->val[_AI_ONBOOT] = strdup("false");
+
+               r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
+               if(restart == true)
+                       res->val[_AI_RESTART] = strdup("true");
+               else res->val[_AI_RESTART] = strdup("false");
+       }
+
+       r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+       res->val[_AI_EXEC] = strdup(exec);
+
+       r = pkgmgrinfo_appinfo_get_apptype(handle, &type);
+       if(strncmp(type, "capp", 4) == 0 ) {
+               res->val[_AI_TYPE] = strdup("rpm");
+       } else if (strncmp(type, "c++app", 6) == 0 || strncmp(type, "ospapp", 6) == 0) {
+               res->val[_AI_TYPE] = strdup("tpk");
+       } else if (strncmp(type, "webapp", 6) == 0) {
+               res->val[_AI_TYPE] = strdup("wgt");
+       }
+
+       r = pkgmgrinfo_appinfo_get_permission_type(handle, &permission);
+       if (permission == PMINFO_PERMISSION_SIGNATURE) {
+               res->val[_AI_PERM] = strdup("signature");
+       } else if (permission == PMINFO_PERMISSION_PRIVILEGE) {
+               res->val[_AI_PERM] = strdup("privilege");
+       } else {
+               res->val[_AI_PERM] = strdup("normal");
+       }
+
+       r = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+       res->val[_AI_PKGID] = strdup(pkgid);
+
+       SECURE_LOGD("%s : %s : %s", res->val[_AI_FILE], res->val[_AI_COMP], res->val[_AI_TYPE]);
+
+       return res;
 }
 
 const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
index f7340e6..39077b1 100755 (executable)
@@ -24,7 +24,7 @@ void appinfo_fini(struct appinfomgr **cf);
 const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *filename);
 void appinfo_delete(struct appinfomgr *cf, const char *filename);
 
-const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename);
+const struct appinfo *appinfo_find(uid_t caller_uid, const char *appid);
 const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type);
 const char *appinfo_get_filename(const struct appinfo *c);
 int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type);
index 440e46a..2bf833b 100755 (executable)
@@ -51,6 +51,8 @@
 #define INIT_PID 1
 
 #define AUL_PR_NAME                    16
+
+// SDK related defines
 #define PATH_APP_ROOT tzplatform_getenv(TZ_USER_APP)
 #define PATH_DATA "/data"
 #define SDK_CODE_COVERAGE "CODE_COVERAGE"
@@ -100,7 +102,6 @@ static void _set_sdk_env(const char* appid, char* str) {
        }
 }
 
-#define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
 
 static void _set_env(const char *appid, bundle * kb, const char *hwacc)
 {
@@ -151,7 +152,7 @@ static void _prepare_exec(const char *appid, bundle *kb)
        signal(SIGTERM, SIG_DFL);
        signal(SIGCHLD, SIG_DFL);
 
-       ai = appinfo_find(_laf, appid);
+       ai = appinfo_find(getuid(), appid);
 
        app_path = appinfo_get_value(ai, AIT_EXEC);
        pkg_type = appinfo_get_value(ai, AIT_TYPE);
@@ -682,7 +683,7 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
        const char *app_path = NULL;
        const char *pkg_type = NULL;
        int pid = -1;
-       char tmp_pid[MAX_PID_STR_BUFSZ];
+       char tmpbuf[MAX_PID_STR_BUFSZ];
        const char *hwacc;
        const char *permission;
        const char *pkgid;
@@ -693,8 +694,13 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
        int pad_pid = LAUNCHPAD_PID;
        bool consented = true;
 
-       snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", caller_pid);
-       bundle_add(kb, AUL_K_CALLER_PID, tmp_pid);
+       snprintf(tmpbuf, MAX_PID_STR_BUFSZ, "%d", caller_pid);
+       bundle_add(kb, AUL_K_CALLER_PID, tmpbuf);
+
+       snprintf(tmpbuf, MAX_PID_STR_BUFSZ, "%d", caller_uid);
+       bundle_add(kb, AUL_K_CALLER_UID, tmpbuf);
+
+       _D("_start_app: caller pid=%d uid=%d",caller_pid,caller_uid);
 
        if (cmd == APP_START_RES)
                bundle_add(kb, AUL_K_WAIT_RESULT, "1");
@@ -704,7 +710,7 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
                bundle_add(kb, AUL_K_CALLER_APPID, caller_appid);
        }
 
-       ai = appinfo_find(_laf, appid);
+       ai = appinfo_find(caller_uid, appid);
 
        if(ai == NULL) {
                __real_send(fd, -1);
@@ -726,7 +732,7 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
                        appid = PRIVACY_POPUP;
                        bundle_del(kb, AUL_K_PKG_NAME);
                        bundle_add(kb, AUL_K_PKG_NAME, appid);
-                       ai = appinfo_find(_laf, appid);
+                       ai = appinfo_find(caller_uid, appid);
                }
        }
 
@@ -739,7 +745,7 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
        if(permission && strncmp(permission, "signature", 9) == 0 ) {
                if(caller_uid != 0 && (cmd == APP_START || cmd == APP_START_RES)){
                        const struct appinfo *caller_ai;
-                       caller_ai = appinfo_find(_laf, caller_appid);
+                       caller_ai = appinfo_find(caller_uid, caller_appid);
                        preload = appinfo_get_value(caller_ai, AIT_PRELOAD);
                        if( preload && strncmp(preload, "true", 4) != 0 ) {
                                pkgmgrinfo_pkginfo_compare_app_cert_info(caller_appid, appid, &compare_result);
@@ -757,7 +763,7 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
        if (componet && strncmp(componet, "ui", 2) == 0) {
                multiple = appinfo_get_value(ai, AIT_MULTI);
                if (!multiple || strncmp(multiple, "false", 5) == 0) {
-                       pid = _status_app_is_running_v2(appid);
+                       pid = _status_app_is_running(appid, caller_uid);
                }
 
                if (pid > 0) {
@@ -778,19 +784,11 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
                        bundle_add(kb, AUL_K_HWACC, hwacc);
                        bundle_add(kb, AUL_K_EXEC, app_path);
                        bundle_add(kb, AUL_K_PACKAGETYPE, pkg_type);
-                       if(bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
-                               pad_pid = DEBUG_LAUNCHPAD_PID;          
-                       } else if(strncmp(pkg_type, "wgt", 3) == 0) {
-                               pad_pid = WEB_LAUNCHPAD_PID;
-                       }
-                       pid = app_send_cmd(pad_pid, cmd, kb);
-                       if(pid == -3) {
-                               pid = -ENOLAUNCHPAD;
-                       }
-                       //_add_cgroup(_lcg, appid, pid);
+                       pid = app_agent_send_cmd(caller_uid, cmd, kb);
+
                }
        } else if (componet && strncmp(componet, "svc", 3) == 0) {
-               pid = _status_app_is_running_v2(appid);
+               pid = _status_app_is_running_v2(caller_uid,appid);
                if (pid > 0) {
                        if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
                                pid = ret;
@@ -806,7 +804,7 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
                __real_send(fd, pid);
 
        if(pid > 0) {
-               _status_add_app_info_list(appid, app_path, pid, pad_pid);
+               _status_add_app_info_list(appid, app_path, pid, pad_pid, caller_uid);
                ret = ac_server_check_launch_privilege(appid, appinfo_get_value(ai, AIT_TYPE), pid);
                return ret != AC_R_ERROR ? pid : -1;
        }
index 480d0e0..8bebe13 100755 (executable)
 typedef struct _r_app_info_t{
        char pkg_name[MAX_PACKAGE_STR_SIZE];
        int pid;
+       uid_t user;
 } r_app_info_t;
 
 GSList *r_app_info_list = NULL;
 
 static void __vconf_cb(keynode_t *key, void *data);
-static int __app_dead_handler(int pid, void *data);
 static int __init();
 
 extern int _status_init(struct amdmgr* amd);
@@ -110,7 +110,7 @@ static int __kill_bg_apps(int limit)
        return 0;
 }
 
-static int __remove_item_running_list(int pid)
+static int __remove_item_running_list(int pid, uid_t user)
 {
        r_app_info_t *info_t = NULL;
        GSList *iter = NULL;
@@ -118,7 +118,7 @@ static int __remove_item_running_list(int pid)
        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) {
+               if( (pid == info_t->pid) && (user == info_t->user || 0 == info_t->pid )) {
                        r_app_info_list = g_slist_remove(r_app_info_list, info_t);
                        free(info_t);
                        break;
@@ -138,14 +138,14 @@ gboolean __add_item_running_list(gpointer user_data)
        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");
        }
@@ -175,7 +175,7 @@ gboolean __add_item_running_list(gpointer user_data)
        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) {
+               if((pid == info_t->pid) && (user == info_t->user))  {
                        found = 1;
                        r_app_info_list = g_slist_remove(r_app_info_list, info_t);
                        r_app_info_list = g_slist_append(r_app_info_list, info_t);
@@ -223,11 +223,14 @@ static void __vconf_cb(keynode_t *key, void *data)
        }
 }
 
-static int __app_dead_handler(int pid, void *data)
+int __app_dead_handler(int pid)
 {
+       // this function was called in single user mode as a callback to aul_listen_app_dead_signal
+       // but in multiuser mode, AMD daemon can't listen any more on DBUS system to catch those events
+       // AMD Agents must connect to AMD Daemon to signal a dead process
        _unregister_key_event(pid);
-       __remove_item_running_list(pid);
-       _status_remove_app_info_list(pid);
+       __remove_item_running_list(pid, getuid());
+       _status_remove_app_info_list(pid, getuid());
        return 0;
 }
 
@@ -257,7 +260,7 @@ static int __init()
                .cg = NULL
        };
 
-       int ret;
+       int ret=0;
 
        ecore_init();
        evas_init();
@@ -282,7 +285,6 @@ static int __init()
 #endif
        if (vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, __vconf_cb, NULL) != 0)
                _E("Unable to register callback for VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n");
-       aul_listen_app_dead_signal(__app_dead_handler, NULL);
 
        _start_services(&amd);
 
index 0101d1a..f8b2d75 100755 (executable)
@@ -53,6 +53,8 @@ struct cginfo *_rcg;
 static int __send_result_to_client(int fd, int res);
 static gboolean __request_handler(gpointer data);
 
+extern int __app_dead_handler(int pid);
+
 static int __send_result_to_client(int fd, int res)
 {
        if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) {
@@ -135,11 +137,6 @@ static int __app_process_by_pid(int cmd,
        if (pkg_name == NULL)
                return -1;
 
-       if ((cr->uid != 0) && (cr->uid != INHOUSE_UID)) {
-               _E("reject by security rule, your uid is %u\n", cr->uid);
-               return -1;
-       }
-
        pid = atoi(pkg_name);
        if (pid <= 1) {
                _E("invalid pid");
@@ -174,15 +171,15 @@ static gboolean __add_history_handler(gpointer user_data)
        char *appid = NULL;
        char *app_path = NULL;
        struct appinfo *ai;
-       app_pkt_t *pkt = (app_pkt_t *)user_data;
+       pkt_t *pkt_uid = (pkt_t *)user_data;
 
-       if (!pkt)
+       if (!pkt_uid)
                return FALSE;
 
-       kb = bundle_decode(pkt->data, pkt->len);
+       kb = bundle_decode(pkt_uid->pkt->data, pkt_uid->pkt->len);
        appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
 
-       ai = (struct appinfo *)appinfo_find(_raf, appid);
+       ai = (struct appinfo *)appinfo_find(pkt_uid->caller_uid, appid);
        app_path = (char *)appinfo_get_value(ai, AIT_EXEC);
 
        memset((void *)&rec, 0, sizeof(rec));
@@ -190,8 +187,8 @@ static gboolean __add_history_handler(gpointer user_data)
        rec.pkg_name = appid;
        rec.app_path = app_path;
 
-       if(pkt->len > 0) {
-               rec.arg = (char *)pkt->data;
+       if(pkt_uid->pkt->len > 0) {
+               rec.arg = (char *)pkt_uid->pkt->data;
        }
 
        SECURE_LOGD("add rua history %s %s", rec.pkg_name, rec.app_path);
@@ -202,7 +199,8 @@ static gboolean __add_history_handler(gpointer user_data)
 
        if (kb != NULL)
                bundle_free(kb);
-       free(pkt);
+       free(pkt_uid->pkt);
+       free(pkt_uid);
 
        return FALSE;
 }
@@ -252,7 +250,7 @@ static int __releasable(const char *filename)
        return 0;
 }
 
-static int __release_srv(const char *filename)
+static int __release_srv(uid_t caller_uid, const char *filename)
 {
        int r;
        const struct appinfo *ai;
@@ -261,7 +259,7 @@ static int __release_srv(const char *filename)
        if (r == -1)
                return -1;
 
-       ai = (struct appinfo *)appinfo_find(_raf, filename);
+       ai = (struct appinfo *)appinfo_find(caller_uid, filename);
        if (!ai) {
                SECURE_LOGE("release service: '%s' not found", filename);
                return -1;
@@ -285,6 +283,42 @@ static int __release_srv(const char *filename)
        return 0;
 }
 
+static int __handle_dead_signal(bundle* kb,int clifd, struct ucred * pcr) {
+       int ret=-1;
+       const char *pid_str;
+       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);
+       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");
+               free(caller);
+               return -1;
+       }
+       free(caller);
+
+       /* get app pid from bundle */
+       pid_str = bundle_get_val(kb, AUL_K_PID);
+       if(!pid_str)
+               return -1;
+
+       pid=atoi(pid_str);
+       if (pid<=1)
+               return -1;
+
+       _D("APP_DEAD_SIGNAL : %d",pid);
+
+       ret=__app_dead_handler(pid);
+
+       return ret;
+}
+
 static gboolean __request_handler(gpointer data)
 {
        GPollFD *gpollfd = (GPollFD *) data;
@@ -301,6 +335,7 @@ static gboolean __request_handler(gpointer data)
        int pid;
        bundle *kb = NULL;
        item_pkt_t *item;
+       pkt_t *pkt_uid;
 
        if ((pkt = __app_recv_raw(fd, &clifd, &cr)) == NULL) {
                _E("recv error");
@@ -319,10 +354,15 @@ static gboolean __request_handler(gpointer data)
                        if(ret > 0) {
                                item = calloc(1, sizeof(item_pkt_t));
                                item->pid = ret;
+                               item->uid = cr.uid;
                                strncpy(item->appid, appid, 511);
                                free_pkt = 0;
 
-                               g_timeout_add(1000, __add_history_handler, pkt);
+                               pkt_uid = calloc(1, sizeof(pkt_t));
+                               pkt_uid->caller_uid = cr.uid;
+                               pkt_uid->pkt = pkt;
+
+                               g_timeout_add(1000, __add_history_handler, pkt_uid);
                                g_timeout_add(1200, __add_item_running_list, item);
                        }
 
@@ -346,12 +386,12 @@ static gboolean __request_handler(gpointer data)
                        __real_send(clifd, ret);
                        break;
                case APP_RUNNING_INFO:
-                       _status_send_running_appinfo_v2(clifd);
+                       _status_send_running_appinfo(clifd);
                        break;
                case APP_IS_RUNNING:
                        appid = malloc(MAX_PACKAGE_STR_SIZE);
                        strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
-                       ret = _status_app_is_running_v2(appid);
+                       ret = _status_app_is_running(appid, cr.uid);
                        SECURE_LOGD("APP_IS_RUNNING : %s : %d",appid, ret);
                        __send_result_to_client(clifd, ret);
                        free(appid);
@@ -371,14 +411,14 @@ static gboolean __request_handler(gpointer data)
                        break;
                case APP_STATUS_UPDATE:
                        status = (int *)pkt->data;
-                       ret = _status_update_app_info_list(cr.pid, *status);
+                       ret = _status_update_app_info_list(cr.pid, *status, cr.uid);
                        //__send_result_to_client(clifd, ret);
                        close(clifd);
                        break;
                case APP_RELEASED:
                        appid = malloc(MAX_PACKAGE_STR_SIZE);
                        strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
-                       ret = __release_srv(appid);
+                       ret = __release_srv(cr.uid,appid);
                        __send_result_to_client(clifd, ret);
                        free(appid);
                        break;
@@ -392,6 +432,10 @@ static gboolean __request_handler(gpointer data)
                        ret = 0;
                        __send_result_to_client(clifd, ret);
                        break;
+               case APP_DEAD_SIGNAL:
+                       kb = bundle_decode(pkt->data, pkt->len);
+                       ret=__handle_dead_signal(kb,clifd,&cr);
+                       break;
                default:
                        _E("no support packet");
                        close(clifd);
index d1e70f0..ce96580 100755 (executable)
@@ -38,7 +38,7 @@ GSList *app_status_info_list = NULL;
 
 struct appinfomgr *_saf = NULL;
 
-int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid)
+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;
@@ -47,7 +47,14 @@ int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid)
        {
                info_t = (app_status_info_t *)iter->data;
                if(pid == info_t->pid) {
-                       return 0;
+                       if(uid == info_t->user)
+                               return 0;
+                       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;
+                   }
                }
        }
 
@@ -57,13 +64,14 @@ int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid)
        info_t->status = STATUS_LAUNCHING;
        info_t->pid = pid;
        info_t->pad_pid = pad_pid;
+       info_t->user = uid;
        app_status_info_list = g_slist_append(app_status_info_list, info_t);
 
        for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
        {
                info_t = (app_status_info_t *)iter->data;
 
-               //SECURE_LOGD("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
+               SECURE_LOGD(" [%d] : %s, %d, %d", info_t->user, info_t->appid, info_t->pid, info_t->status);
        }
 
        return 0;
@@ -83,7 +91,7 @@ static Eina_Bool __app_terminate_timer_cb(void *data)
        return ECORE_CALLBACK_CANCEL;
 }
 
-int _status_update_app_info_list(int pid, int status)
+int _status_update_app_info_list(int pid, int status, uid_t uid)
 {
        GSList *iter = NULL;
        app_status_info_t *info_t = NULL;
@@ -91,7 +99,7 @@ int _status_update_app_info_list(int pid, int status)
        for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
        {
                info_t = (app_status_info_t *)iter->data;
-               if(pid == info_t->pid) {
+               if((pid == info_t->pid) && ((info_t->user == uid) || (info_t->user == 0))) {
                        info_t->status = status;
                        if(status == STATUS_DYING) {
                                if(info_t->pad_pid != DEBUG_LAUNCHPAD_PID)
@@ -111,7 +119,7 @@ int _status_update_app_info_list(int pid, int status)
        return 0;
 }
 
-int _status_remove_app_info_list(int pid)
+int _status_remove_app_info_list(int pid, uid_t uid)
 {
        GSList *iter = NULL;
        app_status_info_t *info_t = NULL;
@@ -119,7 +127,7 @@ int _status_remove_app_info_list(int pid)
        for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
        {
                info_t = (app_status_info_t *)iter->data;
-               if(pid == info_t->pid) {
+               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);
                        free(info_t);
                        break;
@@ -153,7 +161,7 @@ int _status_get_app_info_status(int pid)
 }
 
 
-int _status_app_is_running(char *appid)
+int _status_app_is_running(char *appid, uid_t uid)
 {
        GSList *iter = NULL;
        app_status_info_t *info_t = NULL;
@@ -161,7 +169,7 @@ int _status_app_is_running(char *appid)
        for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
        {
                info_t = (app_status_info_t *)iter->data;
-               if( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE) == 0 ) {
+               if(( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE) == 0 ) && (info_t->user == uid)) {
                        return info_t->pid;
                }
        }
@@ -213,7 +221,7 @@ int _status_send_running_appinfo(int fd)
        return 0;
 }
 
-int _status_app_is_running_v2(char *appid)
+int _status_app_is_running_v2(uid_t caller_uid, char *appid)
 {
        char *apppath = NULL;
        int ret = 0;
@@ -223,7 +231,7 @@ int _status_app_is_running_v2(char *appid)
        if(appid == NULL)
                return -1;
 
-       ai = appinfo_find(_saf, appid);
+       ai = appinfo_find(caller_uid, appid);
 
        if(ai == NULL)
                return -1;
index 157d749..d19486b 100755 (executable)
  *
  */
 
+#include <unistd.h>
+#include <sys/types.h>
 
 
-int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid);
-int _status_update_app_info_list(int pid, int status);
-int _status_remove_app_info_list(int pid);
+
+int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid, uid_t uid);
+int _status_update_app_info_list(int pid, int status,  uid_t uid);
+int _status_remove_app_info_list(int pid, uid_t uid);
 int _status_get_app_info_status(int pid);
-int _status_app_is_running(char *appid);
 int _status_send_running_appinfo(int fd);
-int _status_app_is_running_v2(char *appid);
-int _status_send_running_appinfo_v2(int fd);
+int _status_app_is_running(char *appid,  uid_t uid);
+int _status_send_running_appinfo_v2(int fd); //depcrecated
 int _status_get_appid_bypid(int fd, int pid);
 
 
@@ -38,6 +40,7 @@ int _status_get_appid_bypid(int fd, int pid);
 
 typedef struct _item_pkt_t {
        int pid;
+       uid_t uid;
        char appid[512];
 } item_pkt_t;
 
similarity index 86%
rename from launchpad_src/launchpad.c
rename to am_session_agent/agent.c
index 565d163..4068add 100644 (file)
 
 
 /*
- * simple AUL daemon - launchpad 
+ * AMD user session agent
  */
 
 #include <stdio.h>
 #include <string.h>
 #include <dlfcn.h>
-#ifdef X11
-#include <X11/Xlib.h>
-#endif
 #include <sys/types.h>
 #include <signal.h>
 #include <dirent.h>
 #include <sys/prctl.h>
 #include <malloc.h>
 
+#include "agent_config.h"
+
 #include "app_sock.h"
 #include "aul.h"
 
-#include "config.h"
-
 #include "menu_db_util.h"
 #include "simple_util.h"
 #include "access_control.h"
 #include "preload.h"
 #include "preexec.h"
 #include "perf.h"
-#include "sigchild.h"
 #include "aul_util.h"
-
-#include "heap_dbg.h"
-
-#include "util_x.h"
-
-#include "gl.h"
+#include "sigchild.h"
 
 #include <app-checker.h>
 #include <sqlite3.h>
 
 #define _static_ static inline
 #define POLLFD_MAX 1
-#define SQLITE_FLUSH_MAX       (1048576)       /* (1024*1024) */
+#define SQLITE_FLUSH_MAX       (1048576)       /* (1024*1024) */
 #define AUL_POLL_CNT           15
 #define AUL_PR_NAME                    16
 
 
-static char *launchpad_cmdline;
+static char *agent_cmdline;
 static int initialized = 0;
 
 
@@ -83,7 +74,7 @@ _static_ int __fake_launch_app(int cmd, int pid, bundle * kb);
 _static_ char **__create_argc_argv(bundle * kb, int *margc);
 _static_ int __normal_fork_exec(int argc, char **argv);
 _static_ void __real_launch(const char *app_path, bundle * kb);
-static inline int __parser(const char *arg, char *out, int out_size);
+_static_ int __parser(const char *arg, char *out, int out_size);
 _static_ void __modify_bundle(bundle * kb, int caller_pid,
                            app_info_from_db * menu_info, int cmd);
 _static_ int __child_raise_win_by_x(int pid, void *priv);
@@ -93,11 +84,9 @@ _static_ int __term_app(int pid);
 _static_ int __resume_app(int pid);
 _static_ int __real_send(int clifd, int ret);
 _static_ void __send_result_to_caller(int clifd, int ret);
-_static_ void __launchpad_main_loop(int main_fd);
-_static_ int __launchpad_pre_init(int argc, char **argv);
-_static_ int __launchpad_post_init();
-
-extern ail_error_e ail_db_close(void);
+_static_ void __agent_main_loop(int main_fd);
+_static_ int __agent_pre_init(int argc, char **argv);
+_static_ int __agent_post_init();
 
 
 
@@ -106,7 +95,7 @@ _static_ void __set_oom()
        char buf[MAX_LOCAL_BUFSZ];
        FILE *fp;
 
-       /* we should reset oomadj value as default because child 
+       /* we should reset oomadj value as default because child
        inherits from parent oom_adj*/
        snprintf(buf, MAX_LOCAL_BUFSZ, "/proc/%d/oom_adj", getpid());
        fp = fopen(buf, "w");
@@ -120,8 +109,6 @@ _static_ void __set_env(app_info_from_db * menu_info, bundle * kb)
 {
        const char *str;
        const char **str_array;
-       int len;
-       int i;
 
        setenv("PKG_NAME", _get_pkgname(menu_info), 1);
 
@@ -158,7 +145,7 @@ _static_ int __prepare_exec(const char *pkg_name,
                 _D("pkg_name : %s / pkg_type : %s / app_path : %s ", pkg_name, menu_info->pkg_type, app_path);
                if ((ret = __set_access(pkg_name, menu_info->pkg_type, app_path)) < 0) {
                         _D("fail to set privileges - check your package's credential : %d\n", ret);
-                       return -1;
+             return -1;
                }
        }
        /* SET DUMPABLE - for coredump*/
@@ -241,10 +228,10 @@ _static_ void __real_launch(const char *app_path, bundle * kb)
        PERF("setup argument done");
 
        /* Temporary log: launch time checking */
-       LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:launchpad:done]", app_path);
-
+       LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:agent:done]", app_path);
+#ifdef PRELOAD_ACTIVATE
        __preload_exec(app_argc, app_argv);
-
+#endif
        __normal_fork_exec(app_argc, app_argv);
 }
 
@@ -392,7 +379,11 @@ _static_ void __modify_bundle(bundle * kb, int caller_pid,
 
 _static_ int __child_raise_win_by_x(int pid, void *priv)
 {
+#ifdef X11
        return x_util_raise_win(pid);
+#else
+       return 0;
+#endif
 }
 
 _static_ int __raise_win_by_x(int pid)
@@ -488,6 +479,23 @@ end:
        return pid;
 }
 
+static int __get_caller_uid(bundle *kb)
+{
+       const char *uid_str;
+       int uid;
+
+       uid_str = bundle_get_val(kb, AUL_K_CALLER_UID);
+       if (uid_str == NULL)
+               return -1;
+
+end:
+       uid = atoi(uid_str);
+       if (uid <0)
+               return -1;
+
+       return uid;
+}
+
 _static_ int __foward_cmd(int cmd, bundle *kb, int cr_pid)
 {
        int pid;
@@ -549,7 +557,7 @@ _static_ void __send_result_to_caller(int clifd, int ret)
                if (cmdline == NULL) {
                        _E("error founded when being launched with %d", ret);
 
-               } else if (strcmp(cmdline, launchpad_cmdline)) {
+               } else if (strcmp(cmdline, agent_cmdline)) {
                        free(cmdline);
                        cmdline_changed = 1;
                        break;
@@ -571,12 +579,14 @@ _static_ void __send_result_to_caller(int clifd, int ret)
        if (!cmdline_changed)
                _E("process launched, but cmdline not changed");
 
+       _D("send_result_to_caller: %d",ret);
+
        if(__real_send(clifd, ret) < 0) {
                r = kill(ret, SIGKILL);
                if (r == -1)
                        _E("send SIGKILL: %s", strerror(errno));
        }
-       
+
        return;
 }
 
@@ -605,7 +615,7 @@ static app_info_from_db *_get_app_info_from_bundle_by_pkgname(
        return menu_info;
 }
 
-_static_ void __launchpad_main_loop(int main_fd)
+_static_ void __agent_main_loop(int main_fd)
 {
        bundle *kb = NULL;
        app_pkt_t *pkt = NULL;
@@ -614,12 +624,15 @@ _static_ void __launchpad_main_loop(int main_fd)
        const char *pkg_name = NULL;
        const char *app_path = NULL;
        int pid = -1;
+       int uid = -1;
        int clifd = -1;
        struct ucred cr;
        int is_real_launch = 0;
 
        char sock_path[UNIX_PATH_MAX] = {0,};
 
+       _D("received request");
+
        pkt = __app_recv_raw(main_fd, &clifd, &cr);
        if (!pkt) {
                _D("packet is NULL");
@@ -638,9 +651,21 @@ _static_ void __launchpad_main_loop(int main_fd)
        pkg_name = bundle_get_val(kb, AUL_K_PKG_NAME);
        SECURE_LOGD("pkg name : %s\n", pkg_name);
 
+       /* get caller uid and check if not coming from someone else than AMD */
+       uid = __get_caller_uid(kb);
+       _D("caller uid: %d",uid);
+       if (uid<0) {
+               _E("Invalid caller uid");
+               goto end;
+       }
+       if ((uid != 0) && (uid != getuid())) {
+               _E("Invalid request coming from another user");
+               goto end;
+       }
+
        menu_info = _get_app_info_from_bundle_by_pkgname(pkg_name, kb);
        if (menu_info == NULL) {
-               _D("such pkg no found");
+               _D("package not found");
                goto end;
        }
 
@@ -657,8 +682,10 @@ _static_ void __launchpad_main_loop(int main_fd)
        __modify_bundle(kb, cr.pid, menu_info, pkt->cmd);
        pkg_name = _get_pkgname(menu_info);
 
-       PERF("get package information & modify bundle done");
+       _D("start %s: type=%s caller_uid=%d path=%s",pkg_name,menu_info->pkg_type,uid,app_path);
 
+       PERF("get package information & modify bundle done");
+       if( !strcmp(menu_info->pkg_type, "wgt") || !strcmp(menu_info->pkg_type, "rpm") || !strcmp(menu_info->pkg_type, "tpk"))
        {
                pid = fork();
                if (pid == 0) {
@@ -693,7 +720,6 @@ _static_ void __launchpad_main_loop(int main_fd)
                SECURE_LOGD("==> real launch pid : %d %s\n", pid, app_path);
                is_real_launch = 1;
        }
-
  end:
        __send_result_to_caller(clifd, pid);
 
@@ -701,7 +727,7 @@ _static_ void __launchpad_main_loop(int main_fd)
                if (is_real_launch) {
                        /*TODO: retry*/
                        __signal_block_sigchld();
-                       __send_app_launch_signal(pid);
+                       __send_app_launch_signal_dbus(pid);
                        __signal_unblock_sigchld();
                }
        }
@@ -714,7 +740,6 @@ _static_ void __launchpad_main_loop(int main_fd)
        if (pkt != NULL)
                free(pkt);
 
-       /* Active Flusing for Daemon */
        if (initialized > AUL_POLL_CNT) {
                sqlite3_release_memory(SQLITE_FLUSH_MAX);
                malloc_trim(0);
@@ -723,39 +748,40 @@ _static_ void __launchpad_main_loop(int main_fd)
 
 }
 
-_static_ int __launchpad_pre_init(int argc, char **argv)
+_static_ int __agent_pre_init(int argc, char **argv)
 {
        int fd;
-
+       char *socket_path = NULL;
        /* signal init*/
        __signal_init();
 
-       /* get my(launchpad) command line*/
-       launchpad_cmdline = __proc_get_cmdline_bypid(getpid());
-       if (launchpad_cmdline == NULL) {
-               _E("launchpad cmdline fail to get");
+    /* get my(agent) command line*/
+    agent_cmdline = __proc_get_cmdline_bypid(getpid());
+    if (agent_cmdline == NULL) {
+        _E("agent cmdline fail to get");
+        return -1;
+    }
+    _D("agent cmdline = %s", agent_cmdline);
+
+       /* create agent socket */
+    asprintf(&socket_path,"/run/user/%d/amd_agent",getuid());
+       if(socket_path)
+               fd = __create_server_sock_by_path(socket_path);
+       else
                return -1;
-       }
-       _D("launchpad cmdline = %s", launchpad_cmdline);
-
-       /* create launchpad sock        */
-       fd = __create_server_sock(LAUNCHPAD_PID);
+       free(socket_path);
        if (fd < 0) {
                _E("server sock error");
                return -1;
        }
 
-       __preload_init(argc, argv);
-
-       __preexec_init(argc, argv);
-
        return fd;
 }
 
-_static_ int __launchpad_post_init()
+_static_ int __agent_post_init()
 {
-       /* Setting this as a global variable to keep track 
-       of launchpad poll cnt */
+       /* Setting this as a global variable to keep track
+       of agent poll cnt */
        /* static int initialized = 0;*/
 
        if (initialized) {
@@ -777,10 +803,12 @@ int main(int argc, char **argv)
        struct pollfd pfds[POLLFD_MAX];
        int i;
 
+       _D("amd_session_agent starting");
+
        /* init without concerning X & EFL*/
-       main_fd = __launchpad_pre_init(argc, argv);
+       main_fd = __agent_pre_init(argc, argv);
        if (main_fd < 0) {
-               _E("launchpad pre init failed");
+               _E("agent pre init failed");
                exit(-1);
        }
 
@@ -792,16 +820,16 @@ int main(int argc, char **argv)
                if (poll(pfds, POLLFD_MAX, -1) < 0)
                        continue;
 
-               /* init with concerning X & EFL (because of booting 
+               /* init with concerning X & EFL (because of booting
                sequence problem)*/
-               if (__launchpad_post_init() < 0) {
-                       _E("launcpad post init failed");
+               if (__agent_post_init() < 0) {
+                       _E("agent post init failed");
                        exit(-1);
                }
 
                for (i = 0; i < POLLFD_MAX; i++) {
                        if ((pfds[i].revents & POLLIN) != 0) {
-                               __launchpad_main_loop(pfds[i].fd);
+                               __agent_main_loop(pfds[i].fd);
                        }
                }
        }
diff --git a/am_session_agent/agent_config.h b/am_session_agent/agent_config.h
new file mode 100644 (file)
index 0000000..3283a0c
--- /dev/null
@@ -0,0 +1,16 @@
+
+ /*
+ *  aul
+ *
+ * Copyright (c) 2000 - 2014 Eurogiciel, Ltd. All rights reserved.
+ *
+ *
+ */
+
+
+/*
+ * AMD User Session agent - config file
+ */
+
+
+#define AGENT_LOG
similarity index 79%
rename from launchpad_src/sigchild.h
rename to am_session_agent/sigchild.h
index bb65707..0e0ab77 100755 (executable)
@@ -19,8 +19,7 @@
  *
  */
 
-
-#include <pthread.h>
+#include "aul_util.h"
 #include "app_signal.h"
 
 static struct sigaction old_sigchild;
@@ -52,10 +51,40 @@ static inline void __socket_garbage_collector()
        closedir(dp);
 }
 
-static inline int __send_app_dead_signal(int dead_pid)
+static inline int __send_app_dead_signal_amd(int dead_pid) {
+       bundle* kb=NULL;
+       char tmpbuf[MAX_PID_STR_BUFSZ];
+       int ret;
+
+       // send signal to AMD daemon using direct request
+       kb=bundle_create();
+       if (kb==NULL) {
+               _E("bundle creation failed");
+               return -1;
+       }
+
+       snprintf(tmpbuf, MAX_PID_STR_BUFSZ, "%d", dead_pid);
+       bundle_add(kb,AUL_K_PID,tmpbuf);
+
+       ret=app_send_cmd_with_noreply(AUL_UTIL_PID, APP_DEAD_SIGNAL,kb);
+
+       if (ret) {
+               _E("unable to send dead signal to amd proc PID %d",dead_pid);
+       }
+       else {
+               _D("send_app_dead_signal_amd done (pid=%d)\n",dead_pid);
+       }
+
+       bundle_free(kb);
+
+       return ret;
+}
+
+static inline int __send_app_dead_signal_dbus(int dead_pid)
 {
        DBusMessage *message;
 
+       // send over session dbus for other applications
        if (bus == NULL)
                return -1;
 
@@ -78,12 +107,12 @@ static inline int __send_app_dead_signal(int dead_pid)
        dbus_connection_flush(bus);
        dbus_message_unref(message);
 
-       _D("send dead signal done\n");
+       _D("send_app_dead_signal_dbus done (pid=%d)\n",dead_pid);
 
        return 0;
 }
 
-static inline int __send_app_launch_signal(int launch_pid)
+static inline int __send_app_launch_signal_dbus(int launch_pid)
 {
        DBusMessage *message;
 
@@ -109,7 +138,7 @@ static inline int __send_app_launch_signal(int launch_pid)
        dbus_connection_flush(bus);
        dbus_message_unref(message);
 
-       _D("send launch signal done\n");
+       _D("send_app_launch_signal_dbus done (pid=%d)",launch_pid);
 
        return 0;
 }
@@ -123,7 +152,8 @@ static int __sigchild_action(void *data)
        if (dead_pid <= 0)
                goto end;
 
-       __send_app_dead_signal(dead_pid);
+       __send_app_dead_signal_amd(dead_pid);
+       __send_app_dead_signal_dbus(dead_pid);
 
        snprintf(buf, MAX_LOCAL_BUFSZ, "%s/%d", AUL_SOCK_PREFIX, dead_pid);
        unlink(buf);
@@ -133,7 +163,7 @@ static int __sigchild_action(void *data)
        return 0;
 }
 
-static void __launchpad_sig_child(int signo, siginfo_t *info, void *data)
+static void __agent_sig_child(int signo, siginfo_t *info, void *data)
 {
        int status;
        pid_t child_pid;
@@ -181,16 +211,16 @@ static inline int __signal_set_sigchld(void)
 
        dbus_error_init(&error);
        dbus_threads_init_default();
-       bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+       bus = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
        if (!bus) {
                _E("Failed to connect to the D-BUS daemon: %s", error.message);
                dbus_error_free(&error);
                return -1;
        }
-       /* TODO: if process stop mechanism is included, 
+       /* TODO: if process stop mechanism is included,
        should be modified (SA_NOCLDSTOP)*/
        act.sa_handler = NULL;
-       act.sa_sigaction = __launchpad_sig_child;
+       act.sa_sigaction = __agent_sig_child;
        sigemptyset(&act.sa_mask);
        act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
 
index ee31aa6..20908a3 100755 (executable)
@@ -51,7 +51,10 @@ enum app_cmd {
        APP_STATUS_UPDATE,
        APP_RELEASED,
        APP_RUNNING_LIST_UPDATE,
-       APP_TERM_REQ_BY_PID
+       APP_TERM_REQ_BY_PID,
+
+       /* reserved for AMD Agent */
+       APP_DEAD_SIGNAL
 };
 
 #define AUL_SOCK_PREFIX "/tmp/alaunch"
@@ -70,6 +73,11 @@ typedef struct _app_pkt_t {
        unsigned char data[1];
 } app_pkt_t;
 
+typedef struct _pkt_t {
+       uid_t caller_uid;
+       app_pkt_t *pkt;
+} pkt_t;
+
 int __create_server_sock(int pid);
 int __create_client_sock(int pid);
 int __app_send_raw(int pid, int cmd, unsigned char *kb_data, int datalen);
@@ -77,6 +85,7 @@ int __app_send_raw_with_noreply(int pid, int cmd, unsigned char *kb_data, int da
 int __app_send_raw_with_delay_reply(int pid, int cmd, unsigned char *kb_data, int datalen);
 app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr);
 app_pkt_t *__app_send_cmd_with_result(int pid, int cmd, unsigned char *kb_data, int datalen);
+int __create_agent_client_sock(int uid);
 
 
 #endif
index 3864945..1274dec 100755 (executable)
@@ -147,6 +147,11 @@ typedef enum _aul_type{
 /** AUL public key - To check callee's secuirty */
 #define AUL_K_CALLEE_PID       "__AUL_CALLEE_PID__"
 
+/** AUL public key - added for multiuser mode */
+#define AUL_K_CALLER_UID       "__AUL_CALLER_UID__"
+/** AUL public key - added for multiuser mode */
+#define AUL_K_CALLEE_UID       "__AUL_CALLEE_UID__"
+
 /** AUL public key - To check caller's secuirty */
 #define AUL_K_CALLER_APPID     "__AUL_CALLER_APPID__"
 /** AUL public key - To check caller's secuirty */
index d6f300d..5da34cf 100755 (executable)
 #ifndef __AUL_UTIL_H_
 #define __AUL_UTIL_H_
 
+#include <unistd.h>
+#include <sys/types.h>
+
+#define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
+
 #define AUL_UTIL_PID -2
 
 #define MAX_PACKAGE_STR_SIZE 512
@@ -35,16 +40,18 @@ typedef struct _app_status_info_t{
        int status;
        int pid;
        int pad_pid;
+       uid_t user;
 } app_status_info_t;
 
+
 struct amdmgr {
        struct appinfomgr *af;  /* appinfo manager */
        struct cginfo *cg;  /* cgroup infomation */
 };
 
-int _add_app_status_info_list(char *appid, int pid);
-int _update_app_status_info_list(int pid, int status);
-int _remove_app_status_info_list(int pid);
+int _add_app_status_info_list(char *appid, int pid, uid_t uid);
+int _update_app_status_info_list(int pid, int status, uid_t uid);
+int _remove_app_status_info_list(int pid, uid_t uid);
 
 #endif
 
index e6eb5ee..600ab94 100755 (executable)
 #include <ctype.h>
 #include <dlog.h>
 
+#undef LOG_TAG
+#define LOG_TAG "AUL"
+
 #ifdef LAUNCHPAD_LOG
 #undef LOG_TAG
 #define LOG_TAG "AUL_PAD"
-#else
-#undef LOG_TAG
-#define LOG_TAG "AUL"
 #endif
+
 #ifdef AMD_LOG
 #undef LOG_TAG
 #define LOG_TAG "AUL_AMD"
 #endif
 
+#ifdef AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "AUL_AGENT"
+#endif
 
 #define MAX_LOCAL_BUFSZ 128
 #define MAX_PID_STR_BUFSZ 20
@@ -68,6 +73,7 @@ int __proc_iter_cmdline(int (*iterfunc)
 int __proc_iter_pgid(int pgid, int (*iterfunc) (int pid, void *priv),
                     void *priv);
 char *__proc_get_cmdline_bypid(int pid);
+char *__proc_get_exe_bypid(int pid);
 
 static inline const char *FILENAME(const char *filename)
 {
diff --git a/launchpad_src/config.h b/launchpad_src/config.h
deleted file mode 100755 (executable)
index f5728cf..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  aul
- *
- * 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");
- * 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,
- * 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.
- *
- */
-
-
-#define LAUNCHPAD_LOG
-#define DAC_ACTIVATE
-#define PRELOAD_ACTIVATE
-#define PREEXEC_ACTIVATE
-/*#define GL_ACTIVATE*/
-/*#define HEAPDGB_ACTIVATE*/
-/*#define PERF_ACTIVATE*/
-
diff --git a/launchpad_src/gl.h b/launchpad_src/gl.h
deleted file mode 100755 (executable)
index 4add496..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  aul
- *
- * 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");
- * 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,
- * 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.
- *
- */
-
-
-#ifdef GL_ACTIVATE
-
-#define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
-
-#else
-
-#define USE_ENGINE(engine)
-
-#endif
-
diff --git a/launchpad_src/heap_dbg.h b/launchpad_src/heap_dbg.h
deleted file mode 100755 (executable)
index 7b6c718..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *  aul
- *
- * 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");
- * 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,
- * 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.
- *
- */
-
-
-#include <malloc.h>
-#include <stdio.h>
-#include <signal.h>
-
-#ifdef HEAPDGB_ACTIVATE
-
-#define HOOK_RESET()   \
-do {\
-       __malloc_hook = old_malloc_hook; \
-       __free_hook = old_free_hook;    \
-} while (0);
-
-#define HOOK_SET()     \
-do {\
-       __malloc_hook = my_malloc;      \
-       __free_hook = my_free;          \
-} while (0);
-
-static void *(*old_malloc_hook) (size_t size, const void *caller);
-static void *(*old_realloc_hook) (void *ptr, size_t size, const void *caller);
-static void (*old_free_hook) (void *ptr, const void *caller);
-
-static void *my_malloc(size_t size, const void *caller);
-static void *my_realloc(void *ptr, size_t size, const void *caller);
-static void my_free(void *ptr, const void *caller);
-
-static void my_free(void *ptr, const void *caller)
-{
-       void *callstack_addrs[20];
-       char **callstack_strings;
-       int i;
-
-       HOOK_RESET();
-
-       printf("%c[1;31m[FREE] %x %x", 27, ptr, caller);
-       printf("%c[0m\n", 27);
-       free(ptr);
-
-       HOOK_SET();
-
-}
-
-static void *my_malloc(size_t size, const void *caller)
-{
-       void *ptr;
-
-       HOOK_RESET();
-
-       ptr = malloc(size);
-       printf("%c[1;31m[MALLOC] %x %x", 27, ptr, caller);
-       printf("%c[0m\n", 27);
-
-       HOOK_SET();
-
-       return ptr;
-}
-
-static void malloc_init(void)
-{
-       old_malloc_hook = __malloc_hook;
-       old_free_hook = __free_hook;
-
-       HOOK_SET();
-}
-
-__attribute__ ((visibility("default")))
-void (*__malloc_initialize_hook) (void) = malloc_init;
-
-#else
-
-#endif
diff --git a/launchpad_src/util_x.c b/launchpad_src/util_x.c
deleted file mode 100755 (executable)
index 4e7ecd8..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- *  aul
- *
- * 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");
- * 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,
- * 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.
- *
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-
-#include "simple_util.h"
-
-static Atom a_pid;
-static int (*x_old_error) (Display *, XErrorEvent *);
-
-
-static pid_t __get_win_pid(Display *d, Window win);
-static int __find_win(Display *d, Window *win, pid_t pid);
-static int __raise_win(Display *d, Window win);
-static int __cb_x_error(Display *disp, XErrorEvent *ev);
-
-static pid_t __get_win_pid(Display *d, Window win)
-{
-       int r;
-       pid_t pid;
-
-       Atom a_type;
-       int format;
-       unsigned long nitems;
-       unsigned long bytes_after;
-       unsigned char *prop_ret;
-
-       retv_if(d == NULL || !a_pid, -1);
-
-       prop_ret = NULL;
-       r = XGetWindowProperty(d, win, a_pid, 0, 1, False, XA_CARDINAL,
-                       &a_type, &format, &nitems, &bytes_after, &prop_ret);
-       if (r != Success || prop_ret == NULL)
-               return -1;
-
-       if (a_type == XA_CARDINAL && format == 32)
-               pid = *(unsigned long *)prop_ret;
-       else
-               pid = -1;
-
-       XFree(prop_ret);
-
-       return pid;
-}
-
-static int __find_win(Display *d, Window *win, pid_t pid)
-{
-       int r;
-       pid_t p;
-       unsigned int n;
-       Window root, parent, *child;
-
-       p = __get_win_pid(d, *win);
-       if (p == pid)
-               return 1;
-
-       r = XQueryTree(d, *win, &root, &parent, &child, &n);
-       if (r) {
-               int i;
-               int found = 0;
-
-               for (i = 0; i < n; i++) {
-                       found = __find_win(d, &child[i], pid);
-                       if (found) {
-                               *win = child[i];
-                               break;
-                       }
-               }
-               XFree(child);
-
-               if (found)
-                       return 1;
-       }
-
-       return 0;
-}
-
-static int __raise_win(Display *d, Window win)
-{
-       XWindowAttributes attr;
-       attr.map_state = IsUnmapped;
-
-       XMapRaised(d, win);
-
-       XGetWindowAttributes(d, win, &attr);
-
-       if (attr.map_state == IsUnmapped)
-               _D("unmapped");
-       else if (attr.map_state == IsUnviewable)
-               _D("unviewable");
-       else if (attr.map_state == IsViewable)
-               _D("viewable");
-
-       retv_if(attr.map_state != IsViewable, -1);
-
-       XSetInputFocus(d, win, RevertToPointerRoot, CurrentTime);
-
-       return 0;
-}
-
-int x_util_raise_win(pid_t pid)
-{
-       int r;
-       int found;
-       Display *d;
-       Window win;
-
-       if (pid < 1)
-               return -1;
-
-       r = kill(pid, 0);
-       if (r == -1)
-               return -1;
-
-       d = XOpenDisplay(NULL);
-       retv_if(d == NULL, -1);
-
-       win = XDefaultRootWindow(d);
-
-       if (!a_pid)
-               a_pid = XInternAtom(d, "X_CLIENT_PID", True);
-
-       found = __find_win(d, &win, pid);
-       if (!found) {
-               XCloseDisplay(d);
-               _E("cannot found window with pid - %d", pid);
-               return -1;
-       }
-
-       r = __raise_win(d, win);
-       if (r < 0)
-               _E("fail to raise win");
-
-       XCloseDisplay(d);
-
-       return r;
-}
-
-int x_util_get_default_size(double *w, double *h)
-{
-       Display *d;
-       int screen_num;
-
-       d = XOpenDisplay(NULL);
-       if (d == NULL)
-               return -1;
-
-       screen_num = DefaultScreen(d);
-
-       *w = DisplayWidth(d, screen_num);
-       *h = DisplayHeight(d, screen_num);
-
-       _D("Root Width = %lf, Height = %lf\n", *w, *h);
-
-       XCloseDisplay(d);
-
-       return 0;
-}
-
-static int __cb_x_error(Display *disp, XErrorEvent *ev)
-{
-       _E("X error received - Error Code = %d", ev->error_code);
-       return 0;
-}
-
-int x_util_init()
-{
-       x_old_error = XSetErrorHandler(__cb_x_error);
-       return 0;
-}
-
-int x_util_fini()
-{
-       XSetErrorHandler(x_old_error);
-       return 0;
-}
-
diff --git a/launchpad_src/util_x.h b/launchpad_src/util_x.h
deleted file mode 100755 (executable)
index 650bad5..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- *  aul
- *
- * 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");
- * 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,
- * 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 __UTIL_X_H_
-#define __UTIL_X_H_
-
-int x_util_init();
-int x_util_fini();
-int x_util_get_default_size(double *w, double *h);
-int x_util_raise_win(pid_t pid);
-
-#endif
-
diff --git a/packaging/amd_session_agent.service b/packaging/amd_session_agent.service
new file mode 100644 (file)
index 0000000..285d360
--- /dev/null
@@ -0,0 +1,12 @@
+#
+#  Systemd script to Launch AMD Session agent
+#
+
+[Unit]
+Description=Start the USER Access Control Agent
+
+[Service]
+ExecStart=/usr/bin/amd_session_agent
+
+[Install]
+WantedBy=default.target
index 5e2131c..ed7e741 100644 (file)
@@ -1,15 +1,15 @@
 %bcond_with wayland
 %bcond_with x
-
 Name:       aul
 Summary:    App utility library
-Version:    0.0.286
+Version:    0.0.300
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source101:  launchpad-preload@.service
 Source102:  ac.service
+Source103:  amd_session_agent.service
 Source1001: %{name}.manifest
 
 Requires(post): /sbin/ldconfig
@@ -66,10 +66,11 @@ cp %{SOURCE1001} .
 CFLAGS="%{optflags} -D__emul__"; export CFLAGS
 %endif
 
+%cmake . \
 %if %{with wayland}
-%cmake . -DWITH_WAYLAND=On
+ -DWITH_WAYLAND=On \
 %else
-%cmake . -DWITH_WAYLAND=Off
+ -DWITH_WAYLAND=Off \
 %endif
 
 make %{?jobs:-j%jobs}
@@ -91,16 +92,14 @@ sqlite3 %{buildroot}%{TZ_SYS_DB}/.mida.db < %{buildroot}/usr/share/aul/mida_db.s
 rm -rf %{buildroot}/usr/share/aul/mida_db.sql
 
 mkdir -p %{buildroot}/usr/lib/systemd/system/graphical.target.wants
+mkdir -p %{buildroot}/usr/lib/systemd/user/default.target.wants
 install -m 0644 %SOURCE101 %{buildroot}/usr/lib/systemd/system/launchpad-preload@.service
 install -m 0644 %SOURCE102 %{buildroot}/usr/lib/systemd/system/ac.service
 ln -s ../launchpad-preload@.service %{buildroot}/usr/lib/systemd/system/graphical.target.wants/launchpad-preload@5000.service
 ln -s ../ac.service %{buildroot}/usr/lib/systemd/system/graphical.target.wants/ac.service
 
-mkdir -p %{buildroot}%{TZ_SYS_SMACK}/accesses.d
-
-mkdir -p %{buildroot}/usr/share/license
-cp LICENSE %{buildroot}/usr/share/license/%{name}
-
+install -m 0644 %SOURCE103 %{buildroot}/usr/lib/systemd/user/amd_session_agent.service
+ln -s ../amd_session_agent.service %{buildroot}/usr/lib/systemd/user/default.target.wants/amd_session_agent.service
 
 %preun
 if [ $1 == 0 ]; then
@@ -121,6 +120,7 @@ fi
 systemctl daemon-reload
 
 %files
+%license LICENSE
 %manifest %{name}.manifest
 %attr(0644,root,root) %{_libdir}/libaul.so.0
 %attr(0644,root,root) %{_libdir}/libaul.so.0.1.0
@@ -135,19 +135,20 @@ systemctl daemon-reload
 %{_bindir}/aul_test
 %{_bindir}/launch_app
 %{_bindir}/open_app
+%{_bindir}/amd_session_agent
 /usr/share/aul/miregex/*
 /usr/share/aul/service/*
 /usr/share/aul/preload_list.txt
 /usr/share/aul/preexec_list.txt
-%{_bindir}/launchpad_preloading_preinitializing_daemon
 /usr/lib/systemd/system/graphical.target.wants/launchpad-preload@5000.service
 /usr/lib/systemd/system/graphical.target.wants/ac.service
 /usr/lib/systemd/system/launchpad-preload@.service
 /usr/lib/systemd/system/ac.service
+/usr/lib/systemd/user/amd_session_agent.service
+/usr/lib/systemd/user/default.target.wants/amd_session_agent.service
 /usr/bin/amd
 /usr/bin/daemon-manager-release-agent
 /usr/bin/daemon-manager-launch-agent
-/usr/share/license/%{name}
 
 %files devel
 /usr/include/aul/*.h
index c4b04a5..b11168a 100755 (executable)
@@ -96,7 +96,7 @@ int __app_dbus_signal_handler_init()
                return 0;
 
        dbus_error_init(&error);
-       bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+       bus = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
        if (!bus) {
                _E("Failed to connect to the D-BUS daemon: %s", error.message);
                dbus_error_free(&error);
@@ -115,7 +115,7 @@ int __app_dbus_signal_handler_init()
                return -1;
        }
 
-       if (dbus_connection_add_filter(bus, 
+       if (dbus_connection_add_filter(bus,
                __app_dbus_signal_filter, NULL, NULL) == FALSE)
                return -1;
 
index db1967c..fb71261 100755 (executable)
@@ -142,6 +142,103 @@ int __create_server_sock(int pid)
        return fd;
 }
 
+
+int __create_server_sock_by_path(char *path)
+{
+       struct sockaddr_un saddr;
+       struct sockaddr_un p_saddr;
+       int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+       /*  support above version 2.6.27*/
+       if (fd < 0) {
+               if (errno == EINVAL) {
+                       fd = socket(AF_UNIX, SOCK_STREAM, 0);
+                       if (fd < 0) {
+                               _E("second chance - socket create error");
+                               return -1;
+                       }
+               } else {
+                       _E("socket error");
+                       return -1;
+               }
+       }
+
+       memset(&saddr, 0, sizeof(saddr));
+       saddr.sun_family = AF_UNIX;
+       snprintf(saddr.sun_path, UNIX_PATH_MAX, "%s", path);
+       unlink(saddr.sun_path);
+
+       if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
+               _E("bind error");
+               close(fd);
+               return -1;
+       }
+
+       if (chmod(saddr.sun_path, (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) {
+               /* Flawfinder: ignore*/
+               _E("failed to change the socket permission");
+               close(fd);
+               return -1;
+       }
+       __set_sock_option(fd, 0);
+       if (listen(fd, 128) == -1) {
+               _E("listen error");
+               close(fd);
+               return -1;
+       }
+       return fd;
+}
+
+
+
+
+
+
+int __create_agent_client_sock(int uid)
+{
+       int fd = -1;
+       struct sockaddr_un saddr = { 0, };
+       int retry = 1;
+       int ret = -1;
+
+       fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);    
+       /*  support above version 2.6.27*/
+       if (fd < 0) {
+               if (errno == EINVAL) {
+                       fd = socket(AF_UNIX, SOCK_STREAM, 0);
+                       if (fd < 0) {
+                               _E("second chance - socket create error");
+                               return -1;
+                       }
+               } else {
+                       _E("socket error");
+                       return -1;
+               }
+       }
+
+       saddr.sun_family = AF_UNIX;
+       snprintf(saddr.sun_path, UNIX_PATH_MAX, "/run/user/%d/amd_agent", uid);
+ retry_con:
+       ret = __connect_client_sock(fd, (struct sockaddr *)&saddr, sizeof(saddr),
+                       100 * 1000);
+       if (ret < -1) {
+               _E("maybe peer not launched or peer daed\n");
+               if (retry > 0) {
+                       usleep(100 * 1000);
+                       retry--;
+                       goto retry_con;
+               }
+       }
+       if (ret < 0) {
+               close(fd);
+               return -1;
+       }
+
+       __set_sock_option(fd, 1);
+
+       return fd;
+}
+
+
 int __create_client_sock(int pid)
 {
        int fd = -1;
@@ -332,6 +429,171 @@ retry_recv:
        return res;
 }
 
+
+int __app_agent_send_raw(int uid, int cmd, unsigned char *kb_data, int datalen)
+{
+       int fd;
+       int len;
+       int ret;
+       int res = 0;
+       app_pkt_t *pkt = NULL;
+
+       if (kb_data == NULL || datalen > AUL_SOCK_MAXBUFF - 8) {
+               _E("keybundle error\n");
+               return -EINVAL;
+       }
+
+       _D("uid(%d) : cmd(%d)", uid, cmd);
+
+       fd = __create_agent_client_sock(uid);
+       if (fd < 0)
+               return -ECOMM;
+
+       pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+       if (NULL == pkt) {
+               _E("Malloc Failed!");
+               return -ENOMEM;
+       }
+       memset(pkt, 0, AUL_SOCK_MAXBUFF);
+
+       pkt->cmd = cmd;
+       pkt->len = datalen;
+       memcpy(pkt->data, kb_data, datalen);
+
+       if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) {
+               _E("sendto() failed - %d %d (errno %d)", len, datalen + 8, errno);
+               if(len > 0) {
+                       while (len != datalen + 8) {
+                               ret = send(fd, &pkt->data[len-8], datalen + 8 - len, 0);
+                               if (ret < 0) {
+                                       _E("second sendto() failed - %d %d (errno %d)", ret, datalen + 8, errno);
+                                       if (errno == EPIPE) {
+                                               _E("uid:%d, fd:%d\n", uid, fd);
+                                       }
+                                       close(fd);
+                                       if (pkt) {
+                                               free(pkt);
+                                               pkt = NULL;
+                                       }
+                                       return -ECOMM;
+                               }
+                               len += ret;
+                               _D("sendto() len - %d %d", len, datalen + 8);
+                       }
+               } else {
+                       if (errno == EPIPE) {
+                               _E("uid:%d, fd:%d\n", uid, fd);
+                       }
+                       close(fd);
+                       if (pkt) {
+                               free(pkt);
+                               pkt = NULL;
+                       }
+                       return -ECOMM;
+               }
+       }
+       if (pkt) {
+               free(pkt);
+               pkt = NULL;
+       }
+
+retry_recv:
+       len = recv(fd, &res, sizeof(int), 0);
+       if (len == -1) {
+               if (errno == EAGAIN) {
+                       _E("recv timeout : %s", strerror(errno));
+                       res = -EAGAIN;
+               } else if (errno == EINTR) {
+                       _D("recv : %s", strerror(errno));
+                       goto retry_recv;
+               } else {
+                       _E("recv error : %s", strerror(errno));
+                       res = -ECOMM;
+               }
+       }
+       close(fd);
+
+       return res;
+}
+
+
+int __app_agent_send_raw_with_noreply(int uid, int cmd, unsigned char *kb_data, int datalen)
+{
+       int fd;
+       int len;
+       int ret;
+       int res = 0;
+       app_pkt_t *pkt = NULL;
+
+       if (kb_data == NULL || datalen > AUL_SOCK_MAXBUFF - 8) {
+               _E("keybundle error\n");
+               return -EINVAL;
+       }
+
+       _D("uid(%d) : cmd(%d)", uid, cmd);
+
+       fd = __create_agent_client_sock(uid);
+       if (fd < 0)
+               return -ECOMM;
+
+       pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+       if (NULL == pkt) {
+               _E("Malloc Failed!");
+               return -ENOMEM;
+       }
+       memset(pkt, 0, AUL_SOCK_MAXBUFF);
+
+       pkt->cmd = cmd;
+       pkt->len = datalen;
+       memcpy(pkt->data, kb_data, datalen);
+
+       if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) {
+               _E("sendto() failed - %d %d (errno %d)", len, datalen + 8, errno);
+               if(len > 0) {
+                       while (len != datalen + 8) {
+                               ret = send(fd, &pkt->data[len-8], datalen + 8 - len, 0);
+                               if (ret < 0) {
+                                       _E("second sendto() failed - %d %d (errno %d)", ret, datalen + 8, errno);
+                                       if (errno == EPIPE) {
+                                               _E("uid:%d, fd:%d\n", uid, fd);
+                                       }
+                                       close(fd);
+                                       if (pkt) {
+                                               free(pkt);
+                                               pkt = NULL;
+                                       }
+                                       return -ECOMM;
+                               }
+                               len += ret;
+                               _D("sendto() len - %d %d", len, datalen + 8);
+                       }
+               } else {
+                       if (errno == EPIPE) {
+                               _E("uid:%d, fd:%d\n", uid, fd);
+                       }
+                       close(fd);
+                       if (pkt) {
+                               free(pkt);
+                               pkt = NULL;
+                       }
+                       return -ECOMM;
+               }
+       }
+       if (pkt) {
+               free(pkt);
+               pkt = NULL;
+       }
+
+       close(fd);
+
+       return res;
+}
+
+
+
+
+
+
 int __app_send_raw_with_noreply(int pid, int cmd, unsigned char *kb_data, int datalen)
 {
        int fd;
@@ -404,6 +666,11 @@ int __app_send_raw_with_noreply(int pid, int cmd, unsigned char *kb_data, int da
        return res;
 }
 
+
+
+
+
+
 int __app_send_raw_with_delay_reply(int pid, int cmd, unsigned char *kb_data, int datalen)
 {
        int fd;
index 0fd263e..b3c7bb3 100755 (executable)
@@ -89,6 +89,94 @@ static int app_terminate()
 }
 
 
+
+
+/**
+ * @brief      encode kb and send it to 'pid'
+ * @param[in]  pid             receiver's pid
+ * @param[in]  cmd             message's status (APP_START | APP_RESULT)
+ * @param[in]  kb              data
+ */
+SLPAPI int app_agent_send_cmd(int uid, int cmd, bundle *kb)
+{
+       int datalen;
+       bundle_raw *kb_data;
+       int res;
+
+       bundle_encode(kb, &kb_data, &datalen);
+       if ((res = __app_agent_send_raw(uid, cmd, kb_data, datalen)) < 0) {
+               switch (res) {
+               case -EINVAL:
+                       res = AUL_R_EINVAL;
+                       break;
+               case -ECOMM:
+                       res = AUL_R_ECOMM;
+                       break;
+               case -EAGAIN:
+                       res = AUL_R_ETIMEOUT;
+                       break;
+               case -ELOCALLAUNCH_ID:
+                       res = AUL_R_LOCAL;
+                       break;
+               case -EILLEGALACCESS:
+                       res = AUL_R_EILLACC;
+                       break;
+               case -ETERMINATING:
+                       res = AUL_R_ETERMINATING;
+                       break;
+               case -ENOLAUNCHPAD:
+                       res = AUL_R_ENOLAUNCHPAD;
+                       break;
+               default:
+                       res = AUL_R_ERROR;
+               }
+       }
+       free(kb_data);
+
+       return res;
+}
+
+SLPAPI int app_agent_send_cmd_with_noreply(int uid, int cmd, bundle *kb)
+{
+       int datalen;
+       bundle_raw *kb_data;
+       int res;
+
+       bundle_encode(kb, &kb_data, &datalen);
+       if ((res = __app_send_raw_with_noreply(uid, cmd, kb_data, datalen)) < 0) {
+               switch (res) {
+               case -EINVAL:
+                       res = AUL_R_EINVAL;
+                       break;
+               case -ECOMM:
+                       res = AUL_R_ECOMM;
+                       break;
+               case -EAGAIN:
+                       res = AUL_R_ETIMEOUT;
+                       break;
+               case -ELOCALLAUNCH_ID:
+                       res = AUL_R_LOCAL;
+                       break;
+               case -EILLEGALACCESS:
+                       res = AUL_R_EILLACC;
+                       break;
+               default:
+                       res = AUL_R_ERROR;
+               }
+       }
+       free(kb_data);
+
+       return res;
+}
+
+
+
+
+
+
+
+
+
 /**
  * @brief      encode kb and send it to 'pid'
  * @param[in]  pid             receiver's pid
index deb70ad..7116596 100755 (executable)
@@ -40,9 +40,9 @@
 #define OPTION_VALGRIND_NAME   "valgrind"
 #define OPTION_VALGRIND_SIZE   8
 
-
 #define PROC_STAT_GID_POS      5
 
+#define MAX_CMD_BUFSZ 1024
 
 static inline int __read_proc(const char *path, char *buf, int size);
 static inline int __find_pid_by_cmdline(const char *dname,
@@ -143,8 +143,6 @@ int __proc_iter_cmdline(
 
 char *__proc_get_cmdline_bypid(int pid)
 {
-#define MAX_CMD_BUFSZ 1024
-
        char buf[MAX_CMD_BUFSZ];
        int ret;
 
@@ -188,6 +186,21 @@ char *__proc_get_cmdline_bypid(int pid)
        return strdup(buf);
 }
 
+char *__proc_get_exe_bypid(int pid)
+{
+       char buf[MAX_CMD_BUFSZ];
+       char buf2[MAX_CMD_BUFSZ];
+       int ret;
+       ssize_t len;
+
+       snprintf(buf, sizeof(buf), "/proc/%d/exe", pid);
+       len=readlink(buf,buf2,MAX_CMD_BUFSZ);
+       if (len<=0)
+               return NULL;
+
+       return strdup(buf2);
+}
+
 static inline int __get_pgid_from_stat(int pid)
 {
        char buf[MAX_LOCAL_BUFSZ];
index d3d54f4..b36fb23 100755 (executable)
@@ -65,7 +65,7 @@ int main(int argc, char **argv)
 
        dbus_error_init(&error);
 
-       bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+       bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
        if (bus == NULL)
                _E("Failed to open bus to bus")
 
index f6643ae..c27c5c9 100755 (executable)
@@ -40,7 +40,7 @@ gboolean result_func(gpointer data)
 
        dbus_error_init(&error);
 
-       bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+       bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
 
        reply = dbus_message_new_method_return(msg);
        dbus_message_unref(msg);
@@ -101,7 +101,7 @@ static int init_dbus()
 
        dbus_error_init(&error);
 
-       bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+       bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
        if (!bus)
                _E("couldn't access session bus");
 
index 47b9b2d..cbd1593 100755 (executable)
@@ -28,7 +28,6 @@
 #include "aul.h"
 
 #define ROOT_UID 0
-#define TMP_FILE "/tmp/.testpkg"
 
 static char **gargv;
 static int gargc;
@@ -70,8 +69,6 @@ static bundle *create_internal_bundle(int start)
 
 int launch()
 {
-       FILE *fp;
-       int ret = -1;
        int pid = -1;
 
        kb = create_internal_bundle(2);
@@ -79,18 +76,7 @@ int launch()
                printf("bundle creation fail\n");
                return -1;
        }
-
        pid = aul_launch_app(gargv[1], kb);
-
-       /* Write the package name to TMP_FILE*/
-       fp = fopen(TMP_FILE, "w");
-       if (fp == NULL)
-               return -1;
-       ret = fprintf(fp, "%d", pid);
-       fclose(fp);
-       if (ret < 0)
-               return -1;
-
        return pid;
 }
 
index d9b677c..7525fef 100755 (executable)
@@ -70,8 +70,6 @@ static bundle *create_internal_bundle(int start)
 
 int launch()
 {
-       FILE *fp;
-       int ret = -1;
        int pid = -1;
 
        kb = create_internal_bundle(2);
@@ -81,16 +79,6 @@ int launch()
        }
 
        pid = aul_open_app(gargv[1]);
-
-       /* Write the package name to TMP_FILE*/
-       fp = fopen(TMP_FILE, "w");
-       if (fp == NULL)
-               return -1;
-       ret = fprintf(fp, "%d", pid);
-       fclose(fp);
-       if (ret < 0)
-               return -1;
-
        return pid;
 }