From patchwork Mon Nov 22 03:15:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1557856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=CNGAc5El; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::f39; helo=mail-qv1-xf39.google.com; envelope-from=swupdate+bncbcwivbv7sugrbu4w5sgamgqe2ddimwy@googlegroups.com; receiver=) Received: from mail-qv1-xf39.google.com (mail-qv1-xf39.google.com [IPv6:2607:f8b0:4864:20::f39]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyC864hPcz9t1Q for ; Mon, 22 Nov 2021 14:15:34 +1100 (AEDT) Received: by mail-qv1-xf39.google.com with SMTP id gf10-20020a056214250a00b003c08951ea03sf15299125qvb.17 for ; Sun, 21 Nov 2021 19:15:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1637550932; cv=pass; d=google.com; s=arc-20160816; b=rWXJdSdIpFPLrvWgFfGys6flTIUqLJBUkV6t0JQ+cfx7pf6ig2avCf/8ZxegFEJ3kM 10J4AmVwdkEAive5zZXDgiDINZ5RIpHK9sG0m2/QuER0r/uEnI99XUhjla8icw2bkX7l 9sfaz75ZaLAKmTx+i7tFx+y9UjWKlmYJtJMXhNk9dLXvvNPgSiZuBOoACAteRWGnZic0 fN0rcqUhZrrxKpPWn3VuVmAqwB70M+Hl/vtUfbDCpehcmvTyTlq1S9bnAzVPrcHj471x Olnc3yMK3j3JPzPmp6/PYqTGeKBZfGbW/4168Sq9yAudV8zi8tzxqVh1lNralb/M76KK dgUQ== 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:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=n1RCk7qeG8H6Cieqbqmv++XQJrC8t8HnrAqC7ky0/7c=; b=U2ZAg2MmeQK6gTXr5HPFH/dt6hN9+Avx9j0k4akq96nnt/gHPsPGt/Eot4o1OOakyA 8C0xNkSmOrqTD9WX4m49C7/q3ZMBjbOPEBDvq9YMCaXRgXJAyTyjkmdzDtDuBgJjR3eW rHHLW/HEl6PlxvO5gZqb6nNmnkvZhQ9Lks29dO76+WGc3BeO38TrU1eP/85O0kAE0t8k P2M1mt4AYbD3U+/ce7ZLV5iIMHjXoh5J3dNmFupvBXnML6L2AuhvDvXmN05XLiOL3abA HYFjINUkAJkUCJQTKuN6WDFVRFcZeTb3f0ypXvBM0sL4UbtTaKx5BvMzyJC99oX+EmuM 1HzQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :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=n1RCk7qeG8H6Cieqbqmv++XQJrC8t8HnrAqC7ky0/7c=; b=CNGAc5ElHn1QCM4gqOUH4zSSxrJgsWAfaczFuJ9yIMJ4ZWEtwDK/tWJFGt701Z8WPR MEOSC+9nbTxei4pPbLFOYIuWxYo+x8knL37NVoTbeW7CIzRVHMUf1Cx3KpHhJ9tAGwuC XxbWJtgmaTZHwOH16pu2okuWBEW6kpKthY5W5DFh2Gip3d02v2Sxq0Ucb5SV+GX4r4Hp 6tiMtOXA/f3rcx684PumW9o5nD1e3sLjIpeAe0tyiwn1wv6tbiOU6tgFIIaiWZ65Lp5A NV9jmBEHSbEFR1kTzvOjkriKONzj1vo/FH2o5ufed7p5iltn82kgoYRcU6ml7wYAoygb RUyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references: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=n1RCk7qeG8H6Cieqbqmv++XQJrC8t8HnrAqC7ky0/7c=; b=kvRPJKLrp/FQsjZjXGFVs+XA9kueRQxBW8RlVCPcZjoZE7hKFs3ram8YozwYxYfCF4 oUheX7soh1aeBwdIrhoXMrdERpHcgKvABmx3/CKGQAbuR5uEcwVC6MJe6FWI8+UHfb9A wlobQTEe3uU8Ea0Jqvw5fQOlmsmCVcZMmhkgwuoROUGMqYPm4ahAPZK48S/UFrhAH16b wGNUJ2Fo5oOho1n4K/5obLoMyi4izsjvGekS8MdtXRhvZd88NXtD0kRDe/GckpzgTg5d PtDy3Ur4Pww9JcHKIhbX8LzgFBd1CqoM86mYt4mKqDgc9poZypic/ftsnQfm/ewlU8ll 3w+g== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM53341dtdBTIfbTDl3pkIkVzQhqBL+EbnfS22YUCHgLuVBOhSQNu0 uQlTMNId4rg15all9YaAzjA= X-Google-Smtp-Source: ABdhPJwrMo4f26MCTxfoLrtQpHxbSq+rIhO68B1z/v1OR3k8fC70wVtKGFMimPAbPGQmMi7+fFOikA== X-Received: by 2002:a05:620a:ec2:: with SMTP id x2mr45265361qkm.400.1637550932140; Sun, 21 Nov 2021 19:15:32 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:ac8:5fd4:: with SMTP id k20ls3159433qta.8.gmail; Sun, 21 Nov 2021 19:15:31 -0800 (PST) X-Received: by 2002:ac8:5a8c:: with SMTP id c12mr27254811qtc.222.1637550931662; Sun, 21 Nov 2021 19:15:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637550931; cv=none; d=google.com; s=arc-20160816; b=lqtcWgMfheR8a/hu0uuOUeTOZa2XrTheG7yJHPIAXqbVF6EbMt7N6RP+h6lAyrf7Lx coOLPWcVt/6y5l6nXqKFysQA76wAUV7c+h3k1uv4OG3ZY2Ewi9aDN0v8+3fyF3r2CU+0 d+8NUZBgYNzYFVI1B+kX+RpUdRpZq4fWbpWB3ybbRyJM8y91zJHSAXFtEg2UU75iPvPg eS6QBtPfiACsE+telHap6/LxZy6Dj8vPt/l2Wzv3RqY55vKEtrF7hS2T/Y0TDXPIxVMS JplUwnQRh20Fx4Hr5LK0dBzWZlrU0MFpvJXf3bf0ZsupzVDvHeyWuYe5ce/mdd1Ui5pX fMNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=XkeOmkYi+MZmW8WuTZ1RWVP/t6KFrITixw/73S6ezYQ=; b=a8F/K6/HSvUpdgnWbHM4Y0a6WWgroOGJDQB1NcXLu1GHcjPd0cYm6anAolgMSYUgWl kydJTHWzLM2YpXZ1pqyCuPwEshANAnCWyF8g9fNjL3ZeohcYTdRMMlKUdXXPSaID6pM8 0LrhAw6kJgQWo56OYB2TARVkTG930OEu/cnGI/FMj+lrx+gvs4s9EQlpG1VPj4uuYWPb /+KL1b6jhjaj1JMJASuuqAH3AljfTl4Pb9tgEaWIyAQks+fNWnIR2MVQuGNpLbtEO6Q5 pt3dg5S4IiWceKO9FItcBboOwfb6m9M/CxgFtYtUqM12p/GAhFN9ts1/a5zgcw2ui9lS Gdzg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTP id w22si772597qkp.2.2021.11.21.19.15.31 for ; Sun, 21 Nov 2021 19:15:31 -0800 (PST) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id DEFCB20D66 for ; Mon, 22 Nov 2021 12:15:29 +0900 (JST) Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by gw2.atmark-techno.com (Postfix) with ESMTPS id C78ED20D65 for ; Mon, 22 Nov 2021 12:15:29 +0900 (JST) Received: by mail-pj1-f70.google.com with SMTP id r23-20020a17090a941700b001a74be6cf80so5262136pjo.2 for ; Sun, 21 Nov 2021 19:15:29 -0800 (PST) X-Received: by 2002:a17:902:64c2:b0:141:c171:b99b with SMTP id y2-20020a17090264c200b00141c171b99bmr102608081pli.55.1637550928644; Sun, 21 Nov 2021 19:15:28 -0800 (PST) X-Received: by 2002:a17:902:64c2:b0:141:c171:b99b with SMTP id y2-20020a17090264c200b00141c171b99bmr102608056pli.55.1637550928408; Sun, 21 Nov 2021 19:15:28 -0800 (PST) Received: from pc-0115 (178.101.200.35.bc.googleusercontent.com. [35.200.101.178]) by smtp.gmail.com with ESMTPSA id g9sm6952769pfc.182.2021.11.21.19.15.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Nov 2021 19:15:28 -0800 (PST) Received: from martinet by pc-0115 with local (Exim 4.94.2) (envelope-from ) id 1moznj-009EqL-4J; Mon, 22 Nov 2021 12:15:27 +0900 From: Dominique Martinet To: swupdate@googlegroups.com Cc: Dominique Martinet , Roland Gaudig Subject: [swupdate] [PATCH 2/3] server_hawkbit: make ipc_lock non-recursive Date: Mon, 22 Nov 2021 12:15:17 +0900 Message-Id: <20211122031518.2201903-2-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211122031518.2201903-1-dominique.martinet@atmark-techno.com> References: <20211122031518.2201903-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com 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: , musl does not have PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, instead one is expected to call pthread_mutex_init with PTHREAD_MUTEX_RECURSIVE before using the lock. Unfortunately, this part of the code does not allow for easy init before use: start_suricatta() will first start the ipc thread, then call server_start, but we do not have any guarantee that the ipc thread will not call server_ipc before server_start has had a chance to initialize the mutex. Thanksfully we apparently only need the recursivity here for a tiny portion of the code: get_target_data_length() can be called once with lock and once without lock, so just adding a toggle to get the lock is enough. Signed-off-by: Dominique Martinet Cc: Roland Gaudig --- Roland, could you please comment if that sounds good for you? The only alternative I see would be adding a server_init call before server_start, but I'd rather not change any API if I don't have to. I've tested it on our boards and there doesn't seem to be any recursive locking happening except the one I fixed (at least I didn't experience any deadlock), but it's possible I missed some in code we don't use suricatta/server_hawkbit.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index dbce9a35808c..86f050dc2c86 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -58,7 +58,7 @@ static struct option long_options[] = { static unsigned short mandatory_argument_count = 0; static pthread_mutex_t notifylock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t ipc_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +static pthread_mutex_t ipc_lock = PTHREAD_MUTEX_INITIALIZER; /* * See hawkBit's API for an explanation @@ -109,7 +109,7 @@ server_send_deployment_reply(channel_t *channel, const int job_cnt_cur, const char *finished, const char *execution_status, int numdetails, const char *details[]); server_op_res_t server_send_cancel_reply(channel_t *channel, const int action_id); -static int get_target_data_length(void); +static int get_target_data_length(bool locked); server_hawkbit_t server_hawkbit = {.url = NULL, .polling_interval = CHANNEL_DEFAULT_POLLING_INTERVAL, @@ -526,7 +526,7 @@ server_op_res_t server_set_config_data(json_object *json_root) if (server_hawkbit.configData_url) free(server_hawkbit.configData_url); server_hawkbit.configData_url = tmp; - server_hawkbit.has_to_send_configData = (get_target_data_length() > 0) ? true : false; + server_hawkbit.has_to_send_configData = (get_target_data_length(true) > 0) ? true : false; TRACE("ConfigData: %s", server_hawkbit.configData_url); pthread_mutex_unlock(&ipc_lock); } @@ -1471,19 +1471,21 @@ server_op_res_t server_install_update(void) return result; } -int get_target_data_length(void) +int get_target_data_length(bool locked) { int len = 0; struct dict_entry *entry; - pthread_mutex_lock(&ipc_lock); + if (!locked) + pthread_mutex_lock(&ipc_lock); LIST_FOREACH(entry, &server_hawkbit.configdata, next) { char *key = dict_entry_get_key(entry); char *value = dict_entry_get_value(entry); len += strlen(key) + strlen(value) + strlen (" : ") + 6; } - pthread_mutex_unlock(&ipc_lock); + if (!locked) + pthread_mutex_unlock(&ipc_lock); return len; } @@ -1499,7 +1501,7 @@ server_op_res_t server_send_target_data(void) char *url = NULL; assert(channel != NULL); - len = get_target_data_length(); + len = get_target_data_length(false); if (!len) { server_hawkbit.has_to_send_configData = false;