Coverage Report

Created: 2026-09-28 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/lockfile.h
Line
Count
Source
1
#ifndef LOCKFILE_H
2
#define LOCKFILE_H
3
4
/*
5
 * File write-locks as used by Git.
6
 *
7
 * The lockfile API serves two purposes:
8
 *
9
 * * Mutual exclusion and atomic file updates. When we want to change
10
 *   a file, we create a lockfile `<filename>.lock`, write the new
11
 *   file contents into it, and then rename the lockfile to its final
12
 *   destination `<filename>`. We create the `<filename>.lock` file
13
 *   with `O_CREAT|O_EXCL` so that we can notice and fail if somebody
14
 *   else has already locked the file, then atomically rename the
15
 *   lockfile to its final destination to commit the changes and
16
 *   unlock the file.
17
 *
18
 * * Automatic cruft removal. If the program exits after we lock a
19
 *   file but before the changes have been committed, we want to make
20
 *   sure that we remove the lockfile. This is done by remembering the
21
 *   lockfiles we have created in a linked list and setting up an
22
 *   `atexit(3)` handler and a signal handler that clean up the
23
 *   lockfiles. This mechanism ensures that outstanding lockfiles are
24
 *   cleaned up if the program exits (including when `die()` is
25
 *   called) or if the program is terminated by a signal.
26
 *
27
 * Please note that lockfiles only block other writers. Readers do not
28
 * block, but they are guaranteed to see either the old contents of
29
 * the file or the new contents of the file (assuming that the
30
 * filesystem implements `rename(2)` atomically).
31
 *
32
 * Most of the heavy lifting is done by the tempfile module (see
33
 * "tempfile.h").
34
 *
35
 * Calling sequence
36
 * ----------------
37
 *
38
 * The caller:
39
 *
40
 * * Allocates a `struct lock_file` with whatever storage duration you
41
 *   desire. The struct does not have to be initialized before being
42
 *   used, but it is good practice to do so using by setting it to
43
 *   all-zeros (or using the LOCK_INIT macro). This puts the object in a
44
 *   consistent state that allows you to call rollback_lock_file() even
45
 *   if the lock was never taken (in which case it is a noop).
46
 *
47
 * * Attempts to create a lockfile by calling `hold_lock_file_for_update()`.
48
 *
49
 * * Writes new content for the destination file by either:
50
 *
51
 *   * writing to the file descriptor returned by the
52
 *     `hold_lock_file_for_*()` functions (also available via
53
 *     `lock->fd`).
54
 *
55
 *   * calling `fdopen_lock_file()` to get a `FILE` pointer for the
56
 *     open file and writing to the file using stdio.
57
 *
58
 *   Note that the file descriptor returned by hold_lock_file_for_update()
59
 *   is marked O_CLOEXEC, so the new contents must be written by the
60
 *   current process, not a spawned one.
61
 *
62
 * When finished writing, the caller can:
63
 *
64
 * * Close the file descriptor and rename the lockfile to its final
65
 *   destination by calling `commit_lock_file()` or
66
 *   `commit_lock_file_to()`.
67
 *
68
 * * Close the file descriptor and remove the lockfile by calling
69
 *   `rollback_lock_file()`.
70
 *
71
 * * Close the file descriptor without removing or renaming the
72
 *   lockfile by calling `close_lock_file_gently()`, and later call
73
 *   `commit_lock_file()`, `commit_lock_file_to()`,
74
 *   `rollback_lock_file()`, or `reopen_lock_file()`.
75
 *
76
 * After the lockfile is committed or rolled back, the `lock_file`
77
 * object can be discarded or reused.
78
 *
79
 * If the program exits before `commit_lock_file()`,
80
 * `commit_lock_file_to()`, or `rollback_lock_file()` is called, the
81
 * tempfile module will close and remove the lockfile, thereby rolling
82
 * back any uncommitted changes.
83
 *
84
 * If you need to close the file descriptor you obtained from a
85
 * `hold_lock_file_for_*()` function yourself, do so by calling
86
 * `close_lock_file_gently()`. See "tempfile.h" for more information.
87
 *
88
 *
89
 * Under the covers, a lockfile is just a tempfile with a few helper
90
 * functions. In particular, the state diagram and the cleanup
91
 * machinery are all implemented in the tempfile module.
92
 *
93
 * Permission bits
94
 * ---------------
95
 *
96
 * If you call either `hold_lock_file_for_update_mode` or
97
 * `hold_lock_file_for_update_timeout_mode`, you can specify a suggested
98
 * mode for the underlying temporary file. Note that the file isn't
99
 * guaranteed to have this exact mode, since it may be limited by either
100
 * the umask, 'core.sharedRepository', or both. See `adjust_shared_perm`
101
 * for more.
102
 *
103
 * Error handling
104
 * --------------
105
 *
106
 * The `hold_lock_file_for_*()` functions return a file descriptor on
107
 * success or -1 on failure (unless `LOCK_DIE_ON_ERROR` is used; see
108
 * "flags" below). On errors, `errno` describes the reason for
109
 * failure. Errors can be reported by passing `errno` to
110
 * `unable_to_lock_message()` or `unable_to_lock_die()`.
111
 *
112
 * Similarly, `commit_lock_file`, `commit_lock_file_to`, and
113
 * `close_lock_file` return 0 on success. On failure they set `errno`
114
 * appropriately and return -1. The `commit` variants (but not `close`)
115
 * do their best to delete the temporary file before returning.
116
 */
