[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] tools/livepatch: Save errno where needed
commit 0265fd753b7abafe2c3b9a9007ad7ab306dd1ef3 Author: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx> AuthorDate: Wed Dec 14 07:51:59 2016 +0000 Commit: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> CommitDate: Wed Dec 14 15:27:19 2016 -0500 tools/livepatch: Save errno where needed Fix a number of incorrect uses of errno after an operation that could set it (e.g. fprintf, close). Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx> --- 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; } } -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |