Use mkdirp() in get_process_filename() (#4397)
Avoids race condition in case multiple i3 instances are started in parallel with e.g. systemd user units for multiple X(vfb) servers.
This commit is contained in:
parent
abbf6a85d7
commit
fc65ca36b1
@ -27,15 +27,14 @@ char *get_process_filename(const char *prefix) {
|
|||||||
char *tmp;
|
char *tmp;
|
||||||
sasprintf(&tmp, "%s/i3", dir);
|
sasprintf(&tmp, "%s/i3", dir);
|
||||||
dir = tmp;
|
dir = tmp;
|
||||||
struct stat buf;
|
/* mkdirp() should prevent race between multiple i3 instances started
|
||||||
if (stat(dir, &buf) != 0) {
|
* in parallel from causing problem */
|
||||||
if (mkdir(dir, 0700) == -1) {
|
if (mkdirp(dir, 0700) == -1) {
|
||||||
warn("Could not mkdir(%s)", dir);
|
warn("Could not mkdirp(%s)", dir);
|
||||||
errx(EXIT_FAILURE, "Check permissions of $XDG_RUNTIME_DIR = '%s'",
|
errx(EXIT_FAILURE, "Check permissions of $XDG_RUNTIME_DIR = '%s'",
|
||||||
getenv("XDG_RUNTIME_DIR"));
|
getenv("XDG_RUNTIME_DIR"));
|
||||||
perror("mkdir()");
|
perror("mkdirp()");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* If not, we create a (secure) temp directory using the template
|
/* If not, we create a (secure) temp directory using the template
|
||||||
|
Loading…
x
Reference in New Issue
Block a user