summaryrefslogtreecommitdiffstats
path: root/mqueue_push.c
diff options
context:
space:
mode:
Diffstat (limited to 'mqueue_push.c')
-rw-r--r--mqueue_push.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/mqueue_push.c b/mqueue_push.c
new file mode 100644
index 0000000..4f0e976
--- /dev/null
+++ b/mqueue_push.c
@@ -0,0 +1,110 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <getopt.h>
+#include <unistd.h>
+#include <mqueue.h>
+#include <errno.h>
+
+typedef struct {
+ char *f_mqname;
+ char *f_push;
+ int f_verbose;
+ int f_helper;
+} mqueue_params;
+
+mqueue_params g_params;
+
+void helper(char *progname)
+{
+ printf("Usage: %s [OPTS] VALUE\n\n"
+ "Version: 0.0.1 \n"
+ "-m mqueue name\n"
+ "-v verbose output\n"
+ "-p push value\n"
+ "-h help options\n"
+ "\n"
+ , progname);
+}
+
+#define full_mqpath_len 1024
+
+int main(int argc, char **argv)
+{
+ //stack params
+ int c,err;
+ int i;
+ int mq_fd;
+ char full_mqpath[full_mqpath_len];
+ int prio=10;
+ char *push_val="NONE";
+ int push_size=strlen(push_val);
+
+
+ memset(&g_params,0,sizeof(g_params));
+
+ //process arguments
+ while ((c = getopt(argc, argv, "m:vhp:")) != -1)
+ {
+ switch (c)
+ {
+ case 'm':
+ g_params.f_mqname = optarg;
+ break;
+ case 'v':
+ g_params.f_verbose = 1;
+ break;
+ case 'p':
+ g_params.f_push = optarg;
+ break;
+ case 'h':
+ default:
+ helper(argv[0]);
+ exit(1);
+ }
+ }
+
+ if (g_params.f_helper)
+ {
+ helper(argv[0]);
+ return 0;
+ }
+
+ //set mqueue name
+ if (g_params.f_mqname == NULL)
+ {
+ g_params.f_mqname = "/stack-0";
+ }
+
+ //compose string
+ memset(&full_mqpath[0], 0, full_mqpath_len);
+ snprintf(&full_mqpath[0], full_mqpath_len-1, "%s", g_params.f_mqname);
+ if (g_params.f_verbose)
+ {
+ printf("Full path: %s\n",&full_mqpath);
+ }
+
+ mq_fd = mq_open(g_params.f_mqname,O_RDWR | O_CREAT, 0666, NULL);
+ err = errno;
+ if (mq_fd == -1)
+ {
+ if (g_params.f_verbose)
+ {
+ printf("ERROR:%d,%s\n",err,strerror(err));
+ }
+ return -1;
+ }
+ printf("%s\n",g_params.f_mqname);
+
+ if (g_params.f_push != NULL)
+ {
+ push_val = g_params.f_push;
+ push_size = strlen(push_val);
+ }
+
+ mq_send(mq_fd, push_val, push_size, prio);
+
+ close(mq_fd);
+
+ return 0;
+} \ No newline at end of file