From 5b1458290dd5689b39fe77cb8c536053d099f313 Mon Sep 17 00:00:00 2001 From: Dongsheng Yang Date: Thu, 3 Nov 2016 06:47:11 -0400 Subject: [PATCH] rbd: import/export/mergediff: use STD[IN|OUT]_FILENO instead of 0 or 1 Signed-off-by: Dongsheng Yang --- src/tools/rbd/action/Export.cc | 2 +- src/tools/rbd/action/Import.cc | 12 ++++++------ src/tools/rbd/action/MergeDiff.cc | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tools/rbd/action/Export.cc b/src/tools/rbd/action/Export.cc index 485b0ad841d..eae06aeb51f 100644 --- a/src/tools/rbd/action/Export.cc +++ b/src/tools/rbd/action/Export.cc @@ -214,7 +214,7 @@ int do_export_diff(librbd::Image& image, const char *fromsnapname, int fd; if (strcmp(path, "-") == 0) - fd = 1; + fd = STDOUT_FILENO; else fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644); if (fd < 0) diff --git a/src/tools/rbd/action/Import.cc b/src/tools/rbd/action/Import.cc index 75c07c67d1a..663a3986bf6 100644 --- a/src/tools/rbd/action/Import.cc +++ b/src/tools/rbd/action/Import.cc @@ -33,7 +33,7 @@ int do_import_diff_fd(librbd::Image &image, int fd, string banner = (format == 1 ? utils::RBD_DIFF_BANNER : utils::RBD_DIFF_BANNER_V2); char buf[banner.size() + 1]; - bool from_stdin = (fd == 0); + bool from_stdin = (fd == STDIN_FILENO); if (!from_stdin) { r = ::fstat(fd, &stat_buf); if (r < 0) @@ -201,7 +201,7 @@ int do_import_diff(librbd::Image &image, const char *path, int fd; if (strcmp(path, "-") == 0) { - fd = 0; + fd = STDIN_FILENO; } else { fd = open(path, O_RDONLY); if (fd < 0) { @@ -320,7 +320,7 @@ static int do_import_header(int fd, int import_format, uint64_t &size, librbd::I if (import_format == 1) return r; - if (fd == 0 || size < utils::RBD_IMAGE_BANNER_V2.size()) { + if (fd == STDIN_FILENO || size < utils::RBD_IMAGE_BANNER_V2.size()) { r = -EINVAL; return r; } @@ -494,7 +494,7 @@ static int do_import_v1(int fd, librbd::Image &image, uint64_t size, size_t blklen = 0; // amount accumulated from reads to fill blk char *p = new char[imgblklen]; uint64_t image_pos = 0; - bool from_stdin = (fd == 0); + bool from_stdin = (fd == STDIN_FILENO); reqlen = min(reqlen, size); // loop body handles 0 return, as we may have a block to flush @@ -546,7 +546,7 @@ static int do_import_v1(int fd, librbd::Image &image, uint64_t size, goto out; } - if (fd == 0) { + if (fd == STDIN_FILENO) { r = image.resize(image_pos); if (r < 0) { std::cerr << "rbd: final image resize failed" << std::endl; @@ -583,7 +583,7 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx, bool from_stdin = !strcmp(path, "-"); if (from_stdin) { throttle.reset(new SimpleThrottle(1, false)); - fd = 0; + fd = STDIN_FILENO; size = 1ULL << order; } else { throttle.reset(new SimpleThrottle( diff --git a/src/tools/rbd/action/MergeDiff.cc b/src/tools/rbd/action/MergeDiff.cc index 5c31769d0c4..6dfca77a32b 100644 --- a/src/tools/rbd/action/MergeDiff.cc +++ b/src/tools/rbd/action/MergeDiff.cc @@ -171,7 +171,7 @@ static int do_merge_diff(const char *first, const char *second, bool first_stdin = !strcmp(first, "-"); if (first_stdin) { - fd = 0; + fd = STDIN_FILENO; } else { fd = open(first, O_RDONLY); if (fd < 0) { -- 2.47.3