summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2018-01-25 13:37:13 +0100
committerDavid Sterba <dsterba@suse.com>2018-01-31 15:14:03 +0100
commit24103f42ad7a65457a62ae5c0190ea0e428cb14b (patch)
tree88f632280323a6e82dfafa75d50302bdb48e3bfb /utils.c
parentd7f906c23ae53a75884b759d13e02924fa0febda (diff)
btrfs-progs: don't clobber errno in close_file_or_dir
Preserve the errno value for the caller in case closing happens in the middle of eg. an ioctl and reporing the failure. The errors that could happen in close/closedir do not bother us. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/utils.c b/utils.c
index 4a16413c..5f5965d0 100644
--- a/utils.c
+++ b/utils.c
@@ -1549,10 +1549,16 @@ int open_file_or_dir(const char *fname, DIR **dirstream)
void close_file_or_dir(int fd, DIR *dirstream)
{
- if (dirstream)
+ int old_errno;
+
+ old_errno = errno;
+ if (dirstream) {
closedir(dirstream);
- else if (fd >= 0)
+ } else if (fd >= 0) {
close(fd);
+ }
+
+ errno = old_errno;
}
int get_device_info(int fd, u64 devid,