mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-20 00:30:58 +00:00
Ignore potential race condition between setting up instance path and first log message
This commit is contained in:
parent
52bd428c09
commit
00a2ea2913
14
instance.c
14
instance.c
@ -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
13
os.c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user