diff options
author | tomty89 <tom.ty89@gmail.com> | 2021-07-05 23:21:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-05 17:21:21 +0200 |
commit | fc65ca36b1f89f122b7ef0fe32c3bea1f46cfd27 (patch) | |
tree | 0e7250204aa7500b60495db90896b74f6fe4305a /libi3 | |
parent | abbf6a85d712ef1790b02122eb432e4bafe20576 (diff) | |
download | i3-fc65ca36b1f89f122b7ef0fe32c3bea1f46cfd27.tar.gz i3-fc65ca36b1f89f122b7ef0fe32c3bea1f46cfd27.zip |
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.
Diffstat (limited to 'libi3')
-rw-r--r-- | libi3/get_process_filename.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/libi3/get_process_filename.c b/libi3/get_process_filename.c index 21429ec3..d29f8db1 100644 --- a/libi3/get_process_filename.c +++ b/libi3/get_process_filename.c @@ -27,15 +27,14 @@ char *get_process_filename(const char *prefix) { char *tmp; sasprintf(&tmp, "%s/i3", dir); dir = tmp; - struct stat buf; - if (stat(dir, &buf) != 0) { - if (mkdir(dir, 0700) == -1) { - warn("Could not mkdir(%s)", dir); - errx(EXIT_FAILURE, "Check permissions of $XDG_RUNTIME_DIR = '%s'", - getenv("XDG_RUNTIME_DIR")); - perror("mkdir()"); - return NULL; - } + /* mkdirp() should prevent race between multiple i3 instances started + * in parallel from causing problem */ + if (mkdirp(dir, 0700) == -1) { + warn("Could not mkdirp(%s)", dir); + errx(EXIT_FAILURE, "Check permissions of $XDG_RUNTIME_DIR = '%s'", + getenv("XDG_RUNTIME_DIR")); + perror("mkdirp()"); + return NULL; } } else { /* If not, we create a (secure) temp directory using the template |