summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
Diffstat (limited to 'tool')
-rw-r--r--tool/mqtool.c53
1 files changed, 51 insertions, 2 deletions
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;
@@ -179,5 +197,36 @@ int main(int argc, char **argv)
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);
+ }
} \ No newline at end of file