Message ID | 20210407163947.203995-1-sava.jakovljev@teufel.de |
---|---|
State | Accepted |
Headers | show |
Series | [v2] Suricatta: Avoid busy loop in handling initial state when server is unavailable | expand |
As discussed, I made the retry period configurable and exposed it. Documentation has also been updated, together with example swupdate.cfg. Missing Signed-off is now here. Let me know if you have any remarks. Best regards, Sava Jakovljev Sava Jakovljev schrieb am Mittwoch, 7. April 2021 um 18:40:10 UTC+2: > Signed-off-by: Sava Jakovljev <sava.ja...@teufel.de> > --- > doc/source/swupdate.rst | 11 +++++++-- > examples/configuration/swupdate.cfg | 9 ++++--- > suricatta/server_hawkbit.c | 37 ++++++++++++++++------------- > suricatta/server_hawkbit.h | 1 + > 4 files changed, 37 insertions(+), 21 deletions(-) > > diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst > index 361f248..c19cf37 100644 > --- a/doc/source/swupdate.rst > +++ b/doc/source/swupdate.rst > @@ -184,7 +184,7 @@ Images fully streamed > --------------------- > > In case of remote update, SWUpdate extracts relevant images from the stream > -and copies them into the directory pointed to by the environment variable > +and copies them into the directory pointed to by the environment variable > ``TMPDIR`` (if unset, to ``/tmp``) before calling the handlers. > This guarantee that an update is initiated only if all parts are present > and > correct. However, on some systems with less resources, the amount of RAM > @@ -637,6 +637,13 @@ Mandatory arguments are marked with '\*': > | | | SWUpdate can reuse the file and download | > | | | just the remaining part of the SWU. | > > +-------------------------+----------+--------------------------------------------+ > +| -m <seconds> | integer | Delay in seconds between re-trying to send | > +| | | initial feedback specified with "-c" | > +| | | option. Default value is 10 seconds. If | > +| | | Suricatta is started with initial state of | > +| | | STATE_WAIT ("-c 6"), this value is ignored.| > > ++-------------------------+----------+--------------------------------------------+ > + > > systemd Integration > ------------------- > @@ -690,7 +697,7 @@ files are also handed over on a "regular" start of > SWUpdate via > ``systemctl start swupdate.service``. > > Note that the socket paths in the two ``ListenStream=`` directives > -have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and > +have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and > ``CONFIG_SOCKET_PROGRESS_PATH`` in SWUpdate's configuration. > Here, the default socket path configuration is depicted. > > diff --git a/examples/configuration/swupdate.cfg > b/examples/configuration/swupdate.cfg > index a97f982..42a7243 100644 > --- a/examples/configuration/swupdate.cfg > +++ b/examples/configuration/swupdate.cfg > @@ -15,7 +15,7 @@ > # enable sending logs to syslog daemon > # public-key-file : string > # file with public key for > -# image verification > +# image verification > # mtd-blacklist : list integers > # MTD devices where SWUpdate > # must not try to check for UBI filesystem. > @@ -120,7 +120,7 @@ identify : ( > { name = "swCompatibility"; value = "unknown";} > ); > > -# > +# > # suricatta section: setup for backend > # > # Currently, they refer to the Hawkbit agent. > @@ -166,10 +166,12 @@ identify : ( > # interface : string > # interface name (e.g. "eth0") or IP address to bind communication channel > to. > # This allows to select source interface/address for outgoing traffic, if > needed. > +# initial-report-resend-period : integer > +# Specify period between re-tryint to send initial state, specified with > "-c" option, > +# when connection to Hawkbit is not available. Default value is 10 > seconds. > > suricatta : > { > - > tenant = "default"; > id = "123456"; > url = "http://papero.fritz.box:8080"; > @@ -181,6 +183,7 @@ suricatta : > userid = 1000; > groupid = 1000; > enable = true; > + initial-report-resend-period = 30; > /* > cafile = "/etc/ssl/cafile"; > sslkey = "/etc/ssl/sslkey"; > diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c > index b1372a8..dc4bac6 100644 > --- a/suricatta/server_hawkbit.c > +++ b/suricatta/server_hawkbit.c > @@ -50,6 +50,7 @@ static struct option long_options[] = { > {"interface", required_argument, NULL, 'f'}, > {"disable-token-for-dwl", no_argument, NULL, '1'}, > {"cache", required_argument, NULL, '2'}, > + {"initial-report-resend-period", required_argument, NULL, 'm'}, > {NULL, 0, NULL, 0}}; > > static unsigned short mandatory_argument_count = 0; > @@ -1596,9 +1597,12 @@ void server_print_help(void) > "\t -g, --gatewaytoken Set gateway token.\n" > "\t -f, --interface Set the network interface to connect to hawkBit.\n" > "\t --disable-token-for-dwl Do not send authentication header when > downlloading SWU.\n" > - "\t --cache <file> Use cache file as starting SWU\n", > + "\t --cache <file> Use cache file as starting SWU\n" > + "\t -m, --initial-report-resend-period <seconds> Time to wait prior to > retry " > + "sending initial state with '-c' option (default: %ds).\n", > CHANNEL_DEFAULT_POLLING_INTERVAL, CHANNEL_DEFAULT_RESUME_TRIES, > - CHANNEL_DEFAULT_RESUME_DELAY); > + CHANNEL_DEFAULT_RESUME_DELAY, > + INITIAL_STATUS_REPORT_WAIT_DELAY); > } > > static int server_hawkbit_settings(void *elem, void __attribute__ > ((__unused__)) *data) > @@ -1624,6 +1628,9 @@ static int server_hawkbit_settings(void *elem, void > __attribute__ ((__unused__) > get_field(LIBCFG_PARSER, elem, "polldelay", > &server_hawkbit.polling_interval); > > + get_field(LIBCFG_PARSER, elem, "initial-report-resend-period", > + &server_hawkbit.initial_report_resend_period); > + > suricatta_channel_settings(elem, &channel_data_defaults); > > get_field(LIBCFG_PARSER, elem, "usetokentodwl", > @@ -1649,6 +1656,7 @@ server_op_res_t server_start(char *fname, int argc, > char *argv[]) > > LIST_INIT(&server_hawkbit.configdata); > > + server_hawkbit.initial_report_resend_period = > INITIAL_STATUS_REPORT_WAIT_DELAY; > if (fname) { > swupdate_cfg_handle handle; > swupdate_cfg_init(&handle); > @@ -1675,7 +1683,7 @@ server_op_res_t server_start(char *fname, int argc, > char *argv[]) > /* reset to optind=1 to parse suricatta's argument vector */ > optind = 1; > opterr = 0; > - while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:g:f:2:", > + while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:g:f:2:m:", > long_options, NULL)) != -1) { > switch (choice) { > case 't': > @@ -1760,6 +1768,10 @@ server_op_res_t server_start(char *fname, int argc, > char *argv[]) > case '2': > SETSTRING(server_hawkbit.cached_file, optarg); > break; > + case 'm': > + server_hawkbit.initial_report_resend_period = > + (unsigned int)strtoul(optarg, NULL, 10); > + break; > /* Ignore not recognized options, they can be already parsed by the caller > */ > case '?': > break; > @@ -1806,12 +1818,10 @@ server_op_res_t server_start(char *fname, int > argc, char *argv[]) > } > /* If an update was performed, report its status to the hawkBit server > * prior to entering the main loop. May run indefinitely if server is > - * unavailable. In case of an error, the error is returned to the main > - * loop, thereby exiting suricatta. */ > - server_op_res_t state_handled; > + * unavailable. > + */ > server_hawkbit.update_state = update_state; > > - > /* > * After a successful startup, a configData is always sent > * Prepare default values > @@ -1823,15 +1833,10 @@ server_op_res_t server_start(char *fname, int > argc, char *argv[]) > * by an external process and we have to wait for it > */ > if (update_state != STATE_WAIT) { > - while ((state_handled = server_handle_initial_state(update_state)) != > - SERVER_OK) { > - if (state_handled == SERVER_EAGAIN) { > - INFO("Sleeping for %ds until retrying...", > - INITIAL_STATUS_REPORT_WAIT_DELAY); > - sleep(INITIAL_STATUS_REPORT_WAIT_DELAY); > - continue; > - } > - return state_handled; /* Report error to main loop, exiting. */ > + while (server_handle_initial_state(update_state) != SERVER_OK) { > + INFO("Sleeping for %ds until retrying...", > + server_hawkbit.initial_report_resend_period); > + sleep(server_hawkbit.initial_report_resend_period); > } > } > > diff --git a/suricatta/server_hawkbit.h b/suricatta/server_hawkbit.h > index 2d18a05..aea4bb0 100644 > --- a/suricatta/server_hawkbit.h > +++ b/suricatta/server_hawkbit.h > @@ -43,6 +43,7 @@ typedef struct { > char *gatewaytoken; > char *cached_file; > bool usetokentodwl; > + unsigned int initial_report_resend_period; > } server_hawkbit_t; > > extern server_hawkbit_t server_hawkbit; > -- > 2.26.3 > >
Hello Stefano, Any updates on this patch, is there something that needs adapting? Best regards, Sava Jakovljev Sava Jakovljev schrieb am Mittwoch, 7. April 2021 um 18:41:48 UTC+2: > As discussed, I made the retry period configurable and exposed it. > Documentation has also been updated, together with example swupdate.cfg. > > Missing Signed-off is now here. Let me know if you have any remarks. > > Best regards, > Sava Jakovljev > > Sava Jakovljev schrieb am Mittwoch, 7. April 2021 um 18:40:10 UTC+2: > >> Signed-off-by: Sava Jakovljev <sava.ja...@teufel.de> >> --- >> doc/source/swupdate.rst | 11 +++++++-- >> examples/configuration/swupdate.cfg | 9 ++++--- >> suricatta/server_hawkbit.c | 37 ++++++++++++++++------------- >> suricatta/server_hawkbit.h | 1 + >> 4 files changed, 37 insertions(+), 21 deletions(-) >> >> diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst >> index 361f248..c19cf37 100644 >> --- a/doc/source/swupdate.rst >> +++ b/doc/source/swupdate.rst >> @@ -184,7 +184,7 @@ Images fully streamed >> --------------------- >> >> In case of remote update, SWUpdate extracts relevant images from the >> stream >> -and copies them into the directory pointed to by the environment variable >> +and copies them into the directory pointed to by the environment variable >> ``TMPDIR`` (if unset, to ``/tmp``) before calling the handlers. >> This guarantee that an update is initiated only if all parts are present >> and >> correct. However, on some systems with less resources, the amount of RAM >> @@ -637,6 +637,13 @@ Mandatory arguments are marked with '\*': >> | | | SWUpdate can reuse the file and download | >> | | | just the remaining part of the SWU. | >> >> +-------------------------+----------+--------------------------------------------+ >> +| -m <seconds> | integer | Delay in seconds between re-trying to send | >> +| | | initial feedback specified with "-c" | >> +| | | option. Default value is 10 seconds. If | >> +| | | Suricatta is started with initial state of | >> +| | | STATE_WAIT ("-c 6"), this value is ignored.| >> >> ++-------------------------+----------+--------------------------------------------+ >> + >> >> systemd Integration >> ------------------- >> @@ -690,7 +697,7 @@ files are also handed over on a "regular" start of >> SWUpdate via >> ``systemctl start swupdate.service``. >> >> Note that the socket paths in the two ``ListenStream=`` directives >> -have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and >> +have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and >> ``CONFIG_SOCKET_PROGRESS_PATH`` in SWUpdate's configuration. >> Here, the default socket path configuration is depicted. >> >> diff --git a/examples/configuration/swupdate.cfg >> b/examples/configuration/swupdate.cfg >> index a97f982..42a7243 100644 >> --- a/examples/configuration/swupdate.cfg >> +++ b/examples/configuration/swupdate.cfg >> @@ -15,7 +15,7 @@ >> # enable sending logs to syslog daemon >> # public-key-file : string >> # file with public key for >> -# image verification >> +# image verification >> # mtd-blacklist : list integers >> # MTD devices where SWUpdate >> # must not try to check for UBI filesystem. >> @@ -120,7 +120,7 @@ identify : ( >> { name = "swCompatibility"; value = "unknown";} >> ); >> >> -# >> +# >> # suricatta section: setup for backend >> # >> # Currently, they refer to the Hawkbit agent. >> @@ -166,10 +166,12 @@ identify : ( >> # interface : string >> # interface name (e.g. "eth0") or IP address to bind communication >> channel to. >> # This allows to select source interface/address for outgoing traffic, if >> needed. >> +# initial-report-resend-period : integer >> +# Specify period between re-tryint to send initial state, specified with >> "-c" option, >> +# when connection to Hawkbit is not available. Default value is 10 >> seconds. >> >> suricatta : >> { >> - >> tenant = "default"; >> id = "123456"; >> url = "http://papero.fritz.box:8080"; >> @@ -181,6 +183,7 @@ suricatta : >> userid = 1000; >> groupid = 1000; >> enable = true; >> + initial-report-resend-period = 30; >> /* >> cafile = "/etc/ssl/cafile"; >> sslkey = "/etc/ssl/sslkey"; >> diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c >> index b1372a8..dc4bac6 100644 >> --- a/suricatta/server_hawkbit.c >> +++ b/suricatta/server_hawkbit.c >> @@ -50,6 +50,7 @@ static struct option long_options[] = { >> {"interface", required_argument, NULL, 'f'}, >> {"disable-token-for-dwl", no_argument, NULL, '1'}, >> {"cache", required_argument, NULL, '2'}, >> + {"initial-report-resend-period", required_argument, NULL, 'm'}, >> {NULL, 0, NULL, 0}}; >> >> static unsigned short mandatory_argument_count = 0; >> @@ -1596,9 +1597,12 @@ void server_print_help(void) >> "\t -g, --gatewaytoken Set gateway token.\n" >> "\t -f, --interface Set the network interface to connect to hawkBit.\n" >> "\t --disable-token-for-dwl Do not send authentication header when >> downlloading SWU.\n" >> - "\t --cache <file> Use cache file as starting SWU\n", >> + "\t --cache <file> Use cache file as starting SWU\n" >> + "\t -m, --initial-report-resend-period <seconds> Time to wait prior to >> retry " >> + "sending initial state with '-c' option (default: %ds).\n", >> CHANNEL_DEFAULT_POLLING_INTERVAL, CHANNEL_DEFAULT_RESUME_TRIES, >> - CHANNEL_DEFAULT_RESUME_DELAY); >> + CHANNEL_DEFAULT_RESUME_DELAY, >> + INITIAL_STATUS_REPORT_WAIT_DELAY); >> } >> >> static int server_hawkbit_settings(void *elem, void __attribute__ >> ((__unused__)) *data) >> @@ -1624,6 +1628,9 @@ static int server_hawkbit_settings(void *elem, void >> __attribute__ ((__unused__) >> get_field(LIBCFG_PARSER, elem, "polldelay", >> &server_hawkbit.polling_interval); >> >> + get_field(LIBCFG_PARSER, elem, "initial-report-resend-period", >> + &server_hawkbit.initial_report_resend_period); >> + >> suricatta_channel_settings(elem, &channel_data_defaults); >> >> get_field(LIBCFG_PARSER, elem, "usetokentodwl", >> @@ -1649,6 +1656,7 @@ server_op_res_t server_start(char *fname, int argc, >> char *argv[]) >> >> LIST_INIT(&server_hawkbit.configdata); >> >> + server_hawkbit.initial_report_resend_period = >> INITIAL_STATUS_REPORT_WAIT_DELAY; >> if (fname) { >> swupdate_cfg_handle handle; >> swupdate_cfg_init(&handle); >> @@ -1675,7 +1683,7 @@ server_op_res_t server_start(char *fname, int argc, >> char *argv[]) >> /* reset to optind=1 to parse suricatta's argument vector */ >> optind = 1; >> opterr = 0; >> - while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:g:f:2:", >> + while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:g:f:2:m:", >> long_options, NULL)) != -1) { >> switch (choice) { >> case 't': >> @@ -1760,6 +1768,10 @@ server_op_res_t server_start(char *fname, int >> argc, char *argv[]) >> case '2': >> SETSTRING(server_hawkbit.cached_file, optarg); >> break; >> + case 'm': >> + server_hawkbit.initial_report_resend_period = >> + (unsigned int)strtoul(optarg, NULL, 10); >> + break; >> /* Ignore not recognized options, they can be already parsed by the >> caller */ >> case '?': >> break; >> @@ -1806,12 +1818,10 @@ server_op_res_t server_start(char *fname, int >> argc, char *argv[]) >> } >> /* If an update was performed, report its status to the hawkBit server >> * prior to entering the main loop. May run indefinitely if server is >> - * unavailable. In case of an error, the error is returned to the main >> - * loop, thereby exiting suricatta. */ >> - server_op_res_t state_handled; >> + * unavailable. >> + */ >> server_hawkbit.update_state = update_state; >> >> - >> /* >> * After a successful startup, a configData is always sent >> * Prepare default values >> @@ -1823,15 +1833,10 @@ server_op_res_t server_start(char *fname, int >> argc, char *argv[]) >> * by an external process and we have to wait for it >> */ >> if (update_state != STATE_WAIT) { >> - while ((state_handled = server_handle_initial_state(update_state)) != >> - SERVER_OK) { >> - if (state_handled == SERVER_EAGAIN) { >> - INFO("Sleeping for %ds until retrying...", >> - INITIAL_STATUS_REPORT_WAIT_DELAY); >> - sleep(INITIAL_STATUS_REPORT_WAIT_DELAY); >> - continue; >> - } >> - return state_handled; /* Report error to main loop, exiting. */ >> + while (server_handle_initial_state(update_state) != SERVER_OK) { >> + INFO("Sleeping for %ds until retrying...", >> + server_hawkbit.initial_report_resend_period); >> + sleep(server_hawkbit.initial_report_resend_period); >> } >> } >> >> diff --git a/suricatta/server_hawkbit.h b/suricatta/server_hawkbit.h >> index 2d18a05..aea4bb0 100644 >> --- a/suricatta/server_hawkbit.h >> +++ b/suricatta/server_hawkbit.h >> @@ -43,6 +43,7 @@ typedef struct { >> char *gatewaytoken; >> char *cached_file; >> bool usetokentodwl; >> + unsigned int initial_report_resend_period; >> } server_hawkbit_t; >> >> extern server_hawkbit_t server_hawkbit; >> -- >> 2.26.3 >> >>
Hi Sava, On 13.04.21 13:34, Sava Jakovljev wrote: > Hello Stefano, > > Any updates on this patch, is there something that needs adapting? > I confess, I have not yet reviewed... At first glance it looks good, I will check tomorrow. Best regards, Stefano Babic > Best regards, > Sava Jakovljev > > Sava Jakovljev schrieb am Mittwoch, 7. April 2021 um 18:41:48 UTC+2: > > As discussed, I made the retry period configurable and exposed it. > Documentation has also been updated, together with example swupdate.cfg. > > Missing Signed-off is now here. Let me know if you have any remarks. > > Best regards, > Sava Jakovljev > > Sava Jakovljev schrieb am Mittwoch, 7. April 2021 um 18:40:10 UTC+2: > > Signed-off-by: Sava Jakovljev <sava.ja...@teufel.de> > --- > doc/source/swupdate.rst | 11 +++++++-- > examples/configuration/swupdate.cfg | 9 ++++--- > suricatta/server_hawkbit.c | 37 ++++++++++++++++------------- > suricatta/server_hawkbit.h | 1 + > 4 files changed, 37 insertions(+), 21 deletions(-) > > diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst > index 361f248..c19cf37 100644 > --- a/doc/source/swupdate.rst > +++ b/doc/source/swupdate.rst > @@ -184,7 +184,7 @@ Images fully streamed > --------------------- > > In case of remote update, SWUpdate extracts relevant images from > the stream > -and copies them into the directory pointed to by the > environment variable > +and copies them into the directory pointed to by the > environment variable > ``TMPDIR`` (if unset, to ``/tmp``) before calling the handlers. > This guarantee that an update is initiated only if all parts are > present and > correct. However, on some systems with less resources, the > amount of RAM > @@ -637,6 +637,13 @@ Mandatory arguments are marked with '\*': > | | | SWUpdate can reuse the file and download | > | | | just the remaining part of the SWU. | > +-------------------------+----------+--------------------------------------------+ > > +| -m <seconds> | integer | Delay in seconds between re-trying > to send | > +| | | initial feedback specified with "-c" | > +| | | option. Default value is 10 seconds. If | > +| | | Suricatta is started with initial state of | > +| | | STATE_WAIT ("-c 6"), this value is ignored.| > ++-------------------------+----------+--------------------------------------------+ > > + > > systemd Integration > ------------------- > @@ -690,7 +697,7 @@ files are also handed over on a "regular" > start of SWUpdate via > ``systemctl start swupdate.service``. > > Note that the socket paths in the two ``ListenStream=`` directives > -have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and > +have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and > ``CONFIG_SOCKET_PROGRESS_PATH`` in SWUpdate's configuration. > Here, the default socket path configuration is depicted. > > diff --git a/examples/configuration/swupdate.cfg > b/examples/configuration/swupdate.cfg > index a97f982..42a7243 100644 > --- a/examples/configuration/swupdate.cfg > +++ b/examples/configuration/swupdate.cfg > @@ -15,7 +15,7 @@ > # enable sending logs to syslog daemon > # public-key-file : string > # file with public key for > -# image verification > +# image verification > # mtd-blacklist : list integers > # MTD devices where SWUpdate > # must not try to check for UBI filesystem. > @@ -120,7 +120,7 @@ identify : ( > { name = "swCompatibility"; value = "unknown";} > ); > > -# > +# > # suricatta section: setup for backend > # > # Currently, they refer to the Hawkbit agent. > @@ -166,10 +166,12 @@ identify : ( > # interface : string > # interface name (e.g. "eth0") or IP address to bind > communication channel to. > # This allows to select source interface/address for outgoing > traffic, if needed. > +# initial-report-resend-period : integer > +# Specify period between re-tryint to send initial state, > specified with "-c" option, > +# when connection to Hawkbit is not available. Default value is > 10 seconds. > > suricatta : > { > - > tenant = "default"; > id = "123456"; > url = "http://papero.fritz.box:8080 > <http://papero.fritz.box:8080>"; > @@ -181,6 +183,7 @@ suricatta : > userid = 1000; > groupid = 1000; > enable = true; > + initial-report-resend-period = 30; > /* > cafile = "/etc/ssl/cafile"; > sslkey = "/etc/ssl/sslkey"; > diff --git a/suricatta/server_hawkbit.c > b/suricatta/server_hawkbit.c > index b1372a8..dc4bac6 100644 > --- a/suricatta/server_hawkbit.c > +++ b/suricatta/server_hawkbit.c > @@ -50,6 +50,7 @@ static struct option long_options[] = { > {"interface", required_argument, NULL, 'f'}, > {"disable-token-for-dwl", no_argument, NULL, '1'}, > {"cache", required_argument, NULL, '2'}, > + {"initial-report-resend-period", required_argument, NULL, 'm'}, > {NULL, 0, NULL, 0}}; > > static unsigned short mandatory_argument_count = 0; > @@ -1596,9 +1597,12 @@ void server_print_help(void) > "\t -g, --gatewaytoken Set gateway token.\n" > "\t -f, --interface Set the network interface to connect to > hawkBit.\n" > "\t --disable-token-for-dwl Do not send authentication header > when downlloading SWU.\n" > - "\t --cache <file> Use cache file as starting SWU\n", > + "\t --cache <file> Use cache file as starting SWU\n" > + "\t -m, --initial-report-resend-period <seconds> Time to wait > prior to retry " > + "sending initial state with '-c' option (default: %ds).\n", > CHANNEL_DEFAULT_POLLING_INTERVAL, CHANNEL_DEFAULT_RESUME_TRIES, > - CHANNEL_DEFAULT_RESUME_DELAY); > + CHANNEL_DEFAULT_RESUME_DELAY, > + INITIAL_STATUS_REPORT_WAIT_DELAY); > } > > static int server_hawkbit_settings(void *elem, void > __attribute__ ((__unused__)) *data) > @@ -1624,6 +1628,9 @@ static int server_hawkbit_settings(void > *elem, void __attribute__ ((__unused__) > get_field(LIBCFG_PARSER, elem, "polldelay", > &server_hawkbit.polling_interval); > > + get_field(LIBCFG_PARSER, elem, "initial-report-resend-period", > + &server_hawkbit.initial_report_resend_period); > + > suricatta_channel_settings(elem, &channel_data_defaults); > > get_field(LIBCFG_PARSER, elem, "usetokentodwl", > @@ -1649,6 +1656,7 @@ server_op_res_t server_start(char *fname, > int argc, char *argv[]) > > LIST_INIT(&server_hawkbit.configdata); > > + server_hawkbit.initial_report_resend_period = > INITIAL_STATUS_REPORT_WAIT_DELAY; > if (fname) { > swupdate_cfg_handle handle; > swupdate_cfg_init(&handle); > @@ -1675,7 +1683,7 @@ server_op_res_t server_start(char *fname, > int argc, char *argv[]) > /* reset to optind=1 to parse suricatta's argument vector */ > optind = 1; > opterr = 0; > - while ((choice = getopt_long(argc, argv, > "t:i:c:u:p:xr:y::w:k:g:f:2:", > + while ((choice = getopt_long(argc, argv, > "t:i:c:u:p:xr:y::w:k:g:f:2:m:", > long_options, NULL)) != -1) { > switch (choice) { > case 't': > @@ -1760,6 +1768,10 @@ server_op_res_t server_start(char *fname, > int argc, char *argv[]) > case '2': > SETSTRING(server_hawkbit.cached_file, optarg); > break; > + case 'm': > + server_hawkbit.initial_report_resend_period = > + (unsigned int)strtoul(optarg, NULL, 10); > + break; > /* Ignore not recognized options, they can be already parsed by > the caller */ > case '?': > break; > @@ -1806,12 +1818,10 @@ server_op_res_t server_start(char > *fname, int argc, char *argv[]) > } > /* If an update was performed, report its status to the hawkBit > server > * prior to entering the main loop. May run indefinitely if > server is > - * unavailable. In case of an error, the error is returned to > the main > - * loop, thereby exiting suricatta. */ > - server_op_res_t state_handled; > + * unavailable. > + */ > server_hawkbit.update_state = update_state; > > - > /* > * After a successful startup, a configData is always sent > * Prepare default values > @@ -1823,15 +1833,10 @@ server_op_res_t server_start(char > *fname, int argc, char *argv[]) > * by an external process and we have to wait for it > */ > if (update_state != STATE_WAIT) { > - while ((state_handled = > server_handle_initial_state(update_state)) != > - SERVER_OK) { > - if (state_handled == SERVER_EAGAIN) { > - INFO("Sleeping for %ds until retrying...", > - INITIAL_STATUS_REPORT_WAIT_DELAY); > - sleep(INITIAL_STATUS_REPORT_WAIT_DELAY); > - continue; > - } > - return state_handled; /* Report error to main loop, exiting. */ > + while (server_handle_initial_state(update_state) != SERVER_OK) { > + INFO("Sleeping for %ds until retrying...", > + server_hawkbit.initial_report_resend_period); > + sleep(server_hawkbit.initial_report_resend_period); > } > } > > diff --git a/suricatta/server_hawkbit.h > b/suricatta/server_hawkbit.h > index 2d18a05..aea4bb0 100644 > --- a/suricatta/server_hawkbit.h > +++ b/suricatta/server_hawkbit.h > @@ -43,6 +43,7 @@ typedef struct { > char *gatewaytoken; > char *cached_file; > bool usetokentodwl; > + unsigned int initial_report_resend_period; > } server_hawkbit_t; > > extern server_hawkbit_t server_hawkbit; > -- > 2.26.3 > > -- > You received this message because you are subscribed to the Google > Groups "swupdate" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to swupdate+unsubscribe@googlegroups.com > <mailto:swupdate+unsubscribe@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/swupdate/72b15e3c-6535-4dd0-b0f8-fa594be80641n%40googlegroups.com > <https://groups.google.com/d/msgid/swupdate/72b15e3c-6535-4dd0-b0f8-fa594be80641n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Hi Sava, On 07.04.21 18:39, Sava Jakovljev wrote: > Signed-off-by: Sava Jakovljev <sava.jakovljev@teufel.de> > --- > doc/source/swupdate.rst | 11 +++++++-- > examples/configuration/swupdate.cfg | 9 ++++--- > suricatta/server_hawkbit.c | 37 ++++++++++++++++------------- > suricatta/server_hawkbit.h | 1 + > 4 files changed, 37 insertions(+), 21 deletions(-) > > diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst > index 361f248..c19cf37 100644 > --- a/doc/source/swupdate.rst > +++ b/doc/source/swupdate.rst > @@ -184,7 +184,7 @@ Images fully streamed Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst index 361f248..c19cf37 100644 --- a/doc/source/swupdate.rst +++ b/doc/source/swupdate.rst @@ -184,7 +184,7 @@ Images fully streamed --------------------- In case of remote update, SWUpdate extracts relevant images from the stream -and copies them into the directory pointed to by the environment variable +and copies them into the directory pointed to by the environment variable ``TMPDIR`` (if unset, to ``/tmp``) before calling the handlers. This guarantee that an update is initiated only if all parts are present and correct. However, on some systems with less resources, the amount of RAM @@ -637,6 +637,13 @@ Mandatory arguments are marked with '\*': | | | SWUpdate can reuse the file and download | | | | just the remaining part of the SWU. | +-------------------------+----------+--------------------------------------------+ +| -m <seconds> | integer | Delay in seconds between re-trying to send | +| | | initial feedback specified with "-c" | +| | | option. Default value is 10 seconds. If | +| | | Suricatta is started with initial state of | +| | | STATE_WAIT ("-c 6"), this value is ignored.| ++-------------------------+----------+--------------------------------------------+ + systemd Integration ------------------- @@ -690,7 +697,7 @@ files are also handed over on a "regular" start of SWUpdate via ``systemctl start swupdate.service``. Note that the socket paths in the two ``ListenStream=`` directives -have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and +have to match the socket paths ``CONFIG_SOCKET_CTRL_PATH`` and ``CONFIG_SOCKET_PROGRESS_PATH`` in SWUpdate's configuration. Here, the default socket path configuration is depicted. diff --git a/examples/configuration/swupdate.cfg b/examples/configuration/swupdate.cfg index a97f982..42a7243 100644 --- a/examples/configuration/swupdate.cfg +++ b/examples/configuration/swupdate.cfg @@ -15,7 +15,7 @@ # enable sending logs to syslog daemon # public-key-file : string # file with public key for -# image verification +# image verification # mtd-blacklist : list integers # MTD devices where SWUpdate # must not try to check for UBI filesystem. @@ -120,7 +120,7 @@ identify : ( { name = "swCompatibility"; value = "unknown";} ); -# +# # suricatta section: setup for backend # # Currently, they refer to the Hawkbit agent. @@ -166,10 +166,12 @@ identify : ( # interface : string # interface name (e.g. "eth0") or IP address to bind communication channel to. # This allows to select source interface/address for outgoing traffic, if needed. +# initial-report-resend-period : integer +# Specify period between re-tryint to send initial state, specified with "-c" option, +# when connection to Hawkbit is not available. Default value is 10 seconds. suricatta : { - tenant = "default"; id = "123456"; url = "http://papero.fritz.box:8080"; @@ -181,6 +183,7 @@ suricatta : userid = 1000; groupid = 1000; enable = true; + initial-report-resend-period = 30; /* cafile = "/etc/ssl/cafile"; sslkey = "/etc/ssl/sslkey"; diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index b1372a8..dc4bac6 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -50,6 +50,7 @@ static struct option long_options[] = { {"interface", required_argument, NULL, 'f'}, {"disable-token-for-dwl", no_argument, NULL, '1'}, {"cache", required_argument, NULL, '2'}, + {"initial-report-resend-period", required_argument, NULL, 'm'}, {NULL, 0, NULL, 0}}; static unsigned short mandatory_argument_count = 0; @@ -1596,9 +1597,12 @@ void server_print_help(void) "\t -g, --gatewaytoken Set gateway token.\n" "\t -f, --interface Set the network interface to connect to hawkBit.\n" "\t --disable-token-for-dwl Do not send authentication header when downlloading SWU.\n" - "\t --cache <file> Use cache file as starting SWU\n", + "\t --cache <file> Use cache file as starting SWU\n" + "\t -m, --initial-report-resend-period <seconds> Time to wait prior to retry " + "sending initial state with '-c' option (default: %ds).\n", CHANNEL_DEFAULT_POLLING_INTERVAL, CHANNEL_DEFAULT_RESUME_TRIES, - CHANNEL_DEFAULT_RESUME_DELAY); + CHANNEL_DEFAULT_RESUME_DELAY, + INITIAL_STATUS_REPORT_WAIT_DELAY); } static int server_hawkbit_settings(void *elem, void __attribute__ ((__unused__)) *data) @@ -1624,6 +1628,9 @@ static int server_hawkbit_settings(void *elem, void __attribute__ ((__unused__) get_field(LIBCFG_PARSER, elem, "polldelay", &server_hawkbit.polling_interval); + get_field(LIBCFG_PARSER, elem, "initial-report-resend-period", + &server_hawkbit.initial_report_resend_period); + suricatta_channel_settings(elem, &channel_data_defaults); get_field(LIBCFG_PARSER, elem, "usetokentodwl", @@ -1649,6 +1656,7 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) LIST_INIT(&server_hawkbit.configdata); + server_hawkbit.initial_report_resend_period = INITIAL_STATUS_REPORT_WAIT_DELAY; if (fname) { swupdate_cfg_handle handle; swupdate_cfg_init(&handle); @@ -1675,7 +1683,7 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) /* reset to optind=1 to parse suricatta's argument vector */ optind = 1; opterr = 0; - while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:g:f:2:", + while ((choice = getopt_long(argc, argv, "t:i:c:u:p:xr:y::w:k:g:f:2:m:", long_options, NULL)) != -1) { switch (choice) { case 't': @@ -1760,6 +1768,10 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) case '2': SETSTRING(server_hawkbit.cached_file, optarg); break; + case 'm': + server_hawkbit.initial_report_resend_period = + (unsigned int)strtoul(optarg, NULL, 10); + break; /* Ignore not recognized options, they can be already parsed by the caller */ case '?': break; @@ -1806,12 +1818,10 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) } /* If an update was performed, report its status to the hawkBit server * prior to entering the main loop. May run indefinitely if server is - * unavailable. In case of an error, the error is returned to the main - * loop, thereby exiting suricatta. */ - server_op_res_t state_handled; + * unavailable. + */ server_hawkbit.update_state = update_state; - /* * After a successful startup, a configData is always sent * Prepare default values @@ -1823,15 +1833,10 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) * by an external process and we have to wait for it */ if (update_state != STATE_WAIT) { - while ((state_handled = server_handle_initial_state(update_state)) != - SERVER_OK) { - if (state_handled == SERVER_EAGAIN) { - INFO("Sleeping for %ds until retrying...", - INITIAL_STATUS_REPORT_WAIT_DELAY); - sleep(INITIAL_STATUS_REPORT_WAIT_DELAY); - continue; - } - return state_handled; /* Report error to main loop, exiting. */ + while (server_handle_initial_state(update_state) != SERVER_OK) { + INFO("Sleeping for %ds until retrying...", + server_hawkbit.initial_report_resend_period); + sleep(server_hawkbit.initial_report_resend_period); } } diff --git a/suricatta/server_hawkbit.h b/suricatta/server_hawkbit.h index 2d18a05..aea4bb0 100644 --- a/suricatta/server_hawkbit.h +++ b/suricatta/server_hawkbit.h @@ -43,6 +43,7 @@ typedef struct { char *gatewaytoken; char *cached_file; bool usetokentodwl; + unsigned int initial_report_resend_period; } server_hawkbit_t; extern server_hawkbit_t server_hawkbit;
Signed-off-by: Sava Jakovljev <sava.jakovljev@teufel.de> --- doc/source/swupdate.rst | 11 +++++++-- examples/configuration/swupdate.cfg | 9 ++++--- suricatta/server_hawkbit.c | 37 ++++++++++++++++------------- suricatta/server_hawkbit.h | 1 + 4 files changed, 37 insertions(+), 21 deletions(-) -- 2.26.3