117
118
#include "tempfile.h"
119
120
struct lock_file {
121
  struct tempfile *tempfile;
122
  struct tempfile *pid_tempfile;
123
};
124
125
0
#define LOCK_INIT { 0 }
126
127
/* String appended to a filename to derive the lockfile name: */
128
0
#define LOCK_SUFFIX ".lock"
129
0
#define LOCK_SUFFIX_LEN 5
130
131
/*
132
 * PID file naming: for a lock file "foo.lock", the PID file is "foo~pid.lock".
133
 * The tilde is forbidden in refnames and allowed in Windows filenames, avoiding
134
 * namespace collisions (e.g., refs "foo" and "foo~pid" cannot both exist).
135
 */
136
0
#define LOCK_PID_INFIX "~pid"
137
#define LOCK_PID_INFIX_LEN 4
138
139
/* Maximum length for PID file content */
140
0
#define LOCK_PID_MAXLEN 32
141
142
/*
143
 * Whether to create PID files alongside lock files.
144
 * Configured via core.lockfilePid (boolean).
145
 */
146
extern int lockfile_pid_enabled;
147
148
/*
149
 * Flags
150
 * -----
151
 *
152
 * The following flags can be passed to `hold_lock_file_for_update()`.
153
 */
154
155
/*
156
 * If a lock is already taken for the file, `die()` with an error
157
 * message. If this flag is not specified, trying to lock a file that
158
 * is already locked silently returns -1 to the caller, or ...
159
 */
160
0
#define LOCK_DIE_ON_ERROR 1
161
162
/*
163
 * ... this flag can be passed instead to return -1 and give the usual
164
 * error message upon an error.
165
 */
166
0
#define LOCK_REPORT_ON_ERROR 4
167
168
/*
169
 * Usually symbolic links in the destination path are resolved. This
170
 * means that (1) the lockfile is created by adding ".lock" to the
171
 * resolved path, and (2) upon commit, the resolved path is
172
 * overwritten. However, if `LOCK_NO_DEREF` is set, then the lockfile
173
 * is created by adding ".lock" to the path argument itself. This
174
 * option is used, for example, when detaching a symbolic reference,
175
 * which for backwards-compatibility reasons, can be a symbolic link
176
 * containing the name of the referred-to-reference.
177
 */
178
0
#define LOCK_NO_DEREF 2
179
180
/*
181
 * Attempt to create a lockfile for the file at `path` and return a
182
 * file descriptor for writing to it, or -1 on error. If the file is
183
 * currently locked, retry with quadratic backoff for at least
184
 * timeout_ms milliseconds. If timeout_ms is 0, try exactly once; if
185
 * timeout_ms is -1, retry indefinitely. The flags argument, error
186
 * handling, and mode are described above.
187
 */
188
int hold_lock_file_for_update_timeout_mode(
189
  struct lock_file *lk, const char *path,
190
  int flags, long timeout_ms, int mode);
191
192
int repo_hold_lock_file_for_update_timeout_mode(struct repository *r,
193
            struct lock_file *lk,
194
            const char *path, int flags,
195
            long timeout_ms, int mode);
196
197
static inline int hold_lock_file_for_update_timeout(
198
  struct lock_file *lk, const char *path,
199
  int flags, long timeout_ms)
200
0
{
201
0
  return hold_lock_file_for_update_timeout_mode(lk, path, flags,
202
0
                  timeout_ms, 0666);
203
0
}
Unexecuted instantiation: repository.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: setup.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: shallow.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: wt-status.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: cache-tree.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: commit.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: config.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: environment.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: lockfile.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: odb.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: source-files.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: path.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: range-diff.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: read-cache.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: refs.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: files-backend.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: packed-backend.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: system.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: sequencer.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: apply.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: bundle.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: commit-graph.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: fetch-pack.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: loose.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: merge-ort-wrappers.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: merge.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: rerere.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: reset.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: send-pack.c:hold_lock_file_for_update_timeout
Unexecuted instantiation: unix-stream-server.c:hold_lock_file_for_update_timeout
204
205
static inline int repo_hold_lock_file_for_update_timeout(struct repository *r,
206
               struct lock_file *lk,
207
               const char *path,
208
               int flags,
209
               long timeout_ms)
210
0
{
211
0
  return repo_hold_lock_file_for_update_timeout_mode(r, lk, path, flags,
212
0
                 timeout_ms, 0666);
213
0
}
Unexecuted instantiation: repository.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: setup.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: shallow.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: wt-status.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: cache-tree.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: commit.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: config.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: environment.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: lockfile.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: odb.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: source-files.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: path.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: range-diff.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: read-cache.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: refs.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: files-backend.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: packed-backend.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: system.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: sequencer.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: apply.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: bundle.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: commit-graph.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: fetch-pack.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: loose.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: merge-ort-wrappers.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: merge.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: rerere.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: reset.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: send-pack.c:repo_hold_lock_file_for_update_timeout
Unexecuted instantiation: unix-stream-server.c:repo_hold_lock_file_for_update_timeout
214
215
/*
216
 * Attempt to create a lockfile for the file at `path` and return a
217
 * file descriptor for writing to it, or -1 on error. The flags
218
 * argument and error handling are described above.
219
 */
