From patchwork Wed Dec 14 07:51:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9473781 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 785FA60571 for ; Wed, 14 Dec 2016 07:54:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D36F28681 for ; Wed, 14 Dec 2016 07:54:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61E91286E2; Wed, 14 Dec 2016 07:54:54 +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 183D028681 for ; Wed, 14 Dec 2016 07:54:53 +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 1cH4MI-0001aD-Fk; Wed, 14 Dec 2016 07:52:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH4MH-0001Za-PN for xen-devel@lists.xen.org; Wed, 14 Dec 2016 07:52:13 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 80/E5-15112-D2AF0585; Wed, 14 Dec 2016 07:52:13 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42JxWrohUlfnV0C EQddGFYslHxezODB6HN39mymAMYo1My8pvyKBNePFyWNMBVclK7be+8PUwPhOoIuRk0NCwF/i 1vsLrCA2m4CBxK1L35lBbBEBWYnVXXPYuxi5OJgFVjBK3Pu+kwUkISzgINHdsgqsiEVAVWLl6 z+MIDavgKfExPl/2CCGykncPNcJVsMp4CXR/OgeWFwIqOb88j2sELaaxNvlZ1ggegUlTs58Am YzC0hIHHzxgnkCI+8sJKlZSFILGJlWMWoUpxaVpRbpGhnqJRVlpmeU5CZm5ugaGpjp5aYWFye mp+YkJhXrJefnbmIEhg8DEOxg/LMs4BCjJAeTkigv19WACCG+pPyUyozE4oz4otKc1OJDjDIc HEoSvCY/gXKCRanpqRVpmTnAQIZJS3DwKInwdoGkeYsLEnOLM9MhUqcYFaXEeQ1AEgIgiYzSP Lg2WPRcYpSVEuZlBDpEiKcgtSg3swRV/hWjOAejkjDvdJApPJl5JXDTXwEtZgJaLLrEH2RxSS JCSqqBccolTQ3uGYtPz+MQ7DVXbZ220kdCJWr+rigfiWP1H93WX16SG8e6Km357mnxjxlO/Ko 3Fre0OLi+OF093eYj77FHRnNLWpakRT3j/+rh13dSoEYnbNO5tbHpfifF3rOsk3X+wG22Z+6i 3U//tNd0xIVnHzBbGB+4/MRup3kSs33OmFdair65psRSnJFoqMVcVJwIAMwVo2aZAgAA X-Env-Sender: prvs=149da8861=ross.lagerwall@citrix.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1481701927!25115382!4 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 39930 invoked from network); 14 Dec 2016 07:52:12 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 14 Dec 2016 07:52:12 -0000 X-IronPort-AV: E=Sophos;i="5.33,345,1477958400"; d="scan'208";a="394683835" From: Ross Lagerwall To: Date: Wed, 14 Dec 2016 07:51:59 +0000 Message-ID: <1481701920-13758-8-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 7/8] tools/livepatch: Save errno where needed 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 Fix a number of incorrect uses of errno after an operation that could set it (e.g. fprintf, close). Signed-off-by: Ross Lagerwall Acked-by: Wei Liu --- tools/misc/xen-livepatch.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c index fd2f968..140445d 100644 --- a/tools/misc/xen-livepatch.c +++ b/tools/misc/xen-livepatch.c @@ -101,9 +101,10 @@ static int list_func(int argc, char *argv[]) rc = xc_livepatch_list(xch, MAX_LEN, idx, info, name, len, &done, &left); if ( rc ) { + rc = errno; fprintf(stderr, "Failed to list %d/%d.\n" "Error %d: %s\n", - idx, left, errno, strerror(errno)); + idx, left, rc, strerror(rc)); break; } if ( !idx ) @@ -175,37 +176,40 @@ static int upload_func(int argc, char *argv[]) fd = open(filename, O_RDONLY); if ( fd < 0 ) { + int saved_errno = errno; fprintf(stderr, "Could not open %s.\n" "Error %d: %s\n", - filename, errno, strerror(errno)); - return errno; + filename, saved_errno, strerror(saved_errno)); + return saved_errno; } if ( stat(filename, &buf) != 0 ) { + int saved_errno = errno; fprintf(stderr, "Could not get size of %s.\n" "Error %d: %s\n", - filename, errno, strerror(errno)); + filename, saved_errno, strerror(saved_errno)); close(fd); - return errno; + return saved_errno; } len = buf.st_size; fbuf = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); if ( fbuf == MAP_FAILED ) { + int saved_errno = errno; fprintf(stderr, "Could not map %s.\n" "Error %d: %s\n", - filename, errno, strerror(errno)); + filename, saved_errno, strerror(saved_errno)); close (fd); - return errno; + return saved_errno; } printf("Uploading %s... ", filename); rc = xc_livepatch_upload(xch, name, fbuf, len); if ( rc ) { + rc = errno; printf("failed\n"); - fprintf(stderr, "Error %d: %s\n", - errno, strerror(errno)); + fprintf(stderr, "Error %d: %s\n", rc, strerror(rc)); } else printf("completed\n"); @@ -216,8 +220,6 @@ static int upload_func(int argc, char *argv[]) fprintf(stderr, "Could not unmap %s.\n" "Error %d: %s\n", filename, errno, strerror(errno)); - if ( !rc ) - rc = errno; } close(fd); @@ -333,8 +335,10 @@ int action_func(int argc, char *argv[], unsigned int idx) rc = action_options[idx].function(xch, name, HYPERVISOR_TIMEOUT_NS); if ( rc ) { + int saved_errno = errno; printf("failed\n"); - fprintf(stderr, "Error %d: %s\n", errno, strerror(errno)); + fprintf(stderr, "Error %d: %s\n", + saved_errno, strerror(saved_errno)); return -1; } }