From: Sage Weil Date: Mon, 21 Jul 2014 20:43:42 +0000 (-0700) Subject: os/LFNIndex: FDCloser helper X-Git-Tag: v0.84~71^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a320c260a9e088ab0a4ea3d5298c06a2d077de37;p=ceph.git os/LFNIndex: FDCloser helper Add a helper to close fd's when we leave scope. This is important when injecting failures by throwing exceptions. Signed-off-by: Sage Weil --- diff --git a/src/os/LFNIndex.cc b/src/os/LFNIndex.cc index 52ce86e1e1f5..6f14589ac15f 100644 --- a/src/os/LFNIndex.cc +++ b/src/os/LFNIndex.cc @@ -61,6 +61,17 @@ void LFNIndex::maybe_inject_failure() } } +// Helper to close fd's when we leave scope. This is useful when used +// in combination with RetryException, thrown by the above. +struct FDCloser { + int fd; + FDCloser(int f) : fd(f) {} + ~FDCloser() { + VOID_TEMP_FAILURE_RETRY(::close(fd)); + } +}; + + /* Public methods */ void LFNIndex::set_ref(ceph::shared_ptr ref)