diff options
author | koekeishiya <aasvi93@hotmail.com> | 2019-05-21 17:34:53 +0200 |
---|---|---|
committer | koekeishiya <aasvi93@hotmail.com> | 2019-05-21 17:34:53 +0200 |
commit | 63eb2393377792943b91b6f3eb17776c02db921b (patch) | |
tree | 2d967c3653e46150628ada75850b1bf862f54aac /src | |
parent | 97a2ea9744dfc1946bc022389caae834b62a298f (diff) | |
download | skhd-63eb2393377792943b91b6f3eb17776c02db921b.tar.gz skhd-63eb2393377792943b91b6f3eb17776c02db921b.zip |
#83 use fcntl instead of flock to acquire exclusive lock
Diffstat (limited to 'src')
-rw-r--r-- | src/skhd.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -230,13 +230,21 @@ create_pid_file(void) error("skhd: could not create path to pid-file because 'env USER' was not set! abort..\n"); } - int handle = open(pid_file, O_CREAT | O_WRONLY, 0644); + int handle = open(pid_file, O_CREAT | O_RDWR, 0644); if (handle == -1) { error("skhd: could not create pid-file! abort..\n"); } - if (flock(handle, LOCK_EX | LOCK_NB) == -1) { - error("skhd: could not lock pid-file! abort..\n"); + struct flock lockfd = { + .l_start = 0, + .l_len = 0, + .l_pid = pid, + .l_type = F_WRLCK, + .l_whence = SEEK_SET + }; + + if (fcntl(handle, F_SETLK, &lockfd) == -1) { + error("skhd: could not lock pid-file! abort.. %d\n", errno); } else if (write(handle, &pid, sizeof(pid_t)) == -1) { error("skhd: could not write pid-file! abort..\n"); } |