220
static inline int hold_lock_file_for_update(
221
  struct lock_file *lk, const char *path, int flags)
222
0
{
223
0
  return hold_lock_file_for_update_timeout(lk, path, flags, 5000);
224
0
}
Unexecuted instantiation: repository.c:hold_lock_file_for_update
Unexecuted instantiation: setup.c:hold_lock_file_for_update
Unexecuted instantiation: shallow.c:hold_lock_file_for_update
Unexecuted instantiation: wt-status.c:hold_lock_file_for_update
Unexecuted instantiation: cache-tree.c:hold_lock_file_for_update
Unexecuted instantiation: commit.c:hold_lock_file_for_update
Unexecuted instantiation: config.c:hold_lock_file_for_update
Unexecuted instantiation: environment.c:hold_lock_file_for_update
Unexecuted instantiation: lockfile.c:hold_lock_file_for_update
Unexecuted instantiation: odb.c:hold_lock_file_for_update
Unexecuted instantiation: source-files.c:hold_lock_file_for_update
Unexecuted instantiation: path.c:hold_lock_file_for_update
Unexecuted instantiation: range-diff.c:hold_lock_file_for_update
Unexecuted instantiation: read-cache.c:hold_lock_file_for_update
Unexecuted instantiation: refs.c:hold_lock_file_for_update
Unexecuted instantiation: files-backend.c:hold_lock_file_for_update
Unexecuted instantiation: packed-backend.c:hold_lock_file_for_update
Unexecuted instantiation: system.c:hold_lock_file_for_update
Unexecuted instantiation: sequencer.c:hold_lock_file_for_update
Unexecuted instantiation: apply.c:hold_lock_file_for_update
Unexecuted instantiation: bundle.c:hold_lock_file_for_update
Unexecuted instantiation: commit-graph.c:hold_lock_file_for_update
Unexecuted instantiation: fetch-pack.c:hold_lock_file_for_update
Unexecuted instantiation: loose.c:hold_lock_file_for_update
Unexecuted instantiation: merge-ort-wrappers.c:hold_lock_file_for_update
Unexecuted instantiation: merge.c:hold_lock_file_for_update
Unexecuted instantiation: rerere.c:hold_lock_file_for_update
Unexecuted instantiation: reset.c:hold_lock_file_for_update
Unexecuted instantiation: send-pack.c:hold_lock_file_for_update
Unexecuted instantiation: unix-stream-server.c:hold_lock_file_for_update
225
226
static inline int repo_hold_lock_file_for_update(struct repository *r,
227
             struct lock_file *lk,
228
             const char *path, int flags)
229
0
{
230
0
  return repo_hold_lock_file_for_update_timeout(r, lk, path, flags, 0);
231
0
}
Unexecuted instantiation: repository.c:repo_hold_lock_file_for_update
Unexecuted instantiation: setup.c:repo_hold_lock_file_for_update
Unexecuted instantiation: shallow.c:repo_hold_lock_file_for_update
Unexecuted instantiation: wt-status.c:repo_hold_lock_file_for_update
Unexecuted instantiation: cache-tree.c:repo_hold_lock_file_for_update
Unexecuted instantiation: commit.c:repo_hold_lock_file_for_update
Unexecuted instantiation: config.c:repo_hold_lock_file_for_update
Unexecuted instantiation: environment.c:repo_hold_lock_file_for_update
Unexecuted instantiation: lockfile.c:repo_hold_lock_file_for_update
Unexecuted instantiation: odb.c:repo_hold_lock_file_for_update
Unexecuted instantiation: source-files.c:repo_hold_lock_file_for_update
Unexecuted instantiation: path.c:repo_hold_lock_file_for_update
Unexecuted instantiation: range-diff.c:repo_hold_lock_file_for_update
Unexecuted instantiation: read-cache.c:repo_hold_lock_file_for_update
Unexecuted instantiation: refs.c:repo_hold_lock_file_for_update
Unexecuted instantiation: files-backend.c:repo_hold_lock_file_for_update
Unexecuted instantiation: packed-backend.c:repo_hold_lock_file_for_update
Unexecuted instantiation: system.c:repo_hold_lock_file_for_update
Unexecuted instantiation: sequencer.c:repo_hold_lock_file_for_update
Unexecuted instantiation: apply.c:repo_hold_lock_file_for_update
Unexecuted instantiation: bundle.c:repo_hold_lock_file_for_update
Unexecuted instantiation: commit-graph.c:repo_hold_lock_file_for_update
Unexecuted instantiation: fetch-pack.c:repo_hold_lock_file_for_update
Unexecuted instantiation: loose.c:repo_hold_lock_file_for_update
Unexecuted instantiation: merge-ort-wrappers.c:repo_hold_lock_file_for_update
Unexecuted instantiation: merge.c:repo_hold_lock_file_for_update
Unexecuted instantiation: rerere.c:repo_hold_lock_file_for_update
Unexecuted instantiation: reset.c:repo_hold_lock_file_for_update
Unexecuted instantiation: send-pack.c:repo_hold_lock_file_for_update
Unexecuted instantiation: unix-stream-server.c:repo_hold_lock_file_for_update
232
233
static inline int hold_lock_file_for_update_mode(
234
  struct lock_file *lk, const char *path,
235
  int flags, int mode)
