char *loader_name;
} appinfo_t;
-char *_proc_get_cmdline_bypid(int pid);
void _modify_bundle(bundle *kb, int caller_pid, appinfo_t *menu_info, int cmd);
int _create_server_sock(const char *name);
void _set_env(appinfo_t *menu_info, bundle *kb);
char **_create_argc_argv(bundle *kb, int *margc);
char *_get_libdir(const char *path);
-void _prepare_listen_sock(void);
int _delete_sock_path(int pid, uid_t uid);
appinfo_t *_appinfo_create(bundle *kb);
void _appinfo_free(appinfo_t *menu_info);
char *_appinfo_get_app_path(appinfo_t *menu_info);
int _proc_get_attr_by_pid(int pid, char *buf, int size);
-int _close_all_fds(int except);
+int _close_all_fds(void);
void _get_cpu_idle(long long *total, long long *idle);
int _mount_legacy_app_path(const char *app_root_path,
static void __send_result_to_caller(int clifd, int ret, const char *app_path)
{
- char *cmdline;
- int count = 0;
- char path[PATH_MAX];
-
- _W("Check app launching");
+ _W("send result: %d", ret);
if (clifd == -1)
return;
return;
}
- snprintf(path, sizeof(path), "/run/aul/apps/%d/%d/.app-sock",
- getuid(), ret);
- _D("socket path: %s", path);
- do {
- if (access(path, F_OK) == 0) {
- _D("%s exists", path);
- break;
- }
-
- _D("-- now wait socket creation --");
- usleep(50 * 1000);
- count++;
- } while (count < 20);
-
- cmdline = _proc_get_cmdline_bypid(ret);
- if (cmdline == NULL) {
- _E("The app process might be terminated while we are wating %d",
- ret);
- __real_send(clifd, -1); /* abnormally launched*/
- return;
- }
-
if (__real_send(clifd, ret) < 0)
__kill_process(ret);
}
__signal_unblock_sigchld();
__signal_fini();
- _close_all_fds(0);
+ _close_all_fds();
if (execv(argv[LOADER_ARG_PATH], argv) < 0)
_E("Failed to prepare candidate_process");
if (*file_name == '\0')
return PAD_ERR_INVALID_PATH;
- _prepare_listen_sock();
-
memset(process_name, '\0', AUL_PR_NAME);
snprintf(process_name, AUL_PR_NAME, "%s", file_name);
prctl(PR_SET_NAME, process_name);
__signal_unblock_sigchld();
__signal_fini();
- _close_all_fds(0);
+ _close_all_fds();
_delete_sock_path(getpid(), getuid());
ret = _mount_legacy_app_path(launch_arg->menu_info->root_path,
#include "key.h"
#define MAX_PATH_LEN 1024
-#define BINSH_NAME "/bin/sh"
-#define BINSH_SIZE 7
-#define VALGRIND_NAME "/home/developer/sdk_tools/valgrind/usr/bin/valgrind"
-#define VALGRIND_SIZE 51
-#define BASH_NAME "/bin/bash"
-#define BASH_SIZE 9
-#define OPROFILE_NAME "/usr/bin/oprofile_command"
-#define OPROFILE_SIZE 25
-#define OPTION_VALGRIND_NAME "valgrind"
-#define OPTION_VALGRIND_SIZE 8
#define MAX_CMD_BUFSZ 1024
#define LEGACY_APP_ROOT_PATH "/opt/usr/apps"
{
struct sockaddr_un saddr;
int fd;
- int ret;
- if (name)
- fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- else
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
/* support above version 2.6.27*/
if (fd < 0) {
if (errno == EINVAL) {
memset(&saddr, 0, sizeof(saddr));
saddr.sun_family = AF_UNIX;
- if (name) {
- snprintf(saddr.sun_path, sizeof(saddr.sun_path),
- "%s/daemons/%d/%s",
- SOCKET_PATH, getuid(), name);
- } else {
- snprintf(saddr.sun_path, sizeof(saddr.sun_path),
- "%s/apps/%d/%d",
- SOCKET_PATH, getuid(), getpid());
- ret = mkdir(saddr.sun_path, 0700);
- if (ret != 0) {
- if (errno == EEXIST) {
- if (access(saddr.sun_path, R_OK) != 0) {
- _E("Failed to access %s directory - %d",
- saddr.sun_path, errno);
- close(fd);
- return -1;
- }
- } else {
- _E("Failed to create %s directory - %d",
- saddr.sun_path, errno);
- close(fd);
- return -1;
- }
- }
- snprintf(saddr.sun_path, sizeof(saddr.sun_path),
- "%s/apps/%d/%d/.app-sock",
- SOCKET_PATH, getuid(), getpid());
- }
+ snprintf(saddr.sun_path, sizeof(saddr.sun_path),
+ "%s/daemons/%d/%s",
+ SOCKET_PATH, getuid(), name);
unlink(saddr.sun_path);
if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
return -1;
}
-char *_proc_get_cmdline_bypid(int pid)
-{
- char buf[MAX_CMD_BUFSZ];
- int ret;
- char *ptr;
- int len;
-
- snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
- ret = __read_proc(buf, buf, sizeof(buf));
- if (ret <= 0)
- return NULL;
-
- /* support app launched by shell script*/
- if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0)
- return strdup(&buf[BINSH_SIZE + 1]);
- else if (strncmp(buf, VALGRIND_NAME, VALGRIND_SIZE) == 0) {
- ptr = buf;
-
- /* buf comes with double null-terminated string */
- while (1) {
- while (*ptr)
- ptr++;
- ptr++;
-
- if (!(*ptr))
- break;
-
- /* ignore trailing "--" */
- if (strncmp(ptr, "-", 1) != 0)
- break;
- }
-
- return strdup(ptr);
- } else if (strncmp(buf, BASH_NAME, BASH_SIZE) == 0) {
- if (strncmp(&buf[BASH_SIZE + 1], OPROFILE_NAME,
- OPROFILE_SIZE) == 0) {
- if (strncmp(&buf[BASH_SIZE + OPROFILE_SIZE + 2],
- OPTION_VALGRIND_NAME,
- OPTION_VALGRIND_SIZE) == 0) {
- len = BASH_SIZE + OPROFILE_SIZE +
- OPTION_VALGRIND_SIZE + 3;
- return strdup(&buf[len]);
- }
- }
- }
-
- return strdup(buf);
-}
-
appinfo_t *_appinfo_create(bundle *kb)
{
appinfo_t *menu_info;
return 0;
}
-void _prepare_listen_sock(void)
-{
- int fd;
- char buf[12];
-
- fd = _create_server_sock(NULL);
- if (fd < 0)
- return;
-
- snprintf(buf, sizeof(buf), "%d", fd);
- setenv("AUL_LISTEN_SOCK", buf, 1);
-}
-
static int __delete_dir(const char *path)
{
DIR *dp;
return 0;
}
-int _close_all_fds(const int except)
+int _close_all_fds(void)
{
DIR *dp;
struct dirent dentry;
if (dp == NULL) {
/* fallback */
max_fd = sysconf(_SC_OPEN_MAX);
- for (fd = 3; fd < max_fd; fd++) {
- if (fd != except)
- close(fd);
- }
+ for (fd = 3; fd < max_fd; fd++)
+ close(fd);
return 0;
}
if (fd == dirfd(dp))
continue;
- if (fd == except)
- continue;
-
close(fd);
}
closedir(dp);