Skip to content

Commit

Permalink
Merge pull request #7956 from xiexingguo/xxg-wip-fixfstat
Browse files Browse the repository at this point in the history
common: buffer: put a guard for stat() syscall during read_file

Reviewed-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
liewegas committed Apr 9, 2016
2 parents 30e943a + 7b33156 commit e4eab04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/common/Thread.cc
Expand Up @@ -200,8 +200,9 @@ int Thread::set_ioprio(int cls, int prio)

int Thread::set_affinity(int id)
{
int r = 0;
cpuid = id;
if (pid && ceph_gettid() == pid)
_set_affinity(id);
return 0;
r = _set_affinity(id);
return r;
}
10 changes: 9 additions & 1 deletion src/common/buffer.cc
Expand Up @@ -1982,7 +1982,15 @@ int buffer::list::read_file(const char *fn, std::string *error)

struct stat st;
memset(&st, 0, sizeof(st));
::fstat(fd, &st);
if (::fstat(fd, &st) < 0) {
int err = errno;
std::ostringstream oss;
oss << "bufferlist::read_file(" << fn << "): stat error: "
<< cpp_strerror(err);
*error = oss.str();
VOID_TEMP_FAILURE_RETRY(::close(fd));
return -err;
}

ssize_t ret = read_fd(fd, st.st_size);
if (ret < 0) {
Expand Down

0 comments on commit e4eab04

Please sign in to comment.