From: Aleksei Vereshchagin Date: Wed, 15 Aug 2018 16:49:33 +0000 (+0300) Subject: Add TIZEN building option X-Git-Tag: submit/tizen/20180911.125435~36 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0b650c4aba7fdcd2eb09bfcc6ccddc2e17a3e9d6;p=sdk%2Ftools%2Fprofctl.git Add TIZEN building option --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cc19bb..bb5ef9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) PROJECT("profctl") MESSAGE("CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") @@ -16,13 +16,18 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_C_FLAGS_DEBUG "-O2 -g") SET(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") +OPTION(TIZEN "Tizen platform" ON) +ADD_DEFINITIONS(-DTIZEN=$) + SET(PROFCTL "profctl") SET(${PROFCTL}_SOURCE_FILES profctl.c ) ADD_EXECUTABLE(${PROFCTL} ${${PROFCTL}_SOURCE_FILES}) SET_TARGET_PROPERTIES(${PROFCTL} PROPERTIES COMPILE_FLAGS "-fPIE") -TARGET_LINK_LIBRARIES(${PROFCTL} aul) +IF(${TIZEN}) + TARGET_LINK_LIBRARIES(${PROFCTL} aul) +ENDIF(${TIZEN}) TARGET_LINK_LIBRARIES(${PROFCTL} ${${PROJECT_NAME}_LDFLAGS} "-pie -lpthread") SET_TARGET_PROPERTIES(${PROFCTL} diff --git a/profctl.c b/profctl.c index 8e6bbdc..2c9d6c3 100644 --- a/profctl.c +++ b/profctl.c @@ -1,5 +1,9 @@ #define _GNU_SOURCE +#ifndef TIZEN +#define TIZEN 1 +#endif + #include #include #include @@ -7,8 +11,11 @@ #include #include #include + +#if TIZEN #include #include +#endif /* TIZEN */ #include #include @@ -26,7 +33,9 @@ static int verbose = 0; static int doinfo = 0; static int timeoutMicrosec = 500000; // 0.5 seconds static int pid = -1; +#if TIZEN static struct termios sterm; +#endif /* TIZEN */ static char *appid = NULL; static char *pname = NULL; @@ -63,16 +72,20 @@ static void *output_thread(void *arg) exit(0); } +#if TIZEN static void *wait_thread(void *arg) { while (aul_app_get_status_bypid(pid) >= 0) sleep(1); exit(0); } +#endif /* TIZEN */ static void finish() { +#if TIZEN tcsetattr(0,TCSANOW, &sterm); +#endif /* TIZEN */ if (tf != NULL) { fclose(tf); if (isPipeOwner) { @@ -282,6 +295,7 @@ static void CheckValue(char **value, const char *info) value[0] = optarg; } +#if TIZEN static int output_app_info(const aul_app_info *info, void *data) { if (info == NULL || info->appid == NULL) @@ -290,10 +304,13 @@ static int output_app_info(const aul_app_info *info, void *data) info->pid, info->status, info->appid); return 0; } +#endif /* TIZEN */ static int ListApps(int n) { +#if TIZEN aul_app_get_all_running_app_info(output_app_info, NULL); +#endif /* TIZEN */ exit(0); } @@ -345,6 +362,7 @@ static void SimpleThread(void* (*func)(void *)) } +#if TIZEN static int find_pid(const aul_app_info *info, void *data) { if (!strcmp(appid, info->appid)) { @@ -374,7 +392,6 @@ static void waitappid(int n) exit(1); } -#if 1 static int app_launch_handler(int npid, const char *app_id, void *data) { if (verbose) { @@ -401,7 +418,7 @@ static int app_dead_handler(int npid, void *data) exit(0); return 1; } -#endif +#endif /* TIZEN */ static void openFileProcess() { @@ -463,16 +480,20 @@ static void openFileProcess() int main(int argc, char **argv) { +#if TIZEN struct termios term; +#endif /* TIZEN */ char *line = NULL; size_t len = 0; while(!process_option(argc, argv)); +#if TIZEN if (appid == NULL) { fprintf(stderr, "Unknown app id\n"); exit(1); } +#endif /* TIZEN */ if (oname == NULL) { oname = "/tmp/profctl.log"; @@ -487,13 +508,16 @@ int main(int argc, char **argv) perror("mkfifo"); exit(1); } +#if TIZEN /* This may be useful for "root on" start */ if (setxattr(pname, "security.SMACK64", "User::App::Shared", strlen("User::App::Shared"),0)) { perror("setattr"); } +#endif /* TIZEN */ } +#if TIZEN /* stty */ tcgetattr(0, &term); sterm = term; @@ -502,6 +526,7 @@ int main(int argc, char **argv) term.c_oflag &= ~OPOST; /* no additional CR and so on */ tcsetattr(0,TCSANOW, &term); +#endif /* TIZEN */ atexit(finish); @@ -510,10 +535,10 @@ int main(int argc, char **argv) SimpleThread(&output_thread); } -#if 1 +#if TIZEN aul_listen_app_launch_signal_v2(app_launch_handler, NULL); aul_listen_app_dead_signal(app_dead_handler, NULL); -#endif +#endif /* TIZEN */ /* Read command loop */ while((len = getline(&line, &len, stdin)) != -1) { @@ -533,7 +558,11 @@ int main(int argc, char **argv) if (kill(pid, SIGRTMIN+7)) perror("kill"); } else if (!strncmp(line, "test", 4) && (pid == -1)) { +#if TIZEN waitappid(10); /* try 10 seconds */ +#else + pid = getpid(); +#endif /* TIZEN */ if (verbose) { fprintf(stderr, "pid = %d\n", pid); }