merge with master
authorJinkun Jang <jinkun.jang@samsung.com>
Fri, 15 Mar 2013 16:12:32 +0000 (01:12 +0900)
committerJinkun Jang <jinkun.jang@samsung.com>
Fri, 15 Mar 2013 16:12:32 +0000 (01:12 +0900)
20 files changed:
am_daemon/amd_appinfo.c
am_daemon/amd_appinfo.h
am_daemon/amd_launch.c
am_daemon/amd_launch.h
am_daemon/amd_request.c
am_daemon/amd_status.c
am_daemon/amd_status.h
aul.manifest
include/access_control.h [moved from launchpad_src/access_control.h with 100% similarity]
include/app_sock.h
include/aul.h
include/launch.h
launchpad_src/launchpad.c
legacy/preload_list.txt
packaging/ac.service
packaging/aul.spec
src/app_sock.c
src/launch.c
src/launch_with_result.c
src/pkginfo.c

index c4fdc28..3e17b44 100755 (executable)
@@ -29,6 +29,7 @@ enum _appinfo_idx {
        _AI_RESTART,
        _AI_MULTI,
        _AI_HWACC,
+       _AI_PERM,
        _AI_MAX,
 };
 #define _AI_START _AI_NAME /* start index */
@@ -47,6 +48,7 @@ static struct appinfo_t _appinfos[] = {
        [_AI_RESTART] = { "AutoRestart", AIT_RESTART, },
        [_AI_MULTI] = { "Multiple", AIT_MULTI, },
        [_AI_HWACC] = { "Hwacceleration", AIT_HWACC, },
+       [_AI_PERM] = { "PermissionType", AIT_PERM, },
 };
 
 struct appinfo {
@@ -90,6 +92,7 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d
        bool restart;
        pkgmgrinfo_app_hwacceleration hwacc;
        pkgmgrinfo_app_component component;
+       pkgmgrinfo_permission_type permission;
        int ret = -1;
 
        if (!handle) {
@@ -170,6 +173,15 @@ static int __app_info_insert_handler (const pkgmgrinfo_appinfo_h handle, void *d
                c->val[_AI_TYPE] = strdup("wgt");
        }
 
+       r = pkgmgrinfo_appinfo_get_permission_type(handle, &permission);
+       if (permission == PMINFO_PERMISSION_SIGNATURE) {
+               c->val[_AI_PERM] = strdup("signature");
+       } else if (permission == PMINFO_PERMISSION_PRIVILEGE) {
+               c->val[_AI_PERM] = strdup("privilege");
+       } else {
+               c->val[_AI_PERM] = strdup("normal");
+       }
+
        _D("%s : %s : %s", c->val[_AI_FILE], c->val[_AI_COMP], c->val[_AI_TYPE]);
 
        g_hash_table_insert(cf->tbl, c->val[_AI_FILE], c);
@@ -220,7 +232,6 @@ static void __vconf_cb(keynode_t *key, void *data)
        char *type_string;
        char *appid;
        char *saveptr;
-       char *pkgname;
        pkgmgrinfo_appinfo_h handle;
        struct appinfomgr *cf = (struct appinfomgr *)data;
        int ret;
@@ -248,6 +259,14 @@ static void __vconf_cb(keynode_t *key, void *data)
                pkgmgrinfo_appinfo_destroy_appinfo(handle);
        } else if ( strncmp(type_string, "delete", 6) == 0) {
                g_hash_table_remove(cf->tbl, appid);
+       } else if (strncmp(type_string, "update", 6) == 0){
+               /*REMOVE EXISTING ENTRY & CREATE AGAIN*/
+               if (g_hash_table_remove(cf->tbl, appid) == true){
+                       if (pkgmgrinfo_appinfo_get_appinfo(appid, &handle) == PMINFO_R_OK){
+                               __app_info_insert_handler(handle, data);
+                               pkgmgrinfo_appinfo_destroy_appinfo(handle);
+                       }
+               }
        }
 }
 
index a5840f4..609ee58 100755 (executable)
@@ -13,6 +13,7 @@ enum appinfo_type {
        AIT_RESTART, /* auto restart: boolean */
        AIT_MULTI,
        AIT_HWACC,
+       AIT_PERM,
 };
 
 int appinfo_init(struct appinfomgr **cf);
