Message ID | 20220929092212.3191522-1-mirza.kapetanovic@gmail.com |
---|---|
State | Changes Requested |
Headers | show |
Series | [1/1] Add update hawkbit identify option to ipc tools | expand |
Hi Mirka, On 29.09.22 11:22, Mirza Kapetanovic wrote: > Add option to swupdate-ipc hawkbitcfg for updating indetify properties. > Can be used to easily set properties dynamically without having to implement > the ipc protocol yourself. > That is nice. > Usage: swupdate-ipc hawkbitcfg -i Name=Value > However, there is a discrepancy. According to IPC, SWUpdatwe can accept an array of identifiers, see server_set_additional_device_attributes_ipc() in suricatta/server_hawkbit.c. This patch extends hawkbitcfg, but it just allows to set a single identifier. Multiple device identifier requires multiple swupdate-ipc, and this means the setup is not atomic, and SWUpdate can send to the server just a partial list of identifiers. Could you change to allow to work with multiple identify properties at once ? You could allow multiple -i at once, like: swupdate-ipc hawkbitcfg -i Name1=Value1 -i Name2=Value2 -i Name3=Value3 ... Best regards, Stefano Babic > Signed-off-by: Mirza Kapetanovic <mirza.kapetanovic@gmail.com> > --- > tools/swupdate-ipc.c | 42 ++++++++++++++++++++++++++++++++++-------- > 1 file changed, 34 insertions(+), 8 deletions(-) > > diff --git a/tools/swupdate-ipc.c b/tools/swupdate-ipc.c > index aa0afe5..eb1f33a 100644 > --- a/tools/swupdate-ipc.c > +++ b/tools/swupdate-ipc.c > @@ -69,19 +69,20 @@ static void usage_sysrestart(const char *programname) > { > fprintf(stdout, "\t %s [OPTION]\n", programname); > fprintf(stdout, > - "\t\t-w, --wait : wait for a connection with SWUpdate\n" > - "\t\t-s, --socket <path> : path to progress IPC socket\n" > - "\t\t-h, --help : print this help and exit\n" > + "\t\t-w, --wait : wait for a connection with SWUpdate\n" > + "\t\t-s, --socket <path> : path to progress IPC socket\n" > + "\t\t-h, --help : print this help and exit\n" > ); > } > > static void usage_hawkbitcfg(const char *program) { > fprintf(stdout,"\t %s \n", program); > fprintf(stdout, > - "\t\t-p, --polling-time : Set polling time (0=from server) to ask the backend server\n" > - "\t\t-e, --enable : Enable polling of backend server\n" > - "\t\t-d, --disable : Disable polling of backend server\n" > - "\t\t-t, --trigger : Enable and check for update\n" > + "\t\t-p, --polling-time : Set polling time (0=from server) to ask the backend server\n" > + "\t\t-i, --identify <name>=<value> : Set custom device attribute sent to backend server\n" > + "\t\t-e, --enable : Enable polling of backend server\n" > + "\t\t-d, --disable : Disable polling of backend server\n" > + "\t\t-t, --trigger : Enable and check for update\n" > ); > } > > @@ -136,6 +137,7 @@ static void send_msg(ipc_message *msg) > static struct option hawkbitcfg_options[] = { > {"help", no_argument, NULL, 'h'}, > {"polling-time", required_argument, NULL, 'p'}, > + {"identify", required_argument, NULL, 'i'}, > {"enable", no_argument, NULL, 'e'}, > {"disable", no_argument, NULL, 'd'}, > {"trigger", no_argument, NULL, 't'}, > @@ -148,9 +150,12 @@ static int hawkbitcfg(cmd_t __attribute__((__unused__)) *cmd, int argc, char *a > char *buf; > int c; > unsigned long polling_time; > + char *identify_name; > + char *identify_value; > bool enable = false; > bool trigger = false; > int opt_e = 0; > + int opt_i = 0; > int opt_p = 0; > > memset(&msg, 0, sizeof(msg)); > @@ -161,13 +166,29 @@ static int hawkbitcfg(cmd_t __attribute__((__unused__)) *cmd, int argc, char *a > buf = msg.data.procmsg.buf; > > /* Process options with getopt */ > - while ((c = getopt_long(argc, argv, "p:edth", > + while ((c = getopt_long(argc, argv, "p:i:edth", > hawkbitcfg_options, NULL)) != EOF) { > switch (c) { > case 'p': > opt_p = 1; > msg.data.procmsg.cmd = CMD_CONFIG; > polling_time = strtoul(optarg, NULL, 10); > + break; > + case 'i': > + opt_i = 1; > + msg.data.procmsg.cmd = CMD_CONFIG; > + > + char *eq = strchr(optarg, '='); > + > + if (eq) { > + *eq = '\0'; > + identify_name = strdup(optarg); > + identify_value = strdup(eq + 1); > + } else { > + fprintf(stderr, "Error: expected <name>=<value> pair.\n"); > + return 1; > + } > + > break; > case 'e': > case 'd': > @@ -192,6 +213,11 @@ static int hawkbitcfg(cmd_t __attribute__((__unused__)) *cmd, int argc, char *a > msg.data.procmsg.len = strnlen(buf, size); > send_msg(&msg); > } > + if (opt_i) { > + snprintf(buf, size, "{ \"identify\" : [{ \"name\": \"%s\", \"value\": \"%s\" }] }", identify_name, identify_value); > + msg.data.procmsg.len = strnlen(buf, size); > + send_msg(&msg); > + } > if (opt_e) { > snprintf(buf, size, trigger ? "{ \"trigger\" : %s}" : "{ \"enable\" : %s}", enable ? "true" : "false"); > msg.data.procmsg.len = strnlen(buf, size);
diff --git a/tools/swupdate-ipc.c b/tools/swupdate-ipc.c index aa0afe5..eb1f33a 100644 --- a/tools/swupdate-ipc.c +++ b/tools/swupdate-ipc.c @@ -69,19 +69,20 @@ static void usage_sysrestart(const char *programname) { fprintf(stdout, "\t %s [OPTION]\n", programname); fprintf(stdout, - "\t\t-w, --wait : wait for a connection with SWUpdate\n" - "\t\t-s, --socket <path> : path to progress IPC socket\n" - "\t\t-h, --help : print this help and exit\n" + "\t\t-w, --wait : wait for a connection with SWUpdate\n" + "\t\t-s, --socket <path> : path to progress IPC socket\n" + "\t\t-h, --help : print this help and exit\n" ); } static void usage_hawkbitcfg(const char *program) { fprintf(stdout,"\t %s \n", program); fprintf(stdout, - "\t\t-p, --polling-time : Set polling time (0=from server) to ask the backend server\n" - "\t\t-e, --enable : Enable polling of backend server\n" - "\t\t-d, --disable : Disable polling of backend server\n" - "\t\t-t, --trigger : Enable and check for update\n" + "\t\t-p, --polling-time : Set polling time (0=from server) to ask the backend server\n" + "\t\t-i, --identify <name>=<value> : Set custom device attribute sent to backend server\n" + "\t\t-e, --enable : Enable polling of backend server\n" + "\t\t-d, --disable : Disable polling of backend server\n" + "\t\t-t, --trigger : Enable and check for update\n" ); } @@ -136,6 +137,7 @@ static void send_msg(ipc_message *msg) static struct option hawkbitcfg_options[] = { {"help", no_argument, NULL, 'h'}, {"polling-time", required_argument, NULL, 'p'}, + {"identify", required_argument, NULL, 'i'}, {"enable", no_argument, NULL, 'e'}, {"disable", no_argument, NULL, 'd'}, {"trigger", no_argument, NULL, 't'}, @@ -148,9 +150,12 @@ static int hawkbitcfg(cmd_t __attribute__((__unused__)) *cmd, int argc, char *a char *buf; int c; unsigned long polling_time; + char *identify_name; + char *identify_value; bool enable = false; bool trigger = false; int opt_e = 0; + int opt_i = 0; int opt_p = 0; memset(&msg, 0, sizeof(msg)); @@ -161,13 +166,29 @@ static int hawkbitcfg(cmd_t __attribute__((__unused__)) *cmd, int argc, char *a buf = msg.data.procmsg.buf; /* Process options with getopt */ - while ((c = getopt_long(argc, argv, "p:edth", + while ((c = getopt_long(argc, argv, "p:i:edth", hawkbitcfg_options, NULL)) != EOF) { switch (c) { case 'p': opt_p = 1; msg.data.procmsg.cmd = CMD_CONFIG; polling_time = strtoul(optarg, NULL, 10); + break; + case 'i': + opt_i = 1; + msg.data.procmsg.cmd = CMD_CONFIG; + + char *eq = strchr(optarg, '='); + + if (eq) { + *eq = '\0'; + identify_name = strdup(optarg); + identify_value = strdup(eq + 1); + } else { + fprintf(stderr, "Error: expected <name>=<value> pair.\n"); + return 1; + } + break; case 'e': case 'd': @@ -192,6 +213,11 @@ static int hawkbitcfg(cmd_t __attribute__((__unused__)) *cmd, int argc, char *a msg.data.procmsg.len = strnlen(buf, size); send_msg(&msg); } + if (opt_i) { + snprintf(buf, size, "{ \"identify\" : [{ \"name\": \"%s\", \"value\": \"%s\" }] }", identify_name, identify_value); + msg.data.procmsg.len = strnlen(buf, size); + send_msg(&msg); + } if (opt_e) { snprintf(buf, size, trigger ? "{ \"trigger\" : %s}" : "{ \"enable\" : %s}", enable ? "true" : "false"); msg.data.procmsg.len = strnlen(buf, size);
Add option to swupdate-ipc hawkbitcfg for updating indetify properties. Can be used to easily set properties dynamically without having to implement the ipc protocol yourself. Usage: swupdate-ipc hawkbitcfg -i Name=Value Signed-off-by: Mirza Kapetanovic <mirza.kapetanovic@gmail.com> --- tools/swupdate-ipc.c | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-)