From patchwork Wed Apr 7 16:39:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sava Jakovljev X-Patchwork-Id: 1463409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23e; helo=mail-lj1-x23e.google.com; envelope-from=swupdate+bncbaabb2waw6bqmgqebecwgmi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=Jh+M9Dd5; dkim-atps=neutral Received: from mail-lj1-x23e.google.com (mail-lj1-x23e.google.com [IPv6:2a00:1450:4864:20::23e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FFqrJ2fcXz9sVt for ; Thu, 8 Apr 2021 02:40:14 +1000 (AEST) Received: by mail-lj1-x23e.google.com with SMTP id r12sf5741895ljp.22 for ; Wed, 07 Apr 2021 09:40:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1617813610; cv=pass; d=google.com; s=arc-20160816; b=teTN1yc1P8DZMFwGrm937WFX7df1/ecC03z0k5hAgfiUeIE05AviSChcuknwlhMie8 vDOrtKckbHe+6OHPJbyUXwSsXjg6jY3gzM56+EDVL30PgKphnKtJx0u/biwFOqa0O1r+ LJy/IOGQajl9iT9kaYgDLzuPEoFP1bLiMrDzo1LR9C5KC6+qqpXmWzLCd06vYgPuTYaE 2sn/+UX6LX8pyxlhR/qz7VFIzHh1tv/jiFyzW7qAKALTFbXv2SRij1/WSNNphdvfWqa8 pDu/rm8xl8l5QgBIgR3iaJeQInVtcMTdAP+b94WPHoAp7nNOcEDogyFwm7otODkFMRrc FeWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=DEL7MGn7aDjS4AFd3+hwWGkitWsgP5D+oepSeCZByIc=; b=JtV7/gSfUjDUWn5OOvYFefxtVPLFuMuWlhhkqQeVpVwTmWJl2/MxZEiGaC+cFojbED HNxEn0fs0phww+tbMQD7KrZyjMuE5yjFCg7U3ENpeiAJxq1OKvq2AvCxKpsM6O17wIQ8 L56USbSJk4xqexnZUi7664yB63Q5XaZ/X0lqDoDt6y+ofyHfss8ic62Jj25KiYnuX6TX /w92F2TB4+TF30ql7vRAcEbhqPsRyWDk4lTWxwm2GwwZVCC16BwC5cU3yue4OaNf2Btx FCk0RLSoOm2f84aUppfL9kcLhBQqO21ALJF+6L6jOduZEMM03aADwDtMASekb4wECQDn XCcQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@teufel.de header.s=hse1 header.b=SmqzwrlK; spf=pass (google.com: domain of sava.jakovljev@teufel.de designates 94.100.133.205 as permitted sender) smtp.mailfrom=sava.jakovljev@teufel.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=DEL7MGn7aDjS4AFd3+hwWGkitWsgP5D+oepSeCZByIc=; b=Jh+M9Dd5Sh/7wk4+xGXNutjL5USb4l42tj7k7i6alOlmf2F9x/eP2XdrgDVNbS3qUU 5GHDpcgdZExOJG7kmZqhU3Uh8hZXizjX6jK43UeDJ/G5NpazaBydiDDhZixFZigNtP2K Km9YiXOCDlAtDN4zJV+G4V0gNqs0zz6nMTbI459qvUzdD4knKUA9ee1K7vFZ1z3gtVvh nnVnupzHHtRtdqoviZtHfl9+UyK70Wylfd1//9IpA8ChFODRQl6cQB53sZJv3sz2Vf1X o+eo08nQ1wPdK7owKHRvBHR2TBvMooRZ985zu39fq3vG6I0SQOKuy+/WRMKvfhCxkqtT wQdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=DEL7MGn7aDjS4AFd3+hwWGkitWsgP5D+oepSeCZByIc=; b=PXzgLNJepBaQKvArB4mt/FjCnnhPkxrn16HFLCdhm/u3gShc9nfy5WEoLS4+d3vK3k 26puc7G2vPRDtqPKXwY42fIDZuFq5zb5tTagnnEfIZCzpgbsDbimg3jDTT6A8xuHH+xx gvZ1x6/+X265fXU0tbxFBr7L6i22ZGP54ywhSrKi3XleHxtlIzvgQyy1OHdPFk6x4C9C 4at60n17Rbnq/2BUTEUfNPTgId196qBgp0FKIvA0bMUkr7nNeeJ27qOJrFA0TCs4okSs mzjmgRV8MqPzZC8Yiw5ZT6TQjRYty+yo3RMbmfZ5e6YTSWQm2hIGC/+tjTdYuLac1YXl eFiw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532bQJnjePK+En5QuW+9nA3KxT2n8JcwKcFCDW4trk14mN5Zckfs Bk6ap70SvTa1HjSPohwrSqI= X-Google-Smtp-Source: ABdhPJy3IQcd+wLmuELs2n0yMI9IKR4EEvRRrh51Vvds2xQGskAvLD/5OCo4FEjLcX3Fqtk33C64xQ== X-Received: by 2002:a05:6512:3a81:: with SMTP id q1mr3013268lfu.388.1617813610451; Wed, 07 Apr 2021 09:40:10 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a19:e86:: with SMTP id 128ls2559093lfo.0.gmail; Wed, 07 Apr 2021 09:40:09 -0700 (PDT) X-Received: by 2002:ac2:43a3:: with SMTP id t3mr2988755lfl.340.1617813609636; Wed, 07 Apr 2021 09:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617813609; cv=none; d=google.com; s=arc-20160816; b=uPbZ3M7MWqjhIsdwQ1pXQSHDZp5k2p+dh0qtdqD3MXh0rFgFj7tVHN3JNiNFp0Y+/l rdIXkR+G2XmwLU3BUxNNdcOyP5y6ZZFPV6BjR5YnzIvqylq5BPPB+ganEOF2wKygyKKw 5Bc8x5HdrluEgBZgbFP8nYldtxTuqO765AQ40iwUCM8pYZa0DbR2vFZfTaQKaiRSTx9+ R2fnnC39GDHF3aNDWSM7UOF/61EomvsA7gC1r9FilcW0ICL9wUgJkq0vQfGzg7cIZCtw GZ8oq4FttaN4el4o+ZskERMtAVOIxijfOZFfflWGDSKw5qXgEYYFE6OCVTl5B/zTkPYl ozRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version:message-id :date:subject:cc:to:from; bh=DgkbY/jrcQjzpihVoJICNDTAUI3dYoxmCKV7/OJQv80=; b=kxyaqOQepEvGD6lGaSzu2n3eEW2j20e5MI5anVku7/pGfkFhqSP6Rn9ZkRNYNzvELR S4J0IYP5nGegCsmcddUy+8IHPDEZudjlEgr74EimZMj9hET7ZgHCKwvd7+l5N98LNYli ruu/LylXZWle0mcvgmGzj3kho2eba3/3ujB+BO6+mFG4cMQ58RMlrUt6oiVI5pP9ReIZ Qoeq+zKEiJz3U/NWWIoe1q28MsywwQmAVgtPaJyYXsts6Dl1mqs2X3ZkW88EuWgfHvpJ BfpmU95lXSjhowvxXN5HJSqHorinwkRdTtxAKvqGmfwFrjm+lxOImHYsfJBY3NMlNXoQ a5IQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@teufel.de header.s=hse1 header.b=SmqzwrlK; spf=pass (google.com: domain of sava.jakovljev@teufel.de designates 94.100.133.205 as permitted sender) smtp.mailfrom=sava.jakovljev@teufel.de Received: from mx-relay29-hz1.antispameurope.com (mx-relay29-hz1.antispameurope.com. [94.100.133.205]) by gmr-mx.google.com with ESMTPS id c17si1798412ljn.7.2021.04.07.09.40.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Apr 2021 09:40:09 -0700 (PDT) Received-SPF: pass (google.com: domain of sava.jakovljev@teufel.de designates 94.100.133.205 as permitted sender) client-ip=94.100.133.205; Received: from unknown ([212.91.255.190]) by mx-relay29-hz1.antispameurope.com; Wed, 07 Apr 2021 18:40:08 +0200 From: Sava Jakovljev To: CC: Sava Jakovljev Subject: [swupdate] [PATCH v2] Suricatta: Avoid busy loop in handling initial state when server is unavailable Date: Wed, 7 Apr 2021 18:39:47 +0200 Message-ID: <20210407163947.203995-1-sava.jakovljev@teufel.de> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Originating-IP: [10.10.25.44] X-ClientProxiedBy: DNS-EX-01.teufel.local (10.10.0.80) To DNS-EX-02.teufel.local (10.10.0.81) X-C2ProcessedOrg: b93e13a0-e8da-4ba4-97b8-f14375b21c41 X-cloud-security-sender: sava.jakovljev@teufel.de X-cloud-security-recipient: swupdate@googlegroups.com X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mx-relay29-hz1.antispameurope.com with AE9CC9673EA X-cloud-security-connect: unknown[212.91.255.190], TLS=1, IP=212.91.255.190 X-cloud-security-Digest: 5a0aded67717d7a943a792ae815e8d2b X-cloud-security: scantime:1.557 X-Original-Sender: sava.jakovljev@teufel.de X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@teufel.de header.s=hse1 header.b=SmqzwrlK; spf=pass (google.com: domain of sava.jakovljev@teufel.de designates 94.100.133.205 as permitted sender) smtp.mailfrom=sava.jakovljev@teufel.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Signed-off-by: Sava Jakovljev --- 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 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 | 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 Use cache file as starting SWU\n", + "\t --cache Use cache file as starting SWU\n" + "\t -m, --initial-report-resend-period 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;