236
0
{
237
0
  return hold_lock_file_for_update_timeout_mode(lk, path, flags, 0, mode);
238
0
}
Unexecuted instantiation: repository.c:hold_lock_file_for_update_mode
Unexecuted instantiation: setup.c:hold_lock_file_for_update_mode
Unexecuted instantiation: shallow.c:hold_lock_file_for_update_mode
Unexecuted instantiation: wt-status.c:hold_lock_file_for_update_mode
Unexecuted instantiation: cache-tree.c:hold_lock_file_for_update_mode
Unexecuted instantiation: commit.c:hold_lock_file_for_update_mode
Unexecuted instantiation: config.c:hold_lock_file_for_update_mode
Unexecuted instantiation: environment.c:hold_lock_file_for_update_mode
Unexecuted instantiation: lockfile.c:hold_lock_file_for_update_mode
Unexecuted instantiation: odb.c:hold_lock_file_for_update_mode
Unexecuted instantiation: source-files.c:hold_lock_file_for_update_mode
Unexecuted instantiation: path.c:hold_lock_file_for_update_mode
Unexecuted instantiation: range-diff.c:hold_lock_file_for_update_mode
Unexecuted instantiation: read-cache.c:hold_lock_file_for_update_mode
Unexecuted instantiation: refs.c:hold_lock_file_for_update_mode
Unexecuted instantiation: files-backend.c:hold_lock_file_for_update_mode
Unexecuted instantiation: packed-backend.c:hold_lock_file_for_update_mode
Unexecuted instantiation: system.c:hold_lock_file_for_update_mode
Unexecuted instantiation: sequencer.c:hold_lock_file_for_update_mode
Unexecuted instantiation: apply.c:hold_lock_file_for_update_mode
Unexecuted instantiation: bundle.c:hold_lock_file_for_update_mode
Unexecuted instantiation: commit-graph.c:hold_lock_file_for_update_mode
Unexecuted instantiation: fetch-pack.c:hold_lock_file_for_update_mode
Unexecuted instantiation: loose.c:hold_lock_file_for_update_mode
Unexecuted instantiation: merge-ort-wrappers.c:hold_lock_file_for_update_mode
Unexecuted instantiation: merge.c:hold_lock_file_for_update_mode
Unexecuted instantiation: rerere.c:hold_lock_file_for_update_mode
Unexecuted instantiation: reset.c:hold_lock_file_for_update_mode
Unexecuted instantiation: send-pack.c:hold_lock_file_for_update_mode
Unexecuted instantiation: unix-stream-server.c:hold_lock_file_for_update_mode
239
240
static inline int repo_hold_lock_file_for_update_mode(struct repository *r,
241
                  struct lock_file *lk,
242
                  const char *path,
243
                  int flags, int mode)
244
0
{
245
0
  return repo_hold_lock_file_for_update_timeout_mode(r, lk, path, flags,
246
0
                 0, mode);
247
0
}
Unexecuted instantiation: repository.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: setup.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: shallow.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: wt-status.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: cache-tree.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: commit.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: config.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: environment.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: lockfile.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: odb.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: source-files.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: path.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: range-diff.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: read-cache.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: refs.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: files-backend.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: packed-backend.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: system.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: sequencer.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: apply.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: bundle.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: commit-graph.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: fetch-pack.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: loose.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: merge-ort-wrappers.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: merge.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: rerere.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: reset.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: send-pack.c:repo_hold_lock_file_for_update_mode
Unexecuted instantiation: unix-stream-server.c:repo_hold_lock_file_for_update_mode
248
249
/*
250
 * Return a nonzero value iff `lk` is currently locked.
251
 */
