-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmisc.cpp
36 lines (27 loc) · 950 Bytes
/
misc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (C) 2019 by Yuri Victorovich. All rights reserved.
#include "misc.h"
#include "util.h"
#include "err.h"
#include "locs.h"
#include <sys/stat.h>
#include <errno.h>
//
// internals
//
static void createDirectoryIfNeeded(const char *dir, const char *what) {
int res;
// first, just try to create it. It might already exist which is ok.
res = ::mkdir(dir, 0700); // it should be only readable/writable by root
if (res == -1 && errno != EEXIST)
ERR2(STR("create " << what << " directory"), "failed to create the " << what << " directory '" << dir << "': " << strerror(errno))
// TODO check that permissions are correct on Locations::jailDirectoryPath
}
//
// interface
//
void createJailsDirectoryIfNeeded(const char *subdir) {
createDirectoryIfNeeded(CSTR(Locations::jailDirectoryPath << subdir), "jails");
}
void createCacheDirectoryIfNeeded() {
createDirectoryIfNeeded(Locations::cacheDirectoryPath, "cache");
}