From: Ross Lagerwall <ross.lagerwall@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ross Lagerwall <ross.lagerwall@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Wei Liu <wei.liu2@citrix.com>
Subject: [PATCH v2 7/8] tools/livepatch: Save errno where needed
Date: Wed, 14 Dec 2016 07:51:59 +0000 [thread overview]
Message-ID: <1481701920-13758-8-git-send-email-ross.lagerwall@citrix.com> (raw)
In-Reply-To: <1481701920-13758-1-git-send-email-ross.lagerwall@citrix.com>
Fix a number of incorrect uses of errno after an operation that could
set it (e.g. fprintf, close).
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
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;
}
}
--
2.7.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-12-14 7:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-14 7:51 [PATCH v2 0/8] xen-livepatch misc fixes/changes Ross Lagerwall
2016-12-14 7:51 ` [PATCH v2 1/8] tools/livepatch: Show the correct expected state before action Ross Lagerwall
2016-12-14 7:51 ` [PATCH v2 2/8] tools/livepatch: Set stdout and stderr unbuffered Ross Lagerwall
2016-12-14 7:54 ` Wei Liu
2016-12-14 7:51 ` [PATCH v2 3/8] tools/livepatch: Improve output Ross Lagerwall
2016-12-14 7:51 ` [PATCH v2 4/8] livepatch: Fix documentation of timeout Ross Lagerwall
2016-12-14 7:54 ` Wei Liu
2016-12-14 7:51 ` [PATCH v2 5/8] tools/livepatch: Remove pointless retry loop Ross Lagerwall
2016-12-14 7:55 ` Wei Liu
2016-12-14 7:51 ` [PATCH v2 6/8] tools/livepatch: Remove unused struct member Ross Lagerwall
2016-12-14 7:51 ` Ross Lagerwall [this message]
2016-12-14 7:55 ` [PATCH v2 7/8] tools/livepatch: Save errno where needed Wei Liu
2016-12-14 7:52 ` [PATCH v2 8/8] tools/livepatch: Exit with 2 if a timeout occurs Ross Lagerwall
2016-12-14 7:56 ` Wei Liu
2016-12-14 18:16 ` [PATCH v2 0/8] xen-livepatch misc fixes/changes Konrad Rzeszutek Wilk
2016-12-14 20:32 ` Konrad Rzeszutek Wilk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1481701920-13758-8-git-send-email-ross.lagerwall@citrix.com \
--to=ross.lagerwall@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).