252
static inline int is_lock_file_locked(struct lock_file *lk)
253
0
{
254
0
  return is_tempfile_active(lk->tempfile);
255
0
}
Unexecuted instantiation: repository.c:is_lock_file_locked
Unexecuted instantiation: setup.c:is_lock_file_locked
Unexecuted instantiation: shallow.c:is_lock_file_locked
Unexecuted instantiation: wt-status.c:is_lock_file_locked
Unexecuted instantiation: cache-tree.c:is_lock_file_locked
Unexecuted instantiation: commit.c:is_lock_file_locked
Unexecuted instantiation: config.c:is_lock_file_locked
Unexecuted instantiation: environment.c:is_lock_file_locked
Unexecuted instantiation: lockfile.c:is_lock_file_locked
Unexecuted instantiation: odb.c:is_lock_file_locked
Unexecuted instantiation: source-files.c:is_lock_file_locked
Unexecuted instantiation: path.c:is_lock_file_locked
Unexecuted instantiation: range-diff.c:is_lock_file_locked
Unexecuted instantiation: read-cache.c:is_lock_file_locked
Unexecuted instantiation: refs.c:is_lock_file_locked
Unexecuted instantiation: files-backend.c:is_lock_file_locked
Unexecuted instantiation: packed-backend.c:is_lock_file_locked
Unexecuted instantiation: system.c:is_lock_file_locked
Unexecuted instantiation: sequencer.c:is_lock_file_locked
Unexecuted instantiation: apply.c:is_lock_file_locked
Unexecuted instantiation: bundle.c:is_lock_file_locked
Unexecuted instantiation: commit-graph.c:is_lock_file_locked
Unexecuted instantiation: fetch-pack.c:is_lock_file_locked
Unexecuted instantiation: loose.c:is_lock_file_locked
Unexecuted instantiation: merge-ort-wrappers.c:is_lock_file_locked
Unexecuted instantiation: merge.c:is_lock_file_locked
Unexecuted instantiation: rerere.c:is_lock_file_locked
Unexecuted instantiation: reset.c:is_lock_file_locked
Unexecuted instantiation: send-pack.c:is_lock_file_locked
Unexecuted instantiation: unix-stream-server.c:is_lock_file_locked
256
257
/*
258
 * Append an appropriate error message to `buf` following the failure
259
 * of `hold_lock_file_for_update()` to lock `path`. `err` should be the
260
 * `errno` set by the failing call.
261
 */
262
void unable_to_lock_message(const char *path, int err,
263
          struct strbuf *buf);
264
265
/*
266
 * Emit an appropriate error message and `die()` following the failure
267
 * of `hold_lock_file_for_update()` to lock `path`. `err` should be the
268
 * `errno` set by the failing
269
 * call.
270
 */
271
NORETURN void unable_to_lock_die(const char *path, int err);
272
273
/*
274
 * Associate a stdio stream with the lockfile (which must still be
275
 * open). Return `NULL` (*without* rolling back the lockfile) on
276
 * error. The stream is closed automatically when
277
 * `close_lock_file_gently()` is called or when the file is committed or
278
 * rolled back.
279
 */
280
static inline FILE *fdopen_lock_file(struct lock_file *lk, const char *mode)
281
0
{
282
0
  return fdopen_tempfile(lk->tempfile, mode);
283
0
}
Unexecuted instantiation: repository.c:fdopen_lock_file
Unexecuted instantiation: setup.c:fdopen_lock_file
Unexecuted instantiation: shallow.c:fdopen_lock_file
Unexecuted instantiation: wt-status.c:fdopen_lock_file
Unexecuted instantiation: cache-tree.c:fdopen_lock_file
Unexecuted instantiation: commit.c:fdopen_lock_file
Unexecuted instantiation: config.c:fdopen_lock_file
Unexecuted instantiation: environment.c:fdopen_lock_file
Unexecuted instantiation: lockfile.c:fdopen_lock_file
Unexecuted instantiation: odb.c:fdopen_lock_file
Unexecuted instantiation: source-files.c:fdopen_lock_file
Unexecuted instantiation: path.c:fdopen_lock_file
Unexecuted instantiation: range-diff.c:fdopen_lock_file
Unexecuted instantiation: read-cache.c:fdopen_lock_file
Unexecuted instantiation: refs.c:fdopen_lock_file
Unexecuted instantiation: files-backend.c:fdopen_lock_file
Unexecuted instantiation: packed-backend.c:fdopen_lock_file
Unexecuted instantiation: system.c:fdopen_lock_file
Unexecuted instantiation: sequencer.c:fdopen_lock_file
Unexecuted instantiation: apply.c:fdopen_lock_file
Unexecuted instantiation: bundle.c:fdopen_lock_file
Unexecuted instantiation: commit-graph.c:fdopen_lock_file
Unexecuted instantiation: fetch-pack.c:fdopen_lock_file
Unexecuted instantiation: loose.c:fdopen_lock_file
Unexecuted instantiation: merge-ort-wrappers.c:fdopen_lock_file
Unexecuted instantiation: merge.c:fdopen_lock_file
Unexecuted instantiation: rerere.c:fdopen_lock_file
Unexecuted instantiation: reset.c:fdopen_lock_file
Unexecuted instantiation: send-pack.c:fdopen_lock_file
Unexecuted instantiation: unix-stream-server.c:fdopen_lock_file
284
285
/*
286
 * Return the path of the lockfile. The return value is a pointer to a
287
 * field within the lock_file object and should not be freed.
288
 */
