Add possibility to choose pipe owner;
authorRinat Dobrokhotov <rdobrokhotov@dev.rtsoft.ru>
Thu, 28 Jun 2018 13:54:54 +0000 (16:54 +0300)
committerPetr Bred/AI Ecosystem Lab /SRR/Staff Engineer/삼성전자 <p.bred@samsung.com>
Mon, 20 Aug 2018 17:01:22 +0000 (20:01 +0300)
profctl.c

index b9e1f28..cfa1aec 100644 (file)
--- a/profctl.c
+++ b/profctl.c
@@ -32,15 +32,18 @@ static char *pname = NULL;
 static char *ename = NULL;
 static const char *oname = NULL;
 
+static int isPipeOwner = 0;
+
 static struct option long_options[] = {
-       {"appid",   required_argument, 0, 'a'},
-       {"pipe",    required_argument, 0, 'p'},
-       {"exec",    required_argument, 0, 'e'},
-       {"error",   required_argument, 0, 'o'},
-       {"timeout", required_argument, 0, 't'},
-       {"verbose", no_argument,       0, 'v'},
-       {"list",    no_argument,       0, 'l'},
-       {"info",    no_argument,       0, 'i'},
+       {"appid",       required_argument, 0, 'a'},
+       {"pipe",        required_argument, 0, 'p'},
+       {"exec",        required_argument, 0, 'e'},
+       {"error",       required_argument, 0, 'o'},
+       {"timeout",     required_argument, 0, 't'},
+       {"verbose",     no_argument,       0, 'v'},
+       {"list",        no_argument,       0, 'l'},
+       {"info",        no_argument,       0, 'i'},
+       {"pipe-owner",  no_argument,       0, 'w'},
        {0,         0,                 0,  0}
 };
 
@@ -71,7 +74,9 @@ static void finish()
        tcsetattr(0,TCSANOW, &sterm);
        if (tf != NULL) {
                fclose(tf);
-               unlink(pname);
+        if (isPipeOwner) {
+                   unlink(pname);
+        }
        }
        kill(getpid(), SIGKILL);
 }
@@ -251,7 +256,7 @@ static int process_option(int argc, char **argv)
 {
        int option_index;
 
-       switch(getopt_long(argc, argv, "-a:p:vle:o:it:",
+       switch(getopt_long(argc, argv, "-a:p:vle:o:it:w",
                long_options, &option_index)) {
        case 1:
                if (appid == NULL) {
@@ -271,6 +276,7 @@ static int process_option(int argc, char **argv)
        case 'l': ListApps(0); exit(0);
        case 'i': doinfo = 1; break;
        case 't': timeout = atoi(optarg); break;
+       case 'w': isPipeOwner = 1; break;
        default:
                return -1;
        }
@@ -430,7 +436,7 @@ int main(int argc, char **argv)
        freopen(oname, "w", stderr);
        setbuf(stderr, NULL);
 
-       if (pname) {
+       if (pname && isPipeOwner) {
                unlink(pname);
                if (mkfifo(pname, 0666)) {
                        perror("mkfifo");