From 0545be8d111c00f5cfd0e78ec13259a408c9bedd Mon Sep 17 00:00:00 2001 From: Rinat Dobrokhotov Date: Thu, 28 Jun 2018 16:54:54 +0300 Subject: [PATCH] Add possibility to choose pipe owner; --- profctl.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/profctl.c b/profctl.c index b9e1f28..cfa1aec 100644 --- 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"); -- 2.7.4