289
static inline const char *get_lock_file_path(struct lock_file *lk)
290
0
{
291
0
  return get_tempfile_path(lk->tempfile);
292
0
}
Unexecuted instantiation: repository.c:get_lock_file_path
Unexecuted instantiation: setup.c:get_lock_file_path
Unexecuted instantiation: shallow.c:get_lock_file_path
Unexecuted instantiation: wt-status.c:get_lock_file_path
Unexecuted instantiation: cache-tree.c:get_lock_file_path
Unexecuted instantiation: commit.c:get_lock_file_path
Unexecuted instantiation: config.c:get_lock_file_path
Unexecuted instantiation: environment.c:get_lock_file_path
Unexecuted instantiation: lockfile.c:get_lock_file_path
Unexecuted instantiation: odb.c:get_lock_file_path
Unexecuted instantiation: source-files.c:get_lock_file_path
Unexecuted instantiation: path.c:get_lock_file_path
Unexecuted instantiation: range-diff.c:get_lock_file_path
Unexecuted instantiation: read-cache.c:get_lock_file_path
Unexecuted instantiation: refs.c:get_lock_file_path
Unexecuted instantiation: files-backend.c:get_lock_file_path
Unexecuted instantiation: packed-backend.c:get_lock_file_path
Unexecuted instantiation: system.c:get_lock_file_path
Unexecuted instantiation: sequencer.c:get_lock_file_path
Unexecuted instantiation: apply.c:get_lock_file_path
Unexecuted instantiation: bundle.c:get_lock_file_path
Unexecuted instantiation: commit-graph.c:get_lock_file_path
Unexecuted instantiation: fetch-pack.c:get_lock_file_path
Unexecuted instantiation: loose.c:get_lock_file_path
Unexecuted instantiation: merge-ort-wrappers.c:get_lock_file_path
Unexecuted instantiation: merge.c:get_lock_file_path
Unexecuted instantiation: rerere.c:get_lock_file_path
Unexecuted instantiation: reset.c:get_lock_file_path
Unexecuted instantiation: send-pack.c:get_lock_file_path
Unexecuted instantiation: unix-stream-server.c:get_lock_file_path
293
294
static inline int get_lock_file_fd(struct lock_file *lk)
295
0
{
296
0
  return get_tempfile_fd(lk->tempfile);
297
0
}
Unexecuted instantiation: repository.c:get_lock_file_fd
Unexecuted instantiation: setup.c:get_lock_file_fd
Unexecuted instantiation: shallow.c:get_lock_file_fd
Unexecuted instantiation: wt-status.c:get_lock_file_fd
Unexecuted instantiation: cache-tree.c:get_lock_file_fd
Unexecuted instantiation: commit.c:get_lock_file_fd
Unexecuted instantiation: config.c:get_lock_file_fd
Unexecuted instantiation: environment.c:get_lock_file_fd
Unexecuted instantiation: lockfile.c:get_lock_file_fd
Unexecuted instantiation: odb.c:get_lock_file_fd
Unexecuted instantiation: source-files.c:get_lock_file_fd
Unexecuted instantiation: path.c:get_lock_file_fd
Unexecuted instantiation: range-diff.c:get_lock_file_fd
Unexecuted instantiation: read-cache.c:get_lock_file_fd
Unexecuted instantiation: refs.c:get_lock_file_fd
Unexecuted instantiation: files-backend.c:get_lock_file_fd
Unexecuted instantiation: packed-backend.c:get_lock_file_fd
Unexecuted instantiation: system.c:get_lock_file_fd
Unexecuted instantiation: sequencer.c:get_lock_file_fd
Unexecuted instantiation: apply.c:get_lock_file_fd
Unexecuted instantiation: bundle.c:get_lock_file_fd
Unexecuted instantiation: commit-graph.c:get_lock_file_fd
Unexecuted instantiation: fetch-pack.c:get_lock_file_fd
Unexecuted instantiation: loose.c:get_lock_file_fd
Unexecuted instantiation: merge-ort-wrappers.c:get_lock_file_fd
Unexecuted instantiation: merge.c:get_lock_file_fd
Unexecuted instantiation: rerere.c:get_lock_file_fd
Unexecuted instantiation: reset.c:get_lock_file_fd
Unexecuted instantiation: send-pack.c:get_lock_file_fd
Unexecuted instantiation: unix-stream-server.c:get_lock_file_fd
298
299
static inline FILE *get_lock_file_fp(struct lock_file *lk)
300
0
{
301
0
  return get_tempfile_fp(lk->tempfile);
302
0
}
Unexecuted instantiation: repository.c:get_lock_file_fp
Unexecuted instantiation: setup.c:get_lock_file_fp
Unexecuted instantiation: shallow.c:get_lock_file_fp
Unexecuted instantiation: wt-status.c:get_lock_file_fp
Unexecuted instantiation: cache-tree.c:get_lock_file_fp
Unexecuted instantiation: commit.c:get_lock_file_fp
Unexecuted instantiation: config.c:get_lock_file_fp
Unexecuted instantiation: environment.c:get_lock_file_fp
Unexecuted instantiation: lockfile.c:get_lock_file_fp
Unexecuted instantiation: odb.c:get_lock_file_fp
Unexecuted instantiation: source-files.c:get_lock_file_fp
Unexecuted instantiation: path.c:get_lock_file_fp
Unexecuted instantiation: range-diff.c:get_lock_file_fp
Unexecuted instantiation: read-cache.c:get_lock_file_fp
Unexecuted instantiation: refs.c:get_lock_file_fp
Unexecuted instantiation: files-backend.c:get_lock_file_fp
Unexecuted instantiation: packed-backend.c:get_lock_file_fp
Unexecuted instantiation: system.c:get_lock_file_fp
Unexecuted instantiation: sequencer.c:get_lock_file_fp
Unexecuted instantiation: apply.c:get_lock_file_fp
Unexecuted instantiation: bundle.c:get_lock_file_fp
Unexecuted instantiation: commit-graph.c:get_lock_file_fp
Unexecuted instantiation: fetch-pack.c:get_lock_file_fp
Unexecuted instantiation: loose.c:get_lock_file_fp
Unexecuted instantiation: merge-ort-wrappers.c:get_lock_file_fp
Unexecuted instantiation: merge.c:get_lock_file_fp
Unexecuted instantiation: rerere.c:get_lock_file_fp
Unexecuted instantiation: reset.c:get_lock_file_fp
Unexecuted instantiation: send-pack.c:get_lock_file_fp
Unexecuted instantiation: unix-stream-server.c:get_lock_file_fp
303
304
/*
305
 * Return the path of the file that is locked by the specified
306
 * lock_file object. The caller must free the memory.
307
 */
