aboutsummaryrefslogtreecommitdiffstats
path: root/main/mqtt-exec/0001-Let-library-generate-client-id-when-unset.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/mqtt-exec/0001-Let-library-generate-client-id-when-unset.patch')
-rw-r--r--main/mqtt-exec/0001-Let-library-generate-client-id-when-unset.patch68
1 files changed, 68 insertions, 0 deletions
diff --git a/main/mqtt-exec/0001-Let-library-generate-client-id-when-unset.patch b/main/mqtt-exec/0001-Let-library-generate-client-id-when-unset.patch
new file mode 100644
index 0000000000..bd6411e5e3
--- /dev/null
+++ b/main/mqtt-exec/0001-Let-library-generate-client-id-when-unset.patch
@@ -0,0 +1,68 @@
+From 5ba6139990373e77d638f4dd903281673e145e7e Mon Sep 17 00:00:00 2001
+From: Natanael Copa <ncopa@alpinelinux.org>
+Date: Wed, 9 Oct 2019 15:00:51 +0200
+Subject: [PATCH] Let library generate client id when unset
+
+---
+ mqtt-exec.c | 17 ++++-------------
+ 1 file changed, 4 insertions(+), 13 deletions(-)
+
+diff --git a/mqtt-exec.c b/mqtt-exec.c
+index 5c69325..ca585f9 100644
+--- a/mqtt-exec.c
++++ b/mqtt-exec.c
+@@ -151,8 +151,7 @@ int main(int argc, char *argv[])
+ int keepalive = 60;
+ int i, c, rc = 1;
+ struct userdata ud;
+- char hostname[256];
+- static char id[MOSQ_MQTT_ID_MAX_LENGTH+1];
++ char *id = NULL;
+ struct mosquitto *mosq = NULL;
+ char *username = NULL;
+ char *password = NULL;
+@@ -174,9 +173,6 @@ int main(int argc, char *argv[])
+
+ memset(&ud, 0, sizeof(ud));
+
+- memset(hostname, 0, sizeof(hostname));
+- memset(id, 0, sizeof(id));
+-
+ while ((c = getopt_long(argc, argv, "cdh:i:k:p:P:q:t:u:v", opts, &i)) != -1) {
+ switch(c) {
+ case 'c':
+@@ -194,7 +190,7 @@ int main(int argc, char *argv[])
+ MOSQ_MQTT_ID_MAX_LENGTH);
+ return 1;
+ }
+- strncpy(id, optarg, sizeof(id)-1);
++ id = optarg;
+ break;
+ case 'k':
+ keepalive = atoi(optarg);
+@@ -276,12 +272,6 @@ int main(int argc, char *argv[])
+ for (i=0; i <= ud.command_argc; i++)
+ ud.command_argv[i] = optind+i < argc ? argv[optind+i] : NULL;
+
+- if (id[0] == '\0') {
+- /* generate an id */
+- gethostname(hostname, sizeof(hostname)-1);
+- snprintf(id, sizeof(id), "mqttexe/%x-%s", getpid(), hostname);
+- }
+-
+ mosquitto_lib_init();
+ mosq = mosquitto_new(id, clean_session, &ud);
+ if (mosq == NULL)
+@@ -289,7 +279,8 @@ int main(int argc, char *argv[])
+
+ if (debug) {
+ printf("host=%s:%d\nid=%s\ntopic_count=%zu\ncommand=%s\n",
+- host, port, id, ud.topic_count, ud.command_argv[0]);
++ host, port, id ? id : "(null)", ud.topic_count,
++ ud.command_argv[0]);
+ mosquitto_log_callback_set(mosq, log_cb);
+ }
+
+--
+2.23.0
+