Ignore potential race condition between setting up instance path and first log message

This commit is contained in:
Jeremy Lakeman 2015-08-24 16:38:55 +09:30
parent 52bd428c09
commit 00a2ea2913
2 changed files with 17 additions and 10 deletions

View File

@ -204,12 +204,8 @@ int create_serval_instance_dir()
{
int ret = 0;
char path[PATH_MAX];
if (FORMF_SERVAL_ETC_PATH(path, NULL) && emkdirs_info(path, 0755) == -1)
ret = -1;
if (FORMF_SERVAL_RUN_PATH(path, NULL) && emkdirs_info(path, 0700) == -1)
ret = -1;
if (FORMF_SERVAL_CACHE_PATH(path, NULL) && emkdirs_info(path, 0700) == -1)
ret = -1;
// emkdire_info can log if paths don't exist, which will also try to create paths...
// so try to create logging folders first
strbuf sb = strbuf_local(path, sizeof path);
strbuf_system_log_path(sb);
if (!strbuf_overrun(sb) && emkdirs_info(path, 0700) == -1)
@ -218,6 +214,12 @@ int create_serval_instance_dir()
strbuf_serval_log_path(sb);
if (!strbuf_overrun(sb) && emkdirs_info(path, 0700) == -1)
ret = -1;
if (FORMF_SERVAL_ETC_PATH(path, NULL) && emkdirs_info(path, 0755) == -1)
ret = -1;
if (FORMF_SERVAL_RUN_PATH(path, NULL) && emkdirs_info(path, 0700) == -1)
ret = -1;
if (FORMF_SERVAL_CACHE_PATH(path, NULL) && emkdirs_info(path, 0700) == -1)
ret = -1;
if (FORMF_SERVAL_TMP_PATH(path, NULL) && emkdirs_info(path, 0700) == -1)
ret = -1;
if (FORMF_SERVALD_PROC_PATH(path, NULL) && emkdirs_info(path, 0755) == -1)

13
os.c
View File

@ -100,11 +100,16 @@ int _mkdirsn(struct __sourceloc whence, const char *path, size_t len, mode_t mod
if (lastsep != path) {
if (_mkdirsn(whence, path, lastsep - path + 1, mode, logger) == -1)
return -1;
if (mkdir(pathfrag, mode) != -1) {
if (logger)
logger(whence, pathfrag, mode);
return 0;
if (mkdir(pathfrag, mode) == -1) {
if (errno==EEXIST)
return 0;
return -1;
}
if (logger)
logger(whence, pathfrag, mode);
return 0;
}
}
}