Permalink
Browse files

Add additional error checking in IO on fcntl calls

  • Loading branch information...
1 parent 9922f1a commit c166dbdad665e720068ab5b10cd74b5b09e76c45 @dbussink dbussink committed Feb 9, 2014
Showing with 7 additions and 3 deletions.
  1. +7 −3 vm/builtin/io.cpp
View
@@ -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);
}
@@ -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");
}
}

0 comments on commit c166dbd

Please sign in to comment.