diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2013-12-09 11:22:17 +0100 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2013-12-09 11:22:41 +0100 |
commit | 712ea5d346780062ca46826dc94dbcfc2eb5c65e (patch) | |
tree | a2100b1cc9e24a15940b23a08967330a68603600 /main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch | |
parent | 08f6a0698e1b2dae11ad0e6d8d551f36078ac6b8 (diff) | |
download | aports-712ea5d346780062ca46826dc94dbcfc2eb5c65e.tar.bz2 aports-712ea5d346780062ca46826dc94dbcfc2eb5c65e.tar.xz |
main/mqtt-exec: backport -v support
Diffstat (limited to 'main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch')
-rw-r--r-- | main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch b/main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch new file mode 100644 index 0000000000..e2ea3dbe1e --- /dev/null +++ b/main/mqtt-exec/0001-implement-v-verbose-to-optionally-pass-the-the-topic.patch @@ -0,0 +1,77 @@ +From 9b550ad2043dee35b42d053899fed62b6ac53c92 Mon Sep 17 00:00:00 2001 +From: Natanael Copa <ncopa@alpinelinux.org> +Date: Wed, 4 Dec 2013 15:27:47 +0100 +Subject: [PATCH] implement -v/--verbose to optionally pass the the topic + +--- + mqtt-exec.c | 21 +++++++++++++-------- + 1 file changed, 13 insertions(+), 8 deletions(-) + +diff --git a/mqtt-exec.c b/mqtt-exec.c +index be52ba4..e6ab0ee 100644 +--- a/mqtt-exec.c ++++ b/mqtt-exec.c +@@ -25,9 +25,12 @@ void message_cb(struct mosquitto *mosq, void *obj, + const struct mosquitto_message *msg) + { + struct userdata *ud = (struct userdata *)obj; +- if (msg->payloadlen) { ++ if (msg->payloadlen || ud->verbose) { + if (ud->command_argv && fork() == 0) { +- ud->command_argv[ud->command_argc-1] = msg->payload; ++ if (ud->verbose) ++ ud->command_argv[ud->command_argc-2] = msg->topic; ++ ud->command_argv[ud->command_argc-1] = ++ msg->payloadlen ? msg->payload : NULL; + execv(ud->command_argv[0], ud->command_argv); + perror(ud->command_argv[0]); + _exit(1); +@@ -74,6 +77,7 @@ int main(int argc, char *argv[]) + {"keepalive", required_argument, 0, 'k' }, + {"port", required_argument, 0, 'p' }, + {"topic", required_argument, 0, 't' }, ++ {"verbose", no_argument, 0, 'v' }, + { 0, 0, 0, 0} + }; + int debug = 0; +@@ -91,7 +95,7 @@ int main(int argc, char *argv[]) + memset(hostname, 0, sizeof(hostname)); + memset(id, 0, sizeof(id)); + +- while ((c = getopt_long(argc, argv, "dh:k:p:t:", opts, &i)) != -1) { ++ while ((c = getopt_long(argc, argv, "dh:k:p:t:v", opts, &i)) != -1) { + switch(c) { + case 'd': + debug = 1; +@@ -108,6 +112,9 @@ int main(int argc, char *argv[]) + case 't': + ud.topic = optarg; + break; ++ case 'v': ++ ud.verbose = 1; ++ break; + case '?': + return usage(1); + } +@@ -116,15 +123,13 @@ int main(int argc, char *argv[]) + if ((ud.topic == NULL) || (optind == argc)) + return usage(1); + +- ud.command_argc = (argc - optind) + 1; ++ ud.command_argc = (argc - optind) + 1 + ud.verbose; + ud.command_argv = malloc((ud.command_argc + 1) * sizeof(char *)); + if (ud.command_argv == NULL) + return perror_ret("malloc"); + +- for (i=0; i < ud.command_argc; i++) +- ud.command_argv[i] = argv[optind+i]; +- ud.command_argv[ud.command_argc-1] = NULL; +- ud.command_argv[ud.command_argc] = NULL; ++ for (i=0; i <= ud.command_argc; i++) ++ ud.command_argv[i] = optind+i < argc ? argv[optind+i] : NULL; + + /* generate an id */ + gethostname(hostname, sizeof(hostname)-1); +-- +1.8.5.1 + |