aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/apps/vespa-drop-file-from-cache
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-09-26 08:47:42 +0200
committerHenning Baldersheim <balder@oath.com>2018-09-26 08:47:42 +0200
commit08f34e35fca75b3af2b68391a4bb5de6d6252159 (patch)
tree6e2daef7c81967df3b3387cb3c787a48c74a02f8 /vespalib/src/apps/vespa-drop-file-from-cache
parent00d75be4343bbdd95175ab12aaa388944e10ba55 (diff)
Add simple usage test for vespa-drop-file-from-cache
Diffstat (limited to 'vespalib/src/apps/vespa-drop-file-from-cache')
-rw-r--r--vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp b/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp
index eca88c83738..c4129305ac1 100644
--- a/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp
+++ b/vespalib/src/apps/vespa-drop-file-from-cache/drop_file_from_cache.cpp
@@ -1,10 +1,13 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <cstdio>
+#include <cerrno>
+#include <cstring>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv) {
+ char errorBuf[200];
if (argc != 2) {
fprintf(stderr, "%s <filename>", argv[0]);
return 1;
@@ -12,14 +15,18 @@ int main(int argc, char **argv) {
const char *fileName = argv[1];
int fh = open(fileName, O_RDONLY);
if (fh != -1) {
+ int retval = 0;
int err = posix_fadvise(fh, 0, 0, POSIX_FADV_DONTNEED);
if (err != 0) {
- perror("posix_fadvise failed");
+ const char *errorString = strerror_r(errno, errorBuf, sizeof(errorBuf));
+ fprintf(stderr, "posix_fadvise failed: %s", errorString);
+ retval = 3;
}
close(fh);
+ return retval;
} else {
- perror("Failed opening file");
- return 1;
+ const char *errorString = strerror_r(errno, errorBuf, sizeof(errorBuf));
+ fprintf(stderr, "Failed opening file %s: %s", fileName, errorString);
+ return 2;
}
- return 0;
}