index 7f90dc6..c69388e 100755 (executable)
@@ -28,6 +28,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <app2ext_interface.h>
+#include <sys/prctl.h>
+#include <pkgmgr-info.h>
 
 #include "amd_config.h"
 #include "amd_launch.h"
 #include "simple_util.h"
 #include "amd_cgutil.h"
 
+#define DAC_ACTIVATE
+
+#include "access_control.h"
+
 
 #define TERM_WAIT_SEC 3
 #define INIT_PID 1
 
+#define AUL_PR_NAME                    16
+#define PATH_APP_ROOT "/opt/usr/apps"
+#define PATH_DATA "/data"
+#define SDK_CODE_COVERAGE "CODE_COVERAGE"
+#define SDK_DYNAMIC_ANALYSIS "DYNAMIC_ANALYSIS"
+#define PATH_DA_SO "/home/developer/sdk_tools/da/da_probe.so"
+
 struct appinfomgr *_laf;
 struct cginfo *_lcg;
 
@@ -61,14 +74,130 @@ struct ktimer {
        struct cginfo *cg;
 };
 
-static void _prepare_exec(void)
+static void _set_oom()
+{
+       char buf[MAX_LOCAL_BUFSZ];
+       FILE *fp;
+
+       /* 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");
+       if (fp == NULL)
+               return;
+       fprintf(fp, "%d", -16);
+       fclose(fp);
+}
+
+static void _set_sdk_env(char* appid, char* str) {
+       char buf[MAX_LOCAL_BUFSZ];
+       int ret;
+
+       _D("key : %s / value : %s", AUL_K_SDK, str);
+       /* http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html*/
+       /* GCOV_PREFIX contains the prefix to add to the absolute paths in the object file. */
+       /*              Prefix can be absolute, or relative. The default is no prefix.  */
+       /* GCOV_PREFIX_STRIP indicates the how many initial directory names */
+       /*              to stripoff the hardwired absolute paths. Default value is 0. */
+       if (strncmp(str, SDK_CODE_COVERAGE, strlen(str)) == 0) {
+               snprintf(buf, MAX_LOCAL_BUFSZ, PATH_APP_ROOT"/%s"PATH_DATA, appid);
+               ret = setenv("GCOV_PREFIX", buf, 1);
+               _D("GCOV_PREFIX : %d", ret);
+               ret = setenv("GCOV_PREFIX_STRIP", "4096", 1);
+               _D("GCOV_PREFIX_STRIP : %d", ret);
+       } else if (strncmp(str, SDK_DYNAMIC_ANALYSIS, strlen(str)) == 0) {
+               ret = setenv("LD_PRELOAD", PATH_DA_SO, 1);
+               _D("LD_PRELOAD : %d", ret);
+       }
+}
+
+#define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
+
+static void _set_env(char *appid, bundle * kb, char *hwacc)
 {
+       const char *str;
+       const char **str_array;
+       int len;
+       int i;
+
+       setenv("PKG_NAME", appid, 1);
+
+       USE_ENGINE("gl")
+
+       str = bundle_get_val(kb, AUL_K_STARTTIME);
+       if (str != NULL)
+               setenv("APP_START_TIME", str, 1);
+
+       if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
+               str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
+               if(str_array != NULL) {
+                       for (i = 0; i < len; i++) {
+                               _D("index : [%d]", i);
+                               _set_sdk_env(appid, (char *)str_array[i]);
+                       }
+               }
+       } else {
+               str = bundle_get_val(kb, AUL_K_SDK);
+               if(str != NULL) {
+                       _set_sdk_env(appid, (char *)str);
+               }
+       }
+       if (hwacc != NULL)
+               setenv("HWACC", hwacc, 1);
+}
+
+static void _prepare_exec(char *appid, bundle *kb)
+{
+       struct appinfo *ai;
+       char *app_path = NULL;
+       char *pkg_type = NULL;
+       char *file_name;
+       char process_name[AUL_PR_NAME];
+       char *hwacc;
+       int ret;
+
        setsid();
 
        signal(SIGINT, SIG_DFL);
        signal(SIGTERM, SIG_DFL);
        signal(SIGCHLD, SIG_DFL);
 
+       ai = appinfo_find(_laf, appid);
+
+       app_path = appinfo_get_value(ai, AIT_EXEC);
+       pkg_type = appinfo_get_value(ai, AIT_TYPE);
+       hwacc = appinfo_get_value(ai, AIT_HWACC);
+
+       /* SET OOM*/
+       _set_oom();
+
+       /* SET PRIVILEGES*/
+        _D("appid : %s / pkg_type : %s / app_path : %s ", appid, pkg_type, app_path);
+       if ((ret = __set_access(appid, pkg_type, app_path)) < 0) {
+                _D("fail to set privileges - check your package's credential : %d\n", ret);
+               return -1;
+       }
+
+       /* SET DUMPABLE - for coredump*/
+       prctl(PR_SET_DUMPABLE, 1);
+
+       /* SET PROCESS NAME*/
+       if (app_path == NULL) {
+               _D("app_path should not be NULL - check menu db");
+               return -1;
+       }
+       file_name = strrchr(app_path, '/') + 1;
+       if (file_name == NULL) {
+               _D("can't locate file name to execute");
+               return -1;
+       }
+       memset(process_name, '\0', AUL_PR_NAME);
+       snprintf(process_name, AUL_PR_NAME, "%s", file_name);
+       prctl(PR_SET_NAME, process_name);
+
+       /* SET ENVIROMENT*/
+       _set_env(appid, kb, hwacc);
+
        /* TODO: do security job */
        /* TODO: setuid */
 }
