From patchwork Tue Mar 26 04:53:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 'Darko Komljenovic' via swupdate X-Patchwork-Id: 1065131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::c3c; helo=mail-yw1-xc3c.google.com; envelope-from=swupdate+bncbcg4lpfp6aorbwxa43sakgqeomry46i@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=googlegroups.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="rr1X2MKI"; dkim-atps=neutral Received: from mail-yw1-xc3c.google.com (mail-yw1-xc3c.google.com [IPv6:2607:f8b0:4864:20::c3c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44SzL70lv4z9sSg for ; Tue, 26 Mar 2019 15:53:49 +1100 (AEDT) Received: by mail-yw1-xc3c.google.com with SMTP id x185sf17266510ywd.4 for ; Mon, 25 Mar 2019 21:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=date:from:to:message-id:subject:mime-version :content-transfer-encoding:x-original-sender:reply-to:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=nRpp4LUxCiNHzdsTIx6JUvN9YuaKIDhZwwqcNTDUdvY=; b=rr1X2MKIfiUfOSAksCauyDg40b/4YZ7lJgUEFLmUwOdiFeHEg5CmzJVUJGjqc7psDm dCWc6IVptTvI9tTLDH3uJrRFYV1k8+u68ZRFsS7XoNfbo/FRw0ANX+6CdK6Y+/uuK96E ikRzLXwx4lPZTHPNx5rpSDjaWQUcUI/S/bguz8KRrkuQD6EkL8+G9HH9NWPg+Eww53v3 W0M4gLGe12BYHQr6o4bC8gsSTywgyhxL6SdtGpRyWHlpeMuyioLkse0WaolQvKsBtRvC 3MJpvFIBcAgUZBdi2wIAL8tI+F2icAK8SpjJ9izyI5KGSexDI3aBGFSW0WndP9m2lDaV 2pmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:message-id:subject:mime-version :content-transfer-encoding:x-original-sender:reply-to:precedence :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=nRpp4LUxCiNHzdsTIx6JUvN9YuaKIDhZwwqcNTDUdvY=; b=eL9+1q2U/WzOXH29aRA8MC/G/Yl0Ykm8RgdjHlkgzXtTDk6x+RucW9JA9DMdL+vUw8 vC1B/kYth/RkIyYaZKQtMXyGH8OHgPnoQpdHws0VNr8o1ReJuc3xy+i5o1ONDCKo1GJc 2g6y1SU6cKkVjHDCi3xMOoInU8OCVu36BKuO7r7jQr5338RPpQ7WZ+qptwd2ohfFEhTv FhMCodak4FE4rUlEQrmHogqdS4iGK0rnbRnjV33/zJCMiHaqFPaGRpyLOKl3ANGivv4w qaUVTH6ufuRpNwZEBc9Wt4BUMBfzMcYyCK5/PyUFCXAXWGoNSd4aMzGQ8CY/GCsDtWHO WVOw== X-Gm-Message-State: APjAAAVodcLBJ2Y2K+oxWGQTQzbrA6vLPiYpXO8hyG/bV8lcFxBiPRog SJ6zcYVs8KhNBZNNUligAlU= X-Google-Smtp-Source: APXvYqweKe7ajEe64IWRapXnhPH3mYJKLTJyfDvxI9292fVSbBM2XzrDHEOsKfrDb8dy9EdfxHs+pA== X-Received: by 2002:a25:4e09:: with SMTP id c9mr23137150ybb.167.1553576026453; Mon, 25 Mar 2019 21:53:46 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a25:d0c6:: with SMTP id h189ls145094ybg.12.gmail; Mon, 25 Mar 2019 21:53:46 -0700 (PDT) X-Received: by 2002:a25:3b14:: with SMTP id i20mr24264458yba.213.1553576025745; Mon, 25 Mar 2019 21:53:45 -0700 (PDT) Date: Mon, 25 Mar 2019 21:53:45 -0700 (PDT) X-Patchwork-Original-From: "austin.phillips via swupdate" From: 'Darko Komljenovic' via swupdate To: swupdate Message-Id: <19443ee7-b8a1-4b63-bced-14afee65304c@googlegroups.com> Subject: [swupdate] [PATCH] client: Return non-zero exit status on failure MIME-Version: 1.0 X-Original-Sender: austin.phillips@planetinnovation.com.au X-Original-From: austin.phillips@planetinnovation.com.au Reply-To: austin.phillips@planetinnovation.com.au 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: , Hi, This change ensures that the 'client' helper utility returns a non-zero exit status on error. This is useful when scripting and update using this utility. Regards Austin Signed-off-by: Austin Phillips --- tools/client.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/client.c b/tools/client.c index 73fef47..e9eab4c 100644 --- a/tools/client.c +++ b/tools/client.c @@ -41,6 +41,7 @@ char buf[256]; int fd; int verbose = 1; bool dryrun = false; +int end_status = 0; pthread_mutex_t mymutex; @@ -82,6 +83,13 @@ static int printstatus(ipc_message *msg) */ static int end(RECOVERY_STATUS status) { + if (status != FAILURE) { + end_status = 0; + } + else { + end_status = 1; + } + printf("Swupdate %s\n", status == FAILURE ? "*failed* !" : "was successful !"); @@ -103,6 +111,11 @@ static int send_file(const char* filename) { /* synchronize with a mutex */ pthread_mutex_lock(&mymutex); + + + /* May be set non-zero by end() function on failure */ + end_status = 0; + rc = swupdate_async_start(readimage, printstatus, end, dryrun); if (rc) @@ -114,7 +127,7 @@ static int send_file(const char* filename) { /* End called, unlock and exit */ pthread_mutex_unlock(&mymutex); - return 0; + return end_status; }