Module: check_mk
Branch: master
Commit: 85bd51546c4f6b4adc862267a34374c50b0c0693
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=85bd51546c4f6b…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Fri Dec 22 12:14:42 2017 +0100
Windows agent: use RAII for mounted search handle
Change-Id: Ia191e537f4a9f83443639e9c024c8ded9bbbbeb4
---
agents/windows/build_version | 2 +-
agents/windows/sections/SectionDF.cc | 26 +++++++++++++++++++++-----
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 4dd9c1b..488b08b 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3034
+3036
diff --git a/agents/windows/sections/SectionDF.cc b/agents/windows/sections/SectionDF.cc
index 4e8cc9a..919f266 100644
--- a/agents/windows/sections/SectionDF.cc
+++ b/agents/windows/sections/SectionDF.cc
@@ -28,6 +28,18 @@
#include "Logger.h"
#include "WinApiAdaptor.h"
#include "stringutil.h"
+#include "types.h"
+
+namespace {
+
+struct MountPointHandleTraits {
+ using HandleT = HANDLE;
+ static HandleT invalidValue() { return INVALID_HANDLE_VALUE; }
+
+ static void closeHandle(HandleT value, const WinApiAdaptor &winapi) {
+ winapi.FindVolumeMountPointClose(value);
+ }
+};
void char_replace(char what, char into, char *in) {
while (*in) {
@@ -36,6 +48,8 @@ void char_replace(char what, char into, char *in) {
}
}
+} // namespace
+
SectionDF::SectionDF(const Environment &env, Logger *logger,
const WinApiAdaptor &winapi)
: Section("df", "df", env, logger, winapi) {
@@ -77,19 +91,21 @@ void SectionDF::output_filesystem(std::ostream &out, char *volid)
{
void SectionDF::output_mountpoints(std::ostream &out, char *volid) {
char mountpoint[512];
- HANDLE hPt = _winapi.FindFirstVolumeMountPoint(volid, mountpoint,
- sizeof(mountpoint));
- if (hPt != INVALID_HANDLE_VALUE) {
+ WrappedHandle<MountPointHandleTraits> hPt{
+ _winapi.FindFirstVolumeMountPoint(volid, mountpoint,
+ sizeof(mountpoint)),
+ _winapi};
+
+ if (hPt) {
while (true) {
char combined_path[1024];
snprintf(combined_path, sizeof(combined_path), "%s%s", volid,
mountpoint);
output_filesystem(out, combined_path);
- if (!_winapi.FindNextVolumeMountPoint(hPt, mountpoint,
+ if (!_winapi.FindNextVolumeMountPoint(hPt.get(), mountpoint,
sizeof(mountpoint)))
break;
}
- _winapi.FindVolumeMountPointClose(hPt);
}
}