#define MAX_CONNECT_TIMEOUT_TIME 5*60
-int get_comm_pid(void)
-{
- return manager.comm_pid;
-}
-
-void set_comm_pid(int pid)
-{
- manager.comm_pid = pid;
-}
-
-void reset_comm_pid(void)
-{
- set_comm_pid(no_comm_pid);
-}
-
uint64_t get_total_alloc_size_by_pid(pid_t pid)
{
int i;
LOGI("join recv thread %d. done\n", i);
}
}
-
- reset_comm_pid();
}
// terminate all profiling by critical error
static Ecore_Fd_Handler *target_handlers[MAX_TARGET_COUNT];
+
+static int file2str(const char *filename, char *buf, int len)
+{
+ int fd, num_read;
+
+ fd = open(filename, O_RDONLY, 0);
+ if (fd == -1)
+ return -1;
+
+ num_read = read(fd, buf, len - 1);
+
+ close(fd);
+
+ if (num_read <= 0)
+ return -1;
+
+ buf[num_read] = '\0';
+
+ return num_read;
+}
+
+static int get_lpad_pid(int pid)
+{
+ static pid_t lpad_pid = -1;
+ static const char lpad_path[] = DEBUG_LAUNCH_PRELOAD_PATH;
+ enum { lpad_path_len = sizeof(lpad_path) };
+
+ if (lpad_pid == -1) {
+ char fname[64];
+ char buf[lpad_path_len];
+
+ sprintf(fname, "/proc/%d/cmdline", pid);
+ if (-1 == file2str(fname, buf, lpad_path_len))
+ return lpad_pid;
+
+ buf[lpad_path_len - 1] = '\0';
+
+ if (strncmp(buf, lpad_path, lpad_path_len - 1) == 0)
+ lpad_pid = pid;
+ }
+
+ return lpad_pid;
+}
+
+static pid_t get_current_pid(void)
+{
+ static pid_t pid = -1;
+
+ if (pid == -1)
+ pid = getpid();
+
+ return pid;
+}
+
+static void taget_set_type(__da_target_info *taget)
+{
+ if (get_current_pid() == taget->ppid) {
+ taget->app_type = APP_TYPE_COMMON;
+ } else if (get_lpad_pid(taget->ppid) == taget->ppid) {
+ taget->app_type = APP_TYPE_TIZEN;
+ }
+}
+
+
static int target_event_pid_handler(int index, uint64_t msg)
{
struct app_list_t *app = NULL;
struct app_info_t *app_info = NULL;
+
+ taget_set_type(&manager.target[index]);
+
if (index == 0) { // main application
app_info = app_info_get_first(&app);
if (app_info == NULL) {
static int target_event_stop_handler(int index, uint64_t msg)
{
- int cnt, comm_pid;
+ int cnt;
LOGI("target close, socket(%d), pid(%d) : (remaining %d target)\n",
manager.target[index].socket, manager.target[index].pid,
manager.target_count - 1);
- comm_pid = get_comm_pid();
- if (manager.target[index].pid == comm_pid)
- reset_comm_pid();
if (index == 0) // main application
stop_replay();
setEmptyTargetSlot(index);
// all target client are closed
cnt = __sync_sub_and_fetch(&manager.target_count, 1);
- if (0 == cnt && no_comm_pid == comm_pid) {
- LOGI("all targets are stopped\n");
- if (stop_all() != ERR_NO)
- LOGE("Stop failed\n");
- return -11;
+ if (0 == cnt) {
+ switch (manager.target[index].app_type) {
+ case APP_TYPE_TIZEN:
+ case APP_TYPE_COMMON:
+ LOGI("all targets are stopped\n");
+ if (stop_all() != ERR_NO)
+ LOGE("Stop failed\n");
+ return -11;
+ }
}
return 0;
{
int64_t allocmem; // written only by recv thread
pid_t pid; // written only by recv thread
+ pid_t ppid; // written only by recv thread
int socket; // written only by main thread
pthread_t recv_thread; // written only by main thread
int event_fd; // for thread communication (from recv thread to main thread)
int initial_log; // written only by main thread
+ enum app_type_t app_type;
} __da_target_info;
typedef struct
typedef struct
{
- int comm_pid;
int host_server_socket;
int target_server_socket;
int target_count;
extern __da_manager manager;
-enum { no_comm_pid = -1 };
-
-int get_comm_pid(void);
-void set_comm_pid(int pid);
-void reset_comm_pid(void);
-
-
uint64_t get_total_alloc_size(void);
void initialize_log(void);
int daemonLoop(void);
}
else if(log.type == MSG_PID)
{
- LOGI("MSG_PID arrived : %s\n", log.data);
+ LOGI("MSG_PID arrived (pid ppid): %s\n", log.data);
// only when first MSG_PID is arrived
if(target->pid == -1)
{
- char* barloc;
- barloc = strchr(log.data, '|');
- if(barloc == NULL)
+ int n;
+ pid_t pid, ppid;
+
+ n = sscanf(log.data, "%d %d", &pid, &ppid);
+ if (n != 2)
{
/**
* TODO: complain to host about wrong
sizeof(uint64_t));
break;
}
- barloc[0] = '\0';
- barloc++;
- target->pid = atoi(log.data);
+ /* set pid and ppid */
+ target->pid = pid;
+ target->ppid = ppid;
+
+ /* send event */
event = EVENT_PID;
write(target->event_fd, &event, sizeof(uint64_t));
}