Skip to content

Commit

Permalink
rbd: import/export/mergediff: use STD[IN|OUT]_FILENO instead of 0 or 1
Browse files Browse the repository at this point in the history
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
  • Loading branch information
yangdongsheng committed Feb 19, 2017
1 parent fedf772 commit 5b14582
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/tools/rbd/action/Export.cc
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/tools/rbd/action/Import.cc
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rbd/action/MergeDiff.cc
Expand Up @@ -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) {
Expand Down

0 comments on commit 5b14582

Please sign in to comment.