@@ -129,12 +258,12 @@ static void _do_exec(struct cginfo *cg, const char *cmd, const char *group, bund
        if (kb) {
                b_argv = __create_argc_argv(kb, &b_argc);
                b_argv[0] = strdup(argv[0]);
-               _prepare_exec();
+               _prepare_exec(group, kb);
                execv(b_argv[0], b_argv);
        }
 
        if (b) {
-               _prepare_exec();
+               _prepare_exec(group, kb);
                execv(argv[0], argv);
        }
 
@@ -474,7 +603,7 @@ int __sat_ui_launch(char* appid, bundle* kb, int cmd, int caller_pid, int fd)
        return pid;
 }
 
-int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, int fd)
+int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd)
 {
        struct appinfo *ai;
        int ret = -1;
@@ -485,6 +614,9 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, int fd)
        int pid = -1;
        char tmp_pid[MAX_PID_STR_BUFSZ];
        char *hwacc;
+       char *permission;
+       char caller_appid[256];
+       pkgmgrinfo_cert_compare_result_type_e compare_result;
 
        int location = -1;
        app2ext_handle *app2_handle = NULL;
@@ -505,6 +637,20 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, int fd)
        componet = appinfo_get_value(ai, AIT_COMP);
        app_path = appinfo_get_value(ai, AIT_EXEC);
        pkg_type = appinfo_get_value(ai, AIT_TYPE);
+       permission = appinfo_get_value(ai, AIT_PERM);
+
+       if(permission && strncmp(permission, "signature", 9) == 0 ) {
+               if(caller_uid != 0 && (cmd == APP_START || cmd == APP_START_RES)){
+                       aul_app_get_appid_bypid(caller_pid, caller_appid, sizeof(caller_appid));
+                       pkgmgrinfo_pkginfo_compare_app_cert_info(caller_appid, appid, &compare_result);
+                       if(compare_result != PMINFO_CERT_COMPARE_MATCH) {
+                               pid = -EILLEGALACCESS;
+                               __real_send(fd, pid);
+                               return pid;
+                       }
+               }
+       }
+
        if (componet && strncmp(componet, "ui", 2) == 0) {
                multiple = appinfo_get_value(ai, AIT_MULTI);
                if (!multiple || strncmp(multiple, "false", 5) == 0) {
index 8691f4c..d851bc3 100755 (executable)
@@ -30,7 +30,7 @@ int _send_to_sigkill(int pid);
 int _resume_app(int pid);
 int _term_app(int pid);
 int _fake_launch_app(int cmd, int pid, bundle * kb);
-int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, int fd);
+int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd);
 void service_release(const char *group);
 int _start_srv(struct appinfo *ai, bundle *kb);
 
index 8224599..89ab7c0 100755 (executable)
@@ -99,6 +99,7 @@ end:
 static int __foward_cmd(int cmd, bundle *kb, int cr_pid)
 {
        int pid;
+       int pgid;
        char tmp_pid[MAX_PID_STR_BUFSZ];
        int datalen;
        bundle_raw *kb_data;
@@ -107,7 +108,8 @@ static int __foward_cmd(int cmd, bundle *kb, int cr_pid)
        if ((pid = __get_caller_pid(kb)) < 0)
                        return AUL_R_ERROR;
 
-       snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", cr_pid);
+       pgid = getpgid(cr_pid);
+       snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", pgid);
 
        bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid);
 
