_AI_RESTART,
_AI_MULTI,
_AI_HWACC,
+ _AI_PERM,
_AI_MAX,
};
#define _AI_START _AI_NAME /* start index */
[_AI_RESTART] = { "AutoRestart", AIT_RESTART, },
[_AI_MULTI] = { "Multiple", AIT_MULTI, },
[_AI_HWACC] = { "Hwacceleration", AIT_HWACC, },
+ [_AI_PERM] = { "PermissionType", AIT_PERM, },
};
struct appinfo {
bool restart;
pkgmgrinfo_app_hwacceleration hwacc;
pkgmgrinfo_app_component component;
+ pkgmgrinfo_permission_type permission;
int ret = -1;
if (!handle) {
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);
char *type_string;
char *appid;
char *saveptr;
- char *pkgname;
pkgmgrinfo_appinfo_h handle;
struct appinfomgr *cf = (struct appinfomgr *)data;
int ret;
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);
+ }
+ }
}
}
AIT_RESTART, /* auto restart: boolean */
AIT_MULTI,
AIT_HWACC,
+ AIT_PERM,
};
int appinfo_init(struct appinfomgr **cf);
#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;
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 */
}
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);
}
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;
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;
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) {
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);
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;
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);
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;
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:
__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);
break;
default:
_E("no support packet");
+ close(clifd);
}
if (free_pkt)
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;
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);
+
<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"/>
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,
#define LAUNCHPAD_PID -1
#define WEB_LAUNCHPAD_PID -3
#define ELOCALLAUNCH_ID 128
+#define EILLEGALACCESS 127
+
typedef struct _app_pkt_t {
int cmd;
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
* @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 */
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);
{
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 */
__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*/
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);
/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
[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
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
{
int fd;
int len;
+ int ret;
int res = 0;
app_pkt_t *pkt = NULL;
return -EINVAL;
}
+ _D("pid(%d) : cmd(%d)", pid, cmd);
+
fd = __create_client_sock(pid);
if (fd < 0)
return -ECOMM;
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);
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;
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;
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);
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;
}
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 */
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);
_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);
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);
}
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);
_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);
const char *pid_str;
*outb = NULL;
-
+
if(inb == NULL){
_E("return msg create fail");
return AUL_R_EINVAL;
} 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");
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;
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;
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;
+}