commit ef99fdb1099b987bfaed49367904342f77da3e43 from: Stefan Sperling date: Sun Mar 11 01:31:27 2018 UTC use flock(2) because open(2) O_NONBLOCK also enables non-blocking I/O commit - 73a5ef678f0ee5f125fa5154baffb9cde3a1b133 commit + ef99fdb1099b987bfaed49367904342f77da3e43 blob - 3a8dd15749445c01ce379f9b5bae078a58365c39 blob + 04c8fc0fc3ec37db221182a522c6955555eec78b --- lib/worktree.c +++ lib/worktree.c @@ -94,8 +94,12 @@ read_meta_file(char **content, const char *gotpath, co goto done; } - fd = open(path, O_RDONLY | O_EXLOCK | O_NONBLOCK | O_NOFOLLOW); + fd = open(path, O_RDONLY | O_NOFOLLOW); if (fd == -1) { + err = got_error_from_errno(); + goto done; + } + if (flock(fd, LOCK_SH | LOCK_NB) == -1) { err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY) : got_error_from_errno()); goto done; @@ -233,9 +237,12 @@ got_worktree_open(struct got_worktree **worktree, cons goto done; } - fd = open(path_fileindex, O_RDWR | O_EXLOCK | O_NONBLOCK | O_NOFOLLOW, - GOT_DEFAULT_FILE_MODE); + fd = open(path_fileindex, O_RDWR | O_NOFOLLOW, GOT_DEFAULT_FILE_MODE); if (fd == -1) { + err = got_error_from_errno(); + goto done; + } + if (flock(fd, LOCK_SH | LOCK_NB) == -1) { err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY) : got_error_from_errno()); goto done;