@@ -307,7 +309,7 @@ static gboolean __request_handler(gpointer data)
                case APP_START_RES:
                        kb = bundle_decode(pkt->data, pkt->len);
                        appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
-                       ret = _start_app(appid, kb, pkt->cmd, cr.pid, clifd);
+                       ret = _start_app(appid, kb, pkt->cmd, cr.pid, cr.uid, clifd);
 
                        if (kb != NULL)
                                bundle_free(kb), kb = NULL;
@@ -326,7 +328,7 @@ static gboolean __request_handler(gpointer data)
                case APP_CANCEL:
                        kb = bundle_decode(pkt->data, pkt->len);
                        ret = __foward_cmd(pkt->cmd, kb, cr.pid);
-                       __real_send(clifd, ret);
+                       //__real_send(clifd, ret);
                        break;
                case APP_TERM_BY_PID:
                case APP_RESUME_BY_PID:
@@ -347,6 +349,11 @@ static gboolean __request_handler(gpointer data)
                        __send_result_to_client(clifd, ret);
                        free(appid);
                        break;
+               case APP_GET_APPID_BYPID:
+                       memcpy(&pid, pkt->data, pkt->len);
+                       ret = _status_get_appid_bypid(clifd, pid);
+                       _D("APP_GET_APPID_BYPID : %d : %d", pid, ret);
+                       break;
                case APP_KEY_RESERVE:
                        ret = _register_key_event(cr.pid);
                        __send_result_to_client(clifd, ret);
@@ -379,6 +386,7 @@ static gboolean __request_handler(gpointer data)
                        break;
                default:
                        _E("no support packet");
+                       close(clifd);
        }
 
        if (free_pkt)
index b61d86d..9f9ba24 100755 (executable)
@@ -265,6 +265,78 @@ int _status_send_running_appinfo_v2(int fd)
        return 0;
 }
 
