Add TIZEN building option
authorAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Wed, 15 Aug 2018 16:49:33 +0000 (19:49 +0300)
committerAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Tue, 28 Aug 2018 22:24:18 +0000 (01:24 +0300)
CMakeLists.txt
profctl.c

index 3cc19bba63fe206e406a749c7b5fcdb705ba035d..bb5ef9d8306bea0b78537c720437a61361b2a6e4 100644 (file)
@@ -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=$<BOOL:${TIZEN}>)
+
 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}
index 8e6bbdcd3307e8a8a3f3d56c96707f3457d4e45f..2c9d6c381e88baa59bd79a1f7643c66ccf8256c3 100644 (file)
--- a/profctl.c
+++ b/profctl.c
@@ -1,5 +1,9 @@
 #define _GNU_SOURCE
 
+#ifndef TIZEN
+#define TIZEN 1
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -7,8 +11,11 @@
 #include <getopt.h>
 #include <signal.h>
 #include <pthread.h>
+
+#if TIZEN
 #include <termios.h>
 #include <aul/aul.h>
+#endif /* TIZEN */
 
 #include <sys/time.h>
 #include <sys/types.h>
@@ -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);
                        }