308
char *get_locked_file_path(struct lock_file *lk);
309
310
/*
311
 * If the lockfile is still open, close it (and the file pointer if it
312
 * has been opened using `fdopen_lock_file()`) without renaming the
313
 * lockfile over the file being locked. Return 0 upon success. On
314
 * failure to `close(2)`, return a negative value (the lockfile is not
315
 * rolled back). Usually `commit_lock_file()`, `commit_lock_file_to()`,
316
 * or `rollback_lock_file()` should eventually be called.
317
 */
318
static inline int close_lock_file_gently(struct lock_file *lk)
319
0
{
320
0
  return close_tempfile_gently(lk->tempfile);
321
0
}
Unexecuted instantiation: repository.c:close_lock_file_gently
Unexecuted instantiation: setup.c:close_lock_file_gently
Unexecuted instantiation: shallow.c:close_lock_file_gently
Unexecuted instantiation: wt-status.c:close_lock_file_gently
Unexecuted instantiation: cache-tree.c:close_lock_file_gently
Unexecuted instantiation: commit.c:close_lock_file_gently
Unexecuted instantiation: config.c:close_lock_file_gently
Unexecuted instantiation: environment.c:close_lock_file_gently
Unexecuted instantiation: lockfile.c:close_lock_file_gently
Unexecuted instantiation: odb.c:close_lock_file_gently
Unexecuted instantiation: source-files.c:close_lock_file_gently
Unexecuted instantiation: path.c:close_lock_file_gently
Unexecuted instantiation: range-diff.c:close_lock_file_gently
Unexecuted instantiation: read-cache.c:close_lock_file_gently
Unexecuted instantiation: refs.c:close_lock_file_gently
Unexecuted instantiation: files-backend.c:close_lock_file_gently
Unexecuted instantiation: packed-backend.c:close_lock_file_gently
Unexecuted instantiation: system.c:close_lock_file_gently
Unexecuted instantiation: sequencer.c:close_lock_file_gently
Unexecuted instantiation: apply.c:close_lock_file_gently
Unexecuted instantiation: bundle.c:close_lock_file_gently
Unexecuted instantiation: commit-graph.c:close_lock_file_gently
Unexecuted instantiation: fetch-pack.c:close_lock_file_gently
Unexecuted instantiation: loose.c:close_lock_file_gently
Unexecuted instantiation: merge-ort-wrappers.c:close_lock_file_gently
Unexecuted instantiation: merge.c:close_lock_file_gently
Unexecuted instantiation: rerere.c:close_lock_file_gently
Unexecuted instantiation: reset.c:close_lock_file_gently
Unexecuted instantiation: send-pack.c:close_lock_file_gently
Unexecuted instantiation: unix-stream-server.c:close_lock_file_gently
322
323
/*
324
 * Re-open a lockfile that has been closed using `close_lock_file_gently()`
325
 * but not yet committed or rolled back. This can be used to implement
326
 * a sequence of operations like the following:
327
 *
328
 * * Lock file.
329
 *
330
 * * Write new contents to lockfile, then `close_lock_file_gently()` to
331
 *   cause the contents to be written to disk.
332
 *
333
 * * Pass the name of the lockfile to another program to allow it (and
334
 *   nobody else) to inspect the contents you wrote, while still
335
 *   holding the lock yourself.
336
 *
337
 * * `reopen_lock_file()` to reopen the lockfile, truncating the existing
338
 *   contents. Write out the new contents.
339
 *
340
 * * `commit_lock_file()` to make the final version permanent.
341
 */
