Skip to content

Commit

Permalink
Add additional error checking in IO on fcntl calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dbussink committed Feb 10, 2014
1 parent 9922f1a commit c166dbd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions vm/builtin/io.cpp
Expand Up @@ -122,7 +122,10 @@ namespace rubinius {

void IO::new_open_fd(STATE, native_int new_fd) {
if(new_fd > 2) {
fcntl(new_fd, F_SETFD, fcntl(new_fd, F_GETFD) | FD_CLOEXEC);
int flags = fcntl(new_fd, F_GETFD);
if(flags == -1) Exception::errno_error(state, "fcntl(2) failed");
flags = fcntl(new_fd, F_SETFD, fcntl(new_fd, F_GETFD) | FD_CLOEXEC);
if(flags == -1) Exception::errno_error(state, "fcntl(2) failed");
}
update_max_fd(state, new_fd);
}
Expand Down Expand Up @@ -1356,14 +1359,15 @@ namespace rubinius {
void IO::set_nonblock(STATE) {
#ifdef F_GETFL
int flags = fcntl(descriptor_->to_native(), F_GETFL);
if(flags == -1) return;
if(flags == -1) Exception::errno_error(state, "fcntl(2) failed");
#else
int flags = 0;
#endif

if((flags & O_NONBLOCK) == 0) {
flags |= O_NONBLOCK;
fcntl(descriptor_->to_native(), F_SETFL, flags);
flags = fcntl(descriptor_->to_native(), F_SETFL, flags);
if(flags == -1) Exception::errno_error(state, "fcntl(2) failed");
}
}

Expand Down

0 comments on commit c166dbd

Please sign in to comment.