| 59 | } |
| 60 | |
| 61 | int flock_acquire(struct reftable_flock *l, const char *target_path, |
| 62 | long timeout_ms) |
| 63 | { |
| 64 | struct lock_file *lockfile; |
| 65 | int err; |
| 66 | |
| 67 | lockfile = reftable_malloc(sizeof(*lockfile)); |
| 68 | if (!lockfile) |
| 69 | return REFTABLE_OUT_OF_MEMORY_ERROR; |
| 70 | |
| 71 | err = hold_lock_file_for_update_timeout(lockfile, target_path, LOCK_NO_DEREF, |
| 72 | timeout_ms); |
| 73 | if (err < 0) { |
| 74 | reftable_free(lockfile); |
| 75 | if (errno == EEXIST) |
| 76 | return REFTABLE_LOCK_ERROR; |
| 77 | return REFTABLE_IO_ERROR; |
| 78 | } |
| 79 | |
| 80 | l->fd = get_lock_file_fd(lockfile); |
| 81 | l->path = get_lock_file_path(lockfile); |
| 82 | l->priv = lockfile; |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | int flock_close(struct reftable_flock *l) |
| 88 | { |
no test coverage detected