From: greatim Date: Fri, 31 May 2013 11:24:45 +0000 (+0900) Subject: [Title] fix some bugs X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ba2ff871eacae9012a5a56bd170a7d09318c2cb;p=sdk%2Ftarget%2Fdynamic-analysis-manager.git [Title] fix some bugs [Desc.] [Issue] Change-Id: I74a4c68e95c68258db198d3704fca312da118716 --- diff --git a/daemon/daemon.c b/daemon/daemon.c index fd90d85..0121860 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -37,6 +37,7 @@ #include // for mkdir #include // for eventfd #include // for epoll apis +#include // for timerfd #include // for access, sleep #include // for fsetxattr #include @@ -53,6 +54,7 @@ #define EPOLL_SIZE 10 #define MAX_CONNECT_SIZE 12 +#define MAX_APP_LAUNCH_TIME 6 #define INPUT_ID_TOUCH 0 #define INPUT_ID_KEY 1 @@ -325,16 +327,16 @@ static int startProfiling(long launchflag) #else get_executable(manager.appPath, execPath, PATH_MAX); #endif - if(exec_app(execPath, get_app_type(manager.appPath))) + if(samplingStart() < 0) + return -1; + + if(exec_app(execPath, get_app_type(manager.appPath)) == 0) { - if(samplingStart() < 0) - { - return -1; - } - LOGI("Timer Started\n"); - } - else + samplingStop(); return -1; + } + + LOGI("Timer Started\n"); return 0; } @@ -555,7 +557,7 @@ static int parseHostMessage(msg_t* log, char* msg) // return 0 if normal case // return plus value if non critical error occur // return minus value if critical error occur -static int hostMessageHandler(msg_t* log) +static int hostMessageHandler(int efd, msg_t* log) { int ret = 0; long flag = 0; @@ -631,6 +633,7 @@ static int hostMessageHandler(msg_t* log) { char command[PATH_MAX]; + struct epoll_event ev; //save app install path mkdir(DA_WORK_DIR, 0775); @@ -651,6 +654,35 @@ static int hostMessageHandler(msg_t* log) sendACKCodeToHost(MSG_NOTOK, ERR_CANNOT_START_PROFILING); return -1; } + + manager.app_launch_timerfd = timerfd_create(CLOCK_REALTIME, TFD_CLOEXEC); + if(manager.app_launch_timerfd > 0) + { + struct itimerspec ctime; + ctime.it_value.tv_sec = MAX_APP_LAUNCH_TIME; + ctime.it_value.tv_nsec = 0; + ctime.it_interval.tv_sec = 0; + ctime.it_interval.tv_nsec = 0; + if(0 > timerfd_settime(manager.app_launch_timerfd, 0, &ctime, NULL)) + { + LOGE("fail to set app launch timer\n"); + close(manager.app_launch_timerfd); + manager.app_launch_timerfd = -1; + } + else + { + // add event fd to epoll list + ev.events = EPOLLIN; + ev.data.fd = manager.app_launch_timerfd; + if(epoll_ctl(efd, EPOLL_CTL_ADD, manager.app_launch_timerfd, &ev) < 0) + { + // fail to add event fd + LOGE("fail to add app launch timer fd to epoll list\n"); + close(manager.app_launch_timerfd); + manager.app_launch_timerfd = -1; + } + } + } } sendACKStrToHost(MSG_OK, NULL); break; @@ -809,8 +841,8 @@ static int targetEventHandler(int epollfd, int index, uint64_t msg) log.length = sprintf(log.data, "%d`,%Lu", manager.target[index].pid, manager.target[index].starttime); } - manager.target[index].initial_log = 1; sendDataToHost(&log); + manager.target[index].initial_log = 1; } if(msg & EVENT_STOP || msg & EVENT_ERROR) @@ -890,6 +922,13 @@ static int targetServerHandler(int efd) goto TARGET_CONNECT_FAIL; } + if(manager.app_launch_timerfd >= 0) + { + epoll_ctl(efd, EPOLL_CTL_DEL, manager.app_launch_timerfd, NULL); + close(manager.app_launch_timerfd); + manager.app_launch_timerfd = -1; + } + LOGI("target connected = %d(running %d target)\n", manager.target[index].socket, manager.target_count + 1); @@ -965,7 +1004,7 @@ static int hostServerHandler(int efd) // return plus value if non critical error occur // return minus value if critical error occur // return -11 if socket closed -static int controlSocketHandler() +static int controlSocketHandler(int efd) { ssize_t recvLen; char recvBuf[DA_MSG_MAX]; @@ -987,7 +1026,7 @@ static int controlSocketHandler() } // host msg command handling - return hostMessageHandler(&log); + return hostMessageHandler(efd, &log); } else // close request from HOST { @@ -1171,7 +1210,7 @@ int daemonLoop() // control message from host else if(events[i].data.fd == manager.host.control_socket) { - int result = controlSocketHandler(); + int result = controlSocketHandler(efd); if(result == -11) // socket close { // close target and host socket and quit @@ -1200,6 +1239,17 @@ int daemonLoop() LOGW("host message from data socket %d\n", recvLen); } + // check for application launch timerfd + else if(events[i].data.fd == manager.app_launch_timerfd) + { + // send to host timeout error message for launching application + terminate_error("Failed to launch application", 1); + epoll_ctl(efd, EPOLL_CTL_DEL, manager.app_launch_timerfd, NULL); + close(manager.app_launch_timerfd); + manager.app_launch_timerfd = -1; + ret = -1; + goto END_EFD; + } // unknown socket else { diff --git a/daemon/daemon.h b/daemon/daemon.h index 9e5c3cf..8de1bb7 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -52,6 +52,7 @@ enum ErrorCode ERR_INITIALIZE_SYSTEM_INFO_FAILED = -103, ERR_HOST_SERVER_SOCKET_CREATE_FAILED = -104, ERR_TARGET_SERVER_SOCKET_CREATE_FAILED = -105, + ERR_SIGNAL_MASK_SETTING_FAILED = -106, ERR_WRONG_MESSAGE_FORMAT = -201, ERR_WRONG_MESSAGE_TYPE = -202, ERR_WRONG_MESSAGE_DATA = -203, @@ -175,6 +176,7 @@ typedef struct int target_server_socket; int target_count; unsigned int config_flag; + int app_launch_timerfd; pthread_t sampling_thread; __da_host_info host; __da_target_info target[MAX_TARGET_COUNT]; diff --git a/daemon/main.c b/daemon/main.c index 17b2fb9..a06d4e9 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -52,9 +52,10 @@ // initialize global variable __da_manager manager = { - NULL, -1, -1, // portfile pointer, host / target server socket + NULL, -1, -1, // portfile pointer, host / target server socket 0, // target count 0, // config_flag + -1, // app launch timerfd -1, // sampling_thread handle {-1, -1, PTHREAD_MUTEX_INITIALIZER}, // host {{0L, }, }, // target @@ -231,6 +232,7 @@ static int singleton(void) static int initializeManager() { int i; + sigset_t newsigmask; atexit(_close_server_socket); @@ -258,6 +260,16 @@ static int initializeManager() writeToPortfile(i); } + // initialize signal mask + sigemptyset(&newsigmask); + sigaddset(&newsigmask, SIGALRM); + sigaddset(&newsigmask, SIGUSR1); + if(pthread_sigmask(SIG_BLOCK, &newsigmask, NULL) != 0) + { + writeToPortfile(ERR_SIGNAL_MASK_SETTING_FAILED); + return -1; + } + LOGI("SUCCESS to write port\n"); // initialize target client sockets diff --git a/daemon/threads.c b/daemon/threads.c index 11dbc74..26cd7ce 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -253,21 +253,11 @@ static void* samplingThread(void* data) // return plus value if non-critical error int samplingStart() { - sigset_t newsigmask; struct itimerval timerval; if(manager.sampling_thread != -1) // already started return 1; - sigemptyset(&newsigmask); - sigaddset(&newsigmask, SIGALRM); - sigaddset(&newsigmask, SIGUSR1); - if(pthread_sigmask(SIG_BLOCK, &newsigmask, NULL) != 0) - { - LOGE("Failed to signal masking for main thread\n"); - return -1; - } - if(pthread_create(&(manager.sampling_thread), NULL, samplingThread, NULL) < 0) { LOGE("Failed to create sampling thread\n"); @@ -288,11 +278,6 @@ int samplingStop() if(manager.sampling_thread != -1) { struct itimerval stopval; -// int status; -// sigset_t oldsigmask; -// sigemptyset(&oldsigmask); -// sigaddset(&oldsigmask, SIGALRM); -// sigaddset(&oldsigmask, SIGUSR1); // stop timer stopval.it_interval.tv_sec = 0; @@ -304,11 +289,6 @@ int samplingStop() pthread_kill(manager.sampling_thread, SIGUSR1); pthread_join(manager.sampling_thread, NULL); - // this code commented because this phrase occurs an error -// if(sigprocmask(SIG_UNBLOCK, &oldsigmask, NULL) < 0) -// { -// LOGE("Failed to pthread_sigmask\n"); -// } manager.sampling_thread = -1; }