Message ID | 20230817111712.235063-6-stefano.babic@swupdate.org |
---|---|
State | Accepted |
Delegated to: | Stefano Babic |
Headers | show |
Series | None | expand |
Arriving after the battle, sorry for not noticing these patches when you sent them last month. FWIW patch 1 and 3, as well as cover letter if there was any, never made it to this list. These two commits: - 54a66237bc03 "Factorize ipc_thread_fn to be used by all processes" - eea5de285508 "Downloader: integrate post update message in the process" Stefano Babic wrote on Thu, Aug 17, 2023 at 01:17:12PM +0200: > Implement IPC to the downloader to transfer a URL and the credentials > for the transfer. The downloader should be started without URL set (for > example with -d "") and it waits to get a URL just via IPC. I understand swupdate-ipc is meant as an example but I'd have expected something closer to swupdate-client that starts a downloader and sends the file via IPC instead; was there a reason to reuse the downloader thread in swupdate instead? In particular it could make sense to have an option to have this wait for update to end and return its status like swupdate-client does. > Usage: > > swupdate-ipc dwurl -u <URL> -c <user:password> (by the way it's dwurl in the commit message here and in summary but it's dwlurl in the code; made me look twice for this commit... Well, not much to do at this point :))
Hi Dominique, On 15.09.23 08:41, Dominique MARTINET wrote: > Arriving after the battle, sorry for not noticing these patches when you > sent them last month. > > FWIW patch 1 and 3, as well as cover letter if there was any, never made > it to this list. > These two commits: > - 54a66237bc03 "Factorize ipc_thread_fn to be used by all processes" > - eea5de285508 "Downloader: integrate post update message in the process" > Thanks for reporting this - it seems that sometimes googlegroup declare mails as SPAM even if they are not, and they do not reach the ML. > Stefano Babic wrote on Thu, Aug 17, 2023 at 01:17:12PM +0200: >> Implement IPC to the downloader to transfer a URL and the credentials >> for the transfer. The downloader should be started without URL set (for >> example with -d "") and it waits to get a URL just via IPC. > > I understand swupdate-ipc is meant as an example but I'd have expected > something closer to swupdate-client that starts a downloader and sends > the file via IPC instead; was there a reason to reuse the downloader > thread in swupdate instead? Because this was the real use case: just send a trigger to SWUpdate from the application. Nevertheless, it could be nice to implement this into swupdate-client as well, I will do it when I get enough time for it. > > In particular it could make sense to have an option to have this wait > for update to end and return its status like swupdate-client does. I see your point, but then it is probably better to implement it into swupdate-client, isnt't it ? Something like swupdate-client --u <url> > >> Usage: >> >> swupdate-ipc dwurl -u <URL> -c <user:password> > > (by the way it's dwurl in the commit message here and in summary but > it's dwlurl in the code; made me look twice for this commit... Well, > not much to do at this point :)) For this is too late :-) Best regards, Stefano >
Stefano Babic wrote on Fri, Sep 15, 2023 at 09:26:26AM +0200: > On 15.09.23 08:41, Dominique MARTINET wrote: > > FWIW patch 1 and 3, as well as cover letter if there was any, never made > > it to this list. > > These two commits: > > - 54a66237bc03 "Factorize ipc_thread_fn to be used by all processes" > > - eea5de285508 "Downloader: integrate post update message in the process" > > > > Thanks for reporting this - it seems that sometimes googlegroup declare > mails as SPAM even if they are not, and they do not reach the ML. That's annoying if you have no way to tell as the sender :/ > > I understand swupdate-ipc is meant as an example but I'd have expected > > something closer to swupdate-client that starts a downloader and sends > > the file via IPC instead; was there a reason to reuse the downloader > > thread in swupdate instead? > > Because this was the real use case: just send a trigger to SWUpdate from the > application. > > Nevertheless, it could be nice to implement this into swupdate-client as > well, I will do it when I get enough time for it. Thanks! > > In particular it could make sense to have an option to have this wait > > for update to end and return its status like swupdate-client does. > > I see your point, but then it is probably better to implement it into > swupdate-client, isnt't it ? Something like swupdate-client --u <url> Right, it probably makes more sense as swupdate-client from a user point of view.
diff --git a/tools/swupdate-ipc.c b/tools/swupdate-ipc.c index aa0afe55..53aa843c 100644 --- a/tools/swupdate-ipc.c +++ b/tools/swupdate-ipc.c @@ -93,6 +93,15 @@ static void usage_monitor(const char *program) { ); } +static void usage_dwlurl(const char *program) { + fprintf(stdout,"\t %s \n", program); + fprintf(stdout, + "\t\t-u, --url <url> : URL to be passed to the downloader\n" + "\t\t-c, --userpassword user:pass : user / password to be used to download\n" + "\t\t-h, --help : print this help and exit\n" + ); +} + /* * Utility functions called by subcommands */ @@ -201,6 +210,77 @@ static int hawkbitcfg(cmd_t __attribute__((__unused__)) *cmd, int argc, char *a exit(0); } +static struct option dwlurl_options[] = { + {"help", no_argument, NULL, 'h'}, + {"url", required_argument, NULL, 'u'}, + {"userpassword", required_argument, NULL, 'c'}, + {NULL, 0, NULL, 0} +}; + + +static int dwlurl(cmd_t __attribute__((__unused__)) *cmd, int argc, char *argv[]) { + ipc_message msg; + size_t size, len; + char *buf; + int c; + int opt_u = 0, opt_c = 0; + const char *url, *user; + + memset(&msg, 0, sizeof(msg)); + msg.data.procmsg.source = SOURCE_DOWNLOADER; + msg.type = SWUPDATE_SUBPROCESS; + msg.data.procmsg.cmd = CMD_SET_DOWNLOAD_URL; + + size = sizeof(msg.data.procmsg.buf); + buf = msg.data.procmsg.buf; + + /* Process options with getopt */ + while ((c = getopt_long(argc, argv, "u:c:", + dwlurl_options, NULL)) != EOF) { + switch (c) { + case 'u': + opt_u = 1; + url = strdup(optarg); + break; + case 'c': + opt_c = 1; + user = strdup(optarg); + break; + } + } + + /* + * Build a json string with the command line parameters + * do not check anything, let SWUpdate + * doing the checks + * An error or a NACK is returned in + * case of failure + */ + if (!opt_u) { /*this is mandatory */ + fprintf(stderr, "url is mandatory, skipping..\n"); + exit(1); + } + len = snprintf(buf, size, "{ \"url\": \"%s\"", url); + if (len == size) { + fprintf(stderr, "URL is too long : %s\n", url); + exit(1); + } + if (opt_c) { + len += snprintf(buf + len, size - len, ", \"userpassword\" : \"%s\" }", + user); + } else { + len += snprintf(buf + len, size - len, "}"); + } + if (len == size) { + fprintf(stderr, "URL + credentials too long, not supported\n"); + exit(1); + } + msg.data.procmsg.len = len; + send_msg(&msg); + + exit(0); +} + static int sendtohawkbit(cmd_t *cmd, int argc, char *argv[]) { int written, i; ipc_message msg; @@ -690,6 +770,7 @@ cmd_t commands[] = { {"gethawkbit", gethawkbitstatus, usage_gethawkbitstatus}, {"sysrestart", sysrestart, usage_sysrestart}, {"monitor", monitor, usage_monitor}, + {"dwlurl", dwlurl, usage_dwlurl}, {NULL, NULL, NULL} };
Implement IPC to the downloader to transfer a URL and the credentials for the transfer. The downloader should be started without URL set (for example with -d "") and it waits to get a URL just via IPC. Usage: swupdate-ipc dwurl -u <URL> -c <user:password> Signed-off-by: Stefano Babic <stefano.babic@swupdate.org> --- tools/swupdate-ipc.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)