342
static inline int reopen_lock_file(struct lock_file *lk)
343
0
{
344
0
  return reopen_tempfile(lk->tempfile);
345
0
}
Unexecuted instantiation: repository.c:reopen_lock_file
Unexecuted instantiation: setup.c:reopen_lock_file
Unexecuted instantiation: shallow.c:reopen_lock_file
Unexecuted instantiation: wt-status.c:reopen_lock_file
Unexecuted instantiation: cache-tree.c:reopen_lock_file
Unexecuted instantiation: commit.c:reopen_lock_file
Unexecuted instantiation: config.c:reopen_lock_file
Unexecuted instantiation: environment.c:reopen_lock_file
Unexecuted instantiation: lockfile.c:reopen_lock_file
Unexecuted instantiation: odb.c:reopen_lock_file
Unexecuted instantiation: source-files.c:reopen_lock_file
Unexecuted instantiation: path.c:reopen_lock_file
Unexecuted instantiation: range-diff.c:reopen_lock_file
Unexecuted instantiation: read-cache.c:reopen_lock_file
Unexecuted instantiation: refs.c:reopen_lock_file
Unexecuted instantiation: files-backend.c:reopen_lock_file
Unexecuted instantiation: packed-backend.c:reopen_lock_file
Unexecuted instantiation: system.c:reopen_lock_file
Unexecuted instantiation: sequencer.c:reopen_lock_file
Unexecuted instantiation: apply.c:reopen_lock_file
Unexecuted instantiation: bundle.c:reopen_lock_file
Unexecuted instantiation: commit-graph.c:reopen_lock_file
Unexecuted instantiation: fetch-pack.c:reopen_lock_file
Unexecuted instantiation: loose.c:reopen_lock_file
Unexecuted instantiation: merge-ort-wrappers.c:reopen_lock_file
Unexecuted instantiation: merge.c:reopen_lock_file
Unexecuted instantiation: rerere.c:reopen_lock_file
Unexecuted instantiation: reset.c:reopen_lock_file
Unexecuted instantiation: send-pack.c:reopen_lock_file
Unexecuted instantiation: unix-stream-server.c:reopen_lock_file
346
347
/*
348
 * Commit the change represented by `lk`: close the file descriptor
349
 * and/or file pointer if they are still open and rename the lockfile
350
 * to its final destination. Return 0 upon success. On failure, roll
351
 * back the lock file and return -1, with `errno` set to the value
352
 * from the failing call to `close(2)` or `rename(2)`. It is a bug to
353
 * call `commit_lock_file()` for a `lock_file` object that is not
354
 * currently locked.
355
 */
356
int commit_lock_file(struct lock_file *lk);
357
358
/*
359
 * Like `commit_lock_file()`, but rename the lockfile to the provided
360
 * `path`. `path` must be on the same filesystem as the lock file.
361
 */
362
static inline int commit_lock_file_to(struct lock_file *lk, const char *path)
363
0
{
364
0
  return rename_tempfile(&lk->tempfile, path);
365
0
}
Unexecuted instantiation: repository.c:commit_lock_file_to
Unexecuted instantiation: setup.c:commit_lock_file_to
Unexecuted instantiation: shallow.c:commit_lock_file_to
Unexecuted instantiation: wt-status.c:commit_lock_file_to
Unexecuted instantiation: cache-tree.c:commit_lock_file_to
Unexecuted instantiation: commit.c:commit_lock_file_to
Unexecuted instantiation: config.c:commit_lock_file_to
Unexecuted instantiation: environment.c:commit_lock_file_to
Unexecuted instantiation: lockfile.c:commit_lock_file_to
Unexecuted instantiation: odb.c:commit_lock_file_to
Unexecuted instantiation: source-files.c:commit_lock_file_to
Unexecuted instantiation: path.c:commit_lock_file_to
Unexecuted instantiation: range-diff.c:commit_lock_file_to
Unexecuted instantiation: read-cache.c:commit_lock_file_to
Unexecuted instantiation: refs.c:commit_lock_file_to
Unexecuted instantiation: files-backend.c:commit_lock_file_to
Unexecuted instantiation: packed-backend.c:commit_lock_file_to
Unexecuted instantiation: system.c:commit_lock_file_to
Unexecuted instantiation: sequencer.c:commit_lock_file_to
Unexecuted instantiation: apply.c:commit_lock_file_to
Unexecuted instantiation: bundle.c:commit_lock_file_to
Unexecuted instantiation: commit-graph.c:commit_lock_file_to
Unexecuted instantiation: fetch-pack.c:commit_lock_file_to
Unexecuted instantiation: loose.c:commit_lock_file_to
Unexecuted instantiation: merge-ort-wrappers.c:commit_lock_file_to
Unexecuted instantiation: merge.c:commit_lock_file_to
Unexecuted instantiation: rerere.c:commit_lock_file_to
Unexecuted instantiation: reset.c:commit_lock_file_to
Unexecuted instantiation: send-pack.c:commit_lock_file_to
Unexecuted instantiation: unix-stream-server.c:commit_lock_file_to
366
367
/*
368
 * Roll back `lk`: close the file descriptor and/or file pointer and
369
 * remove the lockfile and any associated PID file. It is a NOOP to
370
 * call `rollback_lock_file()` for a `lock_file` object that has already
371
 * been committed or rolled back. No error will be returned in this case.
372
 */
373
int rollback_lock_file(struct lock_file *lk);
374
375
#endif /* LOCKFILE_H */