Repository: mesos Updated Branches: refs/heads/master 3cea94273 -> dede530a2
Fixed check for lseek error. Review: https://reviews.apache.org/r/31480 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/dede530a Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/dede530a Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/dede530a Branch: refs/heads/master Commit: dede530a27d41e561f75932fadc93c368fde812d Parents: 3cea942 Author: Timothy Chen <[email protected]> Authored: Wed Apr 15 11:13:08 2015 -0700 Committer: Timothy Chen <[email protected]> Committed: Wed Apr 15 11:43:29 2015 -0700 ---------------------------------------------------------------------- src/slave/state.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/dede530a/src/slave/state.cpp ---------------------------------------------------------------------- diff --git a/src/slave/state.cpp b/src/slave/state.cpp index 35ce70b..8eda22a 100644 --- a/src/slave/state.cpp +++ b/src/slave/state.cpp @@ -610,11 +610,17 @@ Try<TaskState> TaskState::recover( } } + off_t offset = lseek(fd.get(), 0, SEEK_CUR); + + if (offset < 0) { + return ErrnoError("Failed to lseek status updates file '" + path + "'"); + } + // Always truncate the file to contain only valid updates. // NOTE: This is safe even though we ignore partial protobuf read // errors above, because the 'fd' is properly set to the end of the // last valid update by 'protobuf::read()'. - if (ftruncate(fd.get(), lseek(fd.get(), 0, SEEK_CUR)) != 0) { + if (ftruncate(fd.get(), offset) != 0) { return ErrnoError( "Failed to truncate status updates file '" + path + "'"); } @@ -692,11 +698,16 @@ Try<ResourcesState> ResourcesState::recover( state.resources += resource.get(); } + off_t offset = lseek(fd.get(), 0, SEEK_CUR); + if (offset < 0) { + return ErrnoError("Failed to lseek resources file '" + path + "'"); + } + // Always truncate the file to contain only valid resources. // NOTE: This is safe even though we ignore partial protobuf read // errors above, because the 'fd' is properly set to the end of the // last valid resource by 'protobuf::read()'. - if (ftruncate(fd.get(), lseek(fd.get(), 0, SEEK_CUR)) != 0) { + if (ftruncate(fd.get(), offset) != 0) { return ErrnoError("Failed to truncate resources file '" + path + "'"); }
