summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2021-06-14 09:54:16 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2021-06-14 09:54:16 +0000
commit85c0793630d4ef970bc9f2118d31c29fd2671432 (patch)
tree4d4a9d83225374bb52ff16c49ceba4d95c3b586c /usr.sbin
parent64030781a124993166035881be5281d23e61693a (diff)
Do a fstatvfs() call to figure out if the filesystem used for the cache
is large enough for the cache. People like to build VM images with way too small filesystems and so warning about this situation should help. With deraadt@ and job@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rpki-client/main.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c
index 41c04695a58..b5adfa586b9 100644
--- a/usr.sbin/rpki-client/main.c
+++ b/usr.sbin/rpki-client/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.142 2021/06/03 15:10:05 claudio Exp $ */
+/* $OpenBSD: main.c,v 1.143 2021/06/14 09:54:15 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -15,11 +15,12 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/resource.h>
+#include <sys/statvfs.h>
#include <sys/tree.h>
-#include <sys/types.h>
#include <sys/wait.h>
#include <assert.h>
@@ -579,6 +580,31 @@ tal_load_default(const char *tals[], size_t max)
return s;
}
+static void
+check_fs_size(int fd, const char *cachedir)
+{
+ struct statvfs fs;
+ const long long minsize = 500 * 1024 * 1024;
+ const long long minnode = 300 * 1000;
+
+ if (fstatvfs(fd, &fs) == -1)
+ err(1, "statfs %s", cachedir);
+
+ if (fs.f_bavail < minsize / fs.f_frsize || fs.f_favail < minnode) {
+ fprintf(stderr, "WARNING: rpki-client may need more than "
+ "the availabe disk space\n"
+ "on the file-system holding %s.\n", cachedir);
+ fprintf(stderr, "available space: %lldkB, "
+ "suggested minimum %lldkB\n",
+ (long long)fs.f_bavail * fs.f_frsize / 1024,
+ minsize / 1024);
+ fprintf(stderr, "available inodes %lld, "
+ "suggested minimum %lld\n\n",
+ (long long)fs.f_favail, minnode);
+ fflush(stderr);
+ }
+}
+
void
suicide(int sig __attribute__((unused)))
{
@@ -706,6 +732,8 @@ main(int argc, char *argv[])
if ((outdirfd = open(outputdir, O_RDONLY | O_DIRECTORY, 0)) == -1)
err(1, "output directory %s", outputdir);
+ check_fs_size(cachefd, cachedir);
+
if (outformats == 0)
outformats = FORMAT_OPENBGPD;