+++ /dev/null
-/*
- * 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.
- *
- */
-
-
-/*
- * AMD user session agent
- */
-#include <stdio.h>
-#include <string.h>
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include <poll.h>
-#include <sys/prctl.h>
-#include <malloc.h>
-
-#include "agent_config.h"
-
-#include "app_sock.h"
-#include "aul.h"
-
-#include "menu_db_util.h"
-#include "simple_util.h"
-#include "access_control.h"
-#include "preload.h"
-#include "preexec.h"
-#include "perf.h"
-#include "aul_util.h"
-#include "sigchild.h"
-
-#include <rua.h>
-
-#define _static_ static inline
-#define SQLITE_FLUSH_MAX (1048576) /* (1024*1024) */
-#define AUL_POLL_CNT 15
-#define AUL_PR_NAME 16
-
-enum {
- MAIN_FD = 0,
- SIGCHLD_FD,
- POLLFD_MAX
-};
-
-static char *agent_cmdline;
-static int initialized = 0;
-static bool loop_flag = TRUE;
-
-
-_static_ void __set_oom();
-_static_ void __set_env(app_info_from_db * menu_info, bundle * kb);
-_static_ int __prepare_exec(const char *appId,
- const char *app_path, app_info_from_db * menu_info,
- bundle * kb);
-_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_ 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 __send_to_sigkill(int pid);
-_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 __agent_main_loop(struct pollfd pfds[]);
-_static_ int __agent_pre_init(int argc, char **argv);
-
-
-
-void __sigterm_handler(int signo)
-{
- _D("received SIGTERM siganl %d", signo);
- loop_flag = FALSE;
-}
-
-_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_env(app_info_from_db * menu_info, bundle * kb)
-{
- const char *str;
-
- str = bundle_get_val(kb, AUL_K_STARTTIME);
- if (str != NULL)
- setenv("APP_START_TIME", str, 1);
-
- if (menu_info->hwacc != NULL)
- setenv("HWACC", menu_info->hwacc, 1);
-}
-
-_static_ int __prepare_exec(const char *appId,
- const char *app_path, app_info_from_db * menu_info,
- 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 */
- /* TODO : should be add to check permission in the kernel*/
- setsid();
-
- __preexec_run(menu_info->pkg_type, appId, app_path);
-
- /* SET OOM*/
- __set_oom();
-
- /* SET PRIVILEGES*/
- if(bundle_get_val(kb, AUL_K_PRIVACY_APPID) == NULL) {
- _D("appId: %s / pkg_type : %s / app_path : %s ", appId, menu_info->pkg_type, app_path);
- if ((ret = __set_access(appId, 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*/
- 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(menu_info, kb);
-
- return 0;
-}
-
-_static_ int __fake_launch_app(int cmd, int pid, bundle * kb)
-{
- int datalen;
- int ret;
- bundle_raw *kb_data;
-
- bundle_encode(kb, &kb_data, &datalen);
- if ((ret = __app_send_raw(pid, cmd, kb_data, datalen)) < 0)
- _E("error request fake launch - error code = %d", ret);
- free(kb_data);
- return ret;
-}
-
-_static_ char **__create_argc_argv(bundle * kb, int *margc)
-{
- char **argv;
- int argc;
-
- argc = bundle_export_to_argv(kb, &argv);
-
- *margc = argc;
- return argv;
-}
-
-_static_ int __normal_fork_exec(int argc, char **argv)
-{
- _D("start real fork and exec\n");
-
- if (execv(argv[0], argv) < 0) { /* Flawfinder: ignore */
- if (errno == EACCES)
- _E("such a file is no executable - %s", argv[0]);
- else
- _E("unknown executable error - %s", argv[0]);
- return -1;
- }
- /* never reach*/
- return 0;
-}
-
-_static_ void __real_launch(const char *app_path, bundle * kb)
-{
- int app_argc;
- char **app_argv;
- int i;
-
- if(bundle_get_val(kb, AUL_K_DEBUG) != NULL)
- putenv("TIZEN_DEBUGGING_PORT=1");
-
- app_argv = __create_argc_argv(kb, &app_argc);
- app_argv[0] = strdup(app_path);
-
- for (i = 0; i < app_argc; i++) {
- if( (i%2) == 1)
- continue;
- SECURE_LOGD("input argument %d : %s##", i, app_argv[i]);
- }
-
- PERF("setup argument done");
-
- /* Temporary log: launch time checking */
- 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);
-}
-
-
-/*
- * Parsing original app path to retrieve default bundle
- *
- * -1 : Invalid sequence
- * -2 : Buffer overflow
- *
- */
-static inline int __parser(const char *arg, char *out, int out_size)
-{
- register int i;
- int state = 1;
- char *start_out = out;
-
- if (arg == NULL || out == NULL) {
- /* Handles null buffer*/
- return 0;
- }
-
- for (i = 0; out_size > 1; i++) {
- switch (state) {
- case 1:
- switch (arg[i]) {
- case ' ':
- case '\t':
- state = 5;
- break;
- case '\0':
- state = 7;
- break;
- case '\"':
- state = 2;
- break;
- case '\\':
- state = 4;
- break;
- default:
- *out = arg[i];
- out++;
- out_size--;
- break;
- }
- break;
- case 2: /* escape start*/
- switch (arg[i]) {
- case '\0':
- state = 6;
- break;
- case '\"':
- state = 1;
- break;
- default:
- *out = arg[i];
- out++;
- out_size--;
- break;
- }
- break;
- case 4: /* character escape*/
- if (arg[i] == '\0') {
- state = 6;
- } else {
- *out = arg[i];
- out++;
- out_size--;
- state = 1;
- }
- break;
- case 5: /* token*/
- if (out != start_out) {
- *out = '\0';
- out_size--;
- return i;
- }
- i--;
- state = 1;
- break;
- case 6:
- return -1; /* error*/
- case 7: /* terminate*/
- *out = '\0';
- out_size--;
- return 0;
- default:
- state = 6;
- break; /* error*/
- }
- }
-
- if (out_size == 1) {
- *out = '\0';
- }
- /* Buffer overflow*/
- return -2;
-}
-
-_static_ void __modify_bundle(bundle * kb, int caller_pid,
- app_info_from_db * menu_info, int cmd)
-{
- bundle_del(kb, AUL_K_APPID);
- bundle_del(kb, AUL_K_EXEC);
- bundle_del(kb, AUL_K_PACKAGETYPE);
- bundle_del(kb, AUL_K_HWACC);
-
- /* Parse app_path to retrieve default bundle*/
- if (cmd == APP_START || cmd == APP_START_RES || cmd == APP_OPEN || cmd == APP_RESUME) {
- char *ptr;
- char exe[MAX_PATH_LEN];
- int flag;
-
- ptr = _get_original_app_path(menu_info);
-
- flag = __parser(ptr, exe, sizeof(exe));
- if (flag > 0) {
- char key[256];
- char value[256];
-
- ptr += flag;
- SECURE_LOGD("parsing app_path: EXEC - %s\n", exe);
-
- do {
- flag = __parser(ptr, key, sizeof(key));
- if (flag <= 0)
- break;
- ptr += flag;
-
- flag = __parser(ptr, value, sizeof(value));
- if (flag < 0)
- break;
- ptr += flag;
-
- /*bundle_del(kb, key);*/
- bundle_add(kb, key, value);
- } while (flag > 0);
- } else if (flag == 0) {
- _D("parsing app_path: No arguments\n");
- } else {
- _D("parsing app_path: Invalid argument\n");
- }
- }
-}
-
-_static_ int __send_to_sigkill(int pid)
-{
- int pgid;
-
- pgid = getpgid(pid);
- if (pgid <= 1)
- return -1;
-
- if (killpg(pgid, SIGKILL) < 0)
- return -1;
-
- return 0;
-}
-
-_static_ int __term_app(int pid)
-{
- int dummy;
- if (__app_send_raw
- (pid, APP_TERM_BY_PID, (unsigned char *)&dummy, sizeof(int)) < 0) {
- _D("terminate packet send error - use SIGKILL");
- if (__send_to_sigkill(pid) < 0) {
- _E("fail to killing - %d\n", pid);
- return -1;
- }
- }
- _D("term done\n");
- return 0;
-}
-
-_static_ int __resume_app(int pid)
-{
- int dummy;
- int ret;
- if ((ret =
- __app_send_raw(pid, APP_RESUME_BY_PID, (unsigned char *)&dummy,
- sizeof(int))) < 0) {
- if (ret == -EAGAIN)
- _E("resume packet timeout error");
- }
- _D("resume done\n");
- return ret;
-}
-
-static int __get_caller_pid(bundle *kb)
-{
- const char *pid_str;
- int pid;
-
- pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID);
- if(pid_str)
- goto end;
-
- pid_str = bundle_get_val(kb, AUL_K_CALLER_PID);
- if (pid_str == NULL)
- return -1;
-
-end:
- pid = atoi(pid_str);
- if (pid <= 1)
- return -1;
-
- 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;
-
- uid = atoi(uid_str);
- if (uid <0)
- return -1;
-
- return uid;
-}
-
-_static_ int __foward_cmd(int cmd, bundle *kb, int cr_pid)
-{
- int pid;
- char tmp_pid[MAX_PID_STR_BUFSZ];
- int datalen;
- bundle_raw *kb_data;
- int res;
-
- if ((pid = __get_caller_pid(kb)) < 0)
- return AUL_R_ERROR;
-
- snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", cr_pid);
-
- bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid);
-
- bundle_encode(kb, &kb_data, &datalen);
- if ((res = __app_send_raw_with_noreply(pid, cmd, kb_data, datalen)) < 0)
- res = AUL_R_ERROR;
-
- free(kb_data);
-
- return res;
-}
-
-_static_ int __real_send(int clifd, int ret)
-{
- if (send(clifd, &ret, sizeof(int), MSG_NOSIGNAL) < 0) {
- if (errno == EPIPE) {
- _E("send failed due to EPIPE.\n");
- close(clifd);
- return -1;
- }
- _E("send fail to client");
- }
-
- close(clifd);
- return 0;
-}
-
-_static_ void __send_result_to_caller(int clifd, int ret)
-{
- char *cmdline;
- int wait_count;
- int cmdline_changed = 0;
- int cmdline_exist = 0;
- int r;
-
- if (clifd == -1)
- return;
-
- if (ret <= 1) {
- __real_send(clifd, ret);
- return;
- }
- /* check normally was launched?*/
- wait_count = 1;
- do {
- cmdline = __proc_get_cmdline_bypid(ret);
- if (cmdline == NULL) {
- _E("error founded when being launched with %d", ret);
-
- } else if (strcmp(cmdline, agent_cmdline)) {
- free(cmdline);
- cmdline_changed = 1;
- break;
- } else {
- cmdline_exist = 1;
- free(cmdline);
- }
-
- _D("-- now wait to change cmdline --");
- usleep(50 * 1000); /* 50ms sleep*/
- wait_count++;
- } while (wait_count <= 20); /* max 50*20ms will be sleep*/
-
- if ((!cmdline_exist) && (!cmdline_changed)) {
- __real_send(clifd, -1); /* abnormally launched*/
- return;
- }
-
- 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;
-}
-
-static app_info_from_db *_get_app_info_from_bundle_by_appid(
- const char *appid, bundle *kb)
-{
- app_info_from_db *menu_info;
-
- menu_info = calloc(1, sizeof(app_info_from_db));
- if (menu_info == NULL) {
- return NULL;
- }
-
- menu_info->appid = strdup(appid);
- menu_info->app_path = strdup(bundle_get_val(kb, AUL_K_EXEC));
- if (menu_info->app_path != NULL)
- menu_info->original_app_path = strdup(menu_info->app_path);
- menu_info->pkg_type = strdup(bundle_get_val(kb, AUL_K_PACKAGETYPE));
- menu_info->hwacc = strdup(bundle_get_val(kb, AUL_K_HWACC));
-
- if (!_get_app_path(menu_info)) {
- _free_app_info_from_db(menu_info);
- return NULL;
- }
-
- return menu_info;
-}
-
-static void __add_history(const char *pkg_name, const char *app_path, unsigned char *arg)
-{
- struct rua_rec rec;
-
- rec.pkg_name = (char *)pkg_name;
- rec.app_path = (char *)app_path;
- rec.arg = (char *)arg;
-
- if (rua_add_history(&rec))
- _E("rua add history error");
-}
-
-_static_ void __agent_main_loop(struct pollfd pfds[])
-{
- int main_fd = pfds[MAIN_FD].fd;
- int sigchld_fd = pfds[SIGCHLD_FD].fd;
- bundle *kb = NULL;
- app_pkt_t *pkt = NULL;
- app_info_from_db *menu_info = NULL;
-
- const char *appId = 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");
- goto end;
- }
-
- kb = bundle_decode(pkt->data, pkt->len);
- if (!kb) {
- _D("bundle decode error");
- goto end;
- }
-
- INIT_PERF(kb);
- PERF("packet processing start");
-
- appId = bundle_get_val(kb, AUL_K_APPID);
- SECURE_LOGD("appId : %s\n", appId);
-
- /* 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 != getuid()) {
- _E("Invalid request coming from another user");
- goto end;
- }
-
- menu_info = _get_app_info_from_bundle_by_appid(appId, kb);
- if (menu_info == NULL) {
- _D("package not found");
- goto end;
- }
-
- app_path = _get_app_path(menu_info);
- if(app_path == NULL) {
- _E("app_path is NULL");
- goto end;
- }
- if (app_path[0] != '/') {
- _D("app_path is not absolute path");
- goto end;
- }
-
- __modify_bundle(kb, cr.pid, menu_info, pkt->cmd);
- appId = _get_appid(menu_info);
-
- _D("start %s: type=%s caller_uid=%d path=%s",appId,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) {
- PERF("fork done");
- _D("lock up test log(no error) : fork done");
-
- close(clifd);
- close(main_fd);
- close(sigchld_fd);
- __signal_unblock_sigchld();
- __signal_fini();
-
- snprintf(sock_path, UNIX_PATH_MAX, "/run/user/%d/%d", getuid(), getpid());
- unlink(sock_path);
-
- PERF("prepare exec - first done");
- _D("lock up test log(no error) : prepare exec - first done");
-
- if (__prepare_exec(appId, app_path,
- menu_info, kb) < 0) {
- SECURE_LOGE("preparing work fail to launch - "
- "can not launch %s\n", appId);
- exit(-1);
- }
-
- PERF("prepare exec - second done");
- _D("lock up test log(no error) : prepare exec - second done");
-
- __real_launch(app_path, kb);
-
- exit(-1);
- }
- SECURE_LOGD("==> real launch pid : %d %s\n", pid, app_path);
- is_real_launch = 1;
- }
- end:
- __send_result_to_caller(clifd, pid);
-
- if (pid > 0) {
- if (is_real_launch) {
- /*TODO: retry*/
- __send_app_launch_signal_dbus(pid);
-
- __add_history(appId, app_path, pkt->data);
- }
- }
-
- if (menu_info != NULL)
- _free_app_info_from_db(menu_info);
-
- if (kb != NULL)
- bundle_free(kb);
- if (pkt != NULL)
- free(pkt);
-
- if (initialized > AUL_POLL_CNT) {
- malloc_trim(0);
- initialized = 1;
- }
-
-}
-
-_static_ int __agent_pre_init(int argc, char **argv)
-{
- int fd;
- char socket_path[PATH_MAX];
- /* signal init*/
- __signal_init();
-
- /* 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 */
-
- fd = __create_sock_activation();
- if (fd == -1) {
- _D("Create server socket without socket activation");
- snprintf(socket_path, sizeof(socket_path),
- "/run/user/%d/amd_agent", getuid());
- fd = __create_server_sock_by_path(socket_path);
- }
- if (fd < 0) {
- _E("server sock error");
- return -1;
- }
-
- if (rua_init()) {
- _E("rua init failed");
- return fd;
- }
-
- return fd;
-}
-
-static void __send_dead_siganl_to_amd(void)
-{
- bundle *kb;
-
- kb = bundle_create();
- app_send_cmd_with_noreply(AUL_UTIL_PID, AGENT_DEAD_SIGNAL, kb);
- bundle_free(kb);
-}
-
-int main(int argc, char **argv)
-{
- int main_fd;
- int sigchld_fd;
- struct pollfd pfds[POLLFD_MAX];
- int i;
-
- _D("amd_session_agent starting");
-
- /* init without concerning X & EFL*/
- main_fd = __agent_pre_init(argc, argv);
- if (main_fd < 0) {
- _E("agent pre init failed");
- exit(-1);
- }
-
- pfds[MAIN_FD].fd = main_fd;
- pfds[MAIN_FD].events = POLLIN;
- pfds[MAIN_FD].revents = 0;
-
- sigchld_fd = __signal_get_sigchld_fd();
- if (sigchld_fd < 0) {
- _E("get sigchld fd failed");
- exit(-1);
- }
-
- pfds[SIGCHLD_FD].fd = sigchld_fd;
- pfds[SIGCHLD_FD].events = POLLIN;
- pfds[SIGCHLD_FD].revents = 0;
-
- while (loop_flag == TRUE) {
- if (poll(pfds, POLLFD_MAX, -1) < 0)
- continue;
-
- for (i = 0; i < POLLFD_MAX; i++) {
- if ((pfds[i].revents & POLLIN) == 0)
- continue;
-
- switch (i) {
- case MAIN_FD:
- __agent_main_loop(pfds);
- break;
- case SIGCHLD_FD:
- __agent_sig_child(pfds[i].fd);
- break;
- }
- }
- }
- __send_dead_siganl_to_amd();
-
- return 0;
-}
-
+++ /dev/null
-/*
- * 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 <sys/signalfd.h>
-#include "launch.h"
-#include "aul_util.h"
-#include "app_signal.h"
-
-static DBusConnection *bus = NULL;
-sigset_t oldmask;
-
-extern void __sigterm_handler(int signo);
-
-static inline void __socket_garbage_collector()
-{
- DIR *dp;
- struct dirent *dentry;
- char tmp[MAX_LOCAL_BUFSZ];
-
- snprintf(tmp, sizeof(tmp), "/run/user/%d", getuid());
- dp = opendir(tmp);
- if (dp == NULL)
- return;
-
- while ((dentry = readdir(dp)) != NULL) {
- if (!isdigit(dentry->d_name[0]))
- continue;
-
- snprintf(tmp, MAX_LOCAL_BUFSZ, "/proc/%s", dentry->d_name);
- if (access(tmp, F_OK) < 0) { /* Flawfinder: ignore */
- snprintf(tmp, MAX_LOCAL_BUFSZ, "/run/user/%d/%s", getuid(),
- dentry->d_name);
- unlink(tmp);
- continue;
- }
- }
- closedir(dp);
-}
-
-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;
-
- message = dbus_message_new_signal(AUL_DBUS_PATH,
- AUL_DBUS_SIGNAL_INTERFACE,
- AUL_DBUS_APPDEAD_SIGNAL);
-
- if (dbus_message_append_args(message,
- DBUS_TYPE_UINT32, &dead_pid,
- DBUS_TYPE_INVALID) == FALSE) {
- _E("Failed to load data error");
- return -1;
- }
-
- if (dbus_connection_send(bus, message, NULL) == FALSE) {
- _E("dbus send error");
- return -1;
- }
-
- dbus_connection_flush(bus);
- dbus_message_unref(message);
-
- _D("send_app_dead_signal_dbus done (pid=%d)\n",dead_pid);
-
- return 0;
-}
-
-static inline int __send_app_launch_signal_dbus(int launch_pid)
-{
- DBusMessage *message;
-
- if (bus == NULL)
- return -1;
-
- message = dbus_message_new_signal(AUL_DBUS_PATH,
- AUL_DBUS_SIGNAL_INTERFACE,
- AUL_DBUS_APPLAUNCH_SIGNAL);
-
- if (dbus_message_append_args(message,
- DBUS_TYPE_UINT32, &launch_pid,
- DBUS_TYPE_INVALID) == FALSE) {
- _E("Failed to load data error");
- return -1;
- }
-
- if (dbus_connection_send(bus, message, NULL) == FALSE) {
- _E("dbus send error");
- return -1;
- }
-
- dbus_connection_flush(bus);
- dbus_message_unref(message);
-
- _D("send_app_launch_signal_dbus done (pid=%d)",launch_pid);
-
- return 0;
-}
-
-static int __sigchild_action(void *data)
-{
- pid_t dead_pid;
- char buf[MAX_LOCAL_BUFSZ];
-
- dead_pid = (pid_t)(intptr_t)data;
- if (dead_pid <= 0)
- goto end;
-
- __send_app_dead_signal_dbus(dead_pid);
-
- snprintf(buf, MAX_LOCAL_BUFSZ, "/run/user/%d/%d", getuid(), dead_pid);
- unlink(buf);
-
- __socket_garbage_collector();
- end:
- return 0;
-}
-
-static void __agent_sig_child(int sigchld_fd)
-{
- struct signalfd_siginfo info;
- ssize_t s;
- int status;
- pid_t child_pid;
- pid_t child_pgid;
-
- s = read(sigchld_fd, &info, sizeof(struct signalfd_siginfo));
- if (s != sizeof(struct signalfd_siginfo)) {
- _E("error reading sigchld info");
- return;
- }
-
- child_pgid = getpgid(info.ssi_pid);
- _D("dead_pid = %d pgid = %d", info.ssi_pid, child_pgid);
-
- while ((child_pid = waitpid(-1, &status, WNOHANG)) > 0) {
- if (child_pid == child_pgid)
- killpg(child_pgid, SIGKILL);
- __sigchild_action((void *)(intptr_t)child_pid);
- }
-
- return;
-}
-
-static inline int __signal_init(void)
-{
- int i;
- DBusError error;
-
- dbus_error_init(&error);
- dbus_threads_init_default();
- 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;
- }
-
- for (i = 0; i < _NSIG; i++) {
- switch (i) {
- /* controlled by sys-assert package*/
- case SIGQUIT:
- case SIGILL:
- case SIGABRT:
- case SIGBUS:
- case SIGFPE:
- case SIGSEGV:
- case SIGPIPE:
- break;
- case SIGTERM:
- signal(SIGTERM, __sigterm_handler);
- break;
- default:
- signal(i, SIG_DFL);
- break;
- }
- }
-
- return 0;
-}
-
-static inline int __signal_get_sigchld_fd(void)
-{
- sigset_t mask;
- int sfd;
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGCHLD);
-
- if (sigprocmask(SIG_BLOCK, &mask, &oldmask) == -1)
- _E("failed to sigprocmask");
-
- sfd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
- if (sfd == -1) {
- _E("failed to create signal for SIGCHLD");
- return -1;
- }
-
- return sfd;
-}
-
-static inline int __signal_unblock_sigchld(void)
-{
- if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
- _E("SIG_SETMASK error");
- return -1;
- }
-
- _D("SIGCHLD unblocked");
- return 0;
-}
-
-static inline int __signal_fini(void)
-{
- if (bus)
- dbus_connection_close(bus);
-
-#ifndef PRELOAD_ACTIVATE
- int i;
- for (i = 0; i < _NSIG; i++)
- signal(i, SIG_DFL);
-#endif
- return 0;
-}
-
+++ /dev/null
-/*
- * 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 PREEXEC_ACTIVATE
-
-#include <dlfcn.h>
-#include <glib.h>
-#define PREEXEC_FILE SHARE_PREFIX"/preexec_list.txt"
-
-static int preexec_initialized = 0;
-
-GSList *preexec_list = NULL;
-
-typedef struct _preexec_list_t {
- char *pkg_type;
- char *so_path;
- int (*dl_do_pre_exe) (char *, char *);
-} preexec_list_t;
-
-static void __preexec_list_free(void)
-{
- GSList *iter = NULL;
- preexec_list_t *type_t;
-
- for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
- type_t = iter->data;
- if (type_t) {
- if (type_t->pkg_type)
- free(type_t->pkg_type);
- if (type_t->so_path)
- free(type_t->so_path);
- free(type_t);
- }
- }
- g_slist_free(preexec_list);
- preexec_initialized = 0;
- return;
-}
-
-static inline void __preexec_init(int argc, char **argv)
-{
- void *handle = NULL;
- FILE *preexec_file;
- char *saveptr = NULL;
- char line[MAX_LOCAL_BUFSZ];
- char *type = NULL;
- char *sopath = NULL;
- char *symbol = NULL;
- int (*func) (char *, char *) = NULL;
- preexec_list_t *type_t = NULL;
-
- preexec_file = fopen(PREEXEC_FILE, "rt");
- if (preexec_file == NULL) {
- _E("no preexec\n");
- return;
- }
-
- _D("preexec start\n");
-
- while (fgets(line, MAX_LOCAL_BUFSZ, preexec_file) > 0) {
- /* Parse each line */
- if (line[0] == '#' || line[0] == '\0')
- continue;
-
- type = strtok_r(line, ":\f\n\r\t\v ", &saveptr);
- if (type == NULL)
- continue;
- sopath = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
- if (sopath == NULL)
- continue;
- symbol = strtok_r(NULL, ",\f\n\r\t\v ", &saveptr);
- if (symbol == NULL)
- continue;
-
- type_t = (preexec_list_t *) calloc(1, sizeof(preexec_list_t));
- if (type_t == NULL) {
- _E("no available memory\n");
- __preexec_list_free();
- fclose(preexec_file);
- return;
- }
-
- handle = dlopen(sopath, RTLD_NOW);
- if (handle == NULL) {
- free(type_t);
- continue;
- }
- _D("preexec %s %s# - handle : %x\n", type, sopath, handle);
-
- func = dlsym(handle, symbol);
- if (func == NULL) {
- _E("failed to get symbol type:%s path:%s\n",
- type, sopath);
- free(type_t);
- dlclose(handle);
- handle = NULL;
- continue;
- }
-
- type_t->pkg_type = strdup(type);
- if (type_t->pkg_type == NULL) {
- _E("no available memory\n");
- free(type_t);
- __preexec_list_free();
- fclose(preexec_file);
- return;
- }
- type_t->so_path = strdup(sopath);
- if (type_t->so_path == NULL) {
- _E("no available memory\n");
- free(type_t->pkg_type);
- free(type_t);
- __preexec_list_free();
- fclose(preexec_file);
- return;
- }
- type_t->dl_do_pre_exe = func;
-
- preexec_list = g_slist_append(preexec_list, (void *)type_t);
- }
-
- fclose(preexec_file);
- preexec_initialized = 1;
-}
-
-static inline void __preexec_run(const char *pkg_type, const char *appid,
- const char *app_path)
-{
- GSList *iter = NULL;
- preexec_list_t *type_t;
-
- if (!preexec_initialized)
- return;
-
- for (iter = preexec_list; iter != NULL; iter = g_slist_next(iter)) {
- type_t = iter->data;
- if (type_t) {
- if (!strcmp(pkg_type, type_t->pkg_type)) {
- if (type_t->dl_do_pre_exe != NULL) {
- type_t->dl_do_pre_exe((char *)appid,
- (char *)app_path);
- _D("called dl_do_pre_exe() type: %s",
- pkg_type);
- } else {
- _E("no symbol for this type: %s",
- pkg_type);
- }
- }
- }
- }
-
-}
-
-#else
-static inline void __preexec_init(int argc, char **argv)
-{
-}
-
-static inline void __preexec_run(const char *pkg_type, const char *appid,
- const char *app_path)
-{
-}
-
-#endif