From 0397a4c9dee0300e0ee843fe85aa4c2d77630758 Mon Sep 17 00:00:00 2001 From: ZoRo Date: Tue, 7 Feb 2017 08:32:09 +0000 Subject: Added matching table for executed commands --- tool/mqtool.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'tool/mqtool.c') diff --git a/tool/mqtool.c b/tool/mqtool.c index 61e78af..76bf660 100644 --- a/tool/mqtool.c +++ b/tool/mqtool.c @@ -45,23 +45,41 @@ int main(int argc, char **argv) char* mqNameClear = NULL; //clear print extra info if there is int flagExtra = 0; - + //send string to queue + int flagSendQueue = 0; + char *mqNameSend = NULL; //mq name where to send + //argument value that to send into queue + int flagSendStr = 0; + char *sStrSend = NULL; //mq string that should be push'ed in queue //get arguments - while ((c = getopt(argc, argv, "elp:c:")) != -1) + while ((c = getopt(argc, argv, "elp:c:s:q:")) != -1) switch(c) { + //list all mqueue's case 'l': flagListAll = 1; break; + //show param of mq case 'p': flagMqParam = 1; mqName = optarg; break; + //get all messages, print out and clean queue case 'c': flagClear = 1; mqNameClear = optarg; break; + //send string to queue + case 's': + flagSendQueue = 1; + mqNameSend = optarg; + break; + case 'q': + flagSendStr = 1; + sStrSend = optarg; + break; + //show extra information if avaliable case 'e': flagExtra = 1; break; @@ -177,6 +195,37 @@ int main(int argc, char **argv) printf("Readed %d messages from %ld\n", iCountMsg, mqAttr.mq_curmsgs); + exit(0); + } + if (flagSendQueue && flagSendStr) + { + size_t szStr=0; + int mqFd = -1; + int numRead = -1; + int prio = 0; + struct mq_attr mqAttr; + + mqFd = mq_open(mqNameSend, O_RDWR, 0666, NULL); + if (mqFd == -1) + { + printf("Cant open %s\n", mqName); + exit(1); + } + + iRet = mq_getattr(mqFd, &mqAttr); + if (iRet == -1) + { + perror("Cant get attributes"); + exit(1); + } + + iRet = mq_send(mqFd, sStrSend, strlen(sStrSend), prio); + if (iRet == -1) + { + perror("Cant send message"); + exit(1); + } + exit(0); } -- cgit v1.2.3