From patchwork Sat Dec 26 11:15:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1420672 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::43b; helo=mail-wr1-x43b.google.com; envelope-from=swupdate+bncbcxploxj6ikrbzfwtt7qkgqer55gfzy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de 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=Rqz70i+J; dkim-atps=neutral Received: from mail-wr1-x43b.google.com (mail-wr1-x43b.google.com [IPv6:2a00:1450:4864:20::43b]) (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 4D31TF5lnQz9sWc for ; Sat, 26 Dec 2020 22:15:57 +1100 (AEDT) Received: by mail-wr1-x43b.google.com with SMTP id n11sf2718000wro.7 for ; Sat, 26 Dec 2020 03:15:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1608981349; cv=pass; d=google.com; s=arc-20160816; b=Lxpdq9V8MpP2dRWy5DpE0KmloRbGf6JdXAY6pi3q+7xW19a/QyQlCdrZ2/JOD6js+a TWC1LPCzs2yjOBnyDXb5Vp9IXs1hwdG4FwntaRl+Xm2KFWxWaZsYFFkSFF9Gfle3/0CJ U7EflfHDerHGOJWgNXtRBihsTYyooO8zTy0lLcd81u0tB5Pavb57c2O4vk5XlJ9nb6Fn Gxkh3UGrqDDOIER8FPevegh1t9fErzG0CPoZK7sZyxcErL2MBCmvcuKSkFBg4e1YG4GA dAqEbwjwaHzXFjzip4ROQrlo1mJv8Iv3YqVcP/t/hs5mDkLctirAxDQz4Vwv4AGLptoo gEyg== 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=5dz7mlHwGx1lxrJXRo/Cj6E6/GrIWOPuF4GddyhWyUc=; b=L1XhlR24RVutDZ+AN4xzN78Ldx9XqCzDjP2IzP2urviCQgsLMKK6nz+v7rXCAwzmsH ucFe6QtsfWi8FBpiDFCvbS0ZbLOFgHYd4kLpZA8YbPCwzFdkih4hgcqSVlzCFOnaxXtt 0nhUSAgJig3wUaGkOJ9d20tWe3DtY1NJBw4A1daUYNvP45S3Ra4klle5qsPqwOjqoWju lPg4R6a0dBq56bCjCtrCy9J53ikqp6XMrSdyuxgfe2OoQqEEOmgdcScgB1bnAod+OE2Y pdqTZZhcojSnmZHJKtkYyX9YWEqEIjVwGkM6ABfGzFl/kfngZOmXOYuVCaG+7Nmu7hUD 5o/g== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.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=5dz7mlHwGx1lxrJXRo/Cj6E6/GrIWOPuF4GddyhWyUc=; b=Rqz70i+J1ip51CBYlSWd9E3RZMkH++5od2P/dlD/c2mR7K+qq0NiGhNmNt517KN7Ny Ge5kiZ/jgLuwM0oY8nDfsd1DCBIfN/yEaA+Pm33l0T+qGE4wdXZ4EUFie234wQ/6yj3S drKdKaw3wbTXLsUegkX5H5h5+/T+QNNApaAz86O9Y2BLpllLlxGiaatGxJ9QF7ZQRq2V EzF9oywlzVW/tMw6x0xIk9O294bvFVpIyC28IQxxa0EdGcnc+L/VEQpYP/CWYo6z54NT uoIS4lHdK8zZGelJMLDtLJfnu+YHknwoYjz4rYSwvZZcmRxu294kQElT5VCNYvcWwu/y OsYg== 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=5dz7mlHwGx1lxrJXRo/Cj6E6/GrIWOPuF4GddyhWyUc=; b=FmjYV1N9Cqy66T/0y4Usocx8DSdY7Fe0CiXVHD8Aw7ycexEAWdpmai0TxAO/TFLXd7 +y3OjS0s3dYyPDNnWQvp120/wFPXaep+/ldsqeD4PnxkEbu5aRbQAZee4v2GaA9mzUyl C8CObkXz5dDLqWC8seNwXzGO31hxojYbkghz9GucdMk8b6B733pPzn3r19j6TetxAZ6g x8IJu6t2gq4xiEMyHSWCksDgfFK9TrV+MROqNH4xiyIQ9xJtSCRh27b3ssZ9Ore415Qc 7zqy8KGyx557+zLsqxImry3x8JbfwLYtenvX4JsEXnNVq96fKqQgm67IsHwxqQ6mhqW+ NWow== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532pebkSIs4tPgp53YHAa1KEqd9yyAokzaG6+jzuPU0S2PhOIh85 tQPO/gqS395tMcAk+x5YV0w= X-Google-Smtp-Source: ABdhPJypU+uqVr/TJelaIZuq+N1U6s/bzI/d2AYrELChHwhZUjqx8gIXCfAVMbRMnlaFabKr/fow2Q== X-Received: by 2002:a5d:6708:: with SMTP id o8mr42094880wru.64.1608981349258; Sat, 26 Dec 2020 03:15:49 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a1c:1f8e:: with SMTP id f136ls3420557wmf.0.canary-gmail; Sat, 26 Dec 2020 03:15:48 -0800 (PST) X-Received: by 2002:a1c:e10b:: with SMTP id y11mr12377699wmg.65.1608981348295; Sat, 26 Dec 2020 03:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608981348; cv=none; d=google.com; s=arc-20160816; b=YeO5TuKFIpJAHyhEwQib2ARAxTmVKX5zTolCor7JZeiMdqMDVC/sRkZO72ngs/RneI UMog/5OKeOgf5SvXxJ0lsfCdWXPX+zgQ9/73mCFOMwd8rNbXdt1KZMG1GQ97xp4tP3e3 pIe5SrYU9e1FgAAP5kJfLPlyiTyd+JoMkmhf+xLygGH7xHaCuma5RyqKm2g7F/cEoUu4 hNqcy9QdvLcboKtGLdKaat+XFOz6lF9o5F0AZZ3Cee6PqzAI0Orfkj7q5cwp6JT+dMa0 5srI54NAR3UOYUI5wXuGNY2K2X+qJ+wwMrvWrQ+hqMjxct8J8fP+g5doumwcjkMZTbvY amQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=TICRlgj6bZiV363IWUche1nY39AcbzBPk8Hs+V2q68c=; b=cgi62gVLn5gmtPc9ArnRnFRJFxlhHbrr0O/WJepUo/YKfs1QDcm/nZixFk+crr2j3T 95NORx7CjB7+HndqB3y+zWHQ5WK1zh+IKrELKqRyoDZQTn/miomir3ie/fYMOJki9TP+ uQJItwNe9fFYjWAd65wx+Iit9egRLFvHtS5CWgH/+EEG/+J8rSrdvshlP7PyhOJlDp+r UBEQp2CUWHeyEl7YbSxI+7UGwEwX3PUFI5Tnlv5bQlU9d0QWWTmNNOsFd0vSdEjXerbs 6zBs0xejEtHdQ9pA2SfjEsvVrxUXGJkLopNDVF2Fz73rF6JEzjVIOwqIhY27NoPAb2SC 9n4g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id 7si689760wrp.3.2020.12.26.03.15.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Dec 2020 03:15:48 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4D31T00KYlz1qs0h; Sat, 26 Dec 2020 12:15:48 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4D31T004Vqz1qr4k; Sat, 26 Dec 2020 12:15:48 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id GFtk6S0a5V9l; Sat, 26 Dec 2020 12:15:47 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Sat, 26 Dec 2020 12:15:43 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 4C07F4540594; Sat, 26 Dec 2020 12:15:43 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yDPqXpjoMUYp; Sat, 26 Dec 2020 12:15:40 +0100 (CET) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.64]) by babic.homelinux.org (Postfix) with ESMTP id 9D5574540348; Sat, 26 Dec 2020 12:15:40 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] swupdate-client: use CV for synchronization Date: Sat, 26 Dec 2020 12:15:39 +0100 Message-Id: <20201226111539.13881-1-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.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: , Switch to condition variable to synchronize when an update is finished because using mutex as semaphore raises issues with coverity tool. Signed-off-by: Stefano Babic --- tools/swupdate-client.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tools/swupdate-client.c b/tools/swupdate-client.c index 3e29bad..94f712b 100644 --- a/tools/swupdate-client.c +++ b/tools/swupdate-client.c @@ -56,7 +56,8 @@ bool run_postupdate = false; int end_status = EXIT_SUCCESS; char *software_set = NULL, *running_mode = NULL; -pthread_mutex_t mymutex; +static pthread_mutex_t mymutex; +static pthread_cond_t cv_end = PTHREAD_COND_INITIALIZER; /* * this is the callback to get a new chunk of the @@ -110,6 +111,8 @@ static int end(RECOVERY_STATUS status) fprintf(stderr, "Running post-update failed!\n"); } + pthread_mutex_lock(&mymutex); + pthread_cond_signal(&cv_end); pthread_mutex_unlock(&mymutex); return 0; @@ -125,10 +128,6 @@ static int send_file(const char* filename) { return EXIT_FAILURE; } - /* synchronize with a mutex */ - pthread_mutex_lock(&mymutex); - - /* May be set non-zero by end() function on failure */ end_status = EXIT_SUCCESS; @@ -151,10 +150,9 @@ static int send_file(const char* filename) { return EXIT_FAILURE; } - /* Now block */ - pthread_mutex_lock(&mymutex); - /* End called, unlock and exit */ + pthread_mutex_lock(&mymutex); + pthread_cond_wait(&cv_end, &mymutex); pthread_mutex_unlock(&mymutex); if (filename)