+static int __get_pkgname_bypid(int pid, char *pkgname, int len)
+{
+       char *cmdline;
+       app_info_from_db *menu_info;
+
+       cmdline = __proc_get_cmdline_bypid(pid);
+       if (cmdline == NULL)
+               return -1;
+
+       if ((menu_info = _get_app_info_from_db_by_apppath(cmdline)) == NULL) {
+               free(cmdline);
+               return -1;
+       } else {
+               snprintf(pkgname, len, "%s", _get_pkgname(menu_info));
+       }
+
+       free(cmdline);
+       _free_app_info_from_db(menu_info);
+
+       return 0;
+}
+
+int _status_get_appid_bypid(int fd, int pid)
+{
+       app_pkt_t *pkt = NULL;
+       int len;
+       int pgid;
+
+       pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+       if(!pkt) {
+               _E("malloc fail");
+               close(fd);
+               return 0;
+       }
+
+       memset(pkt, 0, AUL_SOCK_MAXBUFF);
+
+       pkt->cmd = APP_GET_APPID_BYPID_ERROR;
+
+       if (__get_pkgname_bypid(pid, pkt->data, MAX_PACKAGE_STR_SIZE) == 0) {
+               _D("appid for %d is %s", pid, pkt->data);
+               pkt->cmd = APP_GET_APPID_BYPID_OK;
+               goto out;
+       }
+       /* support app launched by shell script*/
+       _D("second chance");
+       pgid = getpgid(pid);
+       if (pgid <= 1)
+               goto out;
+
+       _D("second change pgid = %d, pid = %d", pgid, pid);
+       if (__get_pkgname_bypid(pgid, pkt->data, MAX_PACKAGE_STR_SIZE) == 0)
+               pkt->cmd = APP_GET_APPID_BYPID_OK;
+
+ out:
+       pkt->len = strlen((char *)pkt->data) + 1;
+
+       if ((len = send(fd, pkt, pkt->len + 8, 0)) != pkt->len + 8) {
+               if (errno == EPIPE)
+                       _E("send failed due to EPIPE.\n");
+               _E("send fail to client");
+       }
+
+       if(pkt)
+               free(pkt);
+
+       close(fd);
+
+       return 0;
+}
+
+
 int _status_init(struct amdmgr* amd)
 {
        _saf = amd->af;
index 5b55d56..de1312f 100755 (executable)
@@ -28,6 +28,8 @@ 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_get_appid_bypid(int fd, int pid);
+
 
 
 
index e2947fa..2d3edf7 100644 (file)
                <filesystem path="/etc/init.d/launchpad_run" label="_" exec_label="none"/>
                <filesystem path="/etc/rc.d/rc3.d/S34launchpad_run" label="_" exec_label="none"/>
                <filesystem path="/etc/rc.d/rc4.d/S80launchpad_run" label="_" exec_label="none"/>
+               <filesystem path="/usr/lib/systemd/system/ac.service" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/systemd/system/launchpad-preload@.service" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/systemd/system/graphical.target.wants/ac.service" label="_" exec_label="none" />
+               <filesystem path="/usr/lib/systemd/system/graphical.target.wants/launchpad-preload@app.service" label="_" exec_label="none" />
        </assign>
        <request>
                <domain name="aul"/>
index 5689e2a..a892c90 100755 (executable)
@@ -42,6 +42,9 @@ enum app_cmd {
        APP_RUNNING_INFO,
        APP_RUNNING_INFO_RESULT,
        APP_IS_RUNNING,
+       APP_GET_APPID_BYPID,
+       APP_GET_APPID_BYPID_OK,
+       APP_GET_APPID_BYPID_ERROR,
        APP_KEY_EVENT,
        APP_KEY_RESERVE,
        APP_KEY_RELEASE,
@@ -55,6 +58,8 @@ enum app_cmd {
 #define LAUNCHPAD_PID -1
 #define WEB_LAUNCHPAD_PID -3
 #define ELOCALLAUNCH_ID 128
+#define EILLEGALACCESS 127
+
 
 typedef struct _app_pkt_t {
        int cmd;
@@ -65,8 +70,10 @@ typedef struct _app_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);
+int __app_send_raw_with_noreply(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);
+app_pkt_t *__app_send_cmd_with_result(int pid, int cmd, unsigned char *kb_data, int datalen);
+
 
 #endif
 
index 3f1b14b..84ac783 100755 (executable)
@@ -70,6 +70,7 @@ extern "C" {
  * @brief Return values in AUL. 
  */
 typedef enum _aul_return_val {
+       AUL_R_EILLACC = -8,             /**< Illegal Access */
        AUL_R_LOCAL = -7,               /**< Launch by himself */
        AUL_R_ETIMEOUT = -6,            /**< Timeout */
        AUL_R_ECANCELED = -5,           /**< Operation canceled */
index 090f403..4025cde 100755 (executable)
@@ -34,6 +34,7 @@ int aul_make_bundle_from_argv(int argc, char **argv, bundle **kb);
 
 int app_start(bundle *kb);
 int app_send_cmd(int pid, int cmd, bundle *kb);
+int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb);
 int app_request_to_launchpad(int cmd, const char *pkgname, bundle *kb);
 
 int _app_start_res_prepare(bundle *kb);
index c3b34c2..e3f602b 100755 (executable)
@@ -181,6 +181,7 @@ _static_ int __prepare_exec(const char *pkg_name,
 {
        char *file_name;
        char process_name[AUL_PR_NAME];
+       int ret;
 
        /* Set new session ID & new process group ID*/
        /* In linux, child can set new session ID without check permission */
@@ -193,8 +194,9 @@ _static_ int __prepare_exec(const char *pkg_name,
        __set_oom();
 
        /* SET PRIVILEGES*/
-       if (__set_access(pkg_name, menu_info->pkg_type, app_path) < 0) {
-                _D("fail to set privileges - check your package's credential\n");
+        _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;
        }
        /* SET DUMPABLE - for coredump*/
@@ -538,7 +540,7 @@ _static_ int __foward_cmd(int cmd, bundle *kb, int cr_pid)
        bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid);
 
        bundle_encode(kb, &kb_data, &datalen);
-       if ((res = __app_send_raw(pid, cmd, kb_data, datalen)) < 0)
+       if ((res = __app_send_raw_with_noreply(pid, cmd, kb_data, datalen)) < 0)
                res = AUL_R_ERROR;
 
        free(kb_data);
index 0905689..fbb6fca 100644 (file)
@@ -2,3 +2,4 @@
 /usr/lib/libappcore-common.so.1
 /usr/lib/ecore/immodules/libisf-imf-module.so
 /usr/lib/osp/libosp-appfw.so
+/usr/lib/osp/libosp-uifw.so
index 2b7bbcd..3d65369 100644 (file)
@@ -8,7 +8,7 @@ Description=Start the Access Control server
 [Service]
 Environment=DISPLAY=:0
 ExecStartPre=-/bin/mkdir -m 1777 /tmp/alaunch
-ExecStart=/bin/sh -c 'while test ! -e /tmp/.X0-lock; do sleep 0.1; done; exec /usr/bin/amd'
+ExecStart=/bin/sh -c 'while test ! -e /tmp/.wm_ready; do sleep 0.1; done; exec /usr/bin/amd'
 
 OOMScoreAdjust=-100
 
index 887a67e..e224c3d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       aul
 Summary:    App utility library
-Version:    0.0.240
+Version:    0.0.257
 Release:    1
 Group:      System/Libraries
 License:    Apache License, Version 2.0
index 4be9849..9a6ab9e 100755 (executable)
@@ -250,6 +250,7 @@ int __app_send_raw(int pid, int cmd, unsigned char *kb_data, int datalen)
 {
        int fd;
        int len;
+       int ret;
        int res = 0;
        app_pkt_t *pkt = NULL;
 
@@ -258,6 +259,8 @@ int __app_send_raw(int pid, int cmd, unsigned char *kb_data, int datalen)
                return -EINVAL;
        }
 
+       _D("pid(%d) : cmd(%d)", pid, cmd);
+
        fd = __create_client_sock(pid);
        if (fd < 0)
                return -ECOMM;
@@ -275,15 +278,35 @@ int __app_send_raw(int pid, int cmd, unsigned char *kb_data, int datalen)
 
        if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) {
                _E("sendto() failed - %d %d (errno %d)", len, datalen + 8, errno);
-               if (errno == EPIPE) {
-                       _E("pid:%d, fd:%d\n", pid, fd);
-               }
-               close(fd);
-               if (pkt) {
-                       free(pkt);
-                       pkt = NULL;
+               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("pid:%d, fd:%d\n", pid, 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("pid:%d, fd:%d\n", pid, fd);
+                       }
+                       close(fd);
+                       if (pkt) {
+                               free(pkt);
+                               pkt = NULL;
+                       }
+                       return -ECOMM;
                }
-               return -ECOMM;
        }
        if (pkt) {
                free(pkt);
@@ -305,9 +328,82 @@ int __app_send_raw(int pid, int cmd, unsigned char *kb_data, int datalen)
        return res;
 }
 
+int __app_send_raw_with_noreply(int pid, 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("pid(%d) : cmd(%d)", pid, cmd);
+
+       fd = __create_client_sock(pid);
+       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("pid:%d, fd:%d\n", pid, 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("pid:%d, fd:%d\n", pid, fd);
+                       }
+                       close(fd);
+                       if (pkt) {
+                               free(pkt);
+                               pkt = NULL;
+                       }
+                       return -ECOMM;
+               }
+       }
+       if (pkt) {
+               free(pkt);
+               pkt = NULL;
+       }
+
+       close(fd);
+
+       return res;
+}
+
 app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr)
 {
        int len;
+       int ret;
        struct sockaddr_un aul_addr = { 0, };
        int sun_size;
        app_pkt_t *pkt = NULL;
@@ -345,17 +441,29 @@ app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr)
                if (errno == EINTR)
                        goto retry_recv;
 
-       if ((len < 8) || (len != (pkt->len + 8))) {
+       if (len < 8) {
                _E("recv error %d %d", len, pkt->len);
                free(pkt);
                close(*clifd);
                return NULL;
        }
 
+       while( len != (pkt->len + 8) ) {
+               ret = recv(*clifd, &pkt->data[len-8], AUL_SOCK_MAXBUFF, 0);
+               if (ret < 0) {
+                       _E("recv error %d %d", len, pkt->len);
+                       free(pkt);
+                       close(*clifd);
+                       return NULL;
+               }
+               len += ret;
+               _D("recv len %d %d", len, pkt->len);
+       }
+
        return pkt;
 }
 
-app_pkt_t *__app_send_cmd_with_result(int pid, int cmd)
+app_pkt_t *__app_send_cmd_with_result(int pid, int cmd, unsigned char *kb_data, int datalen)
 {
        int fd;
        int len;
@@ -373,9 +481,12 @@ app_pkt_t *__app_send_cmd_with_result(int pid, int cmd)
        memset(pkt, 0, AUL_SOCK_MAXBUFF);
 
        pkt->cmd = cmd;
-       pkt->len = 0;
+       pkt->len = datalen;
+       if(kb_data) {
+               memcpy(pkt->data, kb_data, datalen);
+       }
 
-       if ((len = send(fd, pkt, 8, 0)) != 8) {
+       if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) {
                _E("sendto() failed - %d", len);
                if (errno == EPIPE) {
                        _E("pid:%d, fd:%d\n", pid, fd);
index 1811101..283ea8c 100755 (executable)
@@ -115,6 +115,42 @@ SLPAPI int app_send_cmd(int pid, int cmd, bundle *kb)
                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;
+}
+
+SLPAPI int app_send_cmd_with_noreply(int pid, 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(pid, 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;
                }
@@ -263,7 +299,8 @@ int aul_sock_handler(int fd)
                return -1;
        }
 
-       __send_result_to_launchpad(clifd, 0);
+       if (pkt->cmd != APP_RESULT && pkt->cmd != APP_CANCEL)
+               __send_result_to_launchpad(clifd, 0);
 
        switch (pkt->cmd) {
        case APP_START: /* run in callee */
index d7dace8..2babac6 100755 (executable)
@@ -143,14 +143,14 @@ static int __call_app_result_callback(bundle *kb, int is_cancel,
                newinfo.launched_pid = atoi(fwdpid_str);
                newinfo.cb_func = info->cb_func;
                newinfo.priv_data = info->priv_data;
-               
+
                __remove_resultcb(info);
                __add_resultcb(newinfo.launched_pid, newinfo.cb_func, newinfo.priv_data);
 
                _D("change callback - %s\n",AUL_K_FWD_CALLEE_PID);
-               
+
                goto end;
-       }               
+       }
 
        info->cb_func(kb, is_cancel, info->priv_data);
        __remove_resultcb(info);
@@ -219,7 +219,7 @@ int _app_start_res_prepare(bundle *kb)
                _E("caller pid is not valid");
                return -1;
        }
-       /* If previous caller is still waiting result, 
+       /* If previous caller is still waiting result,
           send cancel packet to the caller. */
        if (latest_caller_pid != -1)
                __send_to_cancel(latest_caller_pid);
@@ -268,7 +268,7 @@ SLPAPI int aul_launch_app_with_result(const char *pkgname, bundle *kb,
 
 void __iterate(const char *key, const char *val, void *data)
 {
-       static int i=0; 
+       static int i=0;
        _D("%d %s %s", i++, key, val);
 }
 
@@ -282,13 +282,13 @@ SLPAPI int aul_forward_app(const char* pkgname, bundle *kb)
 
        if(pkgname == NULL || kb == NULL)
                return AUL_R_EINVAL;
-       
+
        caller = (char *)bundle_get_val(kb, AUL_K_CALLER_PID);
        if(caller == NULL) {
                _E("original msg doest not have caller pid");
                return AUL_R_EINVAL;
        }
-       
+
        bundle_del(kb, AUL_K_ORG_CALLER_PID);
        bundle_add(kb, AUL_K_ORG_CALLER_PID, caller);
 
@@ -297,25 +297,25 @@ SLPAPI int aul_forward_app(const char* pkgname, bundle *kb)
                _E("bundle duplicate fail");
                return AUL_R_EINVAL;
        }
-       
+
        if(bundle_get_val(kb, AUL_K_WAIT_RESULT) != NULL) {
                ret = app_request_to_launchpad(APP_START_RES, pkgname, kb);
-               if(ret < 0) 
-                       goto end;       
+               if(ret < 0)
+                       goto end;
        } else {
                ret = app_request_to_launchpad(APP_START, pkgname, kb);
                goto end;
        }
-               
+
 //     bundle_iterate(dupb, __iterate, NULL);
 
        snprintf(tmp_pid, MAX_PID_STR_BUFSZ,"%d",ret);
 
        ret = aul_create_result_bundle(dupb, &outb);
        if(ret < 0)
-               return ret;
+               goto end;
 
-       bundle_del(outb, AUL_K_FWD_CALLEE_PID);         
+       bundle_del(outb, AUL_K_FWD_CALLEE_PID);
        bundle_add(outb, AUL_K_FWD_CALLEE_PID, tmp_pid);
 
 //     bundle_iterate(outb, __iterate, NULL);
@@ -335,7 +335,7 @@ SLPAPI int aul_create_result_bundle(bundle *inb, bundle **outb)
        const char *pid_str;
 
        *outb = NULL;
-       
+
        if(inb == NULL){
                _E("return msg create fail");
                return AUL_R_EINVAL;
@@ -353,14 +353,14 @@ SLPAPI int aul_create_result_bundle(bundle *inb, bundle **outb)
        } else {
                _D("original msg is not msg with result");
        }
-       
+
 
        pid_str = bundle_get_val(inb, AUL_K_ORG_CALLER_PID);
        if(pid_str) {
                bundle_add(*outb, AUL_K_ORG_CALLER_PID, pid_str);
                goto end;
        }
-       
+
        pid_str = bundle_get_val(inb, AUL_K_CALLER_PID);
        if (pid_str == NULL) {
                _E("original msg doest not have caller pid");
@@ -382,14 +382,18 @@ int aul_send_result(bundle *kb, int is_cancel)
        if ((pid = __get_caller_pid(kb)) < 0)
                return AUL_R_EINVAL;
 
+       _D("caller pid : %d", pid);
+
        if (bundle_get_val(kb, AUL_K_SEND_RESULT) == NULL)
        {
                _D("original msg is not msg with result");
                return AUL_R_OK;
        }
 
-       ret = app_send_cmd(AUL_UTIL_PID, (is_cancel==1)? APP_CANCEL : APP_RESULT, kb);
-       
+       ret = app_send_cmd_with_noreply(AUL_UTIL_PID, (is_cancel==1)? APP_CANCEL : APP_RESULT, kb);
+
+       _D("app_send_cmd_with_noreply : %d", ret);
+
        if(latest_caller_pid == pid)
                latest_caller_pid = -1;
 
index 4eaaac7..7f5afa5 100755 (executable)
@@ -66,7 +66,7 @@ SLPAPI int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn,
        if (enum_fn == NULL)
                return AUL_R_EINVAL;
 
-       pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_RUNNING_INFO);
+       pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_RUNNING_INFO, NULL, 0);
 
        if (pkt == NULL)
                return AUL_R_ERROR;
@@ -117,26 +117,40 @@ SLPAPI int aul_app_get_pkgname_bypid(int pid, char *pkgname, int len)
 
 SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
 {
+       app_pkt_t *pkt = NULL;
        int pgid;
 
-       if (appid == NULL)
-               return AUL_R_EINVAL;
+       if(pid == getpid() || getuid()==0) {
+               if (__get_pkgname_bypid(pid, appid, len) == 0) {
+                       _D("appid for %d is %s", pid, appid);
+                       return AUL_R_OK;
+               }
+               /* support app launched by shell script*/
+               _D("second chance");
+               pgid = getpgid(pid);
+               if (pgid <= 1)
+                       return AUL_R_ERROR;
+
+               _D("second change pgid = %d, pid = %d", pgid, pid);
+               if (__get_pkgname_bypid(pgid, appid, len) == 0)
+                       return AUL_R_OK;
 
-       if (__get_pkgname_bypid(pid, appid, len) == 0) {
-               _D("appid for %d is %s", pid, appid);
-               return AUL_R_OK;
-       }
-       /* support app launched by shell script*/
-       _D("second chance");
-       pgid = getpgid(pid);
-       if (pgid <= 1)
                return AUL_R_ERROR;
+       }
 
-       _D("second change pgid = %d, pid = %d", pgid, pid);
-       if (__get_pkgname_bypid(pgid, appid, len) == 0)
-               return AUL_R_OK;
+       if (appid == NULL)
+               return AUL_R_EINVAL;
 
-       return AUL_R_ERROR;
-}
+       pkt = __app_send_cmd_with_result(AUL_UTIL_PID, APP_GET_APPID_BYPID, &pid, sizeof(pid));
 
+       if(pkt == NULL)
+               return AUL_R_ERROR;
+       if(pkt->cmd == APP_GET_APPID_BYPID_ERROR) {
+               free(pkt);
+               return AUL_R_ERROR;
+       }
 
+       snprintf(appid, len, "%s", pkt->data);
+       free(pkt);
+       return AUL_R_OK;
+}