From patchwork Wed Dec 14 07:52:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9473777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BBB0060571 for ; Wed, 14 Dec 2016 07:54:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B14EE2855E for ; Wed, 14 Dec 2016 07:54:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A632D286D2; Wed, 14 Dec 2016 07:54:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5296D2855E for ; Wed, 14 Dec 2016 07:54:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH4Mk-0001hs-OL; Wed, 14 Dec 2016 07:52:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH4Mk-0001hN-0i for xen-devel@lists.xen.org; Wed, 14 Dec 2016 07:52:42 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id 22/8F-13192-94AF0585; Wed, 14 Dec 2016 07:52:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42JxWrrBXtfjV0C Ewa5jJhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aeQx8YC46JV+y828XawPhNoIuRk0NCwF+i 6/B5NhCbTcBA4tal78wgtoiArMTqrjnsXYxcHMwCKxgl7n3fyQKSEBbwkPj+bDqYzSKgKvHpc zOYzSvgKfFx5T5miKFyEjfPdYLZnAJeEs2P7oEtEAKqOb98DyuErSbxdvkZqF5BiZMzn4DZzA ISEgdfvGCewMg7C0lqFpLUAkamVYwaxalFZalFukYGeklFmekZJbmJmTm6hgZmermpxcWJ6ak 5iUnFesn5uZsYgeHDAAQ7GH8tCzjEKMnBpCTKy3U1IEKILyk/pTIjsTgjvqg0J7X4EKMMB4eS BK/JT6CcYFFqempFWmYOMJBh0hIcPEoivFd+AKV5iwsSc4sz0yFSpxgVpcR5DUD6BEASGaV5c G2w6LnEKCslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYV51kCk8mXklcNNfAS1mAlosusQfZHFJIk JKqoFxHWf2Ft/cu9W/XdqEnp9c7WfSdb/pZ3pl2Ot6dZ2vpdaZkoFMiXzsJ9VlPuwqD5D3O1q 7stf1/jqVKS/59PPcXNbutHu579w724fsxacNb7d1ZFXnZ98y1WfUnbjkx622+W86NDjZn6hs cF30uOjP0kJ9s+tr/8Xt21qpy3BfkcmqpeBy4lklluKMREMt5qLiRAClQMF6mQIAAA== X-Env-Sender: prvs=149da8861=ross.lagerwall@citrix.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1481701959!48201096!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26679 invoked from network); 14 Dec 2016 07:52:40 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 14 Dec 2016 07:52:40 -0000 X-IronPort-AV: E=Sophos;i="5.33,345,1477958400"; d="scan'208";a="403521737" From: Ross Lagerwall To: Date: Wed, 14 Dec 2016 07:52:00 +0000 Message-ID: <1481701920-13758-9-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481701920-13758-1-git-send-email-ross.lagerwall@citrix.com> References: <1481701920-13758-1-git-send-email-ross.lagerwall@citrix.com> MIME-Version: 1.0 Cc: Ross Lagerwall , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v2 8/8] tools/livepatch: Exit with 2 if a timeout occurs X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Exit with 0 for success. Exit with 1 for an error. Exit with 2 if the operation should be retried for any reason (e.g. a timeout or because another operation was in progress). This allows a program or script driving xen-livepatch to determine if the operation should be retried without parsing the output. Signed-off-by: Ross Lagerwall Acked-by: Wei Liu --- tools/misc/xen-livepatch.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c index 140445d..af9fcd6 100644 --- a/tools/misc/xen-livepatch.c +++ b/tools/misc/xen-livepatch.c @@ -15,6 +15,7 @@ #include #include +#include static xc_interface *xch; @@ -309,17 +310,18 @@ int action_func(int argc, char *argv[], unsigned int idx) rc = xc_livepatch_get(xch, name, &status); if ( rc ) { + int saved_errno = errno; fprintf(stderr, "Failed to get status of %s.\n" "Error %d: %s\n", - name, errno, strerror(errno)); - return -1; + name, saved_errno, strerror(saved_errno)); + return saved_errno; } if ( status.rc == -XEN_EAGAIN ) { fprintf(stderr, "Cannot execute %s.\n" "Operation already in progress.\n", action_options[idx].name); - return -1; + return EAGAIN; } if ( status.state == action_options[idx].expected ) @@ -339,7 +341,7 @@ int action_func(int argc, char *argv[], unsigned int idx) printf("failed\n"); fprintf(stderr, "Error %d: %s\n", saved_errno, strerror(saved_errno)); - return -1; + return saved_errno; } } else @@ -364,7 +366,7 @@ int action_func(int argc, char *argv[], unsigned int idx) { printf("failed\n"); fprintf(stderr, "Operation didn't complete.\n"); - return -1; + return EAGAIN; } if ( rc == 0 ) @@ -376,7 +378,7 @@ int action_func(int argc, char *argv[], unsigned int idx) { printf("failed\n"); fprintf(stderr, "Error %d: %s\n", -rc, strerror(-rc)); - return -1; + return -rc; } else { @@ -488,7 +490,28 @@ int main(int argc, char *argv[]) xc_interface_close(xch); - return !!ret; + /* + * Exitcode 0 for success. + * Exitcode 1 for an error. + * Exitcode 2 if the operation should be retried for any reason (e.g. a + * timeout or because another operation was in progress). + */ +#define EXIT_TIMEOUT (EXIT_FAILURE + 1) + + BUILD_BUG_ON(EXIT_SUCCESS != 0); + BUILD_BUG_ON(EXIT_FAILURE != 1); + BUILD_BUG_ON(EXIT_TIMEOUT != 2); + + switch ( ret ) + { + case 0: + return EXIT_SUCCESS; + case EAGAIN: + case EBUSY: + return EXIT_TIMEOUT; + default: + return EXIT_